From 017b337f006c4b7e498e37404112143d048aec79 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Thu, 7 Dec 2017 19:32:38 +0100 Subject: [PATCH] dashfolders: create folder page Fixes #10085 --- pkg/api/index.go | 2 +- .../manage_dashboards/manage_dashboards.html | 2 +- public/app/core/routes/routes.ts | 5 ++ public/app/features/dashboard/all.ts | 2 + .../features/dashboard/create_folder_ctrl.ts | 41 +++++++++++++++++ .../dashboard/partials/create_folder.html | 46 +++++++++++++++++++ 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 public/app/features/dashboard/create_folder_ctrl.ts create mode 100644 public/app/features/dashboard/partials/create_folder.html diff --git a/pkg/api/index.go b/pkg/api/index.go index 1e44ef33050..058f5541eb5 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -95,7 +95,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { Url: "#", Children: []*dtos.NavLink{ {Text: "Dashboard", Icon: "gicon gicon-dashboard-new", Url: setting.AppSubUrl + "/dashboard/new"}, - {Text: "Folder", Icon: "gicon gicon-folder-new", Url: setting.AppSubUrl + "/dashboard/new/?editview=new-folder"}, + {Text: "Folder", SubTitle: "Create a new folder to organize your dashboards", Id: "folder", Icon: "gicon gicon-folder-new", Url: setting.AppSubUrl + "/dashboards/folder/new"}, {Text: "Import", SubTitle: "Import dashboard from file or Grafana.com", Id: "import", Icon: "gicon gicon-dashboard-import", Url: setting.AppSubUrl + "/dashboard/import"}, }, }) diff --git a/public/app/core/components/manage_dashboards/manage_dashboards.html b/public/app/core/components/manage_dashboards/manage_dashboards.html index 8c5aeb0facd..5daa8ddf55a 100644 --- a/public/app/core/components/manage_dashboards/manage_dashboards.html +++ b/public/app/core/components/manage_dashboards/manage_dashboards.html @@ -8,7 +8,7 @@ Dashboard - + Folder diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts index 8b42545d334..a068cd4a789 100644 --- a/public/app/core/routes/routes.ts +++ b/public/app/core/routes/routes.ts @@ -73,6 +73,11 @@ function setupAngularRoutes($routeProvider, $locationProvider) { controller : 'DashboardListCtrl', controllerAs: 'ctrl', }) + .when('/dashboards/folder/new', { + templateUrl: 'public/app/features/dashboard/partials/create_folder.html', + controller : 'CreateFolderCtrl', + controllerAs: 'ctrl', + }) .when('/dashboards/folder/:folderId/:type/:slug/permissions', { templateUrl: 'public/app/features/dashboard/partials/folder_permissions.html', controller : 'FolderPermissionsCtrl', diff --git a/public/app/features/dashboard/all.ts b/public/app/features/dashboard/all.ts index a18af82215d..f21338f5d6a 100644 --- a/public/app/features/dashboard/all.ts +++ b/public/app/features/dashboard/all.ts @@ -32,8 +32,10 @@ import {DashboardListCtrl} from './dashboard_list_ctrl'; import {FolderDashboardsCtrl} from './folder_dashboards_ctrl'; import {FolderPermissionsCtrl} from './folder_permissions_ctrl'; import {DashboardImportCtrl} from './dashboard_import_ctrl'; +import {CreateFolderCtrl} from './create_folder_ctrl'; coreModule.controller('DashboardListCtrl', DashboardListCtrl); coreModule.controller('FolderDashboardsCtrl', FolderDashboardsCtrl); coreModule.controller('FolderPermissionsCtrl', FolderPermissionsCtrl); coreModule.controller('DashboardImportCtrl', DashboardImportCtrl); +coreModule.controller('CreateFolderCtrl', CreateFolderCtrl); diff --git a/public/app/features/dashboard/create_folder_ctrl.ts b/public/app/features/dashboard/create_folder_ctrl.ts new file mode 100644 index 00000000000..f194dabbf1e --- /dev/null +++ b/public/app/features/dashboard/create_folder_ctrl.ts @@ -0,0 +1,41 @@ +import appEvents from 'app/core/app_events'; + +export class CreateFolderCtrl { + title = ''; + navModel: any; + nameExists = false; + titleTouched = false; + + constructor(private backendSrv, private $location, navModelSrv) { + this.navModel = navModelSrv.getNav('create', 'folder'); + } + + create() { + if (!this.title || this.title.trim().length === 0) { + return; + } + + const title = this.title.trim(); + + return this.backendSrv.createDashboardFolder(title).then(result => { + appEvents.emit('alert-success', ['Folder Created', 'OK']); + + var folderUrl = `/dashboards/folder/${result.id}/db/${result.slug}`; + this.$location.url(folderUrl); + }); + } + + titleChanged() { + this.titleTouched = true; + + this.backendSrv.search({query: this.title}).then(res => { + this.nameExists = false; + for (let hit of res) { + if (this.title === hit.title) { + this.nameExists = true; + break; + } + } + }); + } +} diff --git a/public/app/features/dashboard/partials/create_folder.html b/public/app/features/dashboard/partials/create_folder.html new file mode 100644 index 00000000000..6548057a796 --- /dev/null +++ b/public/app/features/dashboard/partials/create_folder.html @@ -0,0 +1,46 @@ + + +
+

+ Create New Folder +

+ + + +