Commit 17adb58d by bergquist

export: provide more help regarding export format

this will provide the user with more info about
the export format and default to not use the format
for sharing on grafana.com etc.

ref #13781
parent 26cbc6be
...@@ -15,11 +15,19 @@ ...@@ -15,11 +15,19 @@
You can share dashboards on <a class="external-link" href="https://grafana.com">Grafana.com</a> You can share dashboards on <a class="external-link" href="https://grafana.com">Grafana.com</a>
</p> </p>
<gf-form-switch
class="gf-form"
label="Export for sharing externally"
label-class="width-16"
checked="ctrl.shareExternally"
tooltip="Useful for sharing dashboard publicly on grafana.com. Will templatize data source names. Can then only be used with the specific dashboard import API.">
</gf-form-switch>
<div class="gf-form-button-row"> <div class="gf-form-button-row">
<button type="button" class="btn gf-form-btn width-10 btn-success" ng-click="ctrl.save()"> <button type="button" class="btn gf-form-btn width-10 btn-success" ng-click="ctrl.saveDashboardAsFile()">
<i class="fa fa-save"></i> Save to file <i class="fa fa-save"></i> Save to file
</button> </button>
<button type="button" class="btn gf-form-btn width-10 btn-secondary" ng-click="ctrl.saveJson()"> <button type="button" class="btn gf-form-btn width-10 btn-secondary" ng-click="ctrl.viewJson()">
<i class="fa fa-file-text-o"></i> View JSON <i class="fa fa-file-text-o"></i> View JSON
</button> </button>
<a class="btn btn-link" ng-click="ctrl.dismiss()">Cancel</a> <a class="btn btn-link" ng-click="ctrl.dismiss()">Cancel</a>
......
...@@ -8,27 +8,47 @@ export class DashExportCtrl { ...@@ -8,27 +8,47 @@ export class DashExportCtrl {
dash: any; dash: any;
exporter: DashboardExporter; exporter: DashboardExporter;
dismiss: () => void; dismiss: () => void;
shareExternally: boolean;
/** @ngInject */ /** @ngInject */
constructor(private dashboardSrv, datasourceSrv, private $scope, private $rootScope) { constructor(private dashboardSrv, datasourceSrv, private $scope, private $rootScope) {
this.exporter = new DashboardExporter(datasourceSrv); this.exporter = new DashboardExporter(datasourceSrv);
this.exporter.makeExportable(this.dashboardSrv.getCurrent()).then(dash => { this.dash = this.dashboardSrv.getCurrent();
this.$scope.$apply(() => { }
this.dash = dash;
saveDashboardAsFile() {
if (this.shareExternally) {
this.exporter.makeExportable(this.dash).then((dashboardJson: any) => {
this.$scope.$apply(() => {
this._saveFile(dashboardJson);
});
}); });
}); } else {
this._saveFile(this.dash.getSaveModelClone());
}
}
viewJson() {
if (this.shareExternally) {
this.exporter.makeExportable(this.dash).then((dashboardJson: any) => {
this.$scope.$apply(() => {
this._viewJson(dashboardJson);
});
});
} else {
this._viewJson(this.dash.getSaveModelClone());
}
} }
save() { _saveFile(dash: any) {
const blob = new Blob([angular.toJson(this.dash, true)], { const blob = new Blob([angular.toJson(dash, true)], {
type: 'application/json;charset=utf-8', type: 'application/json;charset=utf-8',
}); });
saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json'); saveAs(blob, dash.title + '-' + new Date().getTime() + '.json');
} }
saveJson() { _viewJson(clone: any) {
const clone = this.dash;
const editScope = this.$rootScope.$new(); const editScope = this.$rootScope.$new();
editScope.object = clone; editScope.object = clone;
editScope.enableCopy = true; editScope.enableCopy = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment