1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-01 00:10:39 +02:00

sort groups

This commit is contained in:
Kyle Spearrin 2018-07-06 14:22:20 -04:00
parent 0f9186628b
commit 634e5e27d3

View File

@ -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;
}
}