From 96bc3a5d0e16e48b4aed260f18bb684e905874ad Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Tue, 3 Jan 2017 18:14:36 -0800 Subject: [PATCH 1/6] Adding global params to dashboard by prefixing with '$' --- client/app/pages/dashboards/dashboard.html | 4 +++ client/app/pages/dashboards/dashboard.js | 35 ++++++++++++++++++++-- client/app/pages/dashboards/widget.js | 4 ++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/client/app/pages/dashboards/dashboard.html b/client/app/pages/dashboards/dashboard.html index 34af7e21b7..2037bbe6b8 100644 --- a/client/app/pages/dashboards/dashboard.html +++ b/client/app/pages/dashboards/dashboard.html @@ -54,6 +54,10 @@

This dashboard is archived and won't appear in the dashboards list or search results. +
+ +
+
diff --git a/client/app/pages/dashboards/dashboard.js b/client/app/pages/dashboards/dashboard.js index 5bd1873b73..06f05fbeab 100644 --- a/client/app/pages/dashboards/dashboard.js +++ b/client/app/pages/dashboards/dashboard.js @@ -2,12 +2,13 @@ import * as _ from 'underscore'; import template from './dashboard.html'; import shareDashboardTemplate from './share-dashboard.html'; -function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibModal, +function DashboardCtrl($rootScope, $scope, $routeParams, $location, $timeout, $q, $uibModal, Title, AlertDialog, Dashboard, currentUser, clientConfig, Events) { this.isFullscreen = false; this.refreshRate = null; this.showPermissionsControl = clientConfig.showPermissionsControl; this.currentUser = currentUser; + this.globalParameters = []; this.refreshRates = [ { name: '10 seconds', rate: 10 }, { name: '30 seconds', rate: 30 }, @@ -26,6 +27,34 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo } }; + const extractGlobalParameters = () => { + let globalParams = {}; + this.dashboard.widgets.forEach(row => + row.forEach((widget) => { + widget.getQuery().getParametersDefs().forEach((param) => { + if (param.name[0] === '$') { + const defaults = {}; + defaults[param.name] = _.clone(param); + defaults[param.name].locals = []; + globalParams = _.defaults(globalParams, defaults); + globalParams[param.name].locals.push(param); + } + }); + }) + ); + this.globalParameters = _.values(globalParams); + }; + + $scope.$watch(() => this.globalParameters, (parameters) => { + _.each(parameters, (global) => { + _.each(global.locals, (local) => { + local.value = global.value; + }); + }); + }, true); + + $scope.$on('deleteDashboardWidget', extractGlobalParameters); + const renderDashboard = (dashboard, force) => { Title.set(dashboard.name); const promises = []; @@ -42,6 +71,8 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo }) ); + extractGlobalParameters(); + $q.all(promises).then((queryResults) => { const filters = {}; queryResults.forEach((queryResult) => { @@ -139,7 +170,7 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo resolve: { dashboard: () => this.dashboard, }, - }); + }).result.then(() => extractGlobalParameters()); }; this.toggleFullscreen = () => { diff --git a/client/app/pages/dashboards/widget.js b/client/app/pages/dashboards/widget.js index a6c714ad30..81bb809af3 100644 --- a/client/app/pages/dashboards/widget.js +++ b/client/app/pages/dashboards/widget.js @@ -24,7 +24,7 @@ const EditTextBoxComponent = { }, }; -function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser) { +function DashboardWidgetCtrl($location, $uibModal, $window, $scope, Events, currentUser) { this.canViewQuery = currentUser.hasPermission('view_query'); this.editTextBox = () => { @@ -51,6 +51,8 @@ function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser) this.dashboard.layout = response.layout; this.dashboard.version = response.version; + + $scope.$emit('deleteDashboardWidget'); }); }; From b1fd2101df18e766f6f2f9674c63f0de15a82ba0 Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Wed, 4 Jan 2017 08:29:25 -0800 Subject: [PATCH 2/6] Refactored to make more efficent and cleaner --- client/app/components/parameters.js | 4 ++++ client/app/pages/dashboards/dashboard.html | 2 +- client/app/pages/dashboards/dashboard.js | 20 +++++++++----------- client/app/pages/dashboards/widget.html | 2 +- client/app/services/query.js | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/client/app/components/parameters.js b/client/app/components/parameters.js index 59d314ba04..8e5439e788 100644 --- a/client/app/components/parameters.js +++ b/client/app/components/parameters.js @@ -23,12 +23,16 @@ function ParametersDirective($location, $uibModal) { parameters: '=', syncValues: '=?', editable: '=?', + change: '&onChange', }, template, link(scope) { // is this the correct location for this logic? if (scope.syncValues !== false) { scope.$watch('parameters', () => { + if (scope.change) { + scope.change({}); + } scope.parameters.forEach((param) => { if (param.value !== null || param.value !== '') { $location.search(`p_${param.name}`, param.value); diff --git a/client/app/pages/dashboards/dashboard.html b/client/app/pages/dashboards/dashboard.html index 2037bbe6b8..bcce3fd868 100644 --- a/client/app/pages/dashboards/dashboard.html +++ b/client/app/pages/dashboards/dashboard.html @@ -55,7 +55,7 @@

- +
diff --git a/client/app/pages/dashboards/dashboard.js b/client/app/pages/dashboards/dashboard.js index 06f05fbeab..e04da7108c 100644 --- a/client/app/pages/dashboards/dashboard.js +++ b/client/app/pages/dashboards/dashboard.js @@ -31,27 +31,25 @@ function DashboardCtrl($rootScope, $scope, $routeParams, $location, $timeout, $q let globalParams = {}; this.dashboard.widgets.forEach(row => row.forEach((widget) => { - widget.getQuery().getParametersDefs().forEach((param) => { - if (param.name[0] === '$') { - const defaults = {}; - defaults[param.name] = _.clone(param); - defaults[param.name].locals = []; - globalParams = _.defaults(globalParams, defaults); - globalParams[param.name].locals.push(param); - } + widget.getQuery().getGlobalParametersDefs().forEach((param) => { + const defaults = {}; + defaults[param.name] = _.clone(param); + defaults[param.name].locals = []; + globalParams = _.defaults(globalParams, defaults); + globalParams[param.name].locals.push(param); }); }) ); this.globalParameters = _.values(globalParams); }; - $scope.$watch(() => this.globalParameters, (parameters) => { - _.each(parameters, (global) => { + this.onGlobalParametersChange = () => { + _.each(this.globalParameters, (global) => { _.each(global.locals, (local) => { local.value = global.value; }); }); - }, true); + }; $scope.$on('deleteDashboardWidget', extractGlobalParameters); diff --git a/client/app/pages/dashboards/widget.html b/client/app/pages/dashboards/widget.html index 3109c4dc6a..1bd1622a50 100644 --- a/client/app/pages/dashboards/widget.html +++ b/client/app/pages/dashboards/widget.html @@ -25,7 +25,7 @@
- +
diff --git a/client/app/services/query.js b/client/app/services/query.js index 13b84716ce..fdc1d050b2 100644 --- a/client/app/services/query.js +++ b/client/app/services/query.js @@ -293,6 +293,21 @@ function QueryResource($resource, $http, $q, $location, currentUser, QueryResult return this.getParameters().get(); }; + Query.prototype.getLocalParametersDefs = function getLocalParametersDefs() { + if (!this.$localParameters) { + this.$localParameters = this.getParametersDefs().filter(p => p.name[0] !== '$'); + } + + return this.$localParameters; + }; + + Query.prototype.getGlobalParametersDefs = function getGlobalParametersDefs() { + if (!this.$globalParameters) { + this.$globalParameters = this.getParametersDefs().filter(p => p.name[0] === '$'); + } + return this.$globalParameters; + }; + return Query; } From 894a85ae6368e6bc7992511c0b7d3c2b8f9a6ab5 Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Tue, 10 Jan 2017 08:25:32 -0800 Subject: [PATCH 3/6] Remove events on widget delete --- client/app/components/parameters.js | 6 +++--- client/app/pages/dashboards/dashboard.html | 2 +- client/app/pages/dashboards/dashboard.js | 12 +++++------- client/app/pages/dashboards/widget.js | 5 ++++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/client/app/components/parameters.js b/client/app/components/parameters.js index 8e5439e788..021eda44a1 100644 --- a/client/app/components/parameters.js +++ b/client/app/components/parameters.js @@ -23,15 +23,15 @@ function ParametersDirective($location, $uibModal) { parameters: '=', syncValues: '=?', editable: '=?', - change: '&onChange', + changed: '&onChange', }, template, link(scope) { // is this the correct location for this logic? if (scope.syncValues !== false) { scope.$watch('parameters', () => { - if (scope.change) { - scope.change({}); + if (scope.changed) { + scope.changed({}); } scope.parameters.forEach((param) => { if (param.value !== null || param.value !== '') { diff --git a/client/app/pages/dashboards/dashboard.html b/client/app/pages/dashboards/dashboard.html index bcce3fd868..8731e282a7 100644 --- a/client/app/pages/dashboards/dashboard.html +++ b/client/app/pages/dashboards/dashboard.html @@ -63,6 +63,6 @@

- +
diff --git a/client/app/pages/dashboards/dashboard.js b/client/app/pages/dashboards/dashboard.js index e04da7108c..c46c3632a4 100644 --- a/client/app/pages/dashboards/dashboard.js +++ b/client/app/pages/dashboards/dashboard.js @@ -27,7 +27,7 @@ function DashboardCtrl($rootScope, $scope, $routeParams, $location, $timeout, $q } }; - const extractGlobalParameters = () => { + this.extractGlobalParameters = () => { let globalParams = {}; this.dashboard.widgets.forEach(row => row.forEach((widget) => { @@ -44,15 +44,13 @@ function DashboardCtrl($rootScope, $scope, $routeParams, $location, $timeout, $q }; this.onGlobalParametersChange = () => { - _.each(this.globalParameters, (global) => { - _.each(global.locals, (local) => { + this.globalParameters.forEach((global) => { + global.locals.forEach((local) => { local.value = global.value; }); }); }; - $scope.$on('deleteDashboardWidget', extractGlobalParameters); - const renderDashboard = (dashboard, force) => { Title.set(dashboard.name); const promises = []; @@ -69,7 +67,7 @@ function DashboardCtrl($rootScope, $scope, $routeParams, $location, $timeout, $q }) ); - extractGlobalParameters(); + this.extractGlobalParameters(); $q.all(promises).then((queryResults) => { const filters = {}; @@ -168,7 +166,7 @@ function DashboardCtrl($rootScope, $scope, $routeParams, $location, $timeout, $q resolve: { dashboard: () => this.dashboard, }, - }).result.then(() => extractGlobalParameters()); + }).result.then(() => this.extractGlobalParameters()); }; this.toggleFullscreen = () => { diff --git a/client/app/pages/dashboards/widget.js b/client/app/pages/dashboards/widget.js index 81bb809af3..d7a6f9916a 100644 --- a/client/app/pages/dashboards/widget.js +++ b/client/app/pages/dashboards/widget.js @@ -52,7 +52,9 @@ function DashboardWidgetCtrl($location, $uibModal, $window, $scope, Events, curr this.dashboard.layout = response.layout; this.dashboard.version = response.version; - $scope.$emit('deleteDashboardWidget'); + if (this.deleted) { + this.deleted({}); + } }); }; @@ -90,6 +92,7 @@ export default function (ngModule) { widget: '<', public: '<', dashboard: '<', + deleted: '&onDelete', }, }); } From a2be7bf060fed793b5e38fcd0698829c9bf82f95 Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Tue, 10 Jan 2017 08:46:03 -0800 Subject: [PATCH 4/6] Adding an explict toggle for global parameters --- client/app/components/parameter-settings.html | 4 ++++ client/app/services/query.js | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/app/components/parameter-settings.html b/client/app/components/parameter-settings.html index ebd52b8ada..5315bed8f5 100644 --- a/client/app/components/parameter-settings.html +++ b/client/app/components/parameter-settings.html @@ -18,5 +18,9 @@ +
+ + +
diff --git a/client/app/services/query.js b/client/app/services/query.js index fdc1d050b2..dabcf61679 100644 --- a/client/app/services/query.js +++ b/client/app/services/query.js @@ -78,6 +78,7 @@ class Parameters { name: param, type: 'text', value: null, + global: false, }); } }); @@ -295,7 +296,7 @@ function QueryResource($resource, $http, $q, $location, currentUser, QueryResult Query.prototype.getLocalParametersDefs = function getLocalParametersDefs() { if (!this.$localParameters) { - this.$localParameters = this.getParametersDefs().filter(p => p.name[0] !== '$'); + this.$localParameters = this.getParametersDefs().filter(p => !p.global); } return this.$localParameters; @@ -303,7 +304,7 @@ function QueryResource($resource, $http, $q, $location, currentUser, QueryResult Query.prototype.getGlobalParametersDefs = function getGlobalParametersDefs() { if (!this.$globalParameters) { - this.$globalParameters = this.getParametersDefs().filter(p => p.name[0] === '$'); + this.$globalParameters = this.getParametersDefs().filter(p => p.global); } return this.$globalParameters; }; From cb2e6fddf44d32fc22d54e5f2a2adffcbb44dce1 Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Tue, 10 Jan 2017 08:52:03 -0800 Subject: [PATCH 5/6] Remove unused $scope --- client/app/pages/dashboards/dashboard.js | 2 +- client/app/pages/dashboards/widget.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/app/pages/dashboards/dashboard.js b/client/app/pages/dashboards/dashboard.js index c46c3632a4..f472b0c904 100644 --- a/client/app/pages/dashboards/dashboard.js +++ b/client/app/pages/dashboards/dashboard.js @@ -2,7 +2,7 @@ import * as _ from 'underscore'; import template from './dashboard.html'; import shareDashboardTemplate from './share-dashboard.html'; -function DashboardCtrl($rootScope, $scope, $routeParams, $location, $timeout, $q, $uibModal, +function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibModal, Title, AlertDialog, Dashboard, currentUser, clientConfig, Events) { this.isFullscreen = false; this.refreshRate = null; diff --git a/client/app/pages/dashboards/widget.js b/client/app/pages/dashboards/widget.js index d7a6f9916a..d77db21a73 100644 --- a/client/app/pages/dashboards/widget.js +++ b/client/app/pages/dashboards/widget.js @@ -24,7 +24,7 @@ const EditTextBoxComponent = { }, }; -function DashboardWidgetCtrl($location, $uibModal, $window, $scope, Events, currentUser) { +function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser) { this.canViewQuery = currentUser.hasPermission('view_query'); this.editTextBox = () => { From 11faabed1fc18b619ceea1416c53c4f8452a395a Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Thu, 26 Jan 2017 10:56:12 -0800 Subject: [PATCH 6/6] Move helper functions out of the query obj --- client/app/pages/dashboards/dashboard.js | 2 +- client/app/pages/dashboards/widget.html | 2 +- client/app/pages/dashboards/widget.js | 7 +++++++ client/app/services/query.js | 15 --------------- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/client/app/pages/dashboards/dashboard.js b/client/app/pages/dashboards/dashboard.js index f472b0c904..81f4e36c61 100644 --- a/client/app/pages/dashboards/dashboard.js +++ b/client/app/pages/dashboards/dashboard.js @@ -31,7 +31,7 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo let globalParams = {}; this.dashboard.widgets.forEach(row => row.forEach((widget) => { - widget.getQuery().getGlobalParametersDefs().forEach((param) => { + widget.getQuery().getParametersDefs().filter(p => p.global).forEach((param) => { const defaults = {}; defaults[param.name] = _.clone(param); defaults[param.name].locals = []; diff --git a/client/app/pages/dashboards/widget.html b/client/app/pages/dashboards/widget.html index 1bd1622a50..f74c12609f 100644 --- a/client/app/pages/dashboards/widget.html +++ b/client/app/pages/dashboards/widget.html @@ -25,7 +25,7 @@ - +
diff --git a/client/app/pages/dashboards/widget.js b/client/app/pages/dashboards/widget.js index d77db21a73..2f474073af 100644 --- a/client/app/pages/dashboards/widget.js +++ b/client/app/pages/dashboards/widget.js @@ -36,6 +36,13 @@ function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser) }); }; + this.localParametersDefs = () => { + if (!this.localParameters) { + this.localParameters = this.widget.query.getParametersDefs().filter(p => !p.global); + } + return this.localParameters; + }; + this.deleteWidget = () => { if (!$window.confirm(`Are you sure you want to remove "${this.widget.getName()}" from the dashboard?`)) { return; diff --git a/client/app/services/query.js b/client/app/services/query.js index dabcf61679..2e98abb375 100644 --- a/client/app/services/query.js +++ b/client/app/services/query.js @@ -294,21 +294,6 @@ function QueryResource($resource, $http, $q, $location, currentUser, QueryResult return this.getParameters().get(); }; - Query.prototype.getLocalParametersDefs = function getLocalParametersDefs() { - if (!this.$localParameters) { - this.$localParameters = this.getParametersDefs().filter(p => !p.global); - } - - return this.$localParameters; - }; - - Query.prototype.getGlobalParametersDefs = function getGlobalParametersDefs() { - if (!this.$globalParameters) { - this.$globalParameters = this.getParametersDefs().filter(p => p.global); - } - return this.$globalParameters; - }; - return Query; }