-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
utils.ts
87 lines (78 loc) · 2.57 KB
/
utils.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
import {Observable} from 'rxjs';
import * as models from '../../models';
import {NODE_PHASE} from '../../models';
export const Utils = {
statusIconClasses(status: string): string {
let classes = [];
switch (status) {
case NODE_PHASE.ERROR:
case NODE_PHASE.FAILED:
classes = ['fa-times-circle', 'status-icon--failed'];
break;
case NODE_PHASE.SUCCEEDED:
classes = ['fa-check-circle', 'status-icon--success'];
break;
case NODE_PHASE.RUNNING:
classes = ['fa-circle-notch', 'status-icon--running', 'status-icon--spin'];
break;
case NODE_PHASE.PENDING:
classes = ['fa-clock', 'status-icon--pending', 'status-icon--slow-spin'];
break;
default:
classes = ['fa-clock', 'status-icon--init'];
break;
}
return classes.join(' ');
},
shortNodeName(node: {name: string; displayName: string}): string {
return node.displayName || node.name;
},
toObservable<T>(val: T | Observable<T> | Promise<T>): Observable<T> {
const observable = val as Observable<T>;
if (observable && observable.subscribe && observable.catch) {
return observable as Observable<T>;
}
return Observable.from([val as T]);
},
tryJsonParse(input: string) {
try {
return (input && JSON.parse(input)) || null;
} catch {
return null;
}
},
isWorkflowSuspended(wf: models.Workflow): boolean {
if (!wf || !wf.spec) {
return false;
}
if (wf.spec.suspend !== undefined && wf.spec.suspend) {
return true;
}
if (wf.status && wf.status.nodes) {
for (const node of Object.values(wf.status.nodes)) {
if (node.type === 'Suspend' && node.phase === 'Running') {
return true;
}
}
}
return false;
},
isWorkflowRunning(wf: models.Workflow): boolean {
if (!wf || !wf.spec) {
return false;
}
return wf.status.phase === 'Running';
},
onNamespaceChange(value: string) {
// noop
},
setCurrentNamespace(value: string): void {
if (value) {
localStorage.setItem('current_namespace', value);
this.onNamespaceChange(value);
}
},
getCurrentNamespace(): string {
return localStorage.getItem('current_namespace');
}
};