mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Began work on improving structure and organization of components under features/dashboard, #14062
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import coreModule from 'app/core/core_module';
|
||||
import appEvents from 'app/core/app_events';
|
||||
|
||||
export class MoveToFolderCtrl {
|
||||
dashboards: any;
|
||||
folder: any;
|
||||
dismiss: any;
|
||||
afterSave: any;
|
||||
isValidFolderSelection = true;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private backendSrv) {}
|
||||
|
||||
onFolderChange(folder) {
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
save() {
|
||||
return this.backendSrv.moveDashboards(this.dashboards, this.folder).then(result => {
|
||||
if (result.successCount > 0) {
|
||||
const header = `Dashboard${result.successCount === 1 ? '' : 's'} Moved`;
|
||||
const msg = `${result.successCount} dashboard${result.successCount === 1 ? '' : 's'} moved to ${
|
||||
this.folder.title
|
||||
}`;
|
||||
appEvents.emit('alert-success', [header, msg]);
|
||||
}
|
||||
|
||||
if (result.totalCount === result.alreadyInFolderCount) {
|
||||
appEvents.emit('alert-error', ['Error', `Dashboards already belongs to folder ${this.folder.title}`]);
|
||||
}
|
||||
|
||||
this.dismiss();
|
||||
return this.afterSave();
|
||||
});
|
||||
}
|
||||
|
||||
onEnterFolderCreation() {
|
||||
this.isValidFolderSelection = false;
|
||||
}
|
||||
|
||||
onExitFolderCreation() {
|
||||
this.isValidFolderSelection = true;
|
||||
}
|
||||
}
|
||||
|
||||
export function moveToFolderModal() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'public/app/features/manage-dashboards/components/MoveToFolderModal/template.html',
|
||||
controller: MoveToFolderCtrl,
|
||||
bindToController: true,
|
||||
controllerAs: 'ctrl',
|
||||
scope: {
|
||||
dismiss: '&',
|
||||
dashboards: '=',
|
||||
afterSave: '&',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
coreModule.directive('moveToFolderModal', moveToFolderModal);
|
||||
@@ -0,0 +1 @@
|
||||
export { MoveToFolderCtrl } from './MoveToFolderCtrl';
|
||||
@@ -0,0 +1,33 @@
|
||||
<div class="modal-body">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-header-title">
|
||||
<i class="gicon gicon-folder-new"></i>
|
||||
<span class="p-l-1">Choose Dashboard Folder</span>
|
||||
</h2>
|
||||
|
||||
<a class="modal-header-close" ng-click="ctrl.dismiss();">
|
||||
<i class="fa fa-remove"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<form name="ctrl.saveForm" ng-submit="ctrl.save()" class="modal-content folder-modal" novalidate>
|
||||
<p>Move the {{ctrl.dashboards.length}} selected dashboards to the following folder:</p>
|
||||
|
||||
<div class="p-t-2">
|
||||
<div class="gf-form">
|
||||
<folder-picker
|
||||
on-load="ctrl.onFolderChange($folder)"
|
||||
on-change="ctrl.onFolderChange($folder)"
|
||||
enter-folder-creation="ctrl.onEnterFolderCreation()"
|
||||
exit-folder-creation="ctrl.onExitFolderCreation()"
|
||||
enable-create-new="true"
|
||||
label-class="width-7">
|
||||
</folder-picker>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gf-form-button-row text-center">
|
||||
<button type="submit" class="btn btn-success" ng-disabled="ctrl.saveForm.$invalid || !ctrl.isValidFolderSelection">Move</button>
|
||||
<a class="btn-text" ng-click="ctrl.dismiss();">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user