Travis Ralston 2019-03-24 17:27:45 -06:00
parent 3ab0bbbfd2
commit f10abf95e5
3 changed files with 16 additions and 6 deletions

View File

@ -5,7 +5,7 @@
<span class="text-muted">To get a URL, go to Grafana and click "share" on a graph.</span> <span class="text-muted">To get a URL, go to Grafana and click "share" on a graph.</span>
<input type="text" class="form-control" <input type="text" class="form-control"
placeholder="https://example.com/grafana/dashboard/db/example?orgId=1&panelId=1&fullscreen" placeholder="https://example.com/grafana/dashboard/db/example?orgId=1&panelId=1&fullscreen"
[(ngModel)]="widget.dimension.newData.curl" name="widget-url-{{widget.id}}" [(ngModel)]="widget.dimension.newData.url" name="widget-url-{{widget.id}}"
[disabled]="isUpdating"/> [disabled]="isUpdating"/>
</label> </label>
<label class="label-block"> <label class="label-block">

View File

@ -11,8 +11,17 @@ export class GrafanaWidgetConfigComponent extends WidgetComponent {
super(WIDGET_GRAFANA, "Grafana", "generic-fullscreen", "grafana"); super(WIDGET_GRAFANA, "Grafana", "generic-fullscreen", "grafana");
} }
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;
}
}
}
protected OnNewWidgetPrepared(widget: EditableWidget): void { protected OnNewWidgetPrepared(widget: EditableWidget): void {
widget.dimension.newData.curl = ""; widget.dimension.newData.url = "";
} }
protected OnWidgetBeforeAdd(widget: EditableWidget) { protected OnWidgetBeforeAdd(widget: EditableWidget) {
@ -24,13 +33,13 @@ export class GrafanaWidgetConfigComponent extends WidgetComponent {
} }
private setGrafanaUrl(widget: EditableWidget) { private setGrafanaUrl(widget: EditableWidget) {
if (!widget.dimension.newData.curl || widget.dimension.newData.curl.trim().length === 0) { if (!widget.dimension.newData.url || widget.dimension.newData.url.trim().length === 0) {
throw new Error("Please enter a Grafana URL"); throw new Error("Please enter a Grafana URL");
} }
if (widget.dimension.newData.curl.indexOf("&kiosk") === -1) { if (widget.dimension.newData.url.indexOf("&kiosk") === -1) {
widget.dimension.newData.curl += "&kiosk"; widget.dimension.newData.url += "&kiosk";
} }
widget.dimension.newUrl = widget.dimension.newData.curl; widget.dimension.newUrl = widget.dimension.newData.url;
} }
} }

View File

@ -108,6 +108,7 @@ export class WidgetComponent implements OnInit {
// The widget already has an ID and type, we just need to fill in the bits // The widget already has an ID and type, we just need to fill in the bits
widget.name = widget.dimension.newName || this.defaultName; widget.name = widget.dimension.newName || this.defaultName;
widget.data = widget.dimension.newData || {}; widget.data = widget.dimension.newData || {};
widget.data.url = widget.dimension.newUrl;
widget.url = this.wrapUrl(widget.dimension.newUrl, Object.keys(widget.data).map(k => "$" + k)); widget.url = this.wrapUrl(widget.dimension.newUrl, Object.keys(widget.data).map(k => "$" + k));
widget.type = this.widgetTypes[0]; // always set the type to be the latest type widget.type = this.widgetTypes[0]; // always set the type to be the latest type