2018-10-21 17:17:21 -04:00
|
|
|
import { WidgetComponent } from "../widget.component";
|
|
|
|
import { EditableWidget, WIDGET_GRAFANA } from "../../../shared/models/widget";
|
|
|
|
import { Component } from "@angular/core";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "grafana.widget.component.html",
|
|
|
|
styleUrls: ["grafana.widget.component.scss"],
|
|
|
|
})
|
|
|
|
export class GrafanaWidgetConfigComponent extends WidgetComponent {
|
|
|
|
constructor() {
|
|
|
|
super(WIDGET_GRAFANA, "Grafana", "generic-fullscreen", "grafana");
|
|
|
|
}
|
|
|
|
|
2019-03-24 19:27:45 -04:00
|
|
|
protected OnWidgetsDiscovered(widgets: EditableWidget[]) {
|
|
|
|
for (const widget of widgets) {
|
|
|
|
if (widget.data.curl && !widget.data.url) {
|
|
|
|
// Convert legacy Dimension widgets to new source
|
|
|
|
widget.data.url = widget.data.curl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 17:17:21 -04:00
|
|
|
protected OnNewWidgetPrepared(widget: EditableWidget): void {
|
2019-03-24 19:27:45 -04:00
|
|
|
widget.dimension.newData.url = "";
|
2018-10-21 17:17:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeAdd(widget: EditableWidget) {
|
|
|
|
this.setGrafanaUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeEdit(widget: EditableWidget) {
|
|
|
|
this.setGrafanaUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
private setGrafanaUrl(widget: EditableWidget) {
|
2019-03-24 19:27:45 -04:00
|
|
|
if (!widget.dimension.newData.url || widget.dimension.newData.url.trim().length === 0) {
|
2018-10-21 17:17:21 -04:00
|
|
|
throw new Error("Please enter a Grafana URL");
|
|
|
|
}
|
|
|
|
|
2019-03-24 19:27:45 -04:00
|
|
|
if (widget.dimension.newData.url.indexOf("&kiosk") === -1) {
|
|
|
|
widget.dimension.newData.url += "&kiosk";
|
2018-10-21 17:17:21 -04:00
|
|
|
}
|
2019-03-24 19:27:45 -04:00
|
|
|
widget.dimension.newUrl = widget.dimension.newData.url;
|
2018-10-21 17:17:21 -04:00
|
|
|
}
|
|
|
|
}
|