diff --git a/Plugins/RawCMS.Plugins.Core/Controllers/CRUDController.cs b/Plugins/RawCMS.Plugins.Core/Controllers/CRUDController.cs index c6e7ba6e..e9528ca2 100644 --- a/Plugins/RawCMS.Plugins.Core/Controllers/CRUDController.cs +++ b/Plugins/RawCMS.Plugins.Core/Controllers/CRUDController.cs @@ -183,5 +183,28 @@ public RestMessage Delete(string collection, string id) } return response; } + + // + [HttpGet("{collection}/count")] + public RestMessage Count(string collection) + { + RestMessage response = new RestMessage(0); + try + { + var result = service.Count(collection); + response.Data = result; + }catch(Exception ex) + { + //TODO: log here + response.Errors.Add(new Library.Core.Error() + { + Code = "UNEXPEXTED", + Title = $"{collection} produces an unexpexted error", + Description = ex.Message, + }); + } + + return response; + } } } \ No newline at end of file diff --git a/Plugins/RawCMS.Plugins.Core/UI/components/dashboard/dashboard.js b/Plugins/RawCMS.Plugins.Core/UI/components/dashboard/dashboard.js index 76230fb4..6065dd1d 100644 --- a/Plugins/RawCMS.Plugins.Core/UI/components/dashboard/dashboard.js +++ b/Plugins/RawCMS.Plugins.Core/UI/components/dashboard/dashboard.js @@ -15,7 +15,7 @@ const _DashboardDef = async () => { totalRecordsNum: function () { const quotasObj = optionalChain(() => this.info.recordQuotas); if (quotasObj === undefined) { - return undefined; + return 0; } return Object.keys(quotasObj) @@ -28,10 +28,10 @@ const _DashboardDef = async () => { }); const labels = []; const data = []; - Object.keys(quotasObj).forEach(x => { - labels.push(x); - data.push(quotasObj[x]); - }); + for (const index in quotasObj) { + labels.push(index); + data.push(quotasObj[index]); + } return { data, labels }; } diff --git a/Plugins/RawCMS.Plugins.Core/UI/services/dashboard.service.js b/Plugins/RawCMS.Plugins.Core/UI/services/dashboard.service.js index f3722678..9b25cae6 100644 --- a/Plugins/RawCMS.Plugins.Core/UI/services/dashboard.service.js +++ b/Plugins/RawCMS.Plugins.Core/UI/services/dashboard.service.js @@ -1,29 +1,26 @@ -import { sleep } from "/app/utils/time.utils.js"; -import { BaseApiService } from "/app/common/shared/services/base-api-service.js"; +import { BaseCrudService } from '/app/common/shared/services/base-crud-service.js'; -class DashboardService extends BaseApiService { +class DashboardService extends BaseCrudService { constructor() { - super(); + super({ basePath: "/system/admin/_schema" }); } async getDashboardInfo() { - // FIXME: For now we use mock data - - await sleep(5000); - - const quota = { - TEST: Math.floor(Math.random() * 100), - Items1: Math.floor(Math.random() * 100), - Items2: Math.floor(Math.random() * 100), - Items3: Math.floor(Math.random() * 100), - Items4: Math.floor(Math.random() * 100), - Items5: Math.floor(Math.random() * 100), - Items6: Math.floor(Math.random() * 100) - }; + + this._basePath = '/system/admin/_schema'; + let recordCount = await this.count(); + let collections = await this.getAll(); + let quota = {}; + for await (const item of collections) { + let collName = item.CollectionName; + this._basePath = '/api/CRUD/' + collName; + let collCount = await this.count(); + quota[collName] = collCount; + } + return { recordQuotas: quota, - entitiesNum: Object.keys(quota).length, - lastWeekCallsNum: Math.floor(Math.random() * 500) + entitiesNum: recordCount }; } } diff --git a/Plugins/RawCMS.Plugins.Core/UICore/common/shared/components/charts/simple-pie-chart/simple-pie-chart.js b/Plugins/RawCMS.Plugins.Core/UICore/common/shared/components/charts/simple-pie-chart/simple-pie-chart.js index b56aaf29..4ec76c78 100644 --- a/Plugins/RawCMS.Plugins.Core/UICore/common/shared/components/charts/simple-pie-chart/simple-pie-chart.js +++ b/Plugins/RawCMS.Plugins.Core/UICore/common/shared/components/charts/simple-pie-chart/simple-pie-chart.js @@ -29,13 +29,16 @@ const _SimplePieChart = { return res; }, sortedData: function () { + //let data = optionalChain(() => [...this.context.data], { + // fallbackValue: [] + //}).sort((a, b) => a - b); + + //if (this.options.lowerIsBetter) { + // data = data.reverse(); + //} let data = optionalChain(() => [...this.context.data], { fallbackValue: [] - }).sort((a, b) => a - b); - - if (this.options.lowerIsBetter) { - data = data.reverse(); - } + }) return data; } diff --git a/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/base-crud-service.js b/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/base-crud-service.js index b4d02cd7..6598f967 100644 --- a/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/base-crud-service.js +++ b/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/base-crud-service.js @@ -93,4 +93,14 @@ export class BaseCrudService extends mix(BaseApiService, ICrudService) { return res.data.data; } + + async count() { + + const res = await this._apiClient.get(`${this._basePath}/count`); + if (!this._checkGenericError(res)) { + return false; + } + + return res.data.data; + } } \ No newline at end of file diff --git a/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/crud-service.js b/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/crud-service.js index 498cd5bf..f4f6ba9b 100644 --- a/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/crud-service.js +++ b/Plugins/RawCMS.Plugins.Core/UICore/common/shared/services/crud-service.js @@ -28,4 +28,8 @@ export class ICrudService { async delete(id) { throw new Error(`Please Provide an implementation for ${this.delete.name}`); } + + async count(obj) { + throw new Error(`Please Provide an implementation for ${this.count.name}`); + } } \ No newline at end of file diff --git a/RawCMS.Library/Service/CRUDService.cs b/RawCMS.Library/Service/CRUDService.cs index 9ed74c8c..38b278fe 100644 --- a/RawCMS.Library/Service/CRUDService.cs +++ b/RawCMS.Library/Service/CRUDService.cs @@ -245,7 +245,7 @@ public JObject Get(string collection, string id, List expando = null) return output; } - public long Count(string collection, string query) + public long Count(string collection, string query = null) { FilterDefinition filter = FilterDefinition.Empty; if (!string.IsNullOrWhiteSpace(query))