From 1e865211c9238e13f5cc7f59b776e9a8c5fd51b7 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Fri, 26 May 2017 17:17:04 +0200 Subject: [PATCH] WIP: Create new dashboard button in dash search --- public/app/core/components/search/search.html | 12 +++-- public/app/core/components/search/search.ts | 7 +++ public/app/core/services/backend_srv.ts | 8 ++++ public/app/features/dashboard/acl/acl.ts | 4 -- public/app/features/dashboard/all.js | 1 + .../app/features/dashboard/dashnav/dashnav.ts | 9 ---- .../dashboard/folder_modal/folder.html | 24 ++++++++++ .../features/dashboard/folder_modal/folder.ts | 45 +++++++++++++++++++ 8 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 public/app/features/dashboard/folder_modal/folder.html create mode 100644 public/app/features/dashboard/folder_modal/folder.ts diff --git a/public/app/core/components/search/search.html b/public/app/core/components/search/search.html index 671f8834ef6..40b4640978c 100644 --- a/public/app/core/components/search/search.html +++ b/public/app/core/components/search/search.html @@ -94,9 +94,15 @@   New Dashboard - -   Import Dashboard - + + + Create New Folder + + + + + >  Import Dashboard + Find dashboards on Grafana.com diff --git a/public/app/core/components/search/search.ts b/public/app/core/components/search/search.ts index f6810f2bc76..dcbf0991f3d 100644 --- a/public/app/core/components/search/search.ts +++ b/public/app/core/components/search/search.ts @@ -158,6 +158,13 @@ export class SearchCtrl { this.search(); } + showNewFolderModal() { + this.$scope.appEvent('show-modal', { + templateHtml: '', + modalClass: 'modal--narrow' + }); + } + search() { this.showImport = false; this.selectedIndex = 0; diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 54d7c96dac8..b590a5d947a 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -210,6 +210,14 @@ export class BackendSrv { message: options.message || '', }); } + + saveDashboardFolder(name) { + const dash = { + title: name + }; + + return this.post('/api/dashboards/db/', {dashboard: dash, isFolder: true, overwrite: false}); + } } coreModule.service('backendSrv', BackendSrv); diff --git a/public/app/features/dashboard/acl/acl.ts b/public/app/features/dashboard/acl/acl.ts index 9c0ab8f5a79..496d48d010a 100644 --- a/public/app/features/dashboard/acl/acl.ts +++ b/public/app/features/dashboard/acl/acl.ts @@ -37,10 +37,6 @@ export class AclCtrl { this.get(permission.dashboardId); }); } - - dismiss() { - appEvents.emit('hide-modal'); - } } export function aclSettings() { diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index addc9837b18..bed97809d14 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -26,4 +26,5 @@ define([ './repeat_option/repeat_option', './acl/acl', './folder_picker/picker', + './folder_modal/folder' ], function () {}); diff --git a/public/app/features/dashboard/dashnav/dashnav.ts b/public/app/features/dashboard/dashnav/dashnav.ts index 5f51cf9d66e..e77c2bb3e09 100644 --- a/public/app/features/dashboard/dashnav/dashnav.ts +++ b/public/app/features/dashboard/dashnav/dashnav.ts @@ -47,15 +47,6 @@ export class DashNavCtrl { appEvents.emit('show-modal', {templateHtml: ''}); } - // $scope.showAclModal = function() { - // var modalScope = $scope.$new(); - // modalScope.dashboardId = $scope.dashboard.id; - // $scope.appEvent('show-modal', { - // templateHtml: '', - // scope: modalScope - // }); - // }; - starDashboard() { if (this.dashboard.meta.isStarred) { return this.backendSrv.delete('/api/user/stars/dashboard/' + this.dashboard.id).then(() => { diff --git a/public/app/features/dashboard/folder_modal/folder.html b/public/app/features/dashboard/folder_modal/folder.html new file mode 100644 index 00000000000..5ca67fab2ef --- /dev/null +++ b/public/app/features/dashboard/folder_modal/folder.html @@ -0,0 +1,24 @@ + diff --git a/public/app/features/dashboard/folder_modal/folder.ts b/public/app/features/dashboard/folder_modal/folder.ts new file mode 100644 index 00000000000..5573cff61fc --- /dev/null +++ b/public/app/features/dashboard/folder_modal/folder.ts @@ -0,0 +1,45 @@ +/// + +import coreModule from 'app/core/core_module'; +import appEvents from 'app/core/app_events'; +import _ from 'lodash'; + +export class FolderCtrl { + title: string; + + /** @ngInject */ + constructor(private backendSrv, private $scope, $sce) { + } + + create() { + if (!this.title || this.title.trim().length === 0) { + return; + } + + const title = this.title.trim(); + + + return this.backendSrv.saveDashboardFolder(title).then((result) => { + appEvents.emit('alert-success', ['Dashboard saved', 'Saved as ' + title]); + + appEvents.emit('dashboard-saved', result); + this.dismiss(); + }); + } + + dismiss() { + appEvents.emit('hide-modal'); + } +} + +export function folderModal() { + return { + restrict: 'E', + templateUrl: 'public/app/features/dashboard/folder_modal/folder.html', + controller: FolderCtrl, + bindToController: true, + controllerAs: 'ctrl', + }; +} + +coreModule.directive('folderModal', folderModal);