-
Notifications
You must be signed in to change notification settings - Fork 118
/
runtime-app.component.ts
111 lines (102 loc) · 2.97 KB
/
runtime-app.component.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
110
111
import { Component } from '@angular/core';
import { RuntimeApp } from '../model/runtime-app';
import { Observable, of } from 'rxjs';
import { BsModalRef } from 'ngx-bootstrap';
import { GrafanaService } from '../../shared/grafana/grafana.service';
import { map } from 'rxjs/operators';
import { RuntimeAppInstance } from '../model/runtime-app-instance';
import { NotificationService } from '../../shared/services/notification.service';
/**
* Component that display a Runtime application.
*
* @author Ilayaperumal Gopinathan
* @author Vitrac Damien
*/
@Component({
selector: 'app-runtime-app',
styleUrls: ['./styles.scss'],
templateUrl: './runtime-app.component.html',
})
export class RuntimeAppComponent {
/**
* Observable of Runtime Application
*/
runtimeApp$: Observable<RuntimeApp>;
/**
* Featured Info
*/
grafanaEnabled = false;
/**
* Constructor
*
* @param modalRef
* @param notificationService
* @param grafanaService
*/
constructor(private modalRef: BsModalRef,
private notificationService: NotificationService,
private grafanaService: GrafanaService) {
}
/**
* Set the runtime application
*
* @param {RuntimeApp} runtimeApp
*/
open(runtimeApp: RuntimeApp) {
this.runtimeApp$ = this.grafanaService.isAllowed()
.pipe(
map((active) => {
this.grafanaEnabled = active;
console.log(runtimeApp);
return runtimeApp;
})
);
}
/**
* Hide the modal
*/
cancel() {
this.modalRef.hide();
}
/**
* Open the grafana dashboard application
*/
grafanaDashboard(runtimeApp: RuntimeApp): void {
let appName = '';
let streamName = '';
if (runtimeApp.appInstances && runtimeApp.appInstances.length > 0) {
const firstInstance: RuntimeAppInstance = runtimeApp.appInstances[0];
if (firstInstance.attributes) {
appName = firstInstance.attributes['skipper.application.name'];
streamName = firstInstance.attributes['skipper.release.name'];
}
}
if (streamName && appName) {
this.grafanaService.getDashboardApplication(streamName, appName).subscribe((url: string) => {
window.open(url);
});
} else {
this.notificationService.error('Sorry, we can\' open this grafana dashboard');
}
}
/**
* Open the grafana dashboard application
*/
grafanaInstanceDashboard(instance: RuntimeAppInstance): void {
let appName = '';
let streamName = '';
let guid = '';
if (instance.attributes) {
appName = instance.attributes['skipper.application.name'];
streamName = instance.attributes['skipper.release.name'];
guid = instance.attributes['guid'];
}
if (streamName && appName && guid) {
this.grafanaService.getDashboardApplicationInstance(streamName, appName, guid).subscribe((url: string) => {
window.open(url);
});
} else {
this.notificationService.error('Sorry, we can\' open this grafana dashboard');
}
}
}