1
|
import { Component, OnInit } from '@angular/core';
|
2
|
import { jobTypes } from '../../domain/job-types';
|
3
|
|
4
|
import { MonitorService } from '../../services/monitor.service';
|
5
|
import { AuthenticationService } from '../../services/authentication.service';
|
6
|
import { JobsOfUser, StoredJob } from '../../domain/typeScriptClasses';
|
7
|
import { ValidatorService } from '../../services/validator.service';
|
8
|
import { loadingUserJobs, loadingUserJobsError, noUserJobsFound } from '../../domain/shared-messages';
|
9
|
import { URLParameter } from '../../domain/url-parameter';
|
10
|
|
11
|
@Component ({
|
12
|
selector: 'app-compatibility-validation-history',
|
13
|
templateUrl: 'compatibility-validation-history.component.html'
|
14
|
})
|
15
|
|
16
|
|
17
|
export class CompatibilityValidationHistoryComponent implements OnInit {
|
18
|
userEmail: string;
|
19
|
loadingMessage: string;
|
20
|
errorMessage: string;
|
21
|
infoMessage: string;
|
22
|
successMessage: string;
|
23
|
failureMessage: string;
|
24
|
|
25
|
jobTypes: string[];
|
26
|
jobsOfUser: JobsOfUser;
|
27
|
jobs: StoredJob[];
|
28
|
|
29
|
itemsPerPage: number;
|
30
|
currentPage: number;
|
31
|
currentTotalJobs: number;
|
32
|
totalPages: number;
|
33
|
currentFilter: string;
|
34
|
chosenJobType: string;
|
35
|
|
36
|
constructor(private authService: AuthenticationService,
|
37
|
private monitorService: MonitorService,
|
38
|
private valService: ValidatorService) {}
|
39
|
|
40
|
ngOnInit() {
|
41
|
this.loadTable();
|
42
|
}
|
43
|
|
44
|
loadTable() {
|
45
|
//initialize
|
46
|
this.userEmail = this.authService.getUserEmail();
|
47
|
this.jobTypes = jobTypes;
|
48
|
this.itemsPerPage = 10;
|
49
|
this.currentPage = 0;
|
50
|
this.currentFilter = 'all';
|
51
|
this.chosenJobType = '';
|
52
|
|
53
|
//call API and get all jobs:
|
54
|
this.getJobs();
|
55
|
}
|
56
|
|
57
|
|
58
|
getJobType(type: string) {
|
59
|
this.chosenJobType = type;
|
60
|
this.currentPage = 0;
|
61
|
this.getJobs();
|
62
|
}
|
63
|
|
64
|
filterJobs(filter: string){
|
65
|
this.currentFilter = filter;
|
66
|
this.currentPage = 0;
|
67
|
console.log(`requesting ${this.currentFilter} jobs`);
|
68
|
this.getJobs();
|
69
|
}
|
70
|
|
71
|
getItemsPerPage(num: number){
|
72
|
this.itemsPerPage = num;
|
73
|
this.currentPage = 0;
|
74
|
this.getJobs();
|
75
|
}
|
76
|
|
77
|
goToNextPage(){
|
78
|
if( (this.currentPage+1) < this.totalPages) {
|
79
|
this.currentPage++;
|
80
|
console.log(`Get me page ${this.currentPage}!`);
|
81
|
this.getJobs();
|
82
|
}
|
83
|
}
|
84
|
|
85
|
goToPreviousPage(){
|
86
|
if(this.currentPage > 0) {
|
87
|
this.currentPage--;
|
88
|
console.log(`Get me page ${this.currentPage}!`);
|
89
|
this.getJobs();
|
90
|
}
|
91
|
}
|
92
|
|
93
|
|
94
|
storedJobs () {
|
95
|
this.valService.getStoredJobsNew('ant.lebesis@gmail.com',
|
96
|
'Compatibility Test',
|
97
|
'0',
|
98
|
'10',
|
99
|
'2018-02-01',
|
100
|
'2018-02-28',
|
101
|
'successful').subscribe(
|
102
|
jobs => this.jobs = jobs,
|
103
|
error => console.log(error.status),
|
104
|
() => {
|
105
|
console.log('Also hit getStoredJobsNew and got:');
|
106
|
console.log(this.jobs);
|
107
|
}
|
108
|
);
|
109
|
}
|
110
|
|
111
|
getJobs() {
|
112
|
this.loadingMessage = loadingUserJobs;
|
113
|
this.errorMessage = '';
|
114
|
this.infoMessage = '';
|
115
|
this.successMessage = '';
|
116
|
this.failureMessage = '';
|
117
|
let params: URLParameter[] = [];
|
118
|
params.push({key: 'user', value: [this.userEmail]});
|
119
|
if ( this.chosenJobType ) {
|
120
|
params.push({key: 'jobType', value: [this.chosenJobType]});
|
121
|
}
|
122
|
params.push({key: 'offset', value: [( (this.currentPage)*this.itemsPerPage).toString()]});
|
123
|
params.push({key: 'limit', value: [this.itemsPerPage.toString()]});
|
124
|
/* can also add dateFrom and dateTo if needed */
|
125
|
params.push({key: 'validationStatus', value: [this.currentFilter]});
|
126
|
params.push({key: 'includeJobsTotal', value: ['true']});
|
127
|
this.monitorService.getJobsOfUser(params).subscribe(
|
128
|
jobs => this.jobsOfUser = jobs,
|
129
|
error => {
|
130
|
console.log(`The API returned ${error.status}`);
|
131
|
this.loadingMessage = '';
|
132
|
this.jobsOfUser = null;
|
133
|
this.errorMessage = loadingUserJobsError;
|
134
|
},
|
135
|
() => {
|
136
|
if (this.currentFilter == 'all') {
|
137
|
this.currentTotalJobs = this.jobsOfUser.totalJobs;
|
138
|
} else if (this.currentFilter == 'successful') {
|
139
|
this.currentTotalJobs = this.jobsOfUser.totalJobsSuccessful;
|
140
|
} else if (this.currentFilter == 'failed') {
|
141
|
this.currentTotalJobs = this.jobsOfUser.totalJobsFailed;
|
142
|
} else {
|
143
|
this.currentTotalJobs = this.jobsOfUser.totalJobsOngoing;
|
144
|
}
|
145
|
this.totalPages = Math.ceil(this.currentTotalJobs / this.itemsPerPage);
|
146
|
this.loadingMessage = '';
|
147
|
if (!this.totalPages || !this.jobsOfUser.jobs) {
|
148
|
this.infoMessage = noUserJobsFound;
|
149
|
this.currentPage = -1;
|
150
|
}
|
151
|
}
|
152
|
);
|
153
|
}
|
154
|
|
155
|
getResultImage(status: string) {
|
156
|
if (status == 'ongoing') {
|
157
|
return `../../../assets/imgs/icon_colours-question.jpg`;
|
158
|
} else if (status == 'successful') {
|
159
|
return `../../../assets/imgs/icon_colours-check.jpg`;
|
160
|
} else {
|
161
|
return `../../../assets/imgs/icon_colours-x.jpg`;
|
162
|
}
|
163
|
}
|
164
|
|
165
|
resubmitJob (id: string, email: string) {
|
166
|
this.valService.reSubmitJobForValidation(id, email).subscribe(
|
167
|
res => this.successMessage = `The job with id ${id} was successfully resubmitted`,
|
168
|
error => {
|
169
|
this.failureMessage = `Could not resubmit the job with id ${id}`;
|
170
|
console.log(error);
|
171
|
}
|
172
|
);
|
173
|
this.getJobs();
|
174
|
}
|
175
|
|
176
|
}
|
177
|
|