From 8df255ebc3e3db21d7ad7f27a5ebdc02a21e48c7 Mon Sep 17 00:00:00 2001 From: Lebeau Elise Date: Tue, 8 Feb 2022 08:23:33 +0000 Subject: [PATCH] Bug fix, paginators and sort for user group and role lists --- .../group-management.component.html | 5 ++-- .../group-management.component.ts | 20 ++++++++------- .../role-management.component.html | 5 ++-- .../role-management.component.ts | 25 +++++++++++++++---- .../user-management.component.html | 8 +++--- .../user-management.component.ts | 16 ++++++++---- 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/app/components/group-management/group-management.component.html b/src/app/components/group-management/group-management.component.html index 43d54c66..587d07e3 100644 --- a/src/app/components/group-management/group-management.component.html +++ b/src/app/components/group-management/group-management.component.html @@ -18,7 +18,7 @@
- +
@@ -67,7 +67,8 @@
- diff --git a/src/app/components/group-management/group-management.component.ts b/src/app/components/group-management/group-management.component.ts index 91fe259d..47424cdb 100644 --- a/src/app/components/group-management/group-management.component.ts +++ b/src/app/components/group-management/group-management.component.ts @@ -10,7 +10,7 @@ * * Author: Sylvain MATHIEU, Elise LEBEAU */ -import {Component, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core'; import {ActivatedRoute, Router} from "@angular/router"; import {ServerService} from "../../services/server.service"; import {ToasterService} from "../../services/toaster.service"; @@ -26,7 +26,6 @@ import {forkJoin} from "rxjs"; import {MatPaginator} from "@angular/material/paginator"; import {MatTableDataSource} from "@angular/material/table"; -import {User} from "@models/users/user"; @Component({ selector: 'app-group-management', @@ -36,8 +35,8 @@ import {User} from "@models/users/user"; export class GroupManagementComponent implements OnInit { server: Server; - @ViewChild(MatPaginator) paginator: MatPaginator; - @ViewChild(MatSort, { static: true }) sort: MatSort; + @ViewChildren('groupsPaginator') groupsPaginator: QueryList; + @ViewChildren('groupsSort') groupsSort: QueryList; public displayedColumns = ['select', 'name', 'created_at', 'updated_at', 'is_builtin', 'delete']; selection = new SelectionModel(true, []); @@ -65,13 +64,16 @@ export class GroupManagementComponent implements OnInit { } ngAfterViewInit() { - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.groupsPaginator.changes.subscribe((comps: QueryList ) => + { + this.dataSource.paginator = comps.first; + }); + this.groupsSort.changes.subscribe((comps: QueryList) => { + this.dataSource.sort = comps.first; + }); this.dataSource.sortingDataAccessor = (item, property) => { switch (property) { - case 'username': - case 'full_name': - case 'email': + case 'name': return item[property] ? item[property].toLowerCase() : ''; default: return item[property]; diff --git a/src/app/components/role-management/role-management.component.html b/src/app/components/role-management/role-management.component.html index eff07f44..b3f5d945 100644 --- a/src/app/components/role-management/role-management.component.html +++ b/src/app/components/role-management/role-management.component.html @@ -21,7 +21,7 @@
- + - diff --git a/src/app/components/role-management/role-management.component.ts b/src/app/components/role-management/role-management.component.ts index b0f7b6e6..21840342 100644 --- a/src/app/components/role-management/role-management.component.ts +++ b/src/app/components/role-management/role-management.component.ts @@ -10,7 +10,7 @@ * * Author: Sylvain MATHIEU, Elise LEBEAU */ -import {Component, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core'; import {Server} from "@models/server"; import {MatTableDataSource} from "@angular/material/table"; import {SelectionModel} from "@angular/cdk/collections"; @@ -41,10 +41,11 @@ export class RoleManagementComponent implements OnInit { selection = new SelectionModel(true, []); searchText = ''; - @ViewChild(MatPaginator) paginator: MatPaginator; - @ViewChild(MatSort, {static: true}) sort: MatSort; + @ViewChildren('rolesPaginator') rolesPaginator: QueryList; + @ViewChildren('rolesSort') rolesSort: QueryList; isReady = false; + constructor( private route: ActivatedRoute, private router: Router, @@ -61,11 +62,25 @@ export class RoleManagementComponent implements OnInit { this.server = server; this.refresh(); }); + } ngAfterViewInit() { - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.rolesPaginator.changes.subscribe((comps: QueryList ) => + { + this.dataSource.paginator = comps.first; + }); + this.rolesSort.changes.subscribe((comps: QueryList) => { + this.dataSource.sort = comps.first; + }); + this.dataSource.sortingDataAccessor = (item, property) => { + switch (property) { + case 'name': + return item[property] ? item[property].toLowerCase() : ''; + default: + return item[property]; + } + }; } diff --git a/src/app/components/user-management/user-management.component.html b/src/app/components/user-management/user-management.component.html index e94cc5ee..a99f8fb6 100644 --- a/src/app/components/user-management/user-management.component.html +++ b/src/app/components/user-management/user-management.component.html @@ -21,7 +21,7 @@
- + - +
diff --git a/src/app/components/user-management/user-management.component.ts b/src/app/components/user-management/user-management.component.ts index 9c94bd40..b5d39e93 100644 --- a/src/app/components/user-management/user-management.component.ts +++ b/src/app/components/user-management/user-management.component.ts @@ -10,7 +10,7 @@ * * Author: Sylvain MATHIEU, Elise LEBEAU */ -import {Component, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core'; import {ActivatedRoute, Router} from "@angular/router"; import {Server} from "@models/server"; import {MatSort} from "@angular/material/sort"; @@ -38,8 +38,8 @@ export class UserManagementComponent implements OnInit { selection = new SelectionModel(true, []); searchText = ''; - @ViewChild(MatPaginator) paginator: MatPaginator; - @ViewChild(MatSort, { static: true }) sort: MatSort; + @ViewChildren('usersPaginator') usersPaginator: QueryList; + @ViewChildren('usersSort') usersSort: QueryList; isReady = false; constructor( @@ -60,8 +60,14 @@ export class UserManagementComponent implements OnInit { } ngAfterViewInit() { - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.usersPaginator.changes.subscribe((comps: QueryList ) => + { + this.dataSource.paginator = comps.first; + }); + this.usersSort.changes.subscribe((comps: QueryList) => { + this.dataSource.sort = comps.first; + }) + this.dataSource.sortingDataAccessor = (item, property) => { switch (property) { case 'username':