1
|
/*
|
2
|
* Created by myrto on 12/05/2017
|
3
|
*/
|
4
|
|
5
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
6
|
import { Injectable } from '@angular/core';
|
7
|
import { environment } from '../../environments/environment';
|
8
|
import { Observable } from 'rxjs';
|
9
|
import { JobsOfUser, StoredJob } from '../domain/typeScriptClasses';
|
10
|
import { URLParameter } from '../domain/url-parameter';
|
11
|
|
12
|
const headerOptions = {
|
13
|
headers : new HttpHeaders().set('Content-Type', 'application/json')
|
14
|
.set('Accept', 'application/json'),
|
15
|
withCredentials: true
|
16
|
};
|
17
|
|
18
|
@Injectable ()
|
19
|
export class MonitorService {
|
20
|
private apiUrl = environment.API_ENDPOINT + '/monitor/';
|
21
|
|
22
|
constructor(private httpClient: HttpClient) { }
|
23
|
|
24
|
getJobSummary(jobId: string, groupBy: string): Observable<StoredJob> {
|
25
|
const url = `${this.apiUrl}getJobSummary?jobId=${jobId}&groupBy=${groupBy}`;
|
26
|
console.log(`knocking on: ${url}`);
|
27
|
|
28
|
return this.httpClient.get<StoredJob>(url, headerOptions);
|
29
|
}
|
30
|
|
31
|
getJobsOfUser(params: URLParameter[]): Observable<JobsOfUser> {
|
32
|
let url = `${this.apiUrl}getJobsOfUser`;
|
33
|
for (const param of params) {
|
34
|
if (param.key === 'offset') {
|
35
|
url += `?${param.key}=${param.value[0]}`;
|
36
|
} else {
|
37
|
url += `&${param.key}=${param.value[0]}`;
|
38
|
}
|
39
|
}
|
40
|
console.log(`knocking on: ${url}`);
|
41
|
|
42
|
return this.httpClient.get<JobsOfUser>(url, headerOptions);
|
43
|
}
|
44
|
|
45
|
}
|