Skip to content
This repository was archived by the owner on Apr 10, 2021. It is now read-only.

Commit b6d6082

Browse files
authored
Merge pull request #263 from arduosoft/features/statistics
Connect statistics to database
2 parents 8dcbb41 + 9c241c9 commit b6d6082

File tree

7 files changed

+67
-30
lines changed

7 files changed

+67
-30
lines changed

Plugins/RawCMS.Plugins.Core/Controllers/CRUDController.cs

+23
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,28 @@ public RestMessage<bool> Delete(string collection, string id)
183183
}
184184
return response;
185185
}
186+
187+
//
188+
[HttpGet("{collection}/count")]
189+
public RestMessage<long> Count(string collection)
190+
{
191+
RestMessage<long> response = new RestMessage<long>(0);
192+
try
193+
{
194+
var result = service.Count(collection);
195+
response.Data = result;
196+
}catch(Exception ex)
197+
{
198+
//TODO: log here
199+
response.Errors.Add(new Library.Core.Error()
200+
{
201+
Code = "UNEXPEXTED",
202+
Title = $"{collection} produces an unexpexted error",
203+
Description = ex.Message,
204+
});
205+
}
206+
207+
return response;
208+
}
186209
}
187210
}

Plugins/RawCMS.Plugins.Core/UI/components/dashboard/dashboard.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const _DashboardDef = async () => {
1515
totalRecordsNum: function () {
1616
const quotasObj = optionalChain(() => this.info.recordQuotas);
1717
if (quotasObj === undefined) {
18-
return undefined;
18+
return 0;
1919
}
2020

2121
return Object.keys(quotasObj)
@@ -28,10 +28,10 @@ const _DashboardDef = async () => {
2828
});
2929
const labels = [];
3030
const data = [];
31-
Object.keys(quotasObj).forEach(x => {
32-
labels.push(x);
33-
data.push(quotasObj[x]);
34-
});
31+
for (const index in quotasObj) {
32+
labels.push(index);
33+
data.push(quotasObj[index]);
34+
}
3535

3636
return { data, labels };
3737
}

Plugins/RawCMS.Plugins.Core/UI/services/dashboard.service.js

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
import { sleep } from "/app/utils/time.utils.js";
2-
import { BaseApiService } from "/app/common/shared/services/base-api-service.js";
1+
import { BaseCrudService } from '/app/common/shared/services/base-crud-service.js';
32

4-
class DashboardService extends BaseApiService {
3+
class DashboardService extends BaseCrudService {
54
constructor() {
6-
super();
5+
super({ basePath: "/system/admin/_schema" });
76
}
87

98
async getDashboardInfo() {
10-
// FIXME: For now we use mock data
11-
12-
await sleep(5000);
13-
14-
const quota = {
15-
TEST: Math.floor(Math.random() * 100),
16-
Items1: Math.floor(Math.random() * 100),
17-
Items2: Math.floor(Math.random() * 100),
18-
Items3: Math.floor(Math.random() * 100),
19-
Items4: Math.floor(Math.random() * 100),
20-
Items5: Math.floor(Math.random() * 100),
21-
Items6: Math.floor(Math.random() * 100)
22-
};
9+
10+
this._basePath = '/system/admin/_schema';
11+
let recordCount = await this.count();
12+
let collections = await this.getAll();
13+
let quota = {};
14+
for await (const item of collections) {
15+
let collName = item.CollectionName;
16+
this._basePath = '/api/CRUD/' + collName;
17+
let collCount = await this.count();
18+
quota[collName] = collCount;
19+
}
20+
2321
return {
2422
recordQuotas: quota,
25-
entitiesNum: Object.keys(quota).length,
26-
lastWeekCallsNum: Math.floor(Math.random() * 500)
23+
entitiesNum: recordCount
2724
};
2825
}
2926
}

Plugins/RawCMS.Plugins.Core/UICore/common/shared/components/charts/simple-pie-chart/simple-pie-chart.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ const _SimplePieChart = {
2929
return res;
3030
},
3131
sortedData: function () {
32+
//let data = optionalChain(() => [...this.context.data], {
33+
// fallbackValue: []
34+
//}).sort((a, b) => a - b);
35+
36+
//if (this.options.lowerIsBetter) {
37+
// data = data.reverse();
38+
//}
3239
let data = optionalChain(() => [...this.context.data], {
3340
fallbackValue: []
34-
}).sort((a, b) => a - b);
35-
36-
if (this.options.lowerIsBetter) {
37-
data = data.reverse();
38-
}
41+
})
3942

4043
return data;
4144
}

Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/base-crud-service.js

+10
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,14 @@ export class BaseCrudService extends mix(BaseApiService, ICrudService) {
9393

9494
return res.data.data;
9595
}
96+
97+
async count() {
98+
99+
const res = await this._apiClient.get(`${this._basePath}/count`);
100+
if (!this._checkGenericError(res)) {
101+
return false;
102+
}
103+
104+
return res.data.data;
105+
}
96106
}

Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/crud-service.js

+4
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ export class ICrudService {
2828
async delete(id) {
2929
throw new Error(`Please Provide an implementation for ${this.delete.name}`);
3030
}
31+
32+
async count(obj) {
33+
throw new Error(`Please Provide an implementation for ${this.count.name}`);
34+
}
3135
}

RawCMS.Library/Service/CRUDService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public JObject Get(string collection, string id, List<string> expando = null)
245245
return output;
246246
}
247247

248-
public long Count(string collection, string query)
248+
public long Count(string collection, string query = null)
249249
{
250250
FilterDefinition<BsonDocument> filter = FilterDefinition<BsonDocument>.Empty;
251251
if (!string.IsNullOrWhiteSpace(query))

0 commit comments

Comments
 (0)