1
|
import {Component, EventEmitter, OnDestroy, OnInit, Output} from '@angular/core';
|
2
|
import {DialogService} from 'primeng/dynamicdialog';
|
3
|
import {FileTableDialogComponent} from './file-table-dialog/file-table-dialog.component';
|
4
|
import {takeUntil} from 'rxjs/operators';
|
5
|
import {interval, Observable, Subject, Subscription} from 'rxjs';
|
6
|
import {InvoiceDownloadSchedulerService} from '../../../../shared/services/invoice-download-scheduler.service';
|
7
|
import {DownloadProcessTemp} from '../../../../shared/models/download-process-temp.interafce';
|
8
|
import {SchedulerCriteriaInterface} from '../../../../shared/models/scheduler-criteria.interface';
|
9
|
import { RealTimeExecution } from 'src/app/shared/models/real-time-execution.interface';
|
10
|
import { AuthService } from 'src/app/shared/services/auth.service';
|
11
|
import { NotificationsHandlingService } from 'src/app/shared/services/notifications-handling/notifications-handling.service';
|
12
|
import { USER_RIGHTS } from 'src/app/shared/enums/USER_RIGHTS.enum';
|
13
|
|
14
|
@Component({
|
15
|
selector: 'app-file-download-real-time-monitor',
|
16
|
templateUrl: './file-download-real-time-monitor.component.html',
|
17
|
styleUrls: ['./file-download-real-time-monitor.component.scss']
|
18
|
})
|
19
|
export class FileDownloadRealTimeMonitorComponent implements OnInit, OnDestroy {
|
20
|
@Output() executionInfo: EventEmitter<RealTimeExecution> = new EventEmitter<RealTimeExecution>(true);
|
21
|
downloadProcessTemp: DownloadProcessTemp[] = [];
|
22
|
loading = true;
|
23
|
totalRecords: any;
|
24
|
status : string = '';
|
25
|
destroyed$ = new Subject();
|
26
|
tableValues: DownloadProcessTemp[] = [];
|
27
|
private subscription: Subscription;
|
28
|
private criteria: SchedulerCriteriaInterface;
|
29
|
private currentPage: number;
|
30
|
private source: Observable<number>;
|
31
|
|
32
|
|
33
|
constructor(private dialogService: DialogService, private fileService: InvoiceDownloadSchedulerService, private auth: AuthService, private notificationService: NotificationsHandlingService) {
|
34
|
}
|
35
|
|
36
|
ngOnInit(): void {
|
37
|
this.currentPage = 1;
|
38
|
this.fileService.getAllByUserId(this.auth.userDetails.id).subscribe(documentsDownloaded => {
|
39
|
this.downloadProcessTemp = documentsDownloaded;
|
40
|
documentsDownloaded.sort((first, second) => {
|
41
|
return (first.status > second.status) ? 1 : -1;
|
42
|
});
|
43
|
console.log(documentsDownloaded);
|
44
|
|
45
|
this.tableValues = documentsDownloaded;
|
46
|
console.log(Math.min(documentsDownloaded.length, 10));
|
47
|
console.log(this.tableValues);
|
48
|
this.addInfoForExecutionInfo(this.tableValues);
|
49
|
});
|
50
|
|
51
|
this.source = interval(2000);
|
52
|
this.subscription = this.source.subscribe(() => {
|
53
|
this.downloadData();
|
54
|
});
|
55
|
|
56
|
}
|
57
|
|
58
|
|
59
|
showResultsTable(downloadProcessTemp: DownloadProcessTemp): void {
|
60
|
this.dialogService.open(FileTableDialogComponent, {
|
61
|
data: [downloadProcessTemp]
|
62
|
});
|
63
|
}
|
64
|
|
65
|
reschedule(downloadProcessTemp: DownloadProcessTemp): void {
|
66
|
this.fileService.reschedule(String(downloadProcessTemp.iPowerClientCode)).subscribe(result => {
|
67
|
this.notificationService.showRescheduleSuccess();
|
68
|
});
|
69
|
this.downloadData();
|
70
|
}
|
71
|
|
72
|
doNothing(downloadProcessTemp: any): void {
|
73
|
|
74
|
}
|
75
|
|
76
|
highPriority(downloadProcessTemp: DownloadProcessTemp): void {
|
77
|
this.fileService.highPriority(String(downloadProcessTemp.iPowerClientCode)).subscribe(result => {
|
78
|
this.notificationService.showHighPrioritySuccess();
|
79
|
});
|
80
|
this.downloadData();
|
81
|
|
82
|
}
|
83
|
|
84
|
searchByCriteria(criteria: SchedulerCriteriaInterface): void {
|
85
|
this.criteria = criteria;
|
86
|
console.log('criteria', criteria);
|
87
|
const downloadProcessTemps: DownloadProcessTemp[] = [];
|
88
|
this.downloadProcessTemp.forEach(x => {
|
89
|
console.log(x.iPowerClientCode , criteria);
|
90
|
|
91
|
console.log((criteria.status !== undefined && criteria.status !== null ? criteria.status === x.status : true)
|
92
|
&& (criteria.iPowerClientCode !== undefined && criteria.iPowerClientCode !== null &&
|
93
|
criteria.iPowerClientCode.trim() !== '' ? criteria.iPowerClientCode === x.iPowerClientCode : true));
|
94
|
|
95
|
console.log(x.iPowerClientCode, x.status);
|
96
|
|
97
|
if ((criteria.status !== undefined && criteria.status !== null ? criteria.status === x.status : true)
|
98
|
&& (criteria.iPowerClientCode !== undefined && criteria.iPowerClientCode !== null &&
|
99
|
criteria.iPowerClientCode.trim() !== '' ? criteria.iPowerClientCode === x.iPowerClientCode : true)) {
|
100
|
console.log(x);
|
101
|
downloadProcessTemps.push(x);
|
102
|
}
|
103
|
});
|
104
|
console.log(Math.min(downloadProcessTemps.length, 10 * this.currentPage));
|
105
|
|
106
|
this.tableValues = downloadProcessTemps;
|
107
|
this.addInfoForExecutionInfo(this.tableValues);
|
108
|
}
|
109
|
|
110
|
ngOnDestroy(): void {
|
111
|
this.destroyed$.next();
|
112
|
this.destroyed$.complete();
|
113
|
this.subscription.unsubscribe();
|
114
|
}
|
115
|
|
116
|
private downloadData(): void {
|
117
|
this.fileService.getAllByUserId(this.auth.userDetails.id).subscribe(documentsDownloaded => {
|
118
|
this.downloadProcessTemp = documentsDownloaded;
|
119
|
console.log(this.downloadProcessTemp);
|
120
|
documentsDownloaded.sort((first, second) => {
|
121
|
return (first.status > second.status) ? 1 : -1;
|
122
|
});
|
123
|
if (this.criteria) {
|
124
|
this.searchByCriteria(this.criteria);
|
125
|
} else {
|
126
|
this.tableValues = documentsDownloaded.slice(0, Math.min(documentsDownloaded.length, 10 * this.currentPage));
|
127
|
}
|
128
|
});
|
129
|
}
|
130
|
|
131
|
onPageChange(event: any): void {
|
132
|
// TODO implement method that changes the pages
|
133
|
console.log(event);
|
134
|
this.currentPage = event.first / event.rows;
|
135
|
this.downloadData();
|
136
|
|
137
|
}
|
138
|
|
139
|
addInfoForExecutionInfo(value: DownloadProcessTemp[]) {
|
140
|
let sum = 0;
|
141
|
value.forEach((element) => {
|
142
|
sum = sum + element.results;
|
143
|
|
144
|
if(element.status == 'Working' && element.status != undefined){
|
145
|
this.status = element.iPowerClientName;
|
146
|
}
|
147
|
});
|
148
|
console.log(sum);
|
149
|
if(this.status != undefined){
|
150
|
this.executionInfo.emit({ receivedFiles: sum ,status: this.status });
|
151
|
|
152
|
}
|
153
|
}
|
154
|
|
155
|
canRescheculeUA() : boolean {
|
156
|
return this.auth.userRights.find(rdc => USER_RIGHTS.A04.isGrantedToUser(rdc.rights)) != null;
|
157
|
}
|
158
|
}
|