update
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
import { Sort } from '@angular/material/sort';
|
||||
import { I18nService } from './../../services/i18n.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-permissions',
|
||||
@@ -7,12 +9,33 @@ import { Component, OnInit, Input } from '@angular/core';
|
||||
})
|
||||
export class PermissionsComponent implements OnInit {
|
||||
|
||||
|
||||
@Input() permissions;
|
||||
permissionColumns = ["name", "expires"];
|
||||
|
||||
constructor() { }
|
||||
constructor(private i18n: I18nService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
sortData(sort: Sort) {
|
||||
const data = this.permissions.slice();
|
||||
if (!sort.active || sort.direction === '') {
|
||||
this.permissions = data;
|
||||
return;
|
||||
}
|
||||
|
||||
this.permissions = data.sort((a, b) => {
|
||||
const isAsc = sort.direction === 'asc';
|
||||
switch (sort.active) {
|
||||
case 'name': return this.compare(this.i18n.get('permissions.' + a.name,[]), this.i18n.get('permissions.' + b.name,[]), isAsc);
|
||||
case 'expires': return this.compare(a.expires, b.expires, isAsc);
|
||||
default: return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
compare(a: number | string | String, b: number | string | String, isAsc: boolean) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user