From 4443ef40e3b4f51a663a8093f216f3c05922fb74 Mon Sep 17 00:00:00 2001 From: Mirko Mollik Date: Wed, 16 Aug 2023 12:29:20 +0200 Subject: [PATCH] Cre8/issue57 (#59) fix: broken filter function --------- Signed-off-by: Mirko Mollik --- viewer/src/app/app.service.ts | 11 ++++++++++ .../credential-profile.component.ts | 12 +++++++---- viewer/src/app/filter/filter.component.ts | 21 ++++++++++--------- viewer/src/app/table/table.component.ts | 4 ++-- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/viewer/src/app/app.service.ts b/viewer/src/app/app.service.ts index abac08b..878c70c 100644 --- a/viewer/src/app/app.service.ts +++ b/viewer/src/app/app.service.ts @@ -87,4 +87,15 @@ export class AppService { } return ''; } + + getType(value: any) { + if (value.type) { + return value.type; + } else { + const ref = value.allOf ? value.allOf[0].$ref : value.$ref; + const res = JSON.parse(JSON.stringify(def)); + const id = ref.split('/')[2]; + return res.definitions[id].type; + } + } } diff --git a/viewer/src/app/credential-profile/credential-profile.component.ts b/viewer/src/app/credential-profile/credential-profile.component.ts index 2699427..83e915d 100644 --- a/viewer/src/app/credential-profile/credential-profile.component.ts +++ b/viewer/src/app/credential-profile/credential-profile.component.ts @@ -4,7 +4,7 @@ import { MatSort } from '@angular/material/sort'; import { MatTableDataSource } from '@angular/material/table'; import { CredentialProfileAddDialogComponent } from '../credential-profile-add-dialog/credential-profile-add-dialog.component'; import { AppService, Resource } from '../app.service'; -import { Format, Property, Resources } from '../resources'; +import { Format, Resources } from '../resources'; import { Filter, FilterComponent } from '../filter/filter.component'; import { MatPaginator } from '@angular/material/paginator'; @@ -45,8 +45,9 @@ export class CredentialProfileComponent implements OnInit, AfterViewInit { if (value === '$schema') return; this.allColumns.push({ key: value, - tooltip: (this.data.structure.properties[value] as Property) - .description, + tooltip: this.appService.getTooltip( + this.data.structure.properties[value] + ), }); }); for (const key of this.appService.extraValues) { @@ -101,11 +102,14 @@ export class CredentialProfileComponent implements OnInit, AfterViewInit { }) // filter out the columns that do not match with the filter .filter((value) => { + if (Object.keys(this.filter).length === 0) return true; for (const category in this.filter) { for (const key in this.filter[category]) { if (this.filter[category][key]) { const res = value[`${category} - ${key}`]; - return typeof res === 'object' ? res.Value : res; + if (typeof res === 'object' ? res.Value : res === false) { + return false; + } } } } diff --git a/viewer/src/app/filter/filter.component.ts b/viewer/src/app/filter/filter.component.ts index 744c8f0..332baa1 100644 --- a/viewer/src/app/filter/filter.component.ts +++ b/viewer/src/app/filter/filter.component.ts @@ -40,16 +40,17 @@ export class FilterComponent implements OnInit { .structure.properties; Object.keys(subValues).forEach((value: string) => { if (value === '$schema') return; - elements.push({ - value: `${key} - ${value}`, - show: value, - type: subValues[value].type ?? 'boolean', - tooltip: - subValues[value].description ?? - subValues[value].allOf[1].description, - }); - if (this.isCheckbox(elements[elements.length - 1])) { - group.addControl(value, new FormControl()); + const type = this.appService.getType(subValues[value]); + if (type === 'boolean' || type.includes('boolean')) { + elements.push({ + value: `${key} - ${value}`, + show: value, + type: subValues[value].type ?? 'boolean', + tooltip: this.appService.getTooltip(subValues[value]), + }); + if (this.isCheckbox(elements[elements.length - 1])) { + group.addControl(value, new FormControl()); + } } }); this.selectionColumns.push({ diff --git a/viewer/src/app/table/table.component.ts b/viewer/src/app/table/table.component.ts index 8b3a6a2..e98e9de 100644 --- a/viewer/src/app/table/table.component.ts +++ b/viewer/src/app/table/table.component.ts @@ -10,7 +10,7 @@ import { MatSort } from '@angular/material/sort'; import { MatTableDataSource } from '@angular/material/table'; import { ActivatedRoute, Router } from '@angular/router'; import { AppService } from '../app.service'; -import { Format, Property, Resources } from '../resources'; +import { Format, Resources } from '../resources'; import { MatPaginator } from '@angular/material/paginator'; import { MatChipInputEvent } from '@angular/material/chips'; import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; @@ -66,7 +66,7 @@ export class TableComponent implements OnInit, AfterViewInit { this.allColumns = this.getNames(); this.columns = this.getNames().map((key) => ({ header: key, - tooltip: (this.data.structure.properties[key] as Property).description, + tooltip: this.appService.getTooltip(this.data.structure.properties[key]), })); this.dataSource.data = Object.keys(this.data.values) .filter((key) => key !== 'structure')