init order

This commit is contained in:
_Bastler 2021-12-15 13:30:12 +01:00
parent 572a1c8a45
commit 285ab37e10
2 changed files with 21 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import {Component, OnInit, Input} from '@angular/core';
import {Component, OnInit, Input, SimpleChanges, OnChanges} from '@angular/core';
import {Sort} from '@angular/material/sort';
import {I18nService} from './../../services/i18n.service';
@ -7,7 +7,7 @@ import {I18nService} from './../../services/i18n.service';
templateUrl: './permissions.component.html',
styleUrls: ['./permissions.component.scss']
})
export class PermissionsComponent implements OnInit {
export class PermissionsComponent implements OnInit, OnChanges {
datetimeformat: String;
@Input() permissions;
@ -20,6 +20,10 @@ export class PermissionsComponent implements OnInit {
this.datetimeformat = this.i18n.get('format.datetime', []);
}
ngOnChanges(changes: SimpleChanges): void {
this.sortData({ "active": "name", "direction": "asc" });
}
sortData(sort: Sort) {
const data = this.permissions.slice();
if(!sort.active || sort.direction === '') {

View File

@ -1,34 +1,38 @@
import {Component, OnInit, Input} from '@angular/core';
import {Sort} from '@angular/material/sort';
import {I18nService} from './../../services/i18n.service';
import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
import { Sort } from '@angular/material/sort';
import { I18nService } from './../../services/i18n.service';
@Component({
selector: 'app-quotas',
templateUrl: './quotas.component.html',
styleUrls: ['./quotas.component.scss']
styleUrls: [ './quotas.component.scss' ]
})
export class QuotasComponent implements OnInit {
export class QuotasComponent implements OnInit, OnChanges {
@Input() quotas;
quotaColumns = ["name", "value", "fixed_value", "quotaUnit"];
quotaColumns = [ "name", "value", "fixed_value", "quotaUnit" ];
constructor(private i18n: I18nService) {}
constructor(private i18n: I18nService) { }
ngOnInit(): void {
this.sortData({ "active": "name", "direction": "asc" });
}
ngOnChanges(changes: SimpleChanges): void {
this.sortData({ "active": "name", "direction": "asc" });
}
sortData(sort: Sort) {
const data = this.quotas.slice();
if(!sort.active || sort.direction === '') {
if (!sort.active || sort.direction === '') {
this.quotas = data;
return;
}
this.quotas = data.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch(sort.active) {
switch (sort.active) {
case 'name': return this.compare(this.i18n.get('services.' + a.name + '.title', []), this.i18n.get('services.' + b.name + '.title', []), isAsc);
case 'value': return this.compare(a.value, b.value, isAsc);
default: return 0;
@ -36,9 +40,9 @@ export class QuotasComponent implements OnInit {
});
}
compare(a: number | string , b: number | string , isAsc: boolean) {
compare(a: number | string, b: number | string, isAsc: boolean) {
if (typeof a === 'string' && typeof b === 'string') {
return a.localeCompare(b,undefined, { sensitivity: 'accent' } ) * (isAsc ? 1 : -1);
return a.localeCompare(b, undefined, { sensitivity: 'accent' }) * (isAsc ? 1 : -1);
}
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}