2019-12-09 00:14:25 -08:00
|
|
|
import { e2e } from '@grafana/e2e';
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
import coreModule from 'app/core/core_module';
|
2019-07-30 15:49:32 +02:00
|
|
|
import { DashboardSrv } from '../../services/DashboardSrv';
|
2019-09-05 13:44:37 +01:00
|
|
|
import { CloneOptions } from '../../state/DashboardModel';
|
2017-06-05 14:56:11 +02:00
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
const template = `
|
2017-06-05 14:56:11 +02:00
|
|
|
<div class="modal-body">
|
2017-12-26 16:51:41 +03:00
|
|
|
<div class="modal-header">
|
|
|
|
|
<h2 class="modal-header-title">
|
|
|
|
|
<i class="fa fa-save"></i>
|
|
|
|
|
<span class="p-l-1">Save changes</span>
|
|
|
|
|
</h2>
|
2017-06-05 14:56:11 +02:00
|
|
|
|
2017-12-26 16:51:41 +03:00
|
|
|
<a class="modal-header-close" ng-click="ctrl.dismiss();">
|
|
|
|
|
<i class="fa fa-remove"></i>
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
2017-06-05 14:56:11 +02:00
|
|
|
|
2017-12-26 16:51:41 +03:00
|
|
|
<form name="ctrl.saveForm" ng-submit="ctrl.save()" class="modal-content" novalidate>
|
2018-05-31 15:40:57 +02:00
|
|
|
<div class="p-t-1">
|
2018-06-04 15:35:34 +02:00
|
|
|
<div class="gf-form-group" ng-if="ctrl.timeChange || ctrl.variableValueChange">
|
2018-05-31 15:40:57 +02:00
|
|
|
<gf-form-switch class="gf-form"
|
|
|
|
|
label="Save current time range" ng-if="ctrl.timeChange" label-class="width-12" switch-class="max-width-6"
|
|
|
|
|
checked="ctrl.saveTimerange" on-change="buildUrl()">
|
|
|
|
|
</gf-form-switch>
|
|
|
|
|
<gf-form-switch class="gf-form"
|
2018-06-04 15:35:34 +02:00
|
|
|
label="Save current variables" ng-if="ctrl.variableValueChange" label-class="width-12" switch-class="max-width-6"
|
2018-05-31 15:40:57 +02:00
|
|
|
checked="ctrl.saveVariables" on-change="buildUrl()">
|
|
|
|
|
</gf-form-switch>
|
|
|
|
|
</div>
|
2017-12-26 16:51:41 +03:00
|
|
|
<div class="gf-form">
|
|
|
|
|
<label class="gf-form-hint">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="message"
|
|
|
|
|
class="gf-form-input"
|
2018-05-31 15:40:57 +02:00
|
|
|
placeholder="Add a note to describe your changes …"
|
2017-12-26 16:51:41 +03:00
|
|
|
give-focus="true"
|
|
|
|
|
ng-model="ctrl.message"
|
|
|
|
|
ng-model-options="{allowInvalid: true}"
|
|
|
|
|
ng-maxlength="this.max"
|
2018-05-31 15:40:57 +02:00
|
|
|
maxlength="64"
|
2017-12-26 16:51:41 +03:00
|
|
|
autocomplete="off" />
|
|
|
|
|
<small class="gf-form-hint-text muted" ng-cloak>
|
|
|
|
|
<span ng-class="{'text-error': ctrl.saveForm.message.$invalid && ctrl.saveForm.message.$dirty }">
|
|
|
|
|
{{ctrl.message.length || 0}}
|
|
|
|
|
</span>
|
|
|
|
|
/ {{ctrl.max}} characters
|
|
|
|
|
</small>
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2017-06-05 14:56:11 +02:00
|
|
|
|
2017-12-26 16:51:41 +03:00
|
|
|
<div class="gf-form-button-row text-center">
|
2018-06-12 11:54:50 +02:00
|
|
|
<button
|
|
|
|
|
id="saveBtn"
|
|
|
|
|
type="submit"
|
2019-02-05 12:05:02 +01:00
|
|
|
class="btn btn-primary"
|
|
|
|
|
ng-class="{'btn-primary--processing': ctrl.isSaving}"
|
2018-06-12 11:54:50 +02:00
|
|
|
ng-disabled="ctrl.saveForm.$invalid || ctrl.isSaving"
|
2019-12-09 00:14:25 -08:00
|
|
|
aria-label={{ctrl.selectors.save}}
|
2018-06-12 11:54:50 +02:00
|
|
|
>
|
|
|
|
|
<span ng-if="!ctrl.isSaving">Save</span>
|
|
|
|
|
<span ng-if="ctrl.isSaving === true">Saving...</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button class="btn btn-inverse" ng-click="ctrl.dismiss();">Cancel</button>
|
2017-12-26 16:51:41 +03:00
|
|
|
</div>
|
|
|
|
|
</form>
|
2017-06-05 14:56:11 +02:00
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export class SaveDashboardModalCtrl {
|
|
|
|
|
message: string;
|
2018-05-31 15:40:57 +02:00
|
|
|
saveVariables = false;
|
|
|
|
|
saveTimerange = false;
|
|
|
|
|
time: any;
|
|
|
|
|
originalTime: any;
|
2019-07-30 15:49:32 +02:00
|
|
|
current: any[] = [];
|
|
|
|
|
originalCurrent: any[] = [];
|
2017-06-05 14:56:11 +02:00
|
|
|
max: number;
|
|
|
|
|
saveForm: any;
|
2018-06-12 11:54:50 +02:00
|
|
|
isSaving: boolean;
|
2017-06-05 14:56:11 +02:00
|
|
|
dismiss: () => void;
|
2018-05-31 15:40:57 +02:00
|
|
|
timeChange = false;
|
2018-06-04 15:35:34 +02:00
|
|
|
variableValueChange = false;
|
2019-12-09 00:14:25 -08:00
|
|
|
selectors: typeof e2e.pages.SaveDashboardModal.selectors;
|
2017-06-05 14:56:11 +02:00
|
|
|
|
|
|
|
|
/** @ngInject */
|
2019-07-30 15:49:32 +02:00
|
|
|
constructor(private dashboardSrv: DashboardSrv) {
|
2017-12-20 12:33:33 +01:00
|
|
|
this.message = '';
|
2017-06-05 14:56:11 +02:00
|
|
|
this.max = 64;
|
2018-06-12 11:54:50 +02:00
|
|
|
this.isSaving = false;
|
2018-06-20 00:08:52 +02:00
|
|
|
this.timeChange = this.dashboardSrv.getCurrent().hasTimeChanged();
|
|
|
|
|
this.variableValueChange = this.dashboardSrv.getCurrent().hasVariableValuesChanged();
|
2019-12-09 00:14:25 -08:00
|
|
|
this.selectors = e2e.pages.SaveDashboardModal.selectors;
|
2017-06-05 14:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-21 09:08:07 +00:00
|
|
|
save(): void | Promise<any> {
|
2017-06-05 14:56:11 +02:00
|
|
|
if (!this.saveForm.$valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 13:44:37 +01:00
|
|
|
const options: CloneOptions = {
|
2018-05-31 15:40:57 +02:00
|
|
|
saveVariables: this.saveVariables,
|
|
|
|
|
saveTimerange: this.saveTimerange,
|
|
|
|
|
message: this.message,
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-26 21:52:57 +02:00
|
|
|
const dashboard = this.dashboardSrv.getCurrent();
|
|
|
|
|
const saveModel = dashboard.getSaveModelClone(options);
|
2017-06-05 14:56:11 +02:00
|
|
|
|
2018-06-12 11:54:50 +02:00
|
|
|
this.isSaving = true;
|
2018-06-20 00:08:52 +02:00
|
|
|
return this.dashboardSrv.save(saveModel, options).then(this.postSave.bind(this, options));
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-05 13:44:37 +01:00
|
|
|
postSave(options?: { saveVariables?: boolean; saveTimerange?: boolean }) {
|
2018-06-20 00:08:52 +02:00
|
|
|
if (options.saveVariables) {
|
|
|
|
|
this.dashboardSrv.getCurrent().resetOriginalVariables();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.saveTimerange) {
|
|
|
|
|
this.dashboardSrv.getCurrent().resetOriginalTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.dismiss();
|
2017-06-05 14:56:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function saveDashboardModalDirective() {
|
|
|
|
|
return {
|
2017-12-20 12:33:33 +01:00
|
|
|
restrict: 'E',
|
2017-06-05 14:56:11 +02:00
|
|
|
template: template,
|
|
|
|
|
controller: SaveDashboardModalCtrl,
|
|
|
|
|
bindToController: true,
|
2017-12-20 12:33:33 +01:00
|
|
|
controllerAs: 'ctrl',
|
|
|
|
|
scope: { dismiss: '&' },
|
2017-06-05 14:56:11 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
coreModule.directive('saveDashboardModal', saveDashboardModalDirective);
|