diff --git a/public/app/features/dashboard/settings/settings.html b/public/app/features/dashboard/settings/settings.html index f7eb10ecb24..76a297c50ee 100644 --- a/public/app/features/dashboard/settings/settings.html +++ b/public/app/features/dashboard/settings/settings.html @@ -86,20 +86,30 @@

Delete dashboard

-
-
-
This dashboard contains {{ctrl.alertCount}} alerts. Deleting this dashboard will also delete those alerts
- -
- - -
- -
-
You cannot delete this dashboard
+
+
This dashboard contains {{ctrl.alertCount}} alerts. Deleting this dashboard will also delete those alerts
+
+
+ +
+

Settings view not found

+ +
+
The settings page could not be found or you do not have permission to access it
+
+
+ +
+

Make Editable

+ + +
+ diff --git a/public/app/features/dashboard/settings/settings.ts b/public/app/features/dashboard/settings/settings.ts index 0058529bc7a..d19165e832f 100644 --- a/public/app/features/dashboard/settings/settings.ts +++ b/public/app/features/dashboard/settings/settings.ts @@ -1,5 +1,5 @@ -import {coreModule, appEvents} from 'app/core/core'; -import {DashboardModel} from '../dashboard_model'; +import { coreModule, appEvents, contextSrv } from 'app/core/core'; +import { DashboardModel } from '../dashboard_model'; import $ from 'jquery'; import _ from 'lodash'; @@ -11,17 +11,7 @@ export class SettingsCtrl { alertCount: number; confirmValid: boolean; confirmText: string; - - sections: any[] = [ - {title: 'General', id: 'settings', icon: "fa fa-fw fa-sliders"}, - {title: 'Annotations', id: 'annotations', icon: "fa fa-fw fa-comment-o"}, - {title: 'Variables', id: 'templating', icon: "fa fa-fw fa-dollar"}, - {title: 'Links', id: 'links', icon: "fa fa-fw fa-external-link"}, - {title: 'Versions', id: 'versions', icon: "fa fa-fw fa-history"}, - {title: 'View JSON', id: 'view_json', icon: "fa fa-fw fa-code"}, - {title: 'Save As', id: 'save_as', icon: "fa fa-fw fa-copy"}, - {title: 'Delete', id: 'delete', icon: "fa fa-fw fa-trash"}, - ]; + sections: any[]; /** @ngInject */ constructor(private $scope, private $location, private $rootScope, private backendSrv, private dashboardSrv) { @@ -29,17 +19,9 @@ export class SettingsCtrl { // that rely on inherited scope $scope.dashboard = this.dashboard; - const params = this.$location.search(); - const url = $location.path(); - - for (let section of this.sections) { - const sectionParams = _.defaults({editview: section.id}, params); - section.url = url + '?' + $.param(sectionParams); - } - this.$scope.$on('$destroy', () => { this.dashboard.updateSubmenuVisibility(); - this.$rootScope.$broadcast("refresh"); + this.$rootScope.$broadcast('refresh'); }); this.alertCount = _.sumBy(this.dashboard.panels, panel => { @@ -47,9 +29,54 @@ export class SettingsCtrl { }); this.confirmValid = this.alertCount === 0; - this.onRouteUpdated(); - $rootScope.onAppEvent("$routeUpdate", this.onRouteUpdated.bind(this), $scope); + this.buildSectionList(); + + $rootScope.onAppEvent('$routeUpdate', this.onRouteUpdated.bind(this), $scope); + } + + buildSectionList() { + this.sections = []; + if (this.dashboard.meta.canEdit) { + this.sections.push({ title: 'General', id: 'settings', icon: 'fa fa-fw fa-sliders' }); + this.sections.push({ title: 'Annotations', id: 'annotations', icon: 'fa fa-fw fa-comment-o' }); + this.sections.push({ title: 'Variables', id: 'templating', icon: 'fa fa-fw fa-dollar' }); + this.sections.push({ title: 'Links', id: 'links', icon: 'fa fa-fw fa-external-link' }); + + if (this.dashboard.id) { + this.sections.push({ title: 'Versions', id: 'versions', icon: 'fa fa-fw fa-history' }); + } + } + + if (contextSrv.isEditor && !this.dashboard.editable) { + this.sections.push({ title: 'Make Editable', icon: 'fa fa-fw fa-edit', id: 'make_editable' }); + this.viewId = 'make_editable'; + } + + this.sections.push({ title: 'View JSON', id: 'view_json', icon: 'fa fa-fw fa-code' }); + + if (contextSrv.isEditor) { + this.sections.push({ title: 'Save As', id: 'save_as', icon: 'fa fa-fw fa-copy' }); + } + + if (this.dashboard.meta.canSave) { + this.sections.push({ title: 'Delete', id: 'delete', icon: 'fa fa-fw fa-trash' }); + } + + const params = this.$location.search(); + const url = this.$location.path(); + + for (let section of this.sections) { + const sectionParams = _.defaults({ editview: section.id }, params); + section.url = url + '?' + $.param(sectionParams); + } + + const currentSection = _.find(this.sections, { id: this.viewId }); + if (!currentSection) { + this.sections.unshift({ title: 'Not found', id: '404', icon: 'fa fa-fw fa-warning' }); + this.viewId = '404'; + return; + } } onRouteUpdated() { @@ -73,14 +100,14 @@ export class SettingsCtrl { makeEditable() { this.dashboard.editable = true; - return this.dashboardSrv.saveDashboard({makeEditable: true, overwrite: false}).then(() => { + return this.dashboardSrv.saveDashboard({ makeEditable: true, overwrite: false }).then(() => { // force refresh whole page window.location.href = window.location.href; }); } confirmTextChanged() { - this.confirmValid = this.confirmText === "DELETE"; + this.confirmValid = this.confirmText === 'DELETE'; } deleteDashboard() { @@ -93,7 +120,7 @@ export class SettingsCtrl { onFolderChange(folder) { this.dashboard.folderId = folder.id; this.dashboard.meta.folderId = folder.id; - this.dashboard.meta.folderTitle= folder.title; + this.dashboard.meta.folderTitle = folder.title; } } @@ -105,7 +132,7 @@ export function dashboardSettings() { bindToController: true, controllerAs: 'ctrl', transclude: true, - scope: { dashboard: "=" } + scope: { dashboard: '=' }, }; } diff --git a/public/app/partials/confirm_modal.html b/public/app/partials/confirm_modal.html index 0b706788e90..d0b0d260f78 100644 --- a/public/app/partials/confirm_modal.html +++ b/public/app/partials/confirm_modal.html @@ -21,7 +21,6 @@
-