1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
import { Component, OnInit, Injectable, ViewChild, ChangeDetectorRef, Optional, Inject } from '@angular/core';
import { RestApiService } from '../../shared/rest-api.service';
import { NotificationsService } from '../../shared/notifications.service';
import { FormControl } from '@angular/forms';
import { Observable, of, Subscription } from 'rxjs';
import { tap, startWith, debounceTime, switchMap, map, filter, distinctUntilChanged } from 'rxjs/operators';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
@Injectable({
providedIn: 'root'
})
@Component({
selector: 'app-check-config',
templateUrl: './check-config.component.html',
styleUrls: ['./check-config.component.scss']
})
export class CheckConfigComponent implements OnInit {
myControl2 = new FormControl();
namespaces = [];
displayedColumns: string[] = ['namespacename', 'servicename', 'typeverification', 'status', 'details', 'reportdate', 'action'];
dataSource = new MatTableDataSource<any>();
@ViewChild(MatPaginator, {static: false}) paginator!: MatPaginator;
@ViewChild(MatSort, { static: false }) sort!: MatSort;
totalCount?: number;
KO?: number;
OK?: number;
Solved?: number;
constructor(private dataService: RestApiService, private changeDetectorRefs: ChangeDetectorRef, private notification: NotificationsService, public dialog: MatDialog) {
}
ngOnInit() {
this.getAllComponentsConfig();
}
btnCategoryClick(val: string) {
this.dataSource.filter = val.trim().toLowerCase();
return this.dataSource.filteredData.length;
}
getAllComponentsConfig(){
this.dataService.getFromApiAllComponentsConfig().subscribe( (res) => {
this.dataSource = new MatTableDataSource<any>(res);
this.changeDetectorRefs.detectChanges();
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.dataSource.sort.sort({ id: "dateajout", start: 'desc', disableClear: false });
this.totalCount = this.dataSource.data.length;
this.OK = this.btnCategoryClick('OK');
this.Solved = this.btnCategoryClick('Solved');
this.KO = this.btnCategoryClick('KO');
});
}
applyFilteringDataTable(filterValue: string){
this.dataSource.filter = filterValue.trim().toLowerCase();
}
openDialog(action: string, checkconfig: any) {
checkconfig.action = action;
const dialogRef = this.dialog.open(checkconfig, {
data: checkconfig
});
dialogRef.afterClosed().subscribe(result => {
if (result.event === 'Update') {
this.updateRowData(result.data);
}});
}
updateRowData(checkconfig: any) {
this.dataSource.data = this.dataSource.data.filter((value, key) => {
if (value.id === checkconfig.id) {
value.status = checkconfig.status;
value.details = checkconfig.details;
}
return true;
});
}
putComponentsConfig(checkconfig: any){
this.dataService.putToApiComponentsConfig(checkconfig).subscribe((res)=>{
if(res.status == 200){
this.notification.LittleNotification("La modification du CheckConfig a bien été prise en compte", 3000, "success", false, "top-end");
}else{
this.notification.LittleNotification("La modification du CheckConfig est un echec", 3000, "error", false, "top-end");
}
// this.datanamespaces = res;
// this.TraitementChartNX();
});
}
}
@Component({
// tslint:disable-next-line: component-selector
selector: 'dialog-content',
templateUrl: 'dialog-content.html',
})
// tslint:disable-next-line: component-class-suffix
export class DialogContent {
action: string;
local_data: any;
constructor(
public dialogRef: MatDialogRef<any>,
// @Optional() is used to prevent error if no data is passed
@Optional() @Inject(MAT_DIALOG_DATA) public data: any) {
// *console.log(data);
this.local_data = data;
this.action = this.local_data.action;
}
doAction() {
this.dialogRef.close({ event: this.action, data: this.local_data });
}
closeDialog() {
this.dialogRef.close({ event: 'Cancel' });
}
} |
Partager