From be1e99aef5c6b316d4abc65586a32d21e1b2b764 Mon Sep 17 00:00:00 2001 From: Luud Janssen Date: Tue, 5 Jul 2016 12:33:42 +0200 Subject: [PATCH 1/6] Add default dashboard option Conflicts: src/plugins/kibana/public/dashboard/index.js src/ui/public/config/defaults.js --- src/plugins/kibana/public/dashboard/index.js | 129 +++++++++++++----- .../public/dashboard/partials/options.html | 4 + 2 files changed, 101 insertions(+), 32 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js index 1c145cf357c1b..2894f6d06f10e 100644 --- a/src/plugins/kibana/public/dashboard/index.js +++ b/src/plugins/kibana/public/dashboard/index.js @@ -13,16 +13,14 @@ import 'plugins/kibana/dashboard/components/panel/panel'; import 'plugins/kibana/dashboard/services/saved_dashboards'; import 'plugins/kibana/dashboard/styles/main.less'; import FilterBarQueryFilterProvider from 'ui/filter_bar/query_filter'; +import DefaultSettingsProvider from 'ui/settings/defaults'; import DocTitleProvider from 'ui/doc_title'; import uiRoutes from 'ui/routes'; import uiModules from 'ui/modules'; import indexTemplate from 'plugins/kibana/dashboard/index.html'; - - require('ui/saved_objects/saved_object_registry').register(require('plugins/kibana/dashboard/services/saved_dashboard_register')); - const app = uiModules.get('app/dashboard', [ 'elasticsearch', 'ngRoute', @@ -33,32 +31,72 @@ const app = uiModules.get('app/dashboard', [ ]); uiRoutes -.when('/dashboard', { - template: indexTemplate, - resolve: { - dash: function (savedDashboards, config) { - return savedDashboards.get(); + .when('/dashboard', { + template: function ($location) { + if ($location.new === true) { + return indexTemplate; + } + + return false; + }, + resolve: { + dash: function (savedDashboards, config, kbnUrl, Notifier, $location, $route) { + let defaultDashboard = config.get('dashboard:defaultDashboard', ''); + + let notify = new Notifier({ + location: 'Dashboard' + }); + + if ($location.search().new === true) { + return savedDashboards.get(); + } + + function forceNew() { + $location.search('new', true); + $route.reload(); + } + + if (defaultDashboard !== '') { + return savedDashboards.get(defaultDashboard) + .then(function (result) { + let dashboardUrl = savedDashboards.urlFor(result.id).substring(1); + kbnUrl.change(dashboardUrl); + }) + .catch(function (error) { + notify.error(error); + + forceNew(); + }); + } + + forceNew(); + } } - } -}) -.when('/dashboard/:id', { - template: indexTemplate, - resolve: { - dash: function (savedDashboards, Notifier, $route, $location, courier) { - return savedDashboards.get($route.current.params.id) - .catch(courier.redirectWhenMissing({ - 'dashboard' : '/dashboard' - })); + }) + .when('/dashboard/:id', { + template: indexTemplate, + resolve: { + dash: function (savedDashboards, Notifier, $route, $location, courier, kbnUrl) { + if ($location.search().new === true) { + kbnUrl.change('/dashboard'); + $location.search('new', true); + } + + return savedDashboards.get($route.current.params.id) + .catch(courier.redirectWhenMissing({ + 'dashboard' : '/dashboard' + })); + } } - } -}); + }); app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, kbnUrl) { return { - controller: function ($scope, $rootScope, $route, $routeParams, $location, Private, getAppState) { + controller: function ($scope, $rootScope, $route, $routeParams, $location, Private, getAppState, config) { const queryFilter = Private(FilterBarQueryFilterProvider); - + const configDefaults = Private(DefaultSettingsProvider); + const notify = new Notifier({ location: 'Dashboard' }); @@ -72,6 +110,8 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, $scope.$on('$destroy', dash.destroy); + const configDefaultDashboard = config.get('dashboard:defaultDashboard', ''); + const matchQueryFilter = function (filter) { return filter.query && filter.query.query_string && !filter.meta; }; @@ -97,6 +137,7 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, if (!angular.equals(newVal, oldVal)) $state.save(); }); $scope.$watch('state.options.darkTheme', setDarkTheme); + $scope.$watch('opts.isDefaultDashboard', toggleDefaultDashboard); $scope.topNavMenu = [{ key: 'new', @@ -180,7 +221,29 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, chrome.removeApplicationClass(['theme-dark', 'theme-light']); chrome.addApplicationClass(theme); } + + // Returns whether this dashboard is now default + function toggleDefaultDashboard(isChecked) { + if (isChecked) { + setDefaultDashboard(dash.id); + return true; + } + + if (dash.id === configDefaultDashboard) { + /* If the default option is turned off and the previous default + dashboard was this dashboard set no default dashboard */ + setDefaultDashboard(configDefaults['dashboard:defaultDashboard'].value); + return false; + } + setDefaultDashboard(configDefaultDashboard); + return false; + } + + function setDefaultDashboard(id) { + config.set('dashboard:defaultDashboard', id); + } + // update root source when filters update $scope.$listen(queryFilter, 'update', function () { updateQueryOnRootSource(); @@ -191,7 +254,8 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, $scope.$listen(queryFilter, 'fetch', $scope.refresh); $scope.newDashboard = function () { - kbnUrl.change('/dashboard', {}); + $location.search('new', true); + $route.reload(); }; $scope.filterResults = function () { @@ -249,15 +313,16 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, $state.panels.push({ id: hit.id, type: 'search', panelIndex: getMaxPanelIndex() }); }; - // Setup configurable values for config directive, after objects are initialized - $scope.opts = { - dashboard: dash, - ui: $state.options, - save: $scope.save, - addVis: $scope.addVis, - addSearch: $scope.addSearch, - timefilter: $scope.timefilter - }; + // Setup configurable values for config directive, after objects are initialized + $scope.opts = { + dashboard: dash, + ui: $state.options, + isDefaultDashboard: configDefaultDashboard === dash.id, + save: $scope.save, + addVis: $scope.addVis, + addSearch: $scope.addSearch, + timefilter: $scope.timefilter + }; init(); } diff --git a/src/plugins/kibana/public/dashboard/partials/options.html b/src/plugins/kibana/public/dashboard/partials/options.html index 00216a0d02197..a3142287daadf 100644 --- a/src/plugins/kibana/public/dashboard/partials/options.html +++ b/src/plugins/kibana/public/dashboard/partials/options.html @@ -5,6 +5,10 @@ Use dark theme +

From 1befdb7975ed3463e30baf8daebe55626f439c56 Mon Sep 17 00:00:00 2001 From: Luud Janssen Date: Tue, 5 Jul 2016 12:40:07 +0200 Subject: [PATCH 2/6] Add default dashboard option --- .../public/dashboard/partials/options.html | 22 +++++++++++++------ .../kibana/public/dashboard/styles/main.less | 13 +++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/partials/options.html b/src/plugins/kibana/public/dashboard/partials/options.html index a3142287daadf..d786580032eb1 100644 --- a/src/plugins/kibana/public/dashboard/partials/options.html +++ b/src/plugins/kibana/public/dashboard/partials/options.html @@ -1,14 +1,22 @@
-

-

+
    +
  • +
  • +
  • -
-

+ +
diff --git a/src/plugins/kibana/public/dashboard/styles/main.less b/src/plugins/kibana/public/dashboard/styles/main.less index a0cccdd1e6ddc..6d028c91d5bd0 100644 --- a/src/plugins/kibana/public/dashboard/styles/main.less +++ b/src/plugins/kibana/public/dashboard/styles/main.less @@ -156,3 +156,16 @@ dashboard-grid { .dashboard-panel-picker > .list-group-item { border-top: 0; } + +.dashboard-container { + config { + .options { + padding: 10px 0; + + ul.input-list { + list-style-type: none; + margin-bottom: 0; + } + } + } +} From 2233cba87e678c98e4db3edc5bdfb2d9d231c0e2 Mon Sep 17 00:00:00 2001 From: Luud Janssen Date: Tue, 5 Jul 2016 15:39:17 +0200 Subject: [PATCH 3/6] Cherry pick 'default dashboard' commits --- src/plugins/kibana/public/dashboard/index.js | 58 ++++++++++---------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js index 2894f6d06f10e..79a8dd4af251a 100644 --- a/src/plugins/kibana/public/dashboard/index.js +++ b/src/plugins/kibana/public/dashboard/index.js @@ -83,9 +83,9 @@ uiRoutes } return savedDashboards.get($route.current.params.id) - .catch(courier.redirectWhenMissing({ - 'dashboard' : '/dashboard' - })); + .catch(courier.redirectWhenMissing({ + 'dashboard': '/dashboard' + })); } } }); @@ -96,7 +96,7 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, const queryFilter = Private(FilterBarQueryFilterProvider); const configDefaults = Private(DefaultSettingsProvider); - + const notify = new Notifier({ location: 'Dashboard' }); @@ -142,7 +142,9 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, $scope.topNavMenu = [{ key: 'new', description: 'New Dashboard', - run: function () { kbnUrl.change('/dashboard', {}); }, + run: function () { + kbnUrl.change('/dashboard', {}); + }, }, { key: 'add', description: 'Add a panel to the dashboard', @@ -221,7 +223,7 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, chrome.removeApplicationClass(['theme-dark', 'theme-light']); chrome.addApplicationClass(theme); } - + // Returns whether this dashboard is now default function toggleDefaultDashboard(isChecked) { if (isChecked) { @@ -243,7 +245,7 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, function setDefaultDashboard(id) { config.set('dashboard:defaultDashboard', id); } - + // update root source when filters update $scope.$listen(queryFilter, 'update', function () { updateQueryOnRootSource(); @@ -275,16 +277,16 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, dash.optionsJSON = angular.toJson($state.options); dash.save() - .then(function (id) { - $scope.kbnTopNav.close('save'); - if (id) { - notify.info('Saved Dashboard as "' + dash.title + '"'); - if (dash.id !== $routeParams.id) { - kbnUrl.change('/dashboard/{{id}}', {id: dash.id}); + .then(function (id) { + $scope.kbnTopNav.close('save'); + if (id) { + notify.info('Saved Dashboard as "' + dash.title + '"'); + if (dash.id !== $routeParams.id) { + kbnUrl.change('/dashboard/{{id}}', {id: dash.id}); + } } - } - }) - .catch(notify.fatal); + }) + .catch(notify.fatal); }; let pendingVis = _.size($state.panels); @@ -305,24 +307,24 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, // called by the saved-object-finder when a user clicks a vis $scope.addVis = function (hit) { pendingVis++; - $state.panels.push({ id: hit.id, type: 'visualization', panelIndex: getMaxPanelIndex() }); + $state.panels.push({id: hit.id, type: 'visualization', panelIndex: getMaxPanelIndex()}); }; $scope.addSearch = function (hit) { pendingVis++; - $state.panels.push({ id: hit.id, type: 'search', panelIndex: getMaxPanelIndex() }); + $state.panels.push({id: hit.id, type: 'search', panelIndex: getMaxPanelIndex()}); }; - // Setup configurable values for config directive, after objects are initialized - $scope.opts = { - dashboard: dash, - ui: $state.options, - isDefaultDashboard: configDefaultDashboard === dash.id, - save: $scope.save, - addVis: $scope.addVis, - addSearch: $scope.addSearch, - timefilter: $scope.timefilter - }; + // Setup configurable values for config directive, after objects are initialized + $scope.opts = { + dashboard: dash, + ui: $state.options, + isDefaultDashboard: configDefaultDashboard === dash.id, + save: $scope.save, + addVis: $scope.addVis, + addSearch: $scope.addSearch, + timefilter: $scope.timefilter + }; init(); } From a394714fef771f9a625b248af4d634ae5befe02a Mon Sep 17 00:00:00 2001 From: Luud Janssen Date: Tue, 5 Jul 2016 13:10:01 +0200 Subject: [PATCH 4/6] Cherry pick 'default dashboard' commits and remove jQuery from dependencies Conflicts: src/plugins/kibana/public/dashboard/index.js --- src/plugins/kibana/public/dashboard/index.js | 6 +++--- .../public/dashboard/partials/options.html | 17 +++++++++-------- .../kibana/public/dashboard/styles/main.less | 5 +++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js index 79a8dd4af251a..81aab63463919 100644 --- a/src/plugins/kibana/public/dashboard/index.js +++ b/src/plugins/kibana/public/dashboard/index.js @@ -318,12 +318,12 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, // Setup configurable values for config directive, after objects are initialized $scope.opts = { dashboard: dash, - ui: $state.options, isDefaultDashboard: configDefaultDashboard === dash.id, + isNewDashboard: $location.search().new === true, + ui: $state.options, save: $scope.save, addVis: $scope.addVis, - addSearch: $scope.addSearch, - timefilter: $scope.timefilter + addSearch: $scope.addSearch }; init(); diff --git a/src/plugins/kibana/public/dashboard/partials/options.html b/src/plugins/kibana/public/dashboard/partials/options.html index d786580032eb1..99a4e75821cd6 100644 --- a/src/plugins/kibana/public/dashboard/partials/options.html +++ b/src/plugins/kibana/public/dashboard/partials/options.html @@ -4,18 +4,19 @@
  • -
  • diff --git a/src/plugins/kibana/public/dashboard/styles/main.less b/src/plugins/kibana/public/dashboard/styles/main.less index 6d028c91d5bd0..d458d304e2061 100644 --- a/src/plugins/kibana/public/dashboard/styles/main.less +++ b/src/plugins/kibana/public/dashboard/styles/main.less @@ -165,6 +165,11 @@ dashboard-grid { ul.input-list { list-style-type: none; margin-bottom: 0; + + label span { + display: inline-block; + vertical-align: top; + } } } } From cd2851f44e3eaf7ac56fa1b2eed61f5b71af3193 Mon Sep 17 00:00:00 2001 From: Luud Janssen Date: Tue, 5 Jul 2016 16:09:23 +0200 Subject: [PATCH 5/6] Rebase 'default dashboard' against master --- src/plugins/kibana/public/dashboard/index.js | 9 +++------ src/plugins/kibana/public/dashboard/styles/main.less | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js index 81aab63463919..54295692ac14d 100644 --- a/src/plugins/kibana/public/dashboard/index.js +++ b/src/plugins/kibana/public/dashboard/index.js @@ -1,5 +1,4 @@ import _ from 'lodash'; -import $ from 'jquery'; import angular from 'angular'; import chrome from 'ui/chrome'; import 'ui/courier'; @@ -13,7 +12,6 @@ import 'plugins/kibana/dashboard/components/panel/panel'; import 'plugins/kibana/dashboard/services/saved_dashboards'; import 'plugins/kibana/dashboard/styles/main.less'; import FilterBarQueryFilterProvider from 'ui/filter_bar/query_filter'; -import DefaultSettingsProvider from 'ui/settings/defaults'; import DocTitleProvider from 'ui/doc_title'; import uiRoutes from 'ui/routes'; import uiModules from 'ui/modules'; @@ -92,10 +90,11 @@ uiRoutes app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, kbnUrl) { return { - controller: function ($scope, $rootScope, $route, $routeParams, $location, Private, getAppState, config) { + controller: function ($scope, $rootScope, $route, $routeParams, $location, Private, getAppState, config, uiSettings) { const queryFilter = Private(FilterBarQueryFilterProvider); - const configDefaults = Private(DefaultSettingsProvider); + const configDefaults = uiSettings.defaults; + const configDefaultDashboard = config.get('dashboard:defaultDashboard', ''); const notify = new Notifier({ location: 'Dashboard' @@ -110,8 +109,6 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, $scope.$on('$destroy', dash.destroy); - const configDefaultDashboard = config.get('dashboard:defaultDashboard', ''); - const matchQueryFilter = function (filter) { return filter.query && filter.query.query_string && !filter.meta; }; diff --git a/src/plugins/kibana/public/dashboard/styles/main.less b/src/plugins/kibana/public/dashboard/styles/main.less index d458d304e2061..0df68f6d146b5 100644 --- a/src/plugins/kibana/public/dashboard/styles/main.less +++ b/src/plugins/kibana/public/dashboard/styles/main.less @@ -158,7 +158,7 @@ dashboard-grid { } .dashboard-container { - config { + .config { .options { padding: 10px 0; From 79e92abf52e6d398134fbae1be042509255a101c Mon Sep 17 00:00:00 2001 From: Luud Janssen Date: Wed, 6 Jul 2016 13:08:28 +0200 Subject: [PATCH 6/6] Rebase 'default dashboard' against master --- .../kibana/public/dashboard/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core_plugins/kibana/public/dashboard/index.js b/src/core_plugins/kibana/public/dashboard/index.js index 06c7108596e90..1bbac19e4659d 100644 --- a/src/core_plugins/kibana/public/dashboard/index.js +++ b/src/core_plugins/kibana/public/dashboard/index.js @@ -56,7 +56,7 @@ uiRoutes $route.reload(); } - if (defaultDashboard !== '') { + if (defaultDashboard !== '' && typeof defaultDashboard !== 'undefined') { return savedDashboards.get(defaultDashboard) .then(function (result) { let dashboardUrl = savedDashboards.urlFor(result.id).substring(1); @@ -144,7 +144,7 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, $scope.topNavMenu = [{ key: 'new', description: 'New Dashboard', - run: $scope.newDashboard + run: newDashboard }, { key: 'add', description: 'Add a panel to the dashboard', @@ -246,6 +246,11 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, config.set('dashboard:defaultDashboard', id); } + function newDashboard() { + $location.search('new', true); + $route.reload(); + } + // update root source when filters update $scope.$listen(queryFilter, 'update', function () { updateQueryOnRootSource(); @@ -255,11 +260,6 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, // update data when filters fire fetch event $scope.$listen(queryFilter, 'fetch', $scope.refresh); - $scope.newDashboard = function () { - $location.search('new', true); - $route.reload(); - }; - $scope.filterResults = function () { updateQueryOnRootSource(); $state.save(); @@ -320,7 +320,7 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, // Setup configurable values for config directive, after objects are initialized $scope.opts = { dashboard: dash, - isDefaultDashboard: configDefaultDashboard === dash.id, + isDefaultDashboard: configDefaultDashboard === dash.id && dash.id !== '', isNewDashboard: $location.search().new === true, ui: $state.options, save: $scope.save,