1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-14 02:08:50 +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 { ActivatedRoute } from '@angular/router';
import { ApiService } from 'jslib/abstractions/api.service'; import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { GroupResponse } from 'jslib/models/response/groupResponse'; import { GroupResponse } from 'jslib/models/response/groupResponse';
@ -18,7 +19,8 @@ export class GroupsComponent implements OnInit {
groups: GroupResponse[]; groups: GroupResponse[];
searchText: string; searchText: string;
constructor(private apiService: ApiService, private route: ActivatedRoute) { } constructor(private apiService: ApiService, private route: ActivatedRoute,
private i18nService: I18nService) { }
async ngOnInit() { async ngOnInit() {
this.route.parent.parent.params.subscribe(async (params) => { this.route.parent.parent.params.subscribe(async (params) => {
@ -29,11 +31,22 @@ export class GroupsComponent implements OnInit {
async load() { async load() {
const response = await this.apiService.getGroups(this.organizationId); const response = await this.apiService.getGroups(this.organizationId);
if (response.data != null && response.data.length > 0) { const groups = response.data != null && response.data.length > 0 ? response.data : [];
this.groups = response.data; groups.sort((a, b) => {
} else { if (a.name == null && b.name != null) {
this.groups = []; 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; this.loading = false;
} }
} }