Skip to content

Commit e73e189

Browse files
committed
Merge branch 'export_dashboard_guidence' of https://github.com/bergquist/grafana into bergquist-export_dashboard_guidence
2 parents 454d74a + 7bde98a commit e73e189

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

public/app/features/dashboard/export/export_modal.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@
1515
You can share dashboards on <a class="external-link" href="https://grafana.com">Grafana.com</a>
1616
</p>
1717

18+
<gf-form-switch
19+
class="gf-form"
20+
label="Export for sharing externally"
21+
label-class="width-16"
22+
checked="ctrl.shareExternally"
23+
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.">
24+
</gf-form-switch>
25+
1826
<div class="gf-form-button-row">
19-
<button type="button" class="btn gf-form-btn width-10 btn-success" ng-click="ctrl.save()">
27+
<button type="button" class="btn gf-form-btn width-10 btn-success" ng-click="ctrl.saveDashboardAsFile()">
2028
<i class="fa fa-save"></i> Save to file
2129
</button>
22-
<button type="button" class="btn gf-form-btn width-10 btn-secondary" ng-click="ctrl.saveJson()">
30+
<button type="button" class="btn gf-form-btn width-10 btn-secondary" ng-click="ctrl.viewJson()">
2331
<i class="fa fa-file-text-o"></i> View JSON
2432
</button>
2533
<a class="btn btn-link" ng-click="ctrl.dismiss()">Cancel</a>

public/app/features/dashboard/export/export_modal.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,47 @@ export class DashExportCtrl {
88
dash: any;
99
exporter: DashboardExporter;
1010
dismiss: () => void;
11+
shareExternally: boolean;
1112

1213
/** @ngInject */
1314
constructor(private dashboardSrv, datasourceSrv, private $scope, private $rootScope) {
1415
this.exporter = new DashboardExporter(datasourceSrv);
1516

16-
this.exporter.makeExportable(this.dashboardSrv.getCurrent()).then(dash => {
17-
this.$scope.$apply(() => {
18-
this.dash = dash;
17+
this.dash = this.dashboardSrv.getCurrent();
18+
}
19+
20+
saveDashboardAsFile() {
21+
if (this.shareExternally) {
22+
this.exporter.makeExportable(this.dash).then((dashboardJson: any) => {
23+
this.$scope.$apply(() => {
24+
this.openSaveAsDialog(dashboardJson);
25+
});
1926
});
20-
});
27+
} else {
28+
this.openSaveAsDialog(this.dash.getSaveModelClone());
29+
}
30+
}
31+
32+
viewJson() {
33+
if (this.shareExternally) {
34+
this.exporter.makeExportable(this.dash).then((dashboardJson: any) => {
35+
this.$scope.$apply(() => {
36+
this.openJsonModal(dashboardJson);
37+
});
38+
});
39+
} else {
40+
this.openJsonModal(this.dash.getSaveModelClone());
41+
}
2142
}
2243

23-
save() {
24-
const blob = new Blob([angular.toJson(this.dash, true)], {
44+
private openSaveAsDialog(dash: any) {
45+
const blob = new Blob([angular.toJson(dash, true)], {
2546
type: 'application/json;charset=utf-8',
2647
});
27-
saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
48+
saveAs(blob, dash.title + '-' + new Date().getTime() + '.json');
2849
}
2950

30-
saveJson() {
31-
const clone = this.dash;
51+
private openJsonModal(clone: any) {
3252
const editScope = this.$rootScope.$new();
3353
editScope.object = clone;
3454
editScope.enableCopy = true;

0 commit comments

Comments
 (0)