Newer
Older
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { MediaMatcher } from '@angular/cdk/layout';
import { HttpClient } from '@angular/common/http';
import { LANG } from '../../translate.component';
import { NotificationService } from '../../notification.service';
import { HeaderService } from '../../../service/header.service';
import { MatPaginator, MatTableDataSource, MatSort, MatSidenav } from '@angular/material';
declare function $j(selector: any): any;
declare var angularGlobals: any;
templateUrl: "parameters-administration.component.html",
providers: [NotificationService]
})
export class ParametersAdministrationComponent implements OnInit {
@ViewChild('snav') public sidenavLeft : MatSidenav;
@ViewChild('snav2') public sidenavRight : MatSidenav;
mobileQuery: MediaQueryList;
private _mobileQueryListener: () => void;
coreUrl: string;
lang: any = LANG;
displayedColumns = ['id', 'description', 'value', 'actions'];
dataSource: any;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, private notify: NotificationService, private headerService: HeaderService) {
$j("link[href='merged_css.php']").remove();
this.mobileQuery = media.matchMedia('(max-width: 768px)');
this._mobileQueryListener = () => changeDetectorRef.detectChanges();
this.mobileQuery.addListener(this._mobileQueryListener);
}
ngOnDestroy(): void {
this.mobileQuery.removeListener(this._mobileQueryListener);
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
this.headerService.headerMessage = this.lang.administration + ' ' + this.lang.parameters;
window['MainHeaderComponent'].setSnav(this.sidenavLeft);
window['MainHeaderComponent'].setSnavRight(null);
this.loading = true;
this.http.get(this.coreUrl + 'rest/parameters')
.subscribe((data: any) => {
this.parameters = data.parameters;
this.dataSource = new MatTableDataSource(this.parameters);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
deleteParameter(paramId: string) {
let r = confirm(this.lang.deleteMsg);
if (r) {
this.http.delete(this.coreUrl + 'rest/parameters/' + paramId)
.subscribe((data: any) => {
this.parameters = data.parameters;
this.dataSource = new MatTableDataSource(this.parameters);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.notify.success(this.lang.parameterDeleted);
}, (err) => {
this.notify.error(err.error.errors);

Alex ORLUC
committed
});