Skip to content

Commit 337fca4

Browse files
Updated most dropdowns/lists to sort by name (#129)
* Updated most dropdowns to sort by name * Change sort of datatargets to frontend sorts, added sort for creating lora device
1 parent 10bfe05 commit 337fca4

File tree

17 files changed

+955
-849
lines changed

17 files changed

+955
-849
lines changed

src/app/admin/permission/permission-edit/permission-edit.component.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { TranslateService } from '@ngx-translate/core';
66
import { ReplaySubject, Subject, Subscription } from 'rxjs';
77
import { Location } from '@angular/common';
88
import { PermissionService } from '../permission.service';
9-
import { PermissionRequest, PermissionType, PermissionTypes } from '../permission.model';
9+
import {
10+
PermissionRequest,
11+
PermissionType,
12+
PermissionTypes,
13+
} from '../permission.model';
1014
import { OrganisationResponse } from '../../organisation/organisation.model';
1115
import { OrganisationService } from '../../organisation/organisation.service';
1216
import { UserService } from '../../users/user.service';
@@ -80,8 +84,7 @@ export class PermissionEditComponent implements OnInit, OnDestroy {
8084
private location: Location,
8185
private errormEssageService: ErrorMessageService,
8286
private meService: MeService
83-
) {
84-
}
87+
) {}
8588

