|
|
@@ -1,32 +1,13 @@
|
|
|
-/*
|
|
|
-
|
|
|
- ## Timepicker2
|
|
|
-
|
|
|
- ### Parameters
|
|
|
- * mode :: The default mode of the panel. Options: 'relative', 'absolute' 'since' Default: 'relative'
|
|
|
- * time_options :: An array of possible time options. Default: ['5m','15m','1h','6h','12h','24h','2d','7d','30d']
|
|
|
- * timespan :: The default options selected for the relative view. Default: '15m'
|
|
|
- * timefield :: The field in which time is stored in the document.
|
|
|
- * refresh: Object containing refresh parameters
|
|
|
- * enable :: true/false, enable auto refresh by default. Default: false
|
|
|
- * interval :: Seconds between auto refresh. Default: 30
|
|
|
- * min :: The lowest interval a user may set
|
|
|
-*/
|
|
|
-define([
|
|
|
- 'angular',
|
|
|
- 'app',
|
|
|
- 'lodash',
|
|
|
- 'moment',
|
|
|
- 'kbn'
|
|
|
-],
|
|
|
-function (angular, app, _, moment, kbn) {
|
|
|
- 'use strict';
|
|
|
+///<reference path="../../../headers/common.d.ts" />
|
|
|
|
|
|
- var module = angular.module('grafana.panels.timepicker', []);
|
|
|
- app.useModule(module);
|
|
|
+import angular = require('angular');
|
|
|
+import _ = require('lodash');
|
|
|
+import moment = require('moment');
|
|
|
+import kbn = require('kbn');
|
|
|
|
|
|
- module.controller('timepicker', function($scope, $rootScope, timeSrv) {
|
|
|
+export class TimePickerCtrl {
|
|
|
|
|
|
+ constructor($scope : any, $rootScope, timeSrv) {
|
|
|
$scope.panelMeta = {
|
|
|
status : "Stable",
|
|
|
description : ""
|
|
|
@@ -39,8 +20,6 @@ function (angular, app, _, moment, kbn) {
|
|
|
refresh_intervals : ['5s','10s','30s','1m','5m','15m','30m','1h','2h','1d'],
|
|
|
};
|
|
|
|
|
|
- _.defaults($scope.panel,_d);
|
|
|
-
|
|
|
// ng-pattern regexs
|
|
|
$scope.patterns = {
|
|
|
date: /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/,
|
|
|
@@ -57,6 +36,10 @@ function (angular, app, _, moment, kbn) {
|
|
|
});
|
|
|
|
|
|
$scope.init = function() {
|
|
|
+ $scope.panel = $scope.dashboard.timepicker;
|
|
|
+
|
|
|
+ _.defaults($scope.panel, _d);
|
|
|
+
|
|
|
var time = timeSrv.timeRange(true);
|
|
|
$scope.panel.now = false;
|
|
|
|
|
|
@@ -86,11 +69,11 @@ function (angular, app, _, moment, kbn) {
|
|
|
$scope.temptime = cloneTime($scope.time);
|
|
|
$scope.temptime.now = $scope.panel.now;
|
|
|
|
|
|
- $scope.temptime.from.date.setHours(0,0,0,0);
|
|
|
- $scope.temptime.to.date.setHours(0,0,0,0);
|
|
|
+ $scope.temptime.from.date.setHours(0, 0, 0, 0);
|
|
|
+ $scope.temptime.to.date.setHours(0, 0, 0, 0);
|
|
|
|
|
|
// Date picker needs the date to be at the start of the day
|
|
|
- if(new Date().getTimezoneOffset() < 0) {
|
|
|
+ if (new Date().getTimezoneOffset() < 0) {
|
|
|
$scope.temptime.from.date = moment($scope.temptime.from.date).add(1, 'days').toDate();
|
|
|
$scope.temptime.to.date = moment($scope.temptime.to.date).add(1, 'days').toDate();
|
|
|
}
|
|
|
@@ -100,7 +83,7 @@ function (angular, app, _, moment, kbn) {
|
|
|
|
|
|
// Constantly validate the input of the fields. This function does not change any date variables
|
|
|
// outside of its own scope
|
|
|
- $scope.validate = function(time) {
|
|
|
+ $scope.validate = function(time) : any {
|
|
|
// Assume the form is valid. There is a hidden dummy input for invalidating it programatically.
|
|
|
$scope.input.$setValidity("dummy", true);
|
|
|
|
|
|
@@ -108,13 +91,13 @@ function (angular, app, _, moment, kbn) {
|
|
|
_to = datepickerToLocal(time.to.date),
|
|
|
_t = time;
|
|
|
|
|
|
- if($scope.input.$valid) {
|
|
|
+ if ($scope.input.$valid) {
|
|
|
|
|
|
- _from.setHours(_t.from.hour,_t.from.minute,_t.from.second,_t.from.millisecond);
|
|
|
- _to.setHours(_t.to.hour,_t.to.minute,_t.to.second,_t.to.millisecond);
|
|
|
+ _from.setHours(_t.from.hour, _t.from.minute, _t.from.second, _t.from.millisecond);
|
|
|
+ _to.setHours(_t.to.hour, _t.to.minute, _t.to.second, _t.to.millisecond);
|
|
|
|
|
|
// Check that the objects are valid and to is after from
|
|
|
- if(isNaN(_from.getTime()) || isNaN(_to.getTime()) || _from.getTime() >= _to.getTime()) {
|
|
|
+ if (isNaN(_from.getTime()) || isNaN(_to.getTime()) || _from.getTime() >= _to.getTime()) {
|
|
|
$scope.input.$setValidity("dummy", false);
|
|
|
return false;
|
|
|
}
|
|
|
@@ -122,29 +105,23 @@ function (angular, app, _, moment, kbn) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- return { from: _from, to:_to, now: time.now};
|
|
|
+ return { from: _from, to: _to, now: time.now };
|
|
|
};
|
|
|
|
|
|
$scope.setNow = function() {
|
|
|
$scope.time.to = getTimeObj(new Date());
|
|
|
};
|
|
|
|
|
|
- /*
|
|
|
- time : {
|
|
|
- from: Date
|
|
|
- to: Date
|
|
|
- }
|
|
|
- */
|
|
|
$scope.setAbsoluteTimeFilter = function (time) {
|
|
|
// Create filter object
|
|
|
var _filter = _.clone(time);
|
|
|
|
|
|
- if(time.now) {
|
|
|
+ if (time.now) {
|
|
|
_filter.to = "now";
|
|
|
}
|
|
|
|
|
|
// Update our representation
|
|
|
- $scope.time = getScopeTimeObj(time.from,time.to);
|
|
|
+ $scope.time = getScopeTimeObj(time.from, time.to);
|
|
|
|
|
|
timeSrv.setTime(_filter);
|
|
|
};
|
|
|
@@ -160,10 +137,10 @@ function (angular, app, _, moment, kbn) {
|
|
|
|
|
|
timeSrv.setTime(range);
|
|
|
|
|
|
- $scope.time = getScopeTimeObj(kbn.parseDate(range.from),new Date());
|
|
|
+ $scope.time = getScopeTimeObj(kbn.parseDate(range.from), new Date());
|
|
|
};
|
|
|
|
|
|
- var pad = function(n, width, z) {
|
|
|
+ var pad : any = function(n, width, z) {
|
|
|
z = z || '0';
|
|
|
n = n.toString();
|
|
|
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
|
|
@@ -180,8 +157,8 @@ function (angular, app, _, moment, kbn) {
|
|
|
return _n;
|
|
|
};
|
|
|
|
|
|
- var getScopeTimeObj = function(from,to) {
|
|
|
- var model = {from: getTimeObj(from), to: getTimeObj(to)};
|
|
|
+ var getScopeTimeObj = function(from, to) {
|
|
|
+ var model : any = {from: getTimeObj(from), to: getTimeObj(to)};
|
|
|
|
|
|
if (model.from.date) {
|
|
|
model.tooltip = $scope.dashboard.formatDate(model.from.date) + ' <br>to<br>';
|
|
|
@@ -212,10 +189,10 @@ function (angular, app, _, moment, kbn) {
|
|
|
var getTimeObj = function(date) {
|
|
|
return {
|
|
|
date: new Date(date),
|
|
|
- hour: pad(date.getHours(),2),
|
|
|
- minute: pad(date.getMinutes(),2),
|
|
|
- second: pad(date.getSeconds(),2),
|
|
|
- millisecond: pad(date.getMilliseconds(),3)
|
|
|
+ hour: pad(date.getHours(), 2),
|
|
|
+ minute: pad(date.getMinutes(), 2),
|
|
|
+ second: pad(date.getSeconds(), 2),
|
|
|
+ millisecond: pad(date.getMilliseconds(), 3)
|
|
|
};
|
|
|
};
|
|
|
|
|
|
@@ -234,7 +211,7 @@ function (angular, app, _, moment, kbn) {
|
|
|
var to = (center + (timespan*factor)/2);
|
|
|
var from = (center - (timespan*factor)/2);
|
|
|
|
|
|
- if(to > Date.now() && range.to <= Date.now()) {
|
|
|
+ if (to > Date.now() && range.to <= Date.now()) {
|
|
|
var offset = to - Date.now();
|
|
|
from = from - offset;
|
|
|
to = Date.now();
|
|
|
@@ -246,5 +223,32 @@ function (angular, app, _, moment, kbn) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- });
|
|
|
-});
|
|
|
+ $scope.init();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function settingsDirective() {
|
|
|
+ 'use strict';
|
|
|
+ return {
|
|
|
+ restrict: 'E',
|
|
|
+ templateUrl: 'app/features/dashboard/timepicker/settings.html',
|
|
|
+ controller: TimePickerCtrl,
|
|
|
+ scope: true,
|
|
|
+ link: function() {
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+export function timePickerDirective() {
|
|
|
+ 'use strict';
|
|
|
+ return {
|
|
|
+ restrict: 'E',
|
|
|
+ templateUrl: 'app/features/dashboard/timepicker/timepicker.html',
|
|
|
+ controller: TimePickerCtrl,
|
|
|
+ scope: true
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+angular.module('grafana.directives').directive('gfTimePickerSettings', settingsDirective);
|
|
|
+angular.module('grafana.directives').directive('gfTimePicker', timePickerDirective);
|