From c25b164035d20099243581f56577e72b62a47b99 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Fri, 13 Oct 2023 21:37:22 -0700 Subject: [PATCH] adding loading + empty panel support to the records summary widget. --- .../{testing.json => secondary.json} | 6 +- .../records-summary-widget.component.ts | 63 ++++++++++--------- 2 files changed, 38 insertions(+), 31 deletions(-) rename backend/pkg/web/handler/dashboard/{testing.json => secondary.json} (84%) diff --git a/backend/pkg/web/handler/dashboard/testing.json b/backend/pkg/web/handler/dashboard/secondary.json similarity index 84% rename from backend/pkg/web/handler/dashboard/testing.json rename to backend/pkg/web/handler/dashboard/secondary.json index 3aaa5a59..0d7946bb 100644 --- a/backend/pkg/web/handler/dashboard/testing.json +++ b/backend/pkg/web/handler/dashboard/secondary.json @@ -1,8 +1,8 @@ { - "id": "updated", + "id": "secondary", "schema_version": "1.0", - "title": "Updated Dashboard", - "description": "An example dashboard to show-off the power of Fasten widgets", + "title": "Secondary Dashboard", + "description": "An second dashboard to show-off the flexibility of the dashboard system.", "widgets": [ { "title_text": "Records Summary", diff --git a/frontend/src/app/widgets/records-summary-widget/records-summary-widget.component.ts b/frontend/src/app/widgets/records-summary-widget/records-summary-widget.component.ts index 08a81a59..ce72c9bc 100644 --- a/frontend/src/app/widgets/records-summary-widget/records-summary-widget.component.ts +++ b/frontend/src/app/widgets/records-summary-widget/records-summary-widget.component.ts @@ -166,42 +166,49 @@ export class RecordsSummaryWidgetComponent extends DashboardWidgetComponent impl } as DashboardWidgetConfig super.ngOnInit(); - this.loading = true - this.isEmpty = true + this.chartProcessQueryResults(null) + } + + chartProcessQueryResults(queryResults: any[]) { this.fastenApi.getSummary().subscribe((summary: Summary) => { - this.summary = summary + this.summary = summary + for (let resourceTypeCount of summary.resource_type_counts) { + let foundGroup = false + for (let groupKey in this.groupLookup) { + let group = this.groupLookup[groupKey] + if (group.resourceTypes.indexOf(resourceTypeCount.resource_type) > -1) { + foundGroup = true + this.groupLookup[groupKey].count += resourceTypeCount.count + this.groupLookup[groupKey].includedResourceTypes.push(resourceTypeCount.resource_type) + } + } - for(let resourceTypeCount of summary.resource_type_counts){ - let foundGroup = false - for(let groupKey in this.groupLookup){ - let group = this.groupLookup[groupKey] - if(group.resourceTypes.indexOf(resourceTypeCount.resource_type) > -1){ - foundGroup = true - this.groupLookup[groupKey].count += resourceTypeCount.count - this.groupLookup[groupKey].includedResourceTypes.push(resourceTypeCount.resource_type) + if (!foundGroup) { + this.groupLookup[resourceTypeCount.resource_type] = { + displayName: resourceTypeCount.resource_type, + + resourceTypes: [resourceTypeCount.resource_type], + count: resourceTypeCount.count + } } } - if(!foundGroup){ - console.log('no group found for ' + resourceTypeCount.resource_type) - this.groupLookup[resourceTypeCount.resource_type] = { - displayName: resourceTypeCount.resource_type, + //filter any groups with 0 counts + this.groupLookup = this.groupLookup.filter((group) => { + return group.count > 0 + }) - resourceTypes: [resourceTypeCount.resource_type], - count: resourceTypeCount.count - } + if(this.summary.resource_type_counts.length > 0){ + this.isEmpty = false } - } - - //filter any groups with 0 counts - this.groupLookup = this.groupLookup.filter((group) => { - return group.count > 0 + this.loading = false + }, + (error) => { + this.loading = false + }, + () => { + console.log('completed getting summary') }) - - }) - //call Summary endpoint - this.loading = false - this.isEmpty = false } }