Skip to content
Snippets Groups Projects
statuses-administration.component.ts 3.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Component, OnInit, ViewChild } from '@angular/core';
    
    import { HttpClient } from '@angular/common/http';
    
    import { Router, ActivatedRoute } from '@angular/router';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    import { LANG } from '../translate.component';
    import { NotificationService } from '../notification.service';
    
    import { MatPaginator,MatTableDataSource, MatSort } from '@angular/material';
    
    
    declare function $j(selector: any) : any;
    
    declare var angularGlobals : any;
    
        templateUrl : angularGlobals['statuses-administrationView'],
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        styleUrls   : [],
        providers   : [NotificationService]
    
    Damien's avatar
    Damien committed
    export class StatusesAdministrationComponent implements OnInit {
    
        coreUrl                     : string;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        lang                        : any       = LANG;
    
    
        nbStatus: number;
        statuses: Status[] = [];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        loading                     : boolean   = false;
    
        displayedColumns = ['img_filename','id','label_status','identifier'];
        dataSource = new MatTableDataSource(this.statuses);
        @ViewChild(MatPaginator) paginator: MatPaginator;
        @ViewChild(MatSort) sort: MatSort;
        applyFilter(filterValue: string) {
          filterValue = filterValue.trim(); // Remove whitespace
          filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
          this.dataSource.filter = filterValue;
        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        constructor(public http: HttpClient, private notify: NotificationService) {
    
        }
    
        ngOnInit(): void {
            this.coreUrl = angularGlobals.coreUrl;
    
            this.prepareStatus();
    
    
            this.loading = true;
    
    
            this.http.get(this.coreUrl + 'rest/statuses')
    
                .subscribe((data : any) => {
    
                    this.statuses = data.statuses;
    
                    this.updateBreadcrumb(angularGlobals.applicationName);
    
                    this.loading = false;
    
                    setTimeout(() => {
                        this.dataSource = new MatTableDataSource(this.statuses);
                        this.dataSource.paginator = this.paginator;
                        this.dataSource.sort = this.sort;
                    }, 0);
                    
    
                }, (err) => {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    this.notify.error(JSON.parse(err._body).errors);
    
        prepareStatus() {
    
            $j('#inner_content').remove();
        }
    
        updateBreadcrumb(applicationName: string){
    
            $j('#ariane')[0].innerHTML = "<a href='index.php?reinit=true'>" + applicationName + "</a> > "+
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                "<a onclick='location.hash = \"/administration\"' style='cursor: pointer'>" + this.lang.administration + "</a> > " + this.lang.statuses;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
        deleteStatus(status : any){
            var resp = confirm(this.lang.confirmAction+' '+this.lang.delete+' « '+status.id+' »');
    
                this.http.delete(this.coreUrl + 'rest/statuses/'+status.identifier)
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    .subscribe((data : any) => {
    
                        this.statuses = data.statuses;
    
                        this.notify.success(this.lang.statusDeleted);
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                        
    
                    }, (err) => {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                        this.notify.error(JSON.parse(err._body).errors);
    
    
    export interface Status {
        id: string;
        can_be_modified: string;
        can_be_searchead: string;
        identifier: number;
        img_filename: string;
        is_folder_status: string;
        is_system: string;
        label_status: string;
        maarch_module: string;
    }