Skip to content
Snippets Groups Projects
Commit 89858e21 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

Merge branch 'service-ordering' into 'master'

KST-18: order services

See merge request !4
parents 847eef63 f7c06850
No related branches found
No related tags found
1 merge request!4KST-18: order services
Pipeline #8735 passed
......@@ -72,7 +72,7 @@ export class ServiceListComponent implements OnInit {
ngOnInit(): void {
this.servicesService.listServices().subscribe((s) => {
if (s) {
this.services = s;
this.services = this.orderServices(s);
}
});
this.authService.userData$.subscribe((user) => {
......@@ -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);
const nameCompare = (a, b) => a.name.localeCompare(b.name, "hu");
const sortedFailingServices = services.filter(s => s.isOkay === false).sort(nameCompare);
const sortedHealthyServices = services.filter(s => s.isOkay === true).sort(nameCompare);
return sortedFailingServices.concat(sortedHealthyServices);
}
/**
* Prevent unnecessary rerenders
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment