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

Adding timeshift units #62

Merged
merged 5 commits into from
Jun 27, 2019
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
7 changes: 4 additions & 3 deletions dist/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ function (angular, _, dateMath, moment) {
var periodsToShift = target.periods;
var query = target.query;
var metric = target.metric;
var timeshiftUnit = target.timeshiftUnit;

options.range.from._d = dateToMoment(options.range.from, false).add(periodsToShift,'days').toDate();
options.range.to._d = dateToMoment(options.range.to, false).add(periodsToShift,'days').toDate();
options.range.from._d = dateToMoment(options.range.from, false).add(periodsToShift,timeshiftUnit).toDate();
options.range.to._d = dateToMoment(options.range.to, false).add(periodsToShift,timeshiftUnit).toDate();

var metaTarget = angular.copy(targetsByRefId[query]);
metaTarget.hide = false;
Expand All @@ -248,7 +249,7 @@ function (angular, _, dateMath, moment) {
data.forEach(function (datum) {
if(datum.target===metric){
datum.datapoints.forEach(function (datapoint) {
datapoint[1] = dateToMoment(new Date(datapoint[1]),false).subtract(periodsToShift,'days').toDate().getTime();
datapoint[1] = dateToMoment(new Date(datapoint[1]),false).subtract(periodsToShift,timeshiftUnit).toDate().getTime();
datapoints.push(datapoint)
})
}
Expand Down
23 changes: 22 additions & 1 deletion dist/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</div>

<div class="gf-form-inline" ng-switch on="ctrl.target.queryType">
<div ng-switch-when="MovingAverage|TimeShift" ng-switch-when-separator="|" class="gf-form max-width-20">
<div ng-switch-when="MovingAverage" ng-switch-when-separator="|" class="gf-form max-width-20">
<label class="gf-form-label query-keyword width-9">
Periods
</label>
Expand All @@ -37,6 +37,27 @@
<i class="fa fa-warning"></i>
</label>
</div>
<div ng-switch-when="TimeShift" ng-switch-when-separator="|" class="gf-form max-width-20">
<label class="gf-form-label query-keyword width-9">
Periods
</label>
<input type="text" class="gf-form-input" ng-model="ctrl.target.periods" spellcheck='false' placeholder="7" ng-blur="ctrl.targetBlur()" />
<label class="gf-form-label" bs-tooltip="ctrl.target.errors.periods" style="color: rgb(229, 189, 28)" ng-show="ctrl.target.errors.periods">
<i class="fa fa-warning"></i>
</label>
</div>
<div ng-switch-when="TimeShift" ng-switch-when-separator="|" class="gf-form max-width-20">
<label class="gf-form-label query-keyword width-9">
Unit
</label>
<div class="gf-form-select-wrapper max-width-15">
<select ng-model="ctrl.target.timeshiftUnit" class="gf-form-input" ng-options="timeshiftUnit for timeshiftUnit in ['seconds', 'minutes', 'hours', 'days', 'weeks', 'months']" ng-change="ctrl.targetBlur()">
</select>
</div>
<label class="gf-form-label" bs-tooltip="ctrl.target.errors.timeshiftUnit" style="color: rgb(229, 189, 28)" ng-show="ctrl.target.errors.timeshiftUnit">
<i class="fa fa-warning"></i>
</label>
</div>
<div ng-switch-when="MovingAverage|TimeShift" ng-switch-when-separator="|" class="gf-form">
<label class="gf-form-label query-keyword width-4">
Query
Expand Down
6 changes: 3 additions & 3 deletions dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"hiddenQueries": true,

"queryOptions": {
"minInterval": true
},
"minInterval": true
},

"info": {
"version": "0.0.2",
"author": {
Expand Down
1 change: 1 addition & 0 deletions dist/query_ctrl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export declare class MetaQueriesQueryCtrl extends QueryCtrl {
};
defaultQueryType: string;
defaultPeriods: number;
defaultTimeshiftUnit: string;
/** @ngInject **/
constructor($scope: any, $injector: any, $q: any);
targetBlur(): void;
Expand Down
4 changes: 4 additions & 0 deletions dist/query_ctrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/query_ctrl.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dist/query_ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class MetaQueriesQueryCtrl extends QueryCtrl {

defaultPeriods = 7;

defaultTimeshiftUnit = "days";

/** @ngInject **/
constructor($scope, $injector, $q) {
super($scope, $injector);
Expand All @@ -52,6 +54,9 @@ export class MetaQueriesQueryCtrl extends QueryCtrl {
if (!this.target.periods) {
this.clearPeriods();
}
if (!this.target.timeshiftUnit) {
this.target.timeshiftUnit = this.defaultTimeshiftUnit;
}

this.getQueryLetters = (query, callback) => {
return this.datasource.getTargets()
Expand Down
1 change: 1 addition & 0 deletions dist/test/query_ctrl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export declare class MetaQueriesQueryCtrl extends QueryCtrl {
};
defaultQueryType: string;
defaultPeriods: number;
defaultTimeshiftUnit: string;
/** @ngInject **/
constructor($scope: any, $injector: any, $q: any);
targetBlur(): void;
Expand Down
4 changes: 4 additions & 0 deletions dist/test/query_ctrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading