adding loading + empty panel support to the records summary widget.

This commit is contained in:
Jason Kulatunga 2023-10-13 21:37:22 -07:00
parent 8e999e6b79
commit c25b164035
No known key found for this signature in database
2 changed files with 38 additions and 31 deletions

View File

@ -1,8 +1,8 @@
{ {
"id": "updated", "id": "secondary",
"schema_version": "1.0", "schema_version": "1.0",
"title": "Updated Dashboard", "title": "Secondary Dashboard",
"description": "An example dashboard to show-off the power of Fasten widgets", "description": "An second dashboard to show-off the flexibility of the dashboard system.",
"widgets": [ "widgets": [
{ {
"title_text": "Records Summary", "title_text": "Records Summary",

View File

@ -166,42 +166,49 @@ export class RecordsSummaryWidgetComponent extends DashboardWidgetComponent impl
} as DashboardWidgetConfig } as DashboardWidgetConfig
super.ngOnInit(); super.ngOnInit();
this.loading = true this.chartProcessQueryResults(null)
this.isEmpty = true }
chartProcessQueryResults(queryResults: any[]) {
this.fastenApi.getSummary().subscribe((summary: Summary) => { 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){ if (!foundGroup) {
let foundGroup = false this.groupLookup[resourceTypeCount.resource_type] = {
for(let groupKey in this.groupLookup){ displayName: resourceTypeCount.resource_type,
let group = this.groupLookup[groupKey]
if(group.resourceTypes.indexOf(resourceTypeCount.resource_type) > -1){ resourceTypes: [resourceTypeCount.resource_type],
foundGroup = true count: resourceTypeCount.count
this.groupLookup[groupKey].count += resourceTypeCount.count }
this.groupLookup[groupKey].includedResourceTypes.push(resourceTypeCount.resource_type)
} }
} }
if(!foundGroup){ //filter any groups with 0 counts
console.log('no group found for ' + resourceTypeCount.resource_type) this.groupLookup = this.groupLookup.filter((group) => {
this.groupLookup[resourceTypeCount.resource_type] = { return group.count > 0
displayName: resourceTypeCount.resource_type, })
resourceTypes: [resourceTypeCount.resource_type], if(this.summary.resource_type_counts.length > 0){
count: resourceTypeCount.count this.isEmpty = false
}
} }
} this.loading = false
},
//filter any groups with 0 counts (error) => {
this.groupLookup = this.groupLookup.filter((group) => { this.loading = false
return group.count > 0 },
() => {
console.log('completed getting summary')
}) })
})
//call Summary endpoint
this.loading = false
this.isEmpty = false
} }
} }