diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts index f2e4fa1ec88..666ca811037 100644 --- a/public/app/core/routes/routes.ts +++ b/public/app/core/routes/routes.ts @@ -65,7 +65,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) { }) .when("/dashboard/import", { templateUrl: - "public/app/features/dashboard/partials/dashboardImport.html", + "public/app/features/dashboard/partials/dashboard_import.html", controller: "DashboardImportCtrl", controllerAs: "ctrl" }) diff --git a/public/app/features/dashboard/create_folder_ctrl.ts b/public/app/features/dashboard/create_folder_ctrl.ts index c4a8429f45e..d9eaf95d693 100644 --- a/public/app/features/dashboard/create_folder_ctrl.ts +++ b/public/app/features/dashboard/create_folder_ctrl.ts @@ -3,23 +3,22 @@ import appEvents from "app/core/app_events"; export class CreateFolderCtrl { title = ""; navModel: any; - nameExists = false; titleTouched = false; + hasValidationError: boolean; + validationError: any; /** @ngInject **/ - constructor(private backendSrv, private $location, navModelSrv) { - this.navModel = navModelSrv.getNav("dashboards", "manage-dashboards", 0); + constructor(private backendSrv, private $location, private validationSrv, navModelSrv) { + this.navModel = navModelSrv.getNav('dashboards', 'manage-dashboards', 0); } create() { - if (!this.title || this.title.trim().length === 0) { + if (this.hasValidationError) { return; } - const title = this.title.trim(); - - return this.backendSrv.createDashboardFolder(title).then(result => { - appEvents.emit("alert-success", ["Folder Created", "OK"]); + return this.backendSrv.createDashboardFolder(this.title).then(result => { + appEvents.emit('alert-success', ['Folder Created', 'OK']); var folderUrl = `/dashboards/folder/${result.dashboard.id}/${ result.meta.slug @@ -31,14 +30,13 @@ export class CreateFolderCtrl { 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; - } - } - }); + this.validationSrv.validateNewDashboardOrFolderName(this.title) + .then(() => { + this.hasValidationError = false; + }) + .catch(err => { + this.hasValidationError = true; + this.validationError = err.message; + }); } } diff --git a/public/app/features/dashboard/dashboard_import_ctrl.ts b/public/app/features/dashboard/dashboard_import_ctrl.ts index 51b2d696dac..2dc33fe07f7 100644 --- a/public/app/features/dashboard/dashboard_import_ctrl.ts +++ b/public/app/features/dashboard/dashboard_import_ctrl.ts @@ -13,16 +13,13 @@ export class DashboardImportCtrl { gnetUrl: string; gnetError: string; gnetInfo: any; + titleTouched: boolean; + hasNameValidationError: boolean; + nameValidationError: any; /** @ngInject */ - constructor( - private backendSrv, - navModelSrv, - private $location, - private $scope, - $routeParams - ) { - this.navModel = navModelSrv.getNav("create", "import"); + constructor(private backendSrv, private validationSrv, navModelSrv, private $location, private $scope, $routeParams) { + this.navModel = navModelSrv.getNav('create', 'import'); this.step = 1; this.nameExists = false; @@ -93,15 +90,21 @@ export class DashboardImportCtrl { } titleChanged() { - this.backendSrv.search({ query: this.dash.title }).then(res => { - this.nameExists = false; - for (let hit of res) { - if (this.dash.title === hit.title) { + this.titleTouched = true; + this.nameExists = false; + + this.validationSrv.validateNewDashboardOrFolderName(this.dash.title) + .then(() => { + this.hasNameValidationError = false; + }) + .catch(err => { + if (err.type === 'EXISTING') { this.nameExists = true; - break; } - } - }); + + this.hasNameValidationError = true; + this.nameValidationError = err.message; + }); } saveDashboard() { diff --git a/public/app/features/dashboard/partials/create_folder.html b/public/app/features/dashboard/partials/create_folder.html index 22dbaab1419..21b6dfc1661 100644 --- a/public/app/features/dashboard/partials/create_folder.html +++ b/public/app/features/dashboard/partials/create_folder.html @@ -7,34 +7,25 @@