init order
This commit is contained in:
parent
572a1c8a45
commit
285ab37e10
@ -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 {Sort} from '@angular/material/sort';
|
||||||
import {I18nService} from './../../services/i18n.service';
|
import {I18nService} from './../../services/i18n.service';
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ import {I18nService} from './../../services/i18n.service';
|
|||||||
templateUrl: './permissions.component.html',
|
templateUrl: './permissions.component.html',
|
||||||
styleUrls: ['./permissions.component.scss']
|
styleUrls: ['./permissions.component.scss']
|
||||||
})
|
})
|
||||||
export class PermissionsComponent implements OnInit {
|
export class PermissionsComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
datetimeformat: String;
|
datetimeformat: String;
|
||||||
@Input() permissions;
|
@Input() permissions;
|
||||||
@ -20,6 +20,10 @@ export class PermissionsComponent implements OnInit {
|
|||||||
this.datetimeformat = this.i18n.get('format.datetime', []);
|
this.datetimeformat = this.i18n.get('format.datetime', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
this.sortData({ "active": "name", "direction": "asc" });
|
||||||
|
}
|
||||||
|
|
||||||
sortData(sort: Sort) {
|
sortData(sort: Sort) {
|
||||||
const data = this.permissions.slice();
|
const data = this.permissions.slice();
|
||||||
if(!sort.active || sort.direction === '') {
|
if(!sort.active || sort.direction === '') {
|
||||||
|
@ -1,34 +1,38 @@
|
|||||||
import {Component, OnInit, Input} from '@angular/core';
|
import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||||
import {Sort} from '@angular/material/sort';
|
import { Sort } from '@angular/material/sort';
|
||||||
import {I18nService} from './../../services/i18n.service';
|
import { I18nService } from './../../services/i18n.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-quotas',
|
selector: 'app-quotas',
|
||||||
templateUrl: './quotas.component.html',
|
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;
|
@Input() quotas;
|
||||||
quotaColumns = ["name", "value", "fixed_value", "quotaUnit"];
|
quotaColumns = [ "name", "value", "fixed_value", "quotaUnit" ];
|
||||||
|
|
||||||
constructor(private i18n: I18nService) {}
|
constructor(private i18n: I18nService) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.sortData({ "active": "name", "direction": "asc" });
|
this.sortData({ "active": "name", "direction": "asc" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
this.sortData({ "active": "name", "direction": "asc" });
|
||||||
|
}
|
||||||
|
|
||||||
sortData(sort: Sort) {
|
sortData(sort: Sort) {
|
||||||
const data = this.quotas.slice();
|
const data = this.quotas.slice();
|
||||||
if(!sort.active || sort.direction === '') {
|
if (!sort.active || sort.direction === '') {
|
||||||
this.quotas = data;
|
this.quotas = data;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.quotas = data.sort((a, b) => {
|
this.quotas = data.sort((a, b) => {
|
||||||
const isAsc = sort.direction === 'asc';
|
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 '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);
|
case 'value': return this.compare(a.value, b.value, isAsc);
|
||||||
default: return 0;
|
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') {
|
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);
|
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user