2017-12-20 05:33:33 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
2017-06-05 07:56:11 -05:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
const template = `
|
2017-06-05 07:56:11 -05:00
|
|
|
<div class="modal-body">
|
2017-12-26 07:51:41 -06: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 07:56:11 -05:00
|
|
|
|
2017-12-26 07:51:41 -06:00
|
|
|
<a class="modal-header-close" ng-click="ctrl.dismiss();">
|
|
|
|
<i class="fa fa-remove"></i>
|
|
|
|
</a>
|
|
|
|
</div>
|
2017-06-05 07:56:11 -05:00
|
|
|
|
2017-12-26 07:51:41 -06:00
|
|
|
<form name="ctrl.saveForm" ng-submit="ctrl.save()" class="modal-content" novalidate>
|
2018-05-31 08:40:57 -05:00
|
|
|
<div class="p-t-1">
|
2018-06-04 08:35:34 -05:00
|
|
|
<div class="gf-form-group" ng-if="ctrl.timeChange || ctrl.variableValueChange">
|
2018-05-31 08:40:57 -05: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 08:35:34 -05:00
|
|
|
label="Save current variables" ng-if="ctrl.variableValueChange" label-class="width-12" switch-class="max-width-6"
|
2018-05-31 08:40:57 -05:00
|
|
|
checked="ctrl.saveVariables" on-change="buildUrl()">
|
|
|
|
</gf-form-switch>
|
|
|
|
</div>
|
2017-12-26 07:51:41 -06:00
|
|
|
<div class="gf-form">
|
|
|
|
<label class="gf-form-hint">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="message"
|
|
|
|
class="gf-form-input"
|
2018-05-31 08:40:57 -05:00
|
|
|
placeholder="Add a note to describe your changes …"
|
2017-12-26 07:51:41 -06:00
|
|
|
give-focus="true"
|
|
|
|
ng-model="ctrl.message"
|
|
|
|
ng-model-options="{allowInvalid: true}"
|
|
|
|
ng-maxlength="this.max"
|
2018-05-31 08:40:57 -05:00
|
|
|
maxlength="64"
|
2017-12-26 07:51:41 -06: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 07:56:11 -05:00
|
|
|
|
2017-12-26 07:51:41 -06:00
|
|
|
<div class="gf-form-button-row text-center">
|
2018-06-12 04:54:50 -05:00
|
|
|
<button
|
|
|
|
id="saveBtn"
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-success"
|
|
|
|
ng-class="{'btn-success--processing': ctrl.isSaving}"
|
|
|
|
ng-disabled="ctrl.saveForm.$invalid || ctrl.isSaving"
|
|
|
|
>
|
|
|
|
<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 07:51:41 -06:00
|
|
|
</div>
|
|
|
|
</form>
|
2017-06-05 07:56:11 -05:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
export class SaveDashboardModalCtrl {
|
|
|
|
message: string;
|
2018-05-31 08:40:57 -05:00
|
|
|
saveVariables = false;
|
|
|
|
saveTimerange = false;
|
|
|
|
time: any;
|
|
|
|
originalTime: any;
|
|
|
|
current = [];
|
|
|
|
originalCurrent = [];
|
2017-06-05 07:56:11 -05:00
|
|
|
max: number;
|
|
|
|
saveForm: any;
|
2018-06-12 04:54:50 -05:00
|
|
|
isSaving: boolean;
|
2017-06-05 07:56:11 -05:00
|
|
|
dismiss: () => void;
|
2018-05-31 08:40:57 -05:00
|
|
|
timeChange = false;
|
2018-06-04 08:35:34 -05:00
|
|
|
variableValueChange = false;
|
2017-06-05 07:56:11 -05:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-09-21 09:40:18 -05:00
|
|
|
constructor(private dashboardSrv) {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.message = '';
|
2017-06-05 07:56:11 -05:00
|
|
|
this.max = 64;
|
2018-06-12 04:54:50 -05:00
|
|
|
this.isSaving = false;
|
2018-06-19 17:08:52 -05:00
|
|
|
this.timeChange = this.dashboardSrv.getCurrent().hasTimeChanged();
|
|
|
|
this.variableValueChange = this.dashboardSrv.getCurrent().hasVariableValuesChanged();
|
2017-06-05 07:56:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
if (!this.saveForm.$valid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-26 14:52:57 -05:00
|
|
|
const options = {
|
2018-05-31 08:40:57 -05:00
|
|
|
saveVariables: this.saveVariables,
|
|
|
|
saveTimerange: this.saveTimerange,
|
|
|
|
message: this.message,
|
|
|
|
};
|
|
|
|
|
2018-08-26 14:52:57 -05:00
|
|
|
const dashboard = this.dashboardSrv.getCurrent();
|
|
|
|
const saveModel = dashboard.getSaveModelClone(options);
|
2017-06-05 07:56:11 -05:00
|
|
|
|
2018-06-12 04:54:50 -05:00
|
|
|
this.isSaving = true;
|
|
|
|
|
2018-06-19 17:08:52 -05:00
|
|
|
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();
|
2017-06-05 07:56:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function saveDashboardModalDirective() {
|
|
|
|
return {
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'E',
|
2017-06-05 07:56:11 -05:00
|
|
|
template: template,
|
|
|
|
controller: SaveDashboardModalCtrl,
|
|
|
|
bindToController: true,
|
2017-12-20 05:33:33 -06:00
|
|
|
controllerAs: 'ctrl',
|
|
|
|
scope: { dismiss: '&' },
|
2017-06-05 07:56:11 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('saveDashboardModal', saveDashboardModalDirective);
|