Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: global parameters for dashboards #1504

Merged
merged 6 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/app/components/parameter-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ <h4 class="modal-title">{{$ctrl.parameter.name}}</h4>
<option value="datetime-with-seconds">Date and Time (with seconds)</option>
</select>
</div>
<div class="form-group">
<label>Global</label>
<input type="checkbox" class="form-inline" ng-model="$ctrl.parameter.global">
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions client/app/components/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ function ParametersDirective($location, $uibModal) {
parameters: '=',
syncValues: '=?',
editable: '=?',
changed: '&onChange',
},
template,
link(scope) {
// is this the correct location for this logic?
if (scope.syncValues !== false) {
scope.$watch('parameters', () => {
if (scope.changed) {
scope.changed({});
}
scope.parameters.forEach((param) => {
if (param.value !== null || param.value !== '') {
$location.search(`p_${param.name}`, param.value);
Expand Down
6 changes: 5 additions & 1 deletion client/app/pages/dashboards/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ <h3>
This dashboard is archived and won't appear in the dashboards list or search results.
</div>

<div class="m-b-5">
<parameters parameters="$ctrl.globalParameters" on-change="$ctrl.onGlobalParametersChange()"></parameters>
</div>

<div class="m-b-5">
<filters ng-if="$ctrl.dashboard.dashboard_filters_enabled" filters="$ctrl.filters" on-change="$ctrl.filtersOnChange(filter, $modal)"></filters>
</div>

<div ng-repeat="row in $ctrl.dashboard.widgets" class="row">
<dashboard-widget ng-repeat="widget in row" widget="widget" dashboard="$ctrl.dashboard"></dashboard-widget>
<dashboard-widget ng-repeat="widget in row" widget="widget" dashboard="$ctrl.dashboard" on-delete="$ctrl.extractGlobalParameters()"></dashboard-widget>
</div>
</div>
29 changes: 28 additions & 1 deletion client/app/pages/dashboards/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo
this.refreshRate = null;
this.showPermissionsControl = clientConfig.showPermissionsControl;
this.currentUser = currentUser;
this.globalParameters = [];
this.refreshRates = [
{ name: '10 seconds', rate: 10 },
{ name: '30 seconds', rate: 30 },
Expand All @@ -26,6 +27,30 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo
}
};

this.extractGlobalParameters = () => {
let globalParams = {};
this.dashboard.widgets.forEach(row =>
row.forEach((widget) => {
widget.getQuery().getParametersDefs().filter(p => p.global).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);
};

this.onGlobalParametersChange = () => {
this.globalParameters.forEach((global) => {
global.locals.forEach((local) => {
local.value = global.value;
});
});
};

const renderDashboard = (dashboard, force) => {
Title.set(dashboard.name);
const promises = [];
Expand All @@ -42,6 +67,8 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo
})
);

this.extractGlobalParameters();

$q.all(promises).then((queryResults) => {
const filters = {};
queryResults.forEach((queryResult) => {
Expand Down Expand Up @@ -139,7 +166,7 @@ function DashboardCtrl($rootScope, $routeParams, $location, $timeout, $q, $uibMo
resolve: {
dashboard: () => this.dashboard,
},
});
}).result.then(() => this.extractGlobalParameters());
};

this.toggleFullscreen = () => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/pages/dashboards/widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>
</div>

<parameters parameters="$ctrl.widget.query.getParametersDefs()"></parameters>
<parameters parameters="$ctrl.localParametersDefs()"></parameters>

<div ng-switch="$ctrl.queryResult.getStatus()">
<div ng-switch-when="failed">
Expand Down
12 changes: 12 additions & 0 deletions client/app/pages/dashboards/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,6 +58,10 @@ function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser)

this.dashboard.layout = response.layout;
this.dashboard.version = response.version;

if (this.deleted) {
this.deleted({});
}
});
};

Expand Down Expand Up @@ -88,6 +99,7 @@ export default function (ngModule) {
widget: '<',
public: '<',
dashboard: '<',
deleted: '&onDelete',
},
});
}
1 change: 1 addition & 0 deletions client/app/services/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Parameters {
name: param,
type: 'text',
value: null,
global: false,
});
}
});
Expand Down