Newer
Older

Alex ORLUC
committed
import { Component, ViewChild, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { LANG } from '../../translate.component';
import { NotificationService } from '../../../service/notification/notification.service';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { HeaderService } from '../../../service/header.service';
import { AppService } from '../../../service/app.service';
import { FunctionsService } from '../../../service/functions.service';
import { AdministrationService } from '../administration.service';
templateUrl: 'templates-administration.component.html'
})
export class TemplatesAdministrationComponent implements OnInit {

Alex ORLUC
committed
@ViewChild('adminMenuTemplate', { static: true }) adminMenuTemplate: TemplateRef<any>;
lang: any = LANG;
search: string = null;
templates: any[] = [];
titles: any[] = [];
loading: boolean = false;
displayedColumns = ['template_id', 'template_label', 'template_comment', 'template_type', 'template_target', 'actions'];
filterColumns = ['template_label', 'template_comment', 'template_type', 'template_target'];
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;
@ViewChild(MatSort, { static: false }) sort: MatSort;
public http: HttpClient,
private notify: NotificationService,
private headerService: HeaderService,
public appService: AppService,

Alex ORLUC
committed
public functions: FunctionsService,
public adminService: AdministrationService,

Alex ORLUC
committed
private viewContainerRef: ViewContainerRef
this.headerService.setHeader(this.lang.administration + ' ' + this.lang.templates);

Alex ORLUC
committed
this.headerService.injectInSideBarLeft(this.adminMenuTemplate, this.viewContainerRef, 'adminMenu');
this.http.get('../rest/templates')
.subscribe((data) => {
this.templates = data['templates'];
this.loading = false;
setTimeout(() => {
this.adminService.setDataSource('admin_templates', this.templates, this.sort, this.paginator, this.filterColumns);
this.notify.handleErrors(err);
});
}
deleteTemplate(template: any) {
const r = confirm(this.lang.confirmAction + ' ' + this.lang.delete + ' « ' + template.template_label + ' »');
this.http.delete('../rest/templates/' + template.template_id)
for (const i in this.templates) {
if (this.templates[i].template_id === template.template_id) {
this.templates.splice(Number(i), 1);
}
}
this.adminService.setDataSource('admin_templates', this.templates, this.sort, this.paginator, this.filterColumns);