2018-07-06 18:49:06 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
2018-07-06 20:22:20 +02:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2018-07-06 18:49:06 +02:00
|
|
|
|
2018-07-06 18:55:59 +02:00
|
|
|
import { GroupResponse } from 'jslib/models/response/groupResponse';
|
2018-07-06 16:21:08 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-org-groups',
|
|
|
|
templateUrl: 'groups.component.html',
|
|
|
|
})
|
2018-07-06 18:49:06 +02:00
|
|
|
export class GroupsComponent implements OnInit {
|
|
|
|
loading = true;
|
|
|
|
organizationId: string;
|
|
|
|
groups: GroupResponse[];
|
|
|
|
searchText: string;
|
|
|
|
|
2018-07-06 20:22:20 +02:00
|
|
|
constructor(private apiService: ApiService, private route: ActivatedRoute,
|
|
|
|
private i18nService: I18nService) { }
|
2018-07-06 18:49:06 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
this.route.parent.parent.params.subscribe(async (params) => {
|
|
|
|
this.organizationId = params.organizationId;
|
|
|
|
});
|
|
|
|
await this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
|
|
|
const response = await this.apiService.getGroups(this.organizationId);
|
2018-07-06 20:22:20 +02:00
|
|
|
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;
|
2018-07-06 18:49:06 +02:00
|
|
|
this.loading = false;
|
|
|
|
}
|
|
|
|
}
|