From 634e5e27d35f15f04b0adcebe7cb1be1ab11ba5e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 6 Jul 2018 14:22:20 -0400 Subject: [PATCH] sort groups --- .../organizations/manage/groups.component.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app/organizations/manage/groups.component.ts b/src/app/organizations/manage/groups.component.ts index fc69cc1641..ac3d19513c 100644 --- a/src/app/organizations/manage/groups.component.ts +++ b/src/app/organizations/manage/groups.component.ts @@ -5,6 +5,7 @@ import { import { ActivatedRoute } from '@angular/router'; import { ApiService } from 'jslib/abstractions/api.service'; +import { I18nService } from 'jslib/abstractions/i18n.service'; import { GroupResponse } from 'jslib/models/response/groupResponse'; @@ -18,7 +19,8 @@ export class GroupsComponent implements OnInit { groups: GroupResponse[]; searchText: string; - constructor(private apiService: ApiService, private route: ActivatedRoute) { } + constructor(private apiService: ApiService, private route: ActivatedRoute, + private i18nService: I18nService) { } async ngOnInit() { this.route.parent.parent.params.subscribe(async (params) => { @@ -29,11 +31,22 @@ export class GroupsComponent implements OnInit { async load() { const response = await this.apiService.getGroups(this.organizationId); - if (response.data != null && response.data.length > 0) { - this.groups = response.data; - } else { - this.groups = []; - } + const groups = response.data != null && response.data.length > 0 ? response.data : []; + groups.sort((a, b) => { + if (a.name == null && b.name != null) { + return -1; + } + if (a.name != null && b.name == null) { + return 1; + } + if (a.name == null && b.name == null) { + return 0; + } + + return this.i18nService.collator ? this.i18nService.collator.compare(a.name, b.name) : + a.name.localeCompare(b.name); + }); + this.groups = groups; this.loading = false; } }