Project

General

Profile

1 50364 myrto.kouk
import { Component, OnInit } from '@angular/core';
2 50579 myrto.kouk
import { jobTypes } from '../../domain/job-types';
3 50364 myrto.kouk
4 50592 myrto.kouk
import { MonitorService } from '../../services/monitor.service';
5
import { AuthenticationService } from '../../services/authentication.service';
6 50633 myrto.kouk
import { JobsOfUser, StoredJob } from '../../domain/typeScriptClasses';
7
import { ValidatorService } from '../../services/validator.service';
8 50672 myrto.kouk
import { loadingUserJobs, loadingUserJobsError, noUserJobsFound } from '../../domain/shared-messages';
9 50936 myrto.kouk
import { URLParameter } from '../../domain/url-parameter';
10 50469 myrto.kouk
11 50364 myrto.kouk
@Component ({
12
  selector: 'app-compatibility-validation-history',
13
  templateUrl: 'compatibility-validation-history.component.html'
14
})
15
16 50469 myrto.kouk
17 50364 myrto.kouk
export class CompatibilityValidationHistoryComponent  implements OnInit {
18 50672 myrto.kouk
  userEmail: string;
19
  loadingMessage: string;
20
  errorMessage: string;
21
  infoMessage: string;
22
  successMessage: string;
23
  failureMessage: string;
24
25 50364 myrto.kouk
  jobTypes: string[];
26 50632 myrto.kouk
  jobsOfUser: JobsOfUser;
27 50633 myrto.kouk
  jobs: StoredJob[];
28 50364 myrto.kouk
29 50469 myrto.kouk
  itemsPerPage: number;
30 50579 myrto.kouk
  currentPage: number;
31 50765 myrto.kouk
  currentTotalJobs: number;
32 50469 myrto.kouk
  totalPages: number;
33 50579 myrto.kouk
  currentFilter: string;
34 50592 myrto.kouk
  chosenJobType: string;
35 50469 myrto.kouk
36 50592 myrto.kouk
  constructor(private authService: AuthenticationService,
37 50633 myrto.kouk
              private monitorService: MonitorService,
38
              private valService: ValidatorService) {}
39 50364 myrto.kouk
40
  ngOnInit() {
41 50579 myrto.kouk
    this.loadTable();
42
  }
43
44
  loadTable() {
45 50672 myrto.kouk
    //initialize
46 50706 myrto.kouk
    this.userEmail = this.authService.getUserEmail();
47 50672 myrto.kouk
    this.jobTypes = jobTypes;
48
    this.itemsPerPage = 10;
49 50936 myrto.kouk
    this.currentPage = 0;
50 50672 myrto.kouk
    this.currentFilter = 'all';
51 50685 myrto.kouk
    this.chosenJobType = '';
52 50672 myrto.kouk
53 50579 myrto.kouk
    //call API and get all jobs:
54 50672 myrto.kouk
    this.getJobs();
55 50364 myrto.kouk
  }
56 50469 myrto.kouk
57 50579 myrto.kouk
58 50685 myrto.kouk
  getJobType(type: string) {
59
    this.chosenJobType = type;
60 50936 myrto.kouk
    this.currentPage = 0;
61 50685 myrto.kouk
    this.getJobs();
62
  }
63
64 50579 myrto.kouk
  filterJobs(filter: string){
65
    this.currentFilter = filter;
66 50936 myrto.kouk
    this.currentPage = 0;
67 50579 myrto.kouk
    console.log(`requesting ${this.currentFilter} jobs`);
68 50672 myrto.kouk
    this.getJobs();
69 50579 myrto.kouk
  }
70
71 50469 myrto.kouk
  getItemsPerPage(num: number){
72
    this.itemsPerPage = num;
73 50936 myrto.kouk
    this.currentPage = 0;
74 50672 myrto.kouk
    this.getJobs();
75 50469 myrto.kouk
  }
76 50579 myrto.kouk
77
  goToNextPage(){
78 51870 myrto.kouk
    if( (this.currentPage+1) < this.totalPages) {
79 50672 myrto.kouk
      this.currentPage++;
80
      console.log(`Get me page ${this.currentPage}!`);
81
      this.getJobs();
82 50579 myrto.kouk
    }
83
  }
84
85
  goToPreviousPage(){
86 50936 myrto.kouk
    if(this.currentPage > 0) {
87 50672 myrto.kouk
      this.currentPage--;
88
      console.log(`Get me page ${this.currentPage}!`);
89
      this.getJobs();
90 50579 myrto.kouk
    }
91
  }
92
93 51118 myrto.kouk
94 50633 myrto.kouk
  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 50672 myrto.kouk
111 50592 myrto.kouk
  getJobs() {
112 50672 myrto.kouk
    this.loadingMessage = loadingUserJobs;
113
    this.errorMessage = '';
114
    this.infoMessage = '';
115
    this.successMessage = '';
116
    this.failureMessage = '';
117 50936 myrto.kouk
    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 51015 myrto.kouk
    params.push({key: 'offset', value: [( (this.currentPage)*this.itemsPerPage).toString()]});
123 50936 myrto.kouk
    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 51118 myrto.kouk
        this.loadingMessage = '';
132 51359 myrto.kouk
        this.jobsOfUser = null;
133 50936 myrto.kouk
        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 50672 myrto.kouk
        }
145 50936 myrto.kouk
        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 50672 myrto.kouk
  }
154
155 51320 myrto.kouk
  getResultImage(status: string) {
156
    if (status == 'ongoing') {
157 50765 myrto.kouk
      return `../../../assets/imgs/icon_colours-question.jpg`;
158 51320 myrto.kouk
    } else if (status == 'successful') {
159
        return `../../../assets/imgs/icon_colours-check.jpg`;
160 50672 myrto.kouk
    } else {
161 51320 myrto.kouk
      return `../../../assets/imgs/icon_colours-x.jpg`;
162 50672 myrto.kouk
    }
163
  }
164
165 52780 myrto.kouk
  resubmitJob (id: string, email: string) {
166
    this.valService.reSubmitJobForValidation(id, email).subscribe(
167 50672 myrto.kouk
      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 50592 myrto.kouk
    );
173 50765 myrto.kouk
    this.getJobs();
174 50592 myrto.kouk
  }
175
176 50364 myrto.kouk
}