From c609586ff0c9c79444e79aa54eb7f8518ee78447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 26 Oct 2016 17:42:39 +0200 Subject: [PATCH] ux(dashboard): making progress on new add panel experiance --- pkg/api/frontendsettings.go | 20 +++ public/app/core/routes/dashboard_loaders.js | 9 +- .../app/features/dashboard/dashboard_ctrl.ts | 1 + .../app/features/dashboard/row/options.html | 95 +++++++++----- public/app/features/dashboard/row/options.ts | 116 +++++++++++++++++- public/app/features/dashboard/row/row.html | 73 +++-------- public/app/features/dashboard/row/row.ts | 67 ++-------- public/sass/components/edit_sidemenu.scss | 2 +- public/sass/pages/_dashboard.scss | 45 +++++-- 9 files changed, 263 insertions(+), 165 deletions(-) diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index d599dd10735..384dd7f0ea1 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -127,6 +127,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro "name": panel.Name, "id": panel.Id, "info": panel.Info, + "sort": getPanelSort(panel.Id), } } @@ -150,6 +151,25 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro return jsonObj, nil } +func getPanelSort(id string) int { + sort := 100 + switch id { + case "graph": + sort = 1 + case "singlestat": + sort = 2 + case "table": + sort = 3 + case "text": + sort = 4 + case "alertlist": + sort = 5 + case "dashlist": + sort = 6 + } + return sort +} + func GetFrontendSettings(c *middleware.Context) { settings, err := getFrontendSettingsMap(c) if err != nil { diff --git a/public/app/core/routes/dashboard_loaders.js b/public/app/core/routes/dashboard_loaders.js index 3c16b15c9c3..8a5ce7ad7ed 100644 --- a/public/app/core/routes/dashboard_loaders.js +++ b/public/app/core/routes/dashboard_loaders.js @@ -31,7 +31,14 @@ function (coreModule) { meta: { canStar: false, canShare: false }, dashboard: { title: "New dashboard", - rows: [{title: 'Dashboard Row', height: '250px', panels:[] }] + rows: [ + { + title: 'Dashboard Row', + height: '250px', + panels:[], + isNew: true, + } + ] }, }, $scope); }); diff --git a/public/app/features/dashboard/dashboard_ctrl.ts b/public/app/features/dashboard/dashboard_ctrl.ts index 1dfe54c6636..8845717659d 100644 --- a/public/app/features/dashboard/dashboard_ctrl.ts +++ b/public/app/features/dashboard/dashboard_ctrl.ts @@ -107,6 +107,7 @@ export class DashboardCtrl { title: 'New row', panels: [], height: '250px', + isNew: true, }); }; diff --git a/public/app/features/dashboard/row/options.html b/public/app/features/dashboard/row/options.html index 19d3b92aeed..d30ffb78dc0 100644 --- a/public/app/features/dashboard/row/options.html +++ b/public/app/features/dashboard/row/options.html @@ -1,42 +1,77 @@
-
-

- Row Options -

+
+ - -
- -
- -
-
- -
- Title - +
+
Add Panel
+
+
+ Search + +
-
- Height - + +
+
+
+ +
{{panel.name}}
+
+
- - +
-
-
Row Templating
+
+
+
Options
+
+
+ Title + +
+
+ +
+ +
+
+ + +
+
+
+ Height + +
+
+
-
-
- Repeat Row -
- + +
+
+
diff --git a/public/app/features/dashboard/row/options.ts b/public/app/features/dashboard/row/options.ts index 894596c1bca..c8462985eec 100644 --- a/public/app/features/dashboard/row/options.ts +++ b/public/app/features/dashboard/row/options.ts @@ -2,9 +2,120 @@ import _ from 'lodash'; -import {coreModule} from 'app/core/core'; +import config from 'app/core/config'; +import {coreModule, appEvents} from 'app/core/core'; export class RowOptionsCtrl { + row: any; + dashboard: any; + rowCtrl: any; + subTabIndex: number; + allPanels: any; + panelHits: any; + activeIndex: any; + panelSearch: any; + + fontSizes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']; + + /** @ngInject */ + constructor(private $scope, private $timeout, private $rootScope) { + this.row = this.rowCtrl.row; + this.dashboard = this.rowCtrl.dashboard; + this.subTabIndex = 0; + this.row.titleSize = this.row.titleSize || 'h6'; + this.allPanels = _.orderBy(_.map(config.panels, item => item), 'sort'); + this.panelHits = this.allPanels; + this.activeIndex = 0; + } + + keyDown(evt) { + if (evt.keyCode === 27) { + this.rowCtrl.showOptions = false; + return; + } + + if (evt.keyCode === 40 || evt.keyCode === 39) { + this.moveSelection(1); + } + + if (evt.keyCode === 38 || evt.keyCode === 37) { + this.moveSelection(-1); + } + + if (evt.keyCode === 13) { + var selectedPanel = this.panelHits[this.activeIndex]; + if (selectedPanel) { + this.addPanel(selectedPanel); + } + } + } + + moveSelection(direction) { + var max = this.panelHits.length; + var newIndex = this.activeIndex + direction; + this.activeIndex = ((newIndex %= max) < 0) ? newIndex + max : newIndex; + } + + panelSearchChanged() { + var items = this.allPanels.slice(); + var startsWith = []; + var contains = []; + var searchLower = this.panelSearch.toLowerCase(); + var item; + + while (item = items.shift()) { + var nameLower = item.name.toLowerCase(); + if (nameLower.indexOf(searchLower) === 0) { + startsWith.push(item); + } else if (nameLower.indexOf(searchLower) !== -1) { + contains.push(item); + } + } + + this.panelHits = startsWith.concat(contains); + this.activeIndex = 0; + } + + addPanel(panelPluginInfo) { + var defaultSpan = 12; + var _as = 12 - this.dashboard.rowSpan(this.row); + + var panel = { + id: null, + title: config.new_panel_title, + error: false, + span: _as < defaultSpan && _as > 0 ? _as : defaultSpan, + editable: true, + type: panelPluginInfo.id, + isNew: true, + }; + + this.rowCtrl.showOptions = false; + this.dashboard.addPanel(panel, this.row); + this.$timeout(() => { + this.$rootScope.appEvent('panel-change-view', { + fullscreen: true, edit: true, panelId: panel.id + }); + }); + } + + deleteRow() { + if (!this.row.panels.length) { + this.dashboard.rows = _.without(this.dashboard.rows, this.row); + return; + } + + appEvents.emit('confirm-modal', { + title: 'Delete', + text: 'Are you sure you want to delete this row?', + icon: 'fa-trash', + yesText: 'Delete', + onConfirm: () => { + this.dashboard.rows = _.without(this.dashboard.rows, this.row); + } + }); + } + } export function rowOptionsDirective() { @@ -15,8 +126,7 @@ export function rowOptionsDirective() { bindToController: true, controllerAs: 'ctrl', scope: { - row: "=", - onClose: "&" + rowCtrl: "=", }, }; } diff --git a/public/app/features/dashboard/row/row.html b/public/app/features/dashboard/row/row.html index b9317bc9638..43d9f6f3ed9 100644 --- a/public/app/features/dashboard/row/row.html +++ b/public/app/features/dashboard/row/row.html @@ -1,70 +1,25 @@ -
-