-
-
Notifications
You must be signed in to change notification settings - Fork 225
/
job.octoprint.service.ts
109 lines (95 loc) · 2.95 KB
/
job.octoprint.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { catchError } from 'rxjs/operators';
import { ConfigService } from '../../config/config.service';
import { JobCommand } from '../../model/octoprint';
import { NotificationService } from '../../notification/notification.service';
import { JobService } from './job.service';
@Injectable()
export class JobOctoprintService implements JobService {
public constructor(
private configService: ConfigService,
private notificationService: NotificationService,
private http: HttpClient,
) {}
startJob(): void {
const payload: JobCommand = {
command: 'start',
};
this.http
.post(this.configService.getApiURL('job'), payload, this.configService.getHTTPHeaders())
.pipe(
catchError(error =>
this.notificationService.setError($localize`:@@error-start-job:Can't start job!`, error.message),
),
)
.subscribe();
}
pauseJob(): void {
const payload: JobCommand = {
command: 'pause',
action: 'pause',
};
this.http
.post(this.configService.getApiURL('job'), payload, this.configService.getHTTPHeaders())
.pipe(
catchError(error =>
this.notificationService.setError($localize`:@@error-pause-job:Can't pause job!`, error.message),
),
)
.subscribe();
}
resumeJob(): void {
const payload: JobCommand = {
command: 'pause',
action: 'resume',
};
this.http
.post(this.configService.getApiURL('job'), payload, this.configService.getHTTPHeaders())
.pipe(
catchError(error =>
this.notificationService.setError($localize`:@@error-resume-job:Can't resume job!`, error.message),
),
)
.subscribe();
}
cancelJob(): void {
const payload: JobCommand = {
command: 'cancel',
};
this.http
.post(this.configService.getApiURL('job'), payload, this.configService.getHTTPHeaders())
.pipe(
catchError(error =>
this.notificationService.setError($localize`:@@error-cancel-job:Can't cancel job!`, error.message),
),
)
.subscribe();
}
restartJob(): void {
const payload: JobCommand = {
command: 'restart',
};
this.http
.post(this.configService.getApiURL('job'), payload, this.configService.getHTTPHeaders())
.pipe(
catchError(error =>
this.notificationService.setError($localize`:@@error-restart-job:Can't restart job!`, error.message),
),
)
.subscribe();
}
preheat(): void {
const payload: JobCommand = {
command: 'preheat',
};
this.http
.post(this.configService.getApiURL('plugin/preheat'), payload, this.configService.getHTTPHeaders())
.pipe(
catchError(error =>
this.notificationService.setError($localize`:@@error-preheat:Can't preheat printer!`, error.message),
),
)
.subscribe();
}
}