import coreModule from 'app/core/core_module'; const template = `
`; export class SaveDashboardModalCtrl { message: string; saveVariables = false; saveTimerange = false; time: any; originalTime: any; current = []; originalCurrent = []; max: number; saveForm: any; isSaving: boolean; dismiss: () => void; timeChange = false; variableValueChange = false; /** @ngInject */ constructor(private dashboardSrv) { this.message = ''; this.max = 64; this.isSaving = false; this.timeChange = this.dashboardSrv.getCurrent().hasTimeChanged(); this.variableValueChange = this.dashboardSrv.getCurrent().hasVariableValuesChanged(); } save() { if (!this.saveForm.$valid) { return; } const options = { saveVariables: this.saveVariables, saveTimerange: this.saveTimerange, message: this.message, }; const dashboard = this.dashboardSrv.getCurrent(); const saveModel = dashboard.getSaveModelClone(options); this.isSaving = true; return this.dashboardSrv.save(saveModel, options).then(this.postSave.bind(this, options)); } postSave(options) { if (options.saveVariables) { this.dashboardSrv.getCurrent().resetOriginalVariables(); } if (options.saveTimerange) { this.dashboardSrv.getCurrent().resetOriginalTime(); } this.dismiss(); } } export function saveDashboardModalDirective() { return { restrict: 'E', template: template, controller: SaveDashboardModalCtrl, bindToController: true, controllerAs: 'ctrl', scope: { dismiss: '&' }, }; } coreModule.directive('saveDashboardModal', saveDashboardModalDirective);