From 5479040318f5d68eec1519b7a477f07bead9facb Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 29 Jan 2021 10:47:37 +0000 Subject: [PATCH] [Libraryr | Trunk]: Fix filters on admin tools pages git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60315 d315682c-612b-4755-9ff5-7f18f6832af3 --- dashboard/divId/divIds.component.ts | 30 ++++++++----------------- dashboard/entity/entities.component.ts | 28 ++++++++--------------- dashboard/page/pages.component.ts | 27 ++++++---------------- dashboard/portal/portals.component.ts | 31 ++++++++------------------ 4 files changed, 34 insertions(+), 82 deletions(-) diff --git a/dashboard/divId/divIds.component.ts b/dashboard/divId/divIds.component.ts index f9dc88fc..b39f22d4 100644 --- a/dashboard/divId/divIds.component.ts +++ b/dashboard/divId/divIds.component.ts @@ -51,10 +51,11 @@ export class DivIdsComponent implements OnInit { keyword: [''], type: ['all', Validators.required]}); this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => { - this.filterBySearch(value); + this.searchText = new RegExp(value, 'i'); + this.applyFilters(); })); this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => { - this.applyTypeFilter(); + this.applyFilters(); })); this.getDivIds(); this.subscriptions.push(this.route.queryParams.subscribe(params => { @@ -128,8 +129,7 @@ export class DivIdsComponent implements OnInit { let i = this.divIds.findIndex(_ => _._id == id); this.divIds.splice(i, 1); } - this.applyTypeFilter(); - this.applyFilter(); + this.applyFilters(); } public confirmDeleteDivId(id: string) { @@ -264,34 +264,22 @@ export class DivIdsComponent implements OnInit { public divIdSavedSuccessfully(divId: DivId) { this.divIds.push(divId); - this.applyTypeFilter(); - this.applyFilter(); + this.applyFilters(); this.applyCheck(false); } public divIdUpdatedSuccessfully(divId: DivId) { this.divIds[this.index] = divId; - this.applyTypeFilter(); - this.applyFilter(); + this.applyFilters(); this.applyCheck(false); } - public filterBySearch(text: string) { - this.searchText = new RegExp(text, 'i'); - this.applyFilter(); - } - - public applyFilter() { - this.checkboxes = []; - this.divIds.filter(item => this.filterDivIds(item)).forEach( - _ => this.checkboxes.push({divId: _, checked: false}) - ); - } - public applyTypeFilter() { + public applyFilters() { this.checkboxes = []; this.divIds.filter(item => this.filterByType(item)).forEach( - _ => this.checkboxes.push({divId: _, checked: false}) + item => this.checkboxes.push({divId: item, checked: false}) ); + this.checkboxes = this.checkboxes.filter(item => this.filterDivIds(item.divId)); } public filterByType(divId: DivId): boolean { diff --git a/dashboard/entity/entities.component.ts b/dashboard/entity/entities.component.ts index afd5968d..f2bbaa50 100644 --- a/dashboard/entity/entities.component.ts +++ b/dashboard/entity/entities.component.ts @@ -62,10 +62,11 @@ export class EntitiesComponent implements OnInit { status: ['all', Validators.required] }); this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => { - this.filterBySearch(value); + this.searchText = new RegExp(value, 'i'); + this.applyFilters(); })); this.subscriptions.push(this.filterForm.get('status').valueChanges.subscribe(value => { - this.applyStatusFilter(); + this.applyFilters(); })); this.userManagementService.getUserInfo().subscribe(user => { this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param]; @@ -145,7 +146,7 @@ export class EntitiesComponent implements OnInit { let i = this.entities.findIndex(_ => _._id == id); this.entities.splice(i, 1); } - this.applyFilter(); + this.applyFilters(); } public confirmDeleteEntity(id: string) { @@ -258,26 +259,22 @@ export class EntitiesComponent implements OnInit { public entitySavedSuccessfully(entity: Entity) { this.entities.push(entity); - this.applyFilter(); + this.applyFilters(); this.applyCheck(false); } public entityUpdatedSuccessfully(entity: Entity) { this.entities[this.index] = entity; - this.applyFilter(); + this.applyFilters(); this.applyCheck(false); } - public filterBySearch(text: string) { - this.searchText = new RegExp(text, 'i'); - this.applyFilter(); - } - - public applyFilter() { + public applyFilters() { this.checkboxes = []; - this.entities.filter(item => this.filterEntities(item)).forEach( + this.entities.filter(item => this.filterEntitiesByStatus(item)).forEach( _ => this.checkboxes.push({entity: _, checked: false}) ); + this.checkboxes = this.checkboxes.filter(item => this.filterEntities(item.entity)); } public filterEntities(entity: Entity): boolean { @@ -285,13 +282,6 @@ export class EntitiesComponent implements OnInit { return textFlag; } - public applyStatusFilter() { - this.checkboxes = []; - this.entities.filter(item => this.filterEntitiesByStatus(item)).forEach( - _ => this.checkboxes.push({entity: _, checked: false}) - ); - } - public filterEntitiesByStatus(entity: Entity): boolean { let status = this.filterForm.get("status").value; return status == "all" || (status == "disabled" && !entity.isEnabled) || (status == "enabled" && entity.isEnabled); diff --git a/dashboard/page/pages.component.ts b/dashboard/page/pages.component.ts index 9b159819..3d73bf38 100644 --- a/dashboard/page/pages.component.ts +++ b/dashboard/page/pages.component.ts @@ -78,10 +78,11 @@ export class PagesComponent implements OnInit { type: ['all', Validators.required] }); this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => { - this.filterBySearch(value); + this.searchText = new RegExp(value, 'i'); + this.applyFilters(); })); this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => { - this.applyTypeFilter(); + this.applyFilters(); })); this.subscriptions.push(this.route.queryParams.subscribe(params => { this.pagesType = ''; @@ -228,8 +229,7 @@ export class PagesComponent implements OnInit { let i = this.pages.findIndex(_ => _._id == id); this.pages.splice(i, 1); } - this.applyTypeFilter(); - this.applyFilter(); + this.applyFilters(); } public confirmDeletePage(id: string) { @@ -387,29 +387,16 @@ export class PagesComponent implements OnInit { } else { this.pages[this.index] = page; } - this.applyTypeFilter(); - this.applyFilter(); + this.applyFilters(); this.applyCheck(false); } - - public filterBySearch(text: string) { - this.searchText = new RegExp(text, 'i'); - this.applyFilter(); - } - - public applyFilter() { - this.checkboxes = []; - this.pages.filter(item => this.filterPages(item)).forEach( - _ => this.checkboxes.push({page: _, checked: false}) - ); - } - - public applyTypeFilter() { + public applyFilters() { this.checkboxes = []; this.pages.filter(item => this.filterByType(item)).forEach( _ => this.checkboxes.push({page: _, checked: false}) ); + this.checkboxes = this.checkboxes.filter(item => this.filterPages(item.page)); } public filterByType(page: Page): boolean { diff --git a/dashboard/portal/portals.component.ts b/dashboard/portal/portals.component.ts index b43da0ed..9763d4bb 100644 --- a/dashboard/portal/portals.component.ts +++ b/dashboard/portal/portals.component.ts @@ -49,10 +49,11 @@ export class PortalsComponent implements OnInit { type: ['all', Validators.required] }); this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => { - this.filterBySearch(value); + this.searchText = new RegExp(value, 'i'); + this.applyFilters(); })); this.subscriptions.push(this.filterForm.get('type').valueChanges.subscribe(value => { - this.applyTypeFilter(); + this.applyFilters(); })); HelperFunctions.scroll(); @@ -118,8 +119,7 @@ export class PortalsComponent implements OnInit { let i = this.portals.findIndex(_ => _._id == id); this.portals.splice(i, 1); } - this.applyTypeFilter(); - this.applyFilter(); + this.applyFilters(); } public confirmDeletePortal(id: string) { @@ -268,36 +268,23 @@ export class PortalsComponent implements OnInit { } public portalSavedSuccessfully(portal: Portal) { - this.portals.push(portal) - this.applyTypeFilter(); - this.applyFilter(); + this.portals.push(portal); + this.applyFilters(); this.applyCheck(false); } public portalUpdatedSuccessfully(portal: Portal) { this.portals[this.index] = portal; - this.applyTypeFilter(); - this.applyFilter(); + this.applyFilters(); this.applyCheck(false); } - public filterBySearch(text: string) { - this.searchText = new RegExp(text, 'i'); - this.applyFilter(); - } - - public applyFilter() { - this.checkboxes = []; - this.portals.filter(item => this.filterPortals(item)).forEach( - _ => this.checkboxes.push({portal: _, checked: false}) - ); - } - - public applyTypeFilter() { + public applyFilters() { this.checkboxes = []; this.portals.filter(item => this.filterByType(item)).forEach( _ => this.checkboxes.push({portal: _, checked: false}) ); + this.checkboxes = this.checkboxes.filter(item => this.filterPortals(item.portal)); } public filterByType(portal: Portal): boolean {