From efa0dac954433218ff1567010001bf39a275e85c Mon Sep 17 00:00:00 2001
From: Luud Janssen
Date: Tue, 5 Jul 2016 12:11:09 +0200
Subject: [PATCH 1/4] Remove jQuery dependency, it's not used
---
src/plugins/kibana/public/dashboard/index.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js
index b71c74c07567f..a7c6bb0d178e8 100644
--- a/src/plugins/kibana/public/dashboard/index.js
+++ b/src/plugins/kibana/public/dashboard/index.js
@@ -1,6 +1,5 @@
define(function (require) {
const _ = require('lodash');
- const $ = require('jquery');
const angular = require('angular');
const ConfigTemplate = require('ui/ConfigTemplate');
const chrome = require('ui/chrome');
From 75f4555644336d64506f48d4b5617b03185dd43e Mon Sep 17 00:00:00 2001
From: Luud Janssen
Date: Tue, 5 Jul 2016 12:33:42 +0200
Subject: [PATCH 2/4] Add default dashboard option
---
src/plugins/kibana/public/dashboard/index.js | 83 +++++++++++++++++--
.../public/dashboard/partials/options.html | 4 +
src/ui/public/config/defaults.js | 4 +
3 files changed, 83 insertions(+), 8 deletions(-)
diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js
index a7c6bb0d178e8..a149f500755aa 100644
--- a/src/plugins/kibana/public/dashboard/index.js
+++ b/src/plugins/kibana/public/dashboard/index.js
@@ -2,6 +2,7 @@ define(function (require) {
const _ = require('lodash');
const angular = require('angular');
const ConfigTemplate = require('ui/ConfigTemplate');
+ const dashboardTemplate = require('plugins/kibana/dashboard/index.html');
const chrome = require('ui/chrome');
require('ui/directives/config');
@@ -18,7 +19,6 @@ define(function (require) {
require('ui/saved_objects/saved_object_registry').register(require('plugins/kibana/dashboard/services/saved_dashboard_register'));
-
const app = require('ui/modules').get('app/dashboard', [
'elasticsearch',
'ngRoute',
@@ -30,17 +30,56 @@ define(function (require) {
require('ui/routes')
.when('/dashboard', {
- template: require('plugins/kibana/dashboard/index.html'),
+ template: function ($location) {
+ if ($location.new === true) {
+ return dashboardTemplate;
+ }
+
+ return false;
+ },
resolve: {
- dash: function (savedDashboards, config) {
- return savedDashboards.get();
+ 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: require('plugins/kibana/dashboard/index.html'),
+ template: dashboardTemplate,
resolve: {
- dash: function (savedDashboards, Notifier, $route, $location, courier) {
+ 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'
@@ -51,9 +90,10 @@ define(function (require) {
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(require('ui/filter_bar/query_filter'));
+ const configDefaults = Private(require('ui/config/defaults'));
const notify = new Notifier({
location: 'Dashboard'
@@ -68,6 +108,8 @@ define(function (require) {
$scope.$on('$destroy', dash.destroy);
+ const configDefaultDashboard = config.get('dashboard:defaultDashboard', '');
+
const matchQueryFilter = function (filter) {
return filter.query && filter.query.query_string && !filter.meta;
};
@@ -93,6 +135,7 @@ define(function (require) {
if (!angular.equals(newVal, oldVal)) $state.save();
});
$scope.$watch('state.options.darkTheme', setDarkTheme);
+ $scope.$watch('opts.isDefaultDashboard', toggleDefaultDashboard);
$scope.configTemplate = new ConfigTemplate({
save: require('plugins/kibana/dashboard/partials/save_dashboard.html'),
@@ -159,6 +202,28 @@ define(function (require) {
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();
@@ -169,7 +234,8 @@ define(function (require) {
$scope.$listen(queryFilter, 'fetch', $scope.refresh);
$scope.newDashboard = function () {
- kbnUrl.change('/dashboard', {});
+ $location.search('new', true);
+ $route.reload();
};
$scope.filterResults = function () {
@@ -230,6 +296,7 @@ define(function (require) {
// Setup configurable values for config directive, after objects are initialized
$scope.opts = {
dashboard: dash,
+ isDefaultDashboard: configDefaultDashboard === dash.id,
ui: $state.options,
save: $scope.save,
addVis: $scope.addVis,
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
+
diff --git a/src/ui/public/config/defaults.js b/src/ui/public/config/defaults.js
index 7122b56366c53..5dbe8ffe19660 100644
--- a/src/ui/public/config/defaults.js
+++ b/src/ui/public/config/defaults.js
@@ -206,6 +206,10 @@ define(function (require) {
'dashboard:defaultDarkTheme': {
value: false,
description: 'New dashboards use dark theme by default',
+ },
+ 'dashboard:defaultDashboard': {
+ value: '',
+ description: 'The default dashboard to load. ID can be found in the URL when the dashboard is loaded.'
}
};
};
From 620a6d98c449fbb1d4f797d34be73609c580d1e6 Mon Sep 17 00:00:00 2001
From: Luud Janssen
Date: Tue, 5 Jul 2016 12:40:07 +0200
Subject: [PATCH 3/4] 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 c55428e6e0091..8639fc1bb7192 100644
--- a/src/plugins/kibana/public/dashboard/styles/main.less
+++ b/src/plugins/kibana/public/dashboard/styles/main.less
@@ -126,3 +126,16 @@ dashboard-grid {
.dashboard-load {
margin: 10px;
}
+
+.dashboard-container {
+ config {
+ .options {
+ padding: 10px 0;
+
+ ul.input-list {
+ list-style-type: none;
+ margin-bottom: 0;
+ }
+ }
+ }
+}
From 678f93628c5060b269e7f4feaf7eb29bccc4982e Mon Sep 17 00:00:00 2001
From: Luud Janssen
Date: Tue, 5 Jul 2016 13:10:01 +0200
Subject: [PATCH 4/4] Style the option controls
---
src/plugins/kibana/public/dashboard/index.js | 1 +
.../public/dashboard/partials/options.html | 17 +++++++++--------
.../kibana/public/dashboard/styles/main.less | 5 +++++
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js
index a149f500755aa..2d8e8488edd8a 100644
--- a/src/plugins/kibana/public/dashboard/index.js
+++ b/src/plugins/kibana/public/dashboard/index.js
@@ -297,6 +297,7 @@ define(function (require) {
$scope.opts = {
dashboard: dash,
isDefaultDashboard: configDefaultDashboard === dash.id,
+ isNewDashboard: $location.search().new === true,
ui: $state.options,
save: $scope.save,
addVis: $scope.addVis,
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 8639fc1bb7192..e42089be9c212 100644
--- a/src/plugins/kibana/public/dashboard/styles/main.less
+++ b/src/plugins/kibana/public/dashboard/styles/main.less
@@ -135,6 +135,11 @@ dashboard-grid {
ul.input-list {
list-style-type: none;
margin-bottom: 0;
+
+ label span {
+ display: inline-block;
+ vertical-align: top;
+ }
}
}
}