Skip to content
Snippets Groups Projects
Commit 3519e0e9 authored by Reményi Gergely's avatar Reményi Gergely
Browse files

KST-18: order services

First by status, then by name
parent 847eef63
No related branches found
No related tags found
1 merge request!4KST-18: order services
...@@ -72,7 +72,7 @@ export class ServiceListComponent implements OnInit { ...@@ -72,7 +72,7 @@ export class ServiceListComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.servicesService.listServices().subscribe((s) => { this.servicesService.listServices().subscribe((s) => {
if (s) { if (s) {
this.services = s; this.services = this.orderServices(s);
} }
}); });
this.authService.userData$.subscribe((user) => { this.authService.userData$.subscribe((user) => {
...@@ -80,6 +80,22 @@ export class ServiceListComponent implements OnInit { ...@@ -80,6 +80,22 @@ export class ServiceListComponent implements OnInit {
}); });
} }
/**
* Sort services. First by status, then by name
* @param services unordered list of services
* @returns ordered list of services
*/
orderServices(services: Service[]): Service[] {
if (!services) {
return [];
}
services.sort((a, b) => a.isOkay > b.isOkay ? 1 : a.isOkay === b.isOkay ? 0 : -1);
let nameCompare = (a, b) => a.name.localeCompare(b.name, "hu");
let sortedFailingServices = services.filter(s => s.isOkay === false).sort(nameCompare);
let sortedHealthyServices = services.filter(s => s.isOkay === true).sort(nameCompare);
return sortedFailingServices.concat(sortedHealthyServices);
}
/** /**
* Prevent unnecessary rerenders * Prevent unnecessary rerenders
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment