Commit e3f37adb authored by Simone Vuotto's avatar Simone Vuotto

Add Task service and model

parent cef92378
export enum TaskStatus {
SUCCESS = 'SUCCESS',
FAIL = 'FAIL',
RUNNING = 'RUNNING',
}
export class Task {
id: number;
description: string;
projectId: number;
type: string;
status: TaskStatus;
timestamp: string;
log: string;
constructor(task: Task) {
this.id = task.id;
this.description = task.description;
this.projectId = task.projectId;
this.type = task.type;
this.status = task.status;
this.timestamp = task.timestamp;
this.log = task.log;
}
get success(): boolean { return this.status === TaskStatus.SUCCESS; }
get fail(): boolean { return this.status === TaskStatus.FAIL; }
get running(): boolean { return this.status === TaskStatus.RUNNING; }
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Task } from '../models/task';
@Injectable()
export class TaskService {
constructor(private http: HttpClient) { }
public getTasks(projectId: number): Observable<Task[]> {
return this.http.get<Task[]>(this.tasksUrl(projectId));
}
public getTask(projectId: number, taskId: number): Observable<Task> {
return this.http.get<Task>(this.tasksUrl(projectId, taskId.toString()));
}
public getTranslation(projectId: number): Observable<HttpResponse<Blob>> {
const options = {observe: 'response' as 'response', responseType: 'blob' as 'blob'};
return this.http.get(this.tasksUrl(projectId, 'translate'), options);
}
public performConsistencyCheck(projectId: number): Observable<Task> {
return this.http.get<Task>(this.tasksUrl(projectId, 'consistencyCheck'));
}
private tasksUrl(projectId: number, taskName = '') {
const url = 'api/projects/{pid}/tasks/' + taskName;
return url.replace('{pid}', projectId.toString());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment