import angular from 'angular'; import { saveAs } from 'file-saver'; import coreModule from 'app/core/core_module'; const template = ` `; export class SaveProvisionedDashboardModalCtrl { dash: any; dashboardJson: string; dismiss: () => void; /** @ngInject */ constructor(dashboardSrv) { this.dash = dashboardSrv.getCurrent().getSaveModelClone(); delete this.dash.id; this.dashboardJson = angular.toJson(this.dash, true); } save() { var blob = new Blob([angular.toJson(this.dash, true)], { type: 'application/json;charset=utf-8', }); saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json'); } getJsonForClipboard() { return this.dashboardJson; } } export function saveProvisionedDashboardModalDirective() { return { restrict: 'E', template: template, controller: SaveProvisionedDashboardModalCtrl, bindToController: true, controllerAs: 'ctrl', scope: { dismiss: '&' }, }; } coreModule.directive('saveProvisionedDashboardModal', saveProvisionedDashboardModalDirective);