2023-01-25 16:08:32 +01:00
|
|
|
import { Component, Inject,AfterViewInit, OnInit, ViewChild } from '@angular/core';
|
2023-01-20 16:57:03 +01:00
|
|
|
import { ISService } from '../is.service';
|
2023-01-26 14:56:39 +01:00
|
|
|
import { ISUtilsService } from '../is-utils.service';
|
2023-01-20 16:57:03 +01:00
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
2023-01-24 10:38:39 +01:00
|
|
|
import { MatSort, Sort } from '@angular/material/sort';
|
2023-01-20 16:57:03 +01:00
|
|
|
import { WfHistoryEntry } from '../model/controller.model';
|
2023-01-25 16:08:32 +01:00
|
|
|
import { ActivatedRoute, Params } from '@angular/router';
|
|
|
|
import { Observable, combineLatest } from 'rxjs';
|
2023-01-23 14:22:14 +01:00
|
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
|
|
import { KeyValue } from '../model/controller.model';
|
2023-01-20 16:57:03 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-wf-history',
|
|
|
|
templateUrl: './wf-history.component.html',
|
|
|
|
styleUrls: ['./wf-history.component.css']
|
|
|
|
})
|
2023-01-25 16:08:32 +01:00
|
|
|
export class WfHistoryComponent implements AfterViewInit , OnInit{
|
2023-01-20 16:57:03 +01:00
|
|
|
|
2023-01-23 14:22:14 +01:00
|
|
|
historyDatasource: MatTableDataSource<WfHistoryEntry> = new MatTableDataSource<WfHistoryEntry>([]);
|
2023-01-20 16:57:03 +01:00
|
|
|
|
2023-01-24 10:08:55 +01:00
|
|
|
colums: string[] = ['processId', 'name', 'family', 'dsName', 'status', 'startDate', 'endDate'];
|
2023-01-23 14:22:14 +01:00
|
|
|
|
|
|
|
total: number = 100
|
|
|
|
from: number = -1
|
|
|
|
to: number = -1
|
|
|
|
|
2023-01-26 14:56:39 +01:00
|
|
|
constructor(public service: ISService, public utils:ISUtilsService, public route: ActivatedRoute, public dialog: MatDialog) {
|
2023-01-25 16:08:32 +01:00
|
|
|
}
|
2023-01-20 16:57:03 +01:00
|
|
|
|
2023-01-25 16:08:32 +01:00
|
|
|
ngOnInit() {
|
|
|
|
combineLatest([ this.route.params, this.route.queryParams ],
|
|
|
|
(params: Params, queryParams: Params) => ({ params, queryParams })
|
|
|
|
).subscribe((res: { params: Params; queryParams: Params }) => {
|
|
|
|
const { params, queryParams} = res;
|
|
|
|
let totalP = queryParams['total'];
|
|
|
|
let fromP = queryParams['from'];
|
|
|
|
let toP = queryParams['to'];
|
|
|
|
|
|
|
|
if (totalP) { this.total = parseInt(totalP); }
|
|
|
|
if (fromP) { this.from = parseInt(fromP); }
|
|
|
|
if (toP) { this.to = parseInt(toP); }
|
|
|
|
|
|
|
|
this.service.loadWfHistory(this.total, this.from, this.to).subscribe({
|
|
|
|
next: (data: WfHistoryEntry[]) => this.historyDatasource.data = data,
|
2023-01-26 14:56:39 +01:00
|
|
|
error: error => this.utils.snackError(error)
|
2023-01-25 16:08:32 +01:00
|
|
|
})
|
|
|
|
});
|
2023-01-20 16:57:03 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 10:38:39 +01:00
|
|
|
@ViewChild(MatSort) sort: MatSort | undefined
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
if(this.sort) this.historyDatasource.sort = this.sort;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-23 14:22:14 +01:00
|
|
|
applyFilter(event: Event) {
|
|
|
|
const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase();
|
|
|
|
this.historyDatasource.filter = filterValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
openWfDialog(wf: WfHistoryEntry): void {
|
|
|
|
const wfDialogRef = this.dialog.open(WfDialog, {
|
|
|
|
data: wf
|
|
|
|
});
|
|
|
|
}
|
2023-01-24 10:45:59 +01:00
|
|
|
|
2023-01-23 14:22:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'wf-dialog',
|
|
|
|
templateUrl: 'wf-dialog.html',
|
2023-01-24 10:08:55 +01:00
|
|
|
styleUrls: ['wf-history.component.css']
|
|
|
|
|
2023-01-23 14:22:14 +01:00
|
|
|
})
|
|
|
|
export class WfDialog {
|
2023-01-24 10:08:55 +01:00
|
|
|
startDate:string = '';
|
|
|
|
endDate:string = '';
|
|
|
|
duration:string = '';
|
2023-01-23 14:22:14 +01:00
|
|
|
|
|
|
|
wfDatasource: MatTableDataSource<KeyValue> = new MatTableDataSource<KeyValue>([]);
|
|
|
|
colums: string[] = ['k', 'v'];
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<WfDialog>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: WfHistoryEntry,
|
|
|
|
) {
|
|
|
|
let list:KeyValue[] = [];
|
2023-01-24 10:08:55 +01:00
|
|
|
let map = new Map(Object.entries(data.details));
|
|
|
|
for (let [key, value] of map) {
|
2023-01-23 14:22:14 +01:00
|
|
|
list.push({k: key, v: value});
|
|
|
|
}
|
|
|
|
this.wfDatasource.data = list;
|
2023-01-24 10:08:55 +01:00
|
|
|
this.startDate = data.startDate;
|
|
|
|
this.endDate = data.endDate;
|
|
|
|
this.duration = this.calculateDateDiff(
|
|
|
|
parseInt(map.get('system:startDate')),
|
|
|
|
parseInt(map.get('system:endDate'))
|
|
|
|
);
|
2023-01-23 14:22:14 +01:00
|
|
|
}
|
2023-01-20 16:57:03 +01:00
|
|
|
applyFilter(event: Event) {
|
|
|
|
const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase();
|
|
|
|
this.wfDatasource.filter = filterValue;
|
|
|
|
}
|
2023-01-23 14:22:14 +01:00
|
|
|
onNoClick(): void {
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
2023-01-24 10:08:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
calculateDateDiff(start:number, end:number):string {
|
|
|
|
if (start <= 0 || end <= 0) {
|
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
var seconds = 0;
|
|
|
|
var minutes = 0;
|
|
|
|
var hours = 0;
|
|
|
|
var days = 0;
|
|
|
|
|
|
|
|
if (end > start) {
|
|
|
|
seconds = Math.round((end - start) / 1000);
|
|
|
|
if (seconds > 60) {
|
|
|
|
minutes = Math.floor(seconds / 60);
|
|
|
|
seconds = seconds % 60;
|
|
|
|
if (minutes > 60) {
|
|
|
|
hours = Math.floor(minutes / 60);
|
|
|
|
minutes = minutes % 60;
|
|
|
|
if (hours > 24) {
|
|
|
|
days = Math.floor(hours / 24);
|
|
|
|
hours = hours % 24;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var res = '';
|
|
|
|
if (days > 0) {
|
|
|
|
if (res) { res += ', '; }
|
|
|
|
res += days + " day(s)"
|
|
|
|
}
|
|
|
|
if (hours > 0) {
|
|
|
|
if (res) { res += ', '; }
|
|
|
|
res += hours + " hour(s)"
|
|
|
|
}
|
|
|
|
if (minutes > 0) {
|
|
|
|
if (res) { res += ', '; }
|
|
|
|
res += minutes + " minute(s)"
|
|
|
|
}
|
|
|
|
if (seconds > 0) {
|
|
|
|
if (res) { res += ', '; }
|
|
|
|
res += seconds + " second(s)"
|
|
|
|
}
|
|
|
|
if (!res) {
|
|
|
|
res = '0 seconds';
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-20 16:57:03 +01:00
|
|
|
}
|