8689
ngOnInit(): void {
8790
this.getOrganizations();
@@ -167,7 +170,7 @@ export class PermissionEditComponent implements OnInit, OnDestroy {
167170

168171
private getOrganizations() {
169172
this.organisationSubscription = this.organisationService
170-
.getMultiple()
173+
.getMultiple(1000, 0, 'name', 'asc')
171174
.subscribe(
172175
(orgs) => {
173176
this.organisations = orgs.data;
@@ -179,15 +182,17 @@ export class PermissionEditComponent implements OnInit, OnDestroy {
179182
}
180183

181184
private getUsers() {
182-
this.userSubscription = this.userService.getMultiple().subscribe(
183-
(users) => {
184-
this.users = users.data;
185-
this.filteredUsersMulti.next(this.users.slice());
186-
},
187-
(error: HttpErrorResponse) => {
188-
this.showError(error);
189-
}
190-
);
185+
this.userSubscription = this.userService
186+
.getMultiple(1000, 0, 'name', 'asc')
187+
.subscribe(
188+
(users) => {
189+
this.users = users.data;
190+
this.filteredUsersMulti.next(this.users.slice());
191+
},
192+
(error: HttpErrorResponse) => {
193+
this.showError(error);
194+
}
195+
);
191196
}
192197

193198
public compare(o1: any, o2: any): boolean {
@@ -207,7 +212,9 @@ export class PermissionEditComponent implements OnInit, OnDestroy {
207212
.getApplicationsByOrganizationId(organizationId)
208213
.subscribe(
209214
(res) => {
210-
this.applications = res.data;
215+
this.applications = res.data.sort((a, b) =>
216+
a.name.localeCompare(b.name, 'en', { numeric: true })
217+
);
211218
this.filteredApplicationsMulti.next(this.applications.slice());
212219
},
213220
(error: HttpErrorResponse) => {
@@ -251,7 +258,6 @@ export class PermissionEditComponent implements OnInit, OnDestroy {
251258
);
252259
this.applicationMultiCtrl.setValue(this.permission.applicationIds);
253260
}
254-
255261
},
256262
(error: HttpErrorResponse) => {
257263
this.showError(error);

src/app/admin/users/user-list/awaiting-users-table/awaiting-users-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
mat-table
1010
[dataSource]="users"
1111
matSort
12-
matSortActive="id"
12+
matSortActive="name"
1313
matSortDirection="asc"
1414
matSortDisableClear
1515
>

src/app/admin/users/user-list/user-table/user-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="loading-shade" *ngIf="isLoadingResults">
33
<mat-spinner *ngIf="isLoadingResults"></mat-spinner>
44
</div>
5-
<table mat-table [dataSource]="data" matSort matSortActive="id" matSortDirection="asc" matSortDisableClear>
5+
<table mat-table [dataSource]="data" matSort matSortActive="name" matSortDirection="asc" matSortDisableClear>
66

77
<!-- Name Column -->
88
<ng-container matColumnDef="name">
Lines changed: 111 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,111 @@
1-
import {
2-
AfterViewInit,
3-
Component,
4-
Input,
5-
ViewChild,
6-
} from '@angular/core';
7-
import { MatPaginator } from '@angular/material/paginator';
8-
import { MatSort } from '@angular/material/sort';
9-
import { TranslateService } from '@ngx-translate/core';
10-
import { startWith, switchMap, map, catchError } from 'rxjs/operators';
11-
import { UserGetManyResponse, UserResponse } from '../../user.model';
12-
import { UserService } from '../../user.service';
13-
import { merge, Observable, of as observableOf } from 'rxjs';
14-
import { environment } from '@environments/environment';
15-
import { DefaultPageSizeOptions } from '@shared/constants/page.constants';
16-
import { ActivatedRoute } from '@angular/router';
17-
import { MeService } from '@shared/services/me.service';
18-
19-
@Component({
20-
selector: 'app-user-table',
21-
templateUrl: './user-table.component.html',
22-
styleUrls: ['./user-table.component.scss'],
23-
})
24-
export class UserTableComponent implements AfterViewInit {
25-
displayedColumns: string[] = [
26-
'name',
27-
'email',
28-
'global',
29-
'status',
30-
'lastLogin',
31-
'menu',
32-
];
33-
data: UserResponse[];
34-
35-
public pageSize = environment.tablePageSize;
36-
pageSizeOptions = DefaultPageSizeOptions;
37-
resultsLength = 0;
38-
isLoadingResults = true;
39-
@ViewChild(MatPaginator) paginator: MatPaginator;
40-
@ViewChild(MatSort) sort: MatSort;
41-
42-
// If supplied, users will only be retrieved for the specified organization
43-
// If supplied, permissionId will ignored, even if supplied
44-
@Input() organizationId?: number;
45-
46-
// If supplied, users will be retrieved on the permissionId (userGroup/brugerGruppe)
47-
@Input() permissionId?: number;
48-
49-
@Input() canSort = true;
50-
isGlobalAdmin: boolean;
51-
52-
constructor(
53-
public translate: TranslateService,
54-
private userService: UserService,
55-
private meService: MeService
56-
) {
57-
this.isGlobalAdmin = this.meService.hasGlobalAdmin();
58-
}
59-
60-
getUsers(
61-
orderByColumn: string,
62-
orderByDirection: string
63-
): Observable<UserGetManyResponse> {
64-
if (this.organizationId !== null && this.organizationId !== undefined) {
65-
if (this.isGlobalAdmin) {
66-
return this.userService.getMultiple(
67-
this.paginator.pageSize,
68-
this.paginator.pageIndex * this.paginator.pageSize,
69-
orderByColumn,
70-
orderByDirection
71-
);
72-
} else {
73-
return this.userService.getMultipleByOrganization(
74-
this.paginator.pageSize,
75-
this.paginator.pageIndex * this.paginator.pageSize,
76-
orderByColumn,
77-
orderByDirection,
78-
this.organizationId
79-
);
80-
}
81-
} else {
82-
return this.userService.getMultiple(
83-
this.paginator.pageSize,
84-
this.paginator.pageIndex * this.paginator.pageSize,
85-
orderByColumn,
86-
orderByDirection,
87-
this.permissionId
88-
);
89-
}
90-
}
91-
92-
ngAfterViewInit() {
93-
// If the user changes the sort order, reset back to the first page.
94-
this.sort.sortChange.subscribe(() => (this.paginator.pageIndex = 0));
95-
96-
merge(this.sort.sortChange, this.paginator.page)
97-
.pipe(
98-
startWith({}),
99-
switchMap(() => {
100-
this.isLoadingResults = true;
101-
return this.getUsers(this.sort.active, this.sort.direction);
102-
}),
103-
map((data) => {
104-
// Flip flag to show that loading has finished.
105-
this.isLoadingResults = false;
106-
this.resultsLength = data.count;
107-
108-
return data.data;
109-
}),
110-
catchError(() => {
111-
this.isLoadingResults = false;
112-
return observableOf([]);
113-
})
114-
)
115-
.subscribe((data) => (this.data = data));
116-
}
117-
}
1+
import { AfterViewInit, Component, Input, ViewChild } from '@angular/core';
2+
import { MatPaginator } from '@angular/material/paginator';
3+
import { MatSort } from '@angular/material/sort';
4+
import { TranslateService } from '@ngx-translate/core';
5+
import { catchError, map, startWith, switchMap } from 'rxjs/operators';
6+
import { UserGetManyResponse, UserResponse } from '../../user.model';
7+
import { UserService } from '../../user.service';
8+
import { merge, Observable, of as observableOf } from 'rxjs';
9+
import { environment } from '@environments/environment';
10+
import { DefaultPageSizeOptions } from '@shared/constants/page.constants';
11+
import { MeService } from '@shared/services/me.service';
12+
13+
@Component({
14+
selector: 'app-user-table',
15+
templateUrl: './user-table.component.html',
16+
styleUrls: ['./user-table.component.scss'],
17+
})
18+
export class UserTableComponent implements AfterViewInit {
19+
displayedColumns: string[] = [
20+
'name',
21+
'email',
22+
'global',
23+
'status',
24+
'lastLogin',
25+
'menu',
26+
];
27+
data: UserResponse[];
28+
29+
public pageSize = environment.tablePageSize;
30+
pageSizeOptions = DefaultPageSizeOptions;
31+
resultsLength = 0;
32+
isLoadingResults = true;
33+
@ViewChild(MatPaginator) paginator: MatPaginator;
34+
@ViewChild(MatSort) sort: MatSort;
35+
36+
// If supplied, users will only be retrieved for the specified organization
37+
// If supplied, permissionId will ignored, even if supplied
38+
@Input() organizationId?: number;
39+
40+
// If supplied, users will be retrieved on the permissionId (userGroup/brugerGruppe)
41+
@Input() permissionId?: number;
42+
43+
@Input() canSort = true;
44+
isGlobalAdmin: boolean;
45+
46+
constructor(
47+
public translate: TranslateService,
48+
private userService: UserService,
49+
private meService: MeService
50+
) {
51+
this.isGlobalAdmin = this.meService.hasGlobalAdmin();
52+
}
53+
54+
getUsers(
55+
orderByColumn: string,
56+
orderByDirection: string
57+
): Observable<UserGetManyResponse> {
58+
if (this.organizationId !== null && this.organizationId !== undefined) {
59+
if (this.isGlobalAdmin) {
60+
return this.userService.getMultiple(
61+
this.paginator.pageSize,
62+
this.paginator.pageIndex * this.paginator.pageSize,
63+
orderByColumn,
64+
orderByDirection
65+
);
66+
} else {
67+
return this.userService.getMultipleByOrganization(
68+
this.paginator.pageSize,
69+
this.paginator.pageIndex * this.paginator.pageSize,
70+
orderByColumn,
71+
orderByDirection,
72+
this.organizationId
73+
);
74+
}
75+
} else {
76+
return this.userService.getMultiple(
77+
this.paginator.pageSize,
78+
this.paginator.pageIndex * this.paginator.pageSize,
79+
orderByColumn,
80+
orderByDirection,
81+
this.permissionId
82+
);
83+
}
84+
}
85+
86+
ngAfterViewInit() {
87+
// If the user changes the sort order, reset back to the first page.
88+
this.sort.sortChange.subscribe(() => (this.paginator.pageIndex = 0));
89+
90+
merge(this.sort.sortChange, this.paginator.page)
91+
.pipe(
92+
startWith({}),
93+
switchMap(() => {
94+
this.isLoadingResults = true;
95+
return this.getUsers(this.sort.active, this.sort.direction);
96+
}),
97+
map((data) => {
98+
// Flip flag to show that loading has finished.
99+
this.isLoadingResults = false;
100+
this.resultsLength = data.count;
101+
102+
return data.data;
103+
}),
104+
catchError(() => {
105+
this.isLoadingResults = false;
106+
return observableOf([]);
107+
})
108+
)
109+
.subscribe((data) => (this.data = data));
110+
}
111+
}

0 commit comments

Comments
 (0)