mirror of https://github.com/grafana/grafana.git
				
				
				
			Chore: Fixed no implicit any Typescript errors (#16799)
This commit is contained in:
		
							parent
							
								
									66c9297c36
								
							
						
					
					
						commit
						a4f5c54871
					
				|  | @ -4,7 +4,7 @@ import appEvents from 'app/core/app_events'; | ||||||
| 
 | 
 | ||||||
| export class ErrorCtrl { | export class ErrorCtrl { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor($scope, contextSrv, navModelSrv) { |   constructor($scope: any, contextSrv: any, navModelSrv: any) { | ||||||
|     $scope.navModel = navModelSrv.getNotFoundNav(); |     $scope.navModel = navModelSrv.getNotFoundNav(); | ||||||
|     $scope.appSubUrl = config.appSubUrl; |     $scope.appSubUrl = config.appSubUrl; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ import config from 'app/core/config'; | ||||||
| 
 | 
 | ||||||
| export class InvitedCtrl { | export class InvitedCtrl { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor($scope, $routeParams, contextSrv, backendSrv) { |   constructor($scope: any, $routeParams: any, contextSrv: any, backendSrv: any) { | ||||||
|     contextSrv.sidemenu = false; |     contextSrv.sidemenu = false; | ||||||
|     $scope.formModel = {}; |     $scope.formModel = {}; | ||||||
| 
 | 
 | ||||||
|  | @ -17,7 +17,7 @@ export class InvitedCtrl { | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     $scope.init = () => { |     $scope.init = () => { | ||||||
|       backendSrv.get('/api/user/invite/' + $routeParams.code).then(invite => { |       backendSrv.get('/api/user/invite/' + $routeParams.code).then((invite: any) => { | ||||||
|         $scope.formModel.name = invite.name; |         $scope.formModel.name = invite.name; | ||||||
|         $scope.formModel.email = invite.email; |         $scope.formModel.email = invite.email; | ||||||
|         $scope.formModel.username = invite.email; |         $scope.formModel.username = invite.email; | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ import coreModule from '../core_module'; | ||||||
| 
 | 
 | ||||||
| export class JsonEditorCtrl { | export class JsonEditorCtrl { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor($scope) { |   constructor($scope: any) { | ||||||
|     $scope.json = angular.toJson($scope.model.object, true); |     $scope.json = angular.toJson($scope.model.object, true); | ||||||
|     $scope.canUpdate = $scope.model.updateHandler !== void 0 && $scope.model.canUpdate; |     $scope.canUpdate = $scope.model.updateHandler !== void 0 && $scope.model.canUpdate; | ||||||
|     $scope.canCopy = $scope.model.enableCopy; |     $scope.canCopy = $scope.model.enableCopy; | ||||||
|  |  | ||||||
|  | @ -1,10 +1,11 @@ | ||||||
| import _ from 'lodash'; | import _ from 'lodash'; | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
| import config from 'app/core/config'; | import config from 'app/core/config'; | ||||||
|  | import { BackendSrv } from '../services/backend_srv'; | ||||||
| 
 | 
 | ||||||
| export class LoginCtrl { | export class LoginCtrl { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor($scope, backendSrv, contextSrv, $location) { |   constructor($scope: any, backendSrv: BackendSrv, $location: any) { | ||||||
|     $scope.formModel = { |     $scope.formModel = { | ||||||
|       user: '', |       user: '', | ||||||
|       email: '', |       email: '', | ||||||
|  | @ -15,8 +16,6 @@ export class LoginCtrl { | ||||||
|     $scope.result = ''; |     $scope.result = ''; | ||||||
|     $scope.loggingIn = false; |     $scope.loggingIn = false; | ||||||
| 
 | 
 | ||||||
|     contextSrv.sidemenu = false; |  | ||||||
| 
 |  | ||||||
|     $scope.oauth = config.oauth; |     $scope.oauth = config.oauth; | ||||||
|     $scope.oauthEnabled = _.keys(config.oauth).length > 0; |     $scope.oauthEnabled = _.keys(config.oauth).length > 0; | ||||||
|     $scope.ldapEnabled = config.ldapEnabled; |     $scope.ldapEnabled = config.ldapEnabled; | ||||||
|  | @ -83,7 +82,7 @@ export class LoginCtrl { | ||||||
|       $scope.toGrafana(); |       $scope.toGrafana(); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     $scope.loginModeChanged = newValue => { |     $scope.loginModeChanged = (newValue: boolean) => { | ||||||
|       $scope.submitBtnText = newValue ? 'Log in' : 'Sign up'; |       $scope.submitBtnText = newValue ? 'Log in' : 'Sign up'; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | @ -92,7 +91,7 @@ export class LoginCtrl { | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       backendSrv.post('/api/user/signup', $scope.formModel).then(result => { |       backendSrv.post('/api/user/signup', $scope.formModel).then((result: any) => { | ||||||
|         if (result.status === 'SignUpCreated') { |         if (result.status === 'SignUpCreated') { | ||||||
|           $location.path('/signup').search({ email: $scope.formModel.email }); |           $location.path('/signup').search({ email: $scope.formModel.email }); | ||||||
|         } else { |         } else { | ||||||
|  | @ -111,7 +110,7 @@ export class LoginCtrl { | ||||||
| 
 | 
 | ||||||
|       backendSrv |       backendSrv | ||||||
|         .post('/login', $scope.formModel) |         .post('/login', $scope.formModel) | ||||||
|         .then(result => { |         .then((result: any) => { | ||||||
|           $scope.result = result; |           $scope.result = result; | ||||||
| 
 | 
 | ||||||
|           if ($scope.formModel.password !== 'admin' || $scope.ldapEnabled || $scope.authProxyEnabled) { |           if ($scope.formModel.password !== 'admin' || $scope.ldapEnabled || $scope.authProxyEnabled) { | ||||||
|  |  | ||||||
|  | @ -1,10 +1,10 @@ | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
| import config from 'app/core/config'; | import config from 'app/core/config'; | ||||||
|  | import { BackendSrv } from '../services/backend_srv'; | ||||||
| 
 | 
 | ||||||
| export class ResetPasswordCtrl { | export class ResetPasswordCtrl { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor($scope, contextSrv, backendSrv, $location) { |   constructor($scope: any, backendSrv: BackendSrv, $location: any) { | ||||||
|     contextSrv.sidemenu = false; |  | ||||||
|     $scope.formModel = {}; |     $scope.formModel = {}; | ||||||
|     $scope.mode = 'send'; |     $scope.mode = 'send'; | ||||||
|     $scope.ldapEnabled = config.ldapEnabled; |     $scope.ldapEnabled = config.ldapEnabled; | ||||||
|  |  | ||||||
|  | @ -7,12 +7,12 @@ export function arrayJoin() { | ||||||
|   return { |   return { | ||||||
|     restrict: 'A', |     restrict: 'A', | ||||||
|     require: 'ngModel', |     require: 'ngModel', | ||||||
|     link: (scope, element, attr, ngModel) => { |     link: (scope: any, element: any, attr: any, ngModel: any) => { | ||||||
|       function split_array(text) { |       function split_array(text: string) { | ||||||
|         return (text || '').split(','); |         return (text || '').split(','); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       function join_array(text) { |       function join_array(text: string) { | ||||||
|         if (_.isArray(text)) { |         if (_.isArray(text)) { | ||||||
|           return ((text || '') as any).join(','); |           return ((text || '') as any).join(','); | ||||||
|         } else { |         } else { | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| export function autofillEventFix($compile) { | export function autofillEventFix($compile: any) { | ||||||
|   return { |   return { | ||||||
|     link: ($scope: any, elem: any) => { |     link: ($scope: any, elem: any) => { | ||||||
|       const input = elem[0]; |       const input = elem[0]; | ||||||
|  |  | ||||||
|  | @ -5,8 +5,8 @@ export class DeltaCtrl { | ||||||
|   observer: any; |   observer: any; | ||||||
| 
 | 
 | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $rootScope) { |   constructor(private $rootScope: any) { | ||||||
|     const waitForCompile = mutations => { |     const waitForCompile = (mutations: any) => { | ||||||
|       if (mutations.length === 1) { |       if (mutations.length === 1) { | ||||||
|         this.$rootScope.appEvent('json-diff-ready'); |         this.$rootScope.appEvent('json-diff-ready'); | ||||||
|       } |       } | ||||||
|  | @ -42,10 +42,10 @@ coreModule.directive('diffDelta', delta); | ||||||
| // Link to JSON line number
 | // Link to JSON line number
 | ||||||
| export class LinkJSONCtrl { | export class LinkJSONCtrl { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $scope, private $rootScope, private $anchorScroll) {} |   constructor(private $scope: any, private $rootScope: any, private $anchorScroll: any) {} | ||||||
| 
 | 
 | ||||||
|   goToLine(line: number) { |   goToLine(line: number) { | ||||||
|     let unbind; |     let unbind: () => void; | ||||||
| 
 | 
 | ||||||
|     const scroll = () => { |     const scroll = () => { | ||||||
|       this.$anchorScroll(`l${line}`); |       this.$anchorScroll(`l${line}`); | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ import $ from 'jquery'; | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| export function dropdownTypeahead($compile) { | export function dropdownTypeahead($compile: any) { | ||||||
|   const inputTemplate = |   const inputTemplate = | ||||||
|     '<input type="text"' + |     '<input type="text"' + | ||||||
|     ' class="gf-form-input input-medium tight-form-input"' + |     ' class="gf-form-input input-medium tight-form-input"' + | ||||||
|  | @ -20,7 +20,7 @@ export function dropdownTypeahead($compile) { | ||||||
|       dropdownTypeaheadOnSelect: '&dropdownTypeaheadOnSelect', |       dropdownTypeaheadOnSelect: '&dropdownTypeaheadOnSelect', | ||||||
|       model: '=ngModel', |       model: '=ngModel', | ||||||
|     }, |     }, | ||||||
|     link: ($scope, elem, attrs) => { |     link: ($scope: any, elem: any, attrs: any) => { | ||||||
|       const $input = $(inputTemplate); |       const $input = $(inputTemplate); | ||||||
|       const $button = $(buttonTemplate); |       const $button = $(buttonTemplate); | ||||||
|       $input.appendTo(elem); |       $input.appendTo(elem); | ||||||
|  | @ -31,7 +31,7 @@ export function dropdownTypeahead($compile) { | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (attrs.ngModel) { |       if (attrs.ngModel) { | ||||||
|         $scope.$watch('model', newValue => { |         $scope.$watch('model', (newValue: any) => { | ||||||
|           _.each($scope.menuItems, item => { |           _.each($scope.menuItems, item => { | ||||||
|             _.each(item.submenu, subItem => { |             _.each(item.submenu, subItem => { | ||||||
|               if (subItem.value === newValue) { |               if (subItem.value === newValue) { | ||||||
|  | @ -59,7 +59,7 @@ export function dropdownTypeahead($compile) { | ||||||
|         [] |         [] | ||||||
|       ); |       ); | ||||||
| 
 | 
 | ||||||
|       $scope.menuItemSelected = (index, subIndex) => { |       $scope.menuItemSelected = (index: number, subIndex: number) => { | ||||||
|         const menuItem = $scope.menuItems[index]; |         const menuItem = $scope.menuItems[index]; | ||||||
|         const payload: any = { $item: menuItem }; |         const payload: any = { $item: menuItem }; | ||||||
|         if (menuItem.submenu && subIndex !== void 0) { |         if (menuItem.submenu && subIndex !== void 0) { | ||||||
|  | @ -73,7 +73,7 @@ export function dropdownTypeahead($compile) { | ||||||
|         source: typeaheadValues, |         source: typeaheadValues, | ||||||
|         minLength: 1, |         minLength: 1, | ||||||
|         items: 10, |         items: 10, | ||||||
|         updater: value => { |         updater: (value: string) => { | ||||||
|           const result: any = {}; |           const result: any = {}; | ||||||
|           _.each($scope.menuItems, menuItem => { |           _.each($scope.menuItems, menuItem => { | ||||||
|             _.each(menuItem.submenu, submenuItem => { |             _.each(menuItem.submenu, submenuItem => { | ||||||
|  | @ -123,7 +123,7 @@ export function dropdownTypeahead($compile) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| export function dropdownTypeahead2($compile) { | export function dropdownTypeahead2($compile: any) { | ||||||
|   const inputTemplate = |   const inputTemplate = | ||||||
|     '<input type="text"' + ' class="gf-form-input"' + ' spellcheck="false" style="display:none"></input>'; |     '<input type="text"' + ' class="gf-form-input"' + ' spellcheck="false" style="display:none"></input>'; | ||||||
| 
 | 
 | ||||||
|  | @ -139,7 +139,7 @@ export function dropdownTypeahead2($compile) { | ||||||
|       model: '=ngModel', |       model: '=ngModel', | ||||||
|       buttonTemplateClass: '@', |       buttonTemplateClass: '@', | ||||||
|     }, |     }, | ||||||
|     link: ($scope, elem, attrs) => { |     link: ($scope: any, elem: any, attrs: any) => { | ||||||
|       const $input = $(inputTemplate); |       const $input = $(inputTemplate); | ||||||
| 
 | 
 | ||||||
|       if (!$scope.buttonTemplateClass) { |       if (!$scope.buttonTemplateClass) { | ||||||
|  | @ -148,7 +148,7 @@ export function dropdownTypeahead2($compile) { | ||||||
| 
 | 
 | ||||||
|       const $button = $(buttonTemplate); |       const $button = $(buttonTemplate); | ||||||
|       const timeoutId = { |       const timeoutId = { | ||||||
|         blur: null, |         blur: null as any, | ||||||
|       }; |       }; | ||||||
|       $input.appendTo(elem); |       $input.appendTo(elem); | ||||||
|       $button.appendTo(elem); |       $button.appendTo(elem); | ||||||
|  | @ -158,7 +158,7 @@ export function dropdownTypeahead2($compile) { | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (attrs.ngModel) { |       if (attrs.ngModel) { | ||||||
|         $scope.$watch('model', newValue => { |         $scope.$watch('model', (newValue: any) => { | ||||||
|           _.each($scope.menuItems, item => { |           _.each($scope.menuItems, item => { | ||||||
|             _.each(item.submenu, subItem => { |             _.each(item.submenu, subItem => { | ||||||
|               if (subItem.value === newValue) { |               if (subItem.value === newValue) { | ||||||
|  | @ -194,7 +194,7 @@ export function dropdownTypeahead2($compile) { | ||||||
|         elem.removeClass('open'); |         elem.removeClass('open'); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       $scope.menuItemSelected = (index, subIndex) => { |       $scope.menuItemSelected = (index: number, subIndex: number) => { | ||||||
|         const menuItem = $scope.menuItems[index]; |         const menuItem = $scope.menuItems[index]; | ||||||
|         const payload: any = { $item: menuItem }; |         const payload: any = { $item: menuItem }; | ||||||
|         if (menuItem.submenu && subIndex !== void 0) { |         if (menuItem.submenu && subIndex !== void 0) { | ||||||
|  | @ -209,7 +209,7 @@ export function dropdownTypeahead2($compile) { | ||||||
|         source: typeaheadValues, |         source: typeaheadValues, | ||||||
|         minLength: 1, |         minLength: 1, | ||||||
|         items: 10, |         items: 10, | ||||||
|         updater: value => { |         updater: (value: string) => { | ||||||
|           const result: any = {}; |           const result: any = {}; | ||||||
|           _.each($scope.menuItems, menuItem => { |           _.each($scope.menuItems, menuItem => { | ||||||
|             _.each(menuItem.submenu, submenuItem => { |             _.each(menuItem.submenu, submenuItem => { | ||||||
|  |  | ||||||
|  | @ -1,14 +1,14 @@ | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
| 
 | 
 | ||||||
| coreModule.directive('giveFocus', () => { | coreModule.directive('giveFocus', () => { | ||||||
|   return (scope, element, attrs) => { |   return (scope: any, element: any, attrs: any) => { | ||||||
|     element.click(e => { |     element.click((e: any) => { | ||||||
|       e.stopPropagation(); |       e.stopPropagation(); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     scope.$watch( |     scope.$watch( | ||||||
|       attrs.giveFocus, |       attrs.giveFocus, | ||||||
|       newValue => { |       (newValue: any) => { | ||||||
|         if (!newValue) { |         if (!newValue) { | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -1,9 +1,10 @@ | ||||||
| import _ from 'lodash'; | import _ from 'lodash'; | ||||||
| import $ from 'jquery'; | import $ from 'jquery'; | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
|  | import { TemplateSrv } from 'app/features/templating/template_srv'; | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| export function metricSegment($compile, $sce, templateSrv) { | export function metricSegment($compile: any, $sce: any, templateSrv: TemplateSrv) { | ||||||
|   const inputTemplate = |   const inputTemplate = | ||||||
|     '<input type="text" data-provide="typeahead" ' + |     '<input type="text" data-provide="typeahead" ' + | ||||||
|     ' class="gf-form-input input-medium"' + |     ' class="gf-form-input input-medium"' + | ||||||
|  | @ -24,19 +25,19 @@ export function metricSegment($compile, $sce, templateSrv) { | ||||||
|       onChange: '&', |       onChange: '&', | ||||||
|       debounce: '@', |       debounce: '@', | ||||||
|     }, |     }, | ||||||
|     link: ($scope, elem) => { |     link: ($scope: any, elem: any) => { | ||||||
|       const $input = $(inputTemplate); |       const $input = $(inputTemplate); | ||||||
|       const segment = $scope.segment; |       const segment = $scope.segment; | ||||||
|       const $button = $(segment.selectMode ? selectTemplate : linkTemplate); |       const $button = $(segment.selectMode ? selectTemplate : linkTemplate); | ||||||
|       let options = null; |       let options = null; | ||||||
|       let cancelBlur = null; |       let cancelBlur: any = null; | ||||||
|       let linkMode = true; |       let linkMode = true; | ||||||
|       const debounceLookup = $scope.debounce; |       const debounceLookup = $scope.debounce; | ||||||
| 
 | 
 | ||||||
|       $input.appendTo(elem); |       $input.appendTo(elem); | ||||||
|       $button.appendTo(elem); |       $button.appendTo(elem); | ||||||
| 
 | 
 | ||||||
|       $scope.updateVariableValue = value => { |       $scope.updateVariableValue = (value: string) => { | ||||||
|         if (value === '' || segment.value === value) { |         if (value === '' || segment.value === value) { | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
|  | @ -63,7 +64,7 @@ export function metricSegment($compile, $sce, templateSrv) { | ||||||
|         }); |         }); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       $scope.switchToLink = fromClick => { |       $scope.switchToLink = (fromClick: boolean) => { | ||||||
|         if (linkMode && !fromClick) { |         if (linkMode && !fromClick) { | ||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
|  | @ -82,9 +83,9 @@ export function metricSegment($compile, $sce, templateSrv) { | ||||||
|         cancelBlur = setTimeout($scope.switchToLink, 200); |         cancelBlur = setTimeout($scope.switchToLink, 200); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       $scope.source = (query, callback) => { |       $scope.source = (query: string, callback: any) => { | ||||||
|         $scope.$apply(() => { |         $scope.$apply(() => { | ||||||
|           $scope.getOptions({ $query: query }).then(altSegments => { |           $scope.getOptions({ $query: query }).then((altSegments: any) => { | ||||||
|             $scope.altSegments = altSegments; |             $scope.altSegments = altSegments; | ||||||
|             options = _.map($scope.altSegments, alt => { |             options = _.map($scope.altSegments, alt => { | ||||||
|               return _.escape(alt.value); |               return _.escape(alt.value); | ||||||
|  | @ -102,7 +103,7 @@ export function metricSegment($compile, $sce, templateSrv) { | ||||||
|         }); |         }); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       $scope.updater = value => { |       $scope.updater = (value: string) => { | ||||||
|         value = _.unescape(value); |         value = _.unescape(value); | ||||||
|         if (value === segment.value) { |         if (value === segment.value) { | ||||||
|           clearTimeout(cancelBlur); |           clearTimeout(cancelBlur); | ||||||
|  | @ -116,7 +117,7 @@ export function metricSegment($compile, $sce, templateSrv) { | ||||||
|         return value; |         return value; | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       $scope.matcher = function(item) { |       $scope.matcher = function(item: string) { | ||||||
|         if (linkMode) { |         if (linkMode) { | ||||||
|           return false; |           return false; | ||||||
|         } |         } | ||||||
|  | @ -186,7 +187,7 @@ export function metricSegment($compile, $sce, templateSrv) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| export function metricSegmentModel(uiSegmentSrv, $q) { | export function metricSegmentModel(uiSegmentSrv: any, $q: any) { | ||||||
|   return { |   return { | ||||||
|     template: |     template: | ||||||
|       '<metric-segment segment="segment" get-options="getOptionsInternal()" on-change="onSegmentChange()"></metric-segment>', |       '<metric-segment segment="segment" get-options="getOptionsInternal()" on-change="onSegmentChange()"></metric-segment>', | ||||||
|  | @ -198,10 +199,10 @@ export function metricSegmentModel(uiSegmentSrv, $q) { | ||||||
|       onChange: '&', |       onChange: '&', | ||||||
|     }, |     }, | ||||||
|     link: { |     link: { | ||||||
|       pre: function postLink($scope, elem, attrs) { |       pre: function postLink($scope: any, elem: any, attrs: any) { | ||||||
|         let cachedOptions; |         let cachedOptions: any; | ||||||
| 
 | 
 | ||||||
|         $scope.valueToSegment = value => { |         $scope.valueToSegment = (value: any) => { | ||||||
|           const option: any = _.find($scope.options, { value: value }); |           const option: any = _.find($scope.options, { value: value }); | ||||||
|           const segment = { |           const segment = { | ||||||
|             cssClass: attrs.cssClass, |             cssClass: attrs.cssClass, | ||||||
|  | @ -222,7 +223,7 @@ export function metricSegmentModel(uiSegmentSrv, $q) { | ||||||
|               }) |               }) | ||||||
|             ); |             ); | ||||||
|           } else { |           } else { | ||||||
|             return $scope.getOptions().then(options => { |             return $scope.getOptions().then((options: any) => { | ||||||
|               cachedOptions = options; |               cachedOptions = options; | ||||||
|               return _.map(options, option => { |               return _.map(options, option => { | ||||||
|                 if (option.html) { |                 if (option.html) { | ||||||
|  |  | ||||||
|  | @ -5,10 +5,10 @@ import kbn from 'app/core/utils/kbn'; | ||||||
| import { appEvents } from 'app/core/core'; | import { appEvents } from 'app/core/core'; | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function tip($compile) { | function tip($compile: any) { | ||||||
|   return { |   return { | ||||||
|     restrict: 'E', |     restrict: 'E', | ||||||
|     link: (scope, elem, attrs) => { |     link: (scope: any, elem: any, attrs: any) => { | ||||||
|       let _t = |       let _t = | ||||||
|         '<i class="grafana-tip fa fa-' + |         '<i class="grafana-tip fa fa-' + | ||||||
|         (attrs.icon || 'question-circle') + |         (attrs.icon || 'question-circle') + | ||||||
|  | @ -26,7 +26,7 @@ function clipboardButton() { | ||||||
|     scope: { |     scope: { | ||||||
|       getText: '&clipboardButton', |       getText: '&clipboardButton', | ||||||
|     }, |     }, | ||||||
|     link: (scope, elem) => { |     link: (scope: any, elem: any) => { | ||||||
|       scope.clipboard = new Clipboard(elem[0], { |       scope.clipboard = new Clipboard(elem[0], { | ||||||
|         text: () => { |         text: () => { | ||||||
|           return scope.getText(); |           return scope.getText(); | ||||||
|  | @ -47,15 +47,15 @@ function clipboardButton() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function compile($compile) { | function compile($compile: any) { | ||||||
|   return { |   return { | ||||||
|     restrict: 'A', |     restrict: 'A', | ||||||
|     link: (scope, element, attrs) => { |     link: (scope: any, element: any, attrs: any) => { | ||||||
|       scope.$watch( |       scope.$watch( | ||||||
|         scope => { |         (scope: any) => { | ||||||
|           return scope.$eval(attrs.compile); |           return scope.$eval(attrs.compile); | ||||||
|         }, |         }, | ||||||
|         value => { |         (value: any) => { | ||||||
|           element.html(value); |           element.html(value); | ||||||
|           $compile(element.contents())(scope); |           $compile(element.contents())(scope); | ||||||
|         } |         } | ||||||
|  | @ -67,7 +67,7 @@ function compile($compile) { | ||||||
| function watchChange() { | function watchChange() { | ||||||
|   return { |   return { | ||||||
|     scope: { onchange: '&watchChange' }, |     scope: { onchange: '&watchChange' }, | ||||||
|     link: (scope, element) => { |     link: (scope: any, element: any) => { | ||||||
|       element.on('input', () => { |       element.on('input', () => { | ||||||
|         scope.$apply(() => { |         scope.$apply(() => { | ||||||
|           scope.onchange({ inputValue: element.val() }); |           scope.onchange({ inputValue: element.val() }); | ||||||
|  | @ -78,10 +78,10 @@ function watchChange() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function editorOptBool($compile) { | function editorOptBool($compile: any) { | ||||||
|   return { |   return { | ||||||
|     restrict: 'E', |     restrict: 'E', | ||||||
|     link: (scope, elem, attrs) => { |     link: (scope: any, elem: any, attrs: any) => { | ||||||
|       const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : ''; |       const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : ''; | ||||||
|       const tip = attrs.tip ? ' <tip>' + attrs.tip + '</tip>' : ''; |       const tip = attrs.tip ? ' <tip>' + attrs.tip + '</tip>' : ''; | ||||||
|       const showIf = attrs.showIf ? ' ng-show="' + attrs.showIf + '" ' : ''; |       const showIf = attrs.showIf ? ' ng-show="' + attrs.showIf + '" ' : ''; | ||||||
|  | @ -115,10 +115,10 @@ function editorOptBool($compile) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function editorCheckbox($compile, $interpolate) { | function editorCheckbox($compile: any, $interpolate: any) { | ||||||
|   return { |   return { | ||||||
|     restrict: 'E', |     restrict: 'E', | ||||||
|     link: (scope, elem, attrs) => { |     link: (scope: any, elem: any, attrs: any) => { | ||||||
|       const text = $interpolate(attrs.text)(scope); |       const text = $interpolate(attrs.text)(scope); | ||||||
|       const model = $interpolate(attrs.model)(scope); |       const model = $interpolate(attrs.model)(scope); | ||||||
|       const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : ''; |       const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : ''; | ||||||
|  | @ -150,8 +150,8 @@ function editorCheckbox($compile, $interpolate) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function gfDropdown($parse, $compile, $timeout) { | function gfDropdown($parse: any, $compile: any, $timeout: any) { | ||||||
|   function buildTemplate(items, placement?) { |   function buildTemplate(items: any, placement?: any) { | ||||||
|     const upclass = placement === 'top' ? 'dropup' : ''; |     const upclass = placement === 'top' ? 'dropup' : ''; | ||||||
|     const ul = ['<ul class="dropdown-menu ' + upclass + '" role="menu" aria-labelledby="drop1">', '</ul>']; |     const ul = ['<ul class="dropdown-menu ' + upclass + '" role="menu" aria-labelledby="drop1">', '</ul>']; | ||||||
| 
 | 
 | ||||||
|  | @ -191,7 +191,7 @@ function gfDropdown($parse, $compile, $timeout) { | ||||||
|   return { |   return { | ||||||
|     restrict: 'EA', |     restrict: 'EA', | ||||||
|     scope: true, |     scope: true, | ||||||
|     link: function postLink(scope, iElement, iAttrs) { |     link: function postLink(scope: any, iElement: any, iAttrs: any) { | ||||||
|       const getter = $parse(iAttrs.gfDropdown), |       const getter = $parse(iAttrs.gfDropdown), | ||||||
|         items = getter(scope); |         items = getter(scope); | ||||||
|       $timeout(() => { |       $timeout(() => { | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ function ngModelOnBlur() { | ||||||
|     restrict: 'A', |     restrict: 'A', | ||||||
|     priority: 1, |     priority: 1, | ||||||
|     require: 'ngModel', |     require: 'ngModel', | ||||||
|     link: (scope, elm, attr, ngModelCtrl) => { |     link: (scope: any, elm: any, attr: any, ngModelCtrl: any) => { | ||||||
|       if (attr.type === 'radio' || attr.type === 'checkbox') { |       if (attr.type === 'radio' || attr.type === 'checkbox') { | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|  | @ -25,8 +25,8 @@ function emptyToNull() { | ||||||
|   return { |   return { | ||||||
|     restrict: 'A', |     restrict: 'A', | ||||||
|     require: 'ngModel', |     require: 'ngModel', | ||||||
|     link: (scope, elm, attrs, ctrl) => { |     link: (scope: any, elm: any, attrs: any, ctrl: any) => { | ||||||
|       ctrl.$parsers.push(viewValue => { |       ctrl.$parsers.push((viewValue: any) => { | ||||||
|         if (viewValue === '') { |         if (viewValue === '') { | ||||||
|           return null; |           return null; | ||||||
|         } |         } | ||||||
|  | @ -39,8 +39,8 @@ function emptyToNull() { | ||||||
| function validTimeSpan() { | function validTimeSpan() { | ||||||
|   return { |   return { | ||||||
|     require: 'ngModel', |     require: 'ngModel', | ||||||
|     link: (scope, elm, attrs, ctrl) => { |     link: (scope: any, elm: any, attrs: any, ctrl: any) => { | ||||||
|       ctrl.$validators.integer = (modelValue, viewValue) => { |       ctrl.$validators.integer = (modelValue: any, viewValue: any) => { | ||||||
|         if (ctrl.$isEmpty(modelValue)) { |         if (ctrl.$isEmpty(modelValue)) { | ||||||
|           return true; |           return true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -1,16 +1,16 @@ | ||||||
| import $ from 'jquery'; | import $ from 'jquery'; | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
| 
 | 
 | ||||||
| function getBlockNodes(nodes) { | function getBlockNodes(nodes: any[]) { | ||||||
|   let node = nodes[0]; |   let node = nodes[0]; | ||||||
|   const endNode = nodes[nodes.length - 1]; |   const endNode = nodes[nodes.length - 1]; | ||||||
|   let blockNodes; |   let blockNodes: any[]; | ||||||
|   node = node.nextSibling; |   node = node.nextSibling; | ||||||
| 
 | 
 | ||||||
|   for (let i = 1; node !== endNode && node; i++) { |   for (let i = 1; node !== endNode && node; i++) { | ||||||
|     if (blockNodes || nodes[i] !== node) { |     if (blockNodes || nodes[i] !== node) { | ||||||
|       if (!blockNodes) { |       if (!blockNodes) { | ||||||
|         blockNodes = $([].slice.call(nodes, 0, i)); |         blockNodes = $([].slice.call(nodes, 0, i)) as any; | ||||||
|       } |       } | ||||||
|       blockNodes.push(node); |       blockNodes.push(node); | ||||||
|     } |     } | ||||||
|  | @ -21,15 +21,15 @@ function getBlockNodes(nodes) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function rebuildOnChange($animate) { | function rebuildOnChange($animate: any) { | ||||||
|   return { |   return { | ||||||
|     multiElement: true, |     multiElement: true, | ||||||
|     terminal: true, |     terminal: true, | ||||||
|     transclude: true, |     transclude: true, | ||||||
|     priority: 600, |     priority: 600, | ||||||
|     restrict: 'E', |     restrict: 'E', | ||||||
|     link: (scope, elem, attrs, ctrl, transclude) => { |     link: (scope: any, elem: any, attrs: any, ctrl: any, transclude: any) => { | ||||||
|       let block, childScope, previousElements; |       let block: any, childScope: any, previousElements: any; | ||||||
| 
 | 
 | ||||||
|       function cleanUp() { |       function cleanUp() { | ||||||
|         if (previousElements) { |         if (previousElements) { | ||||||
|  | @ -49,13 +49,13 @@ function rebuildOnChange($animate) { | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       scope.$watch(attrs.property, function rebuildOnChangeAction(value, oldValue) { |       scope.$watch(attrs.property, function rebuildOnChangeAction(value: any, oldValue: any) { | ||||||
|         if (childScope && value !== oldValue) { |         if (childScope && value !== oldValue) { | ||||||
|           cleanUp(); |           cleanUp(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (!childScope && (value || attrs.showNull)) { |         if (!childScope && (value || attrs.showNull)) { | ||||||
|           transclude((clone, newScope) => { |           transclude((clone: any, newScope: any) => { | ||||||
|             childScope = newScope; |             childScope = newScope; | ||||||
|             clone[clone.length++] = document.createComment(' end rebuild on change '); |             clone[clone.length++] = document.createComment(' end rebuild on change '); | ||||||
|             block = { clone: clone }; |             block = { clone: clone }; | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ import coreModule from '../core_module'; | ||||||
| import tags from 'app/core/utils/tags'; | import tags from 'app/core/utils/tags'; | ||||||
| import 'vendor/tagsinput/bootstrap-tagsinput.js'; | import 'vendor/tagsinput/bootstrap-tagsinput.js'; | ||||||
| 
 | 
 | ||||||
| function setColor(name, element) { | function setColor(name: string, element: JQuery) { | ||||||
|   const { color, borderColor } = tags.getTagColorsFromName(name); |   const { color, borderColor } = tags.getTagColorsFromName(name); | ||||||
|   element.css('background-color', color); |   element.css('background-color', color); | ||||||
|   element.css('border-color', borderColor); |   element.css('border-color', borderColor); | ||||||
|  | @ -13,14 +13,14 @@ function setColor(name, element) { | ||||||
| function tagColorFromName() { | function tagColorFromName() { | ||||||
|   return { |   return { | ||||||
|     scope: { tagColorFromName: '=' }, |     scope: { tagColorFromName: '=' }, | ||||||
|     link: (scope, element) => { |     link: (scope: any, element: any) => { | ||||||
|       setColor(scope.tagColorFromName, element); |       setColor(scope.tagColorFromName, element); | ||||||
|     }, |     }, | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function bootstrapTagsinput() { | function bootstrapTagsinput() { | ||||||
|   function getItemProperty(scope, property) { |   function getItemProperty(scope: any, property: any) { | ||||||
|     if (!property) { |     if (!property) { | ||||||
|       return undefined; |       return undefined; | ||||||
|     } |     } | ||||||
|  | @ -29,7 +29,7 @@ function bootstrapTagsinput() { | ||||||
|       return scope.$parent[property]; |       return scope.$parent[property]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return item => { |     return (item: any) => { | ||||||
|       return item[property]; |       return item[property]; | ||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
|  | @ -42,7 +42,7 @@ function bootstrapTagsinput() { | ||||||
|     }, |     }, | ||||||
|     template: '<select multiple></select>', |     template: '<select multiple></select>', | ||||||
|     replace: false, |     replace: false, | ||||||
|     link: function(scope, element, attrs) { |     link: function(scope: any, element: any, attrs: any) { | ||||||
|       if (!angular.isArray(scope.model)) { |       if (!angular.isArray(scope.model)) { | ||||||
|         scope.model = []; |         scope.model = []; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ export class ValueSelectDropdownCtrl { | ||||||
|   onUpdated: any; |   onUpdated: any; | ||||||
| 
 | 
 | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $q) {} |   constructor(private $q: any) {} | ||||||
| 
 | 
 | ||||||
|   show() { |   show() { | ||||||
|     this.oldVariableText = this.variable.current.text; |     this.oldVariableText = this.variable.current.text; | ||||||
|  | @ -84,7 +84,7 @@ export class ValueSelectDropdownCtrl { | ||||||
|     this.selectionsChanged(false); |     this.selectionsChanged(false); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   selectTag(tag) { |   selectTag(tag: any) { | ||||||
|     tag.selected = !tag.selected; |     tag.selected = !tag.selected; | ||||||
|     let tagValuesPromise; |     let tagValuesPromise; | ||||||
|     if (!tag.values) { |     if (!tag.values) { | ||||||
|  | @ -93,7 +93,7 @@ export class ValueSelectDropdownCtrl { | ||||||
|       tagValuesPromise = this.$q.when(tag.values); |       tagValuesPromise = this.$q.when(tag.values); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return tagValuesPromise.then(values => { |     return tagValuesPromise.then((values: any) => { | ||||||
|       tag.values = values; |       tag.values = values; | ||||||
|       tag.valuesText = values.join(' + '); |       tag.valuesText = values.join(' + '); | ||||||
|       _.each(this.options, option => { |       _.each(this.options, option => { | ||||||
|  | @ -106,7 +106,7 @@ export class ValueSelectDropdownCtrl { | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   keyDown(evt) { |   keyDown(evt: any) { | ||||||
|     if (evt.keyCode === 27) { |     if (evt.keyCode === 27) { | ||||||
|       this.hide(); |       this.hide(); | ||||||
|     } |     } | ||||||
|  | @ -128,11 +128,11 @@ export class ValueSelectDropdownCtrl { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   moveHighlight(direction) { |   moveHighlight(direction: number) { | ||||||
|     this.highlightIndex = (this.highlightIndex + direction) % this.search.options.length; |     this.highlightIndex = (this.highlightIndex + direction) % this.search.options.length; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   selectValue(option, event, commitChange?, excludeOthers?) { |   selectValue(option: any, event: any, commitChange?: boolean, excludeOthers?: boolean) { | ||||||
|     if (!option) { |     if (!option) { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  | @ -142,7 +142,7 @@ export class ValueSelectDropdownCtrl { | ||||||
|     commitChange = commitChange || false; |     commitChange = commitChange || false; | ||||||
|     excludeOthers = excludeOthers || false; |     excludeOthers = excludeOthers || false; | ||||||
| 
 | 
 | ||||||
|     const setAllExceptCurrentTo = newValue => { |     const setAllExceptCurrentTo = (newValue: any) => { | ||||||
|       _.each(this.options, other => { |       _.each(this.options, other => { | ||||||
|         if (option !== other) { |         if (option !== other) { | ||||||
|           other.selected = newValue; |           other.selected = newValue; | ||||||
|  | @ -169,7 +169,7 @@ export class ValueSelectDropdownCtrl { | ||||||
|     this.selectionsChanged(commitChange); |     this.selectionsChanged(commitChange); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   selectionsChanged(commitChange) { |   selectionsChanged(commitChange: boolean) { | ||||||
|     this.selectedValues = _.filter(this.options, { selected: true }); |     this.selectedValues = _.filter(this.options, { selected: true }); | ||||||
| 
 | 
 | ||||||
|     if (this.selectedValues.length > 1) { |     if (this.selectedValues.length > 1) { | ||||||
|  | @ -238,14 +238,14 @@ export class ValueSelectDropdownCtrl { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| export function valueSelectDropdown($compile, $window, $timeout, $rootScope) { | export function valueSelectDropdown($compile: any, $window: any, $timeout: any, $rootScope: any) { | ||||||
|   return { |   return { | ||||||
|     scope: { dashboard: '=', variable: '=', onUpdated: '&' }, |     scope: { dashboard: '=', variable: '=', onUpdated: '&' }, | ||||||
|     templateUrl: 'public/app/partials/valueSelectDropdown.html', |     templateUrl: 'public/app/partials/valueSelectDropdown.html', | ||||||
|     controller: 'ValueSelectDropdownCtrl', |     controller: 'ValueSelectDropdownCtrl', | ||||||
|     controllerAs: 'vm', |     controllerAs: 'vm', | ||||||
|     bindToController: true, |     bindToController: true, | ||||||
|     link: (scope, elem) => { |     link: (scope: any, elem: any) => { | ||||||
|       const bodyEl = angular.element($window.document.body); |       const bodyEl = angular.element($window.document.body); | ||||||
|       const linkEl = elem.find('.variable-value-link'); |       const linkEl = elem.find('.variable-value-link'); | ||||||
|       const inputEl = elem.find('input'); |       const inputEl = elem.find('input'); | ||||||
|  | @ -272,7 +272,7 @@ export function valueSelectDropdown($compile, $window, $timeout, $rootScope) { | ||||||
|         bodyEl.off('click', bodyOnClick); |         bodyEl.off('click', bodyOnClick); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       function bodyOnClick(e) { |       function bodyOnClick(e: any) { | ||||||
|         if (elem.has(e.target).length === 0) { |         if (elem.has(e.target).length === 0) { | ||||||
|           scope.$apply(() => { |           scope.$apply(() => { | ||||||
|             scope.vm.commitChanges(); |             scope.vm.commitChanges(); | ||||||
|  | @ -280,7 +280,7 @@ export function valueSelectDropdown($compile, $window, $timeout, $rootScope) { | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       scope.$watch('vm.dropdownVisible', newValue => { |       scope.$watch('vm.dropdownVisible', (newValue: any) => { | ||||||
|         if (newValue) { |         if (newValue) { | ||||||
|           openDropdown(); |           openDropdown(); | ||||||
|         } else { |         } else { | ||||||
|  |  | ||||||
|  | @ -2,23 +2,25 @@ import _ from 'lodash'; | ||||||
| import angular from 'angular'; | import angular from 'angular'; | ||||||
| import moment from 'moment'; | import moment from 'moment'; | ||||||
| import coreModule from '../core_module'; | import coreModule from '../core_module'; | ||||||
|  | import { TemplateSrv } from 'app/features/templating/template_srv'; | ||||||
| 
 | 
 | ||||||
| coreModule.filter('stringSort', () => { | coreModule.filter('stringSort', () => { | ||||||
|   return input => { |   return (input: any) => { | ||||||
|     return input.sort(); |     return input.sort(); | ||||||
|   }; |   }; | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| coreModule.filter('slice', () => { | coreModule.filter('slice', () => { | ||||||
|   return (arr, start, end) => { |   return (arr: any[], start: any, end: any) => { | ||||||
|     if (!_.isUndefined(arr)) { |     if (!_.isUndefined(arr)) { | ||||||
|       return arr.slice(start, end); |       return arr.slice(start, end); | ||||||
|     } |     } | ||||||
|  |     return arr; | ||||||
|   }; |   }; | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| coreModule.filter('stringify', () => { | coreModule.filter('stringify', () => { | ||||||
|   return arr => { |   return (arr: any[]) => { | ||||||
|     if (_.isObject(arr) && !_.isArray(arr)) { |     if (_.isObject(arr) && !_.isArray(arr)) { | ||||||
|       return angular.toJson(arr); |       return angular.toJson(arr); | ||||||
|     } else { |     } else { | ||||||
|  | @ -28,7 +30,7 @@ coreModule.filter('stringify', () => { | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| coreModule.filter('moment', () => { | coreModule.filter('moment', () => { | ||||||
|   return (date, mode) => { |   return (date: string, mode: string) => { | ||||||
|     switch (mode) { |     switch (mode) { | ||||||
|       case 'ago': |       case 'ago': | ||||||
|         return moment(date).fromNow(); |         return moment(date).fromNow(); | ||||||
|  | @ -37,25 +39,9 @@ coreModule.filter('moment', () => { | ||||||
|   }; |   }; | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| coreModule.filter('noXml', () => { |  | ||||||
|   const noXml = text => { |  | ||||||
|     return _.isString(text) |  | ||||||
|       ? text |  | ||||||
|           .replace(/&/g, '&') |  | ||||||
|           .replace(/</g, '<') |  | ||||||
|           .replace(/>/g, '>') |  | ||||||
|           .replace(/'/g, ''') |  | ||||||
|           .replace(/"/g, '"') |  | ||||||
|       : text; |  | ||||||
|   }; |  | ||||||
|   return text => { |  | ||||||
|     return _.isArray(text) ? _.map(text, noXml) : noXml(text); |  | ||||||
|   }; |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function interpolateTemplateVars(templateSrv) { | function interpolateTemplateVars(templateSrv: TemplateSrv) { | ||||||
|   const filterFunc: any = (text, scope) => { |   const filterFunc: any = (text: string, scope: any) => { | ||||||
|     let scopedVars; |     let scopedVars; | ||||||
|     if (scope.ctrl) { |     if (scope.ctrl) { | ||||||
|       scopedVars = (scope.ctrl.panel || scope.ctrl.row).scopedVars; |       scopedVars = (scope.ctrl.panel || scope.ctrl.row).scopedVars; | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ export class LiveSrv { | ||||||
|       console.log('Live: connecting...'); |       console.log('Live: connecting...'); | ||||||
|       this.conn = new WebSocket(this.getWebSocketUrl()); |       this.conn = new WebSocket(this.getWebSocketUrl()); | ||||||
| 
 | 
 | ||||||
|       this.conn.onclose = evt => { |       this.conn.onclose = (evt: any) => { | ||||||
|         console.log('Live: websocket onclose', evt); |         console.log('Live: websocket onclose', evt); | ||||||
|         reject({ message: 'Connection closed' }); |         reject({ message: 'Connection closed' }); | ||||||
| 
 | 
 | ||||||
|  | @ -38,17 +38,17 @@ export class LiveSrv { | ||||||
|         setTimeout(this.reconnect.bind(this), 2000); |         setTimeout(this.reconnect.bind(this), 2000); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       this.conn.onmessage = evt => { |       this.conn.onmessage = (evt: any) => { | ||||||
|         this.handleMessage(evt.data); |         this.handleMessage(evt.data); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       this.conn.onerror = evt => { |       this.conn.onerror = (evt: any) => { | ||||||
|         this.initPromise = null; |         this.initPromise = null; | ||||||
|         reject({ message: 'Connection error' }); |         reject({ message: 'Connection error' }); | ||||||
|         console.log('Live: websocket error', evt); |         console.log('Live: websocket error', evt); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       this.conn.onopen = evt => { |       this.conn.onopen = (evt: any) => { | ||||||
|         console.log('opened'); |         console.log('opened'); | ||||||
|         this.initPromise = null; |         this.initPromise = null; | ||||||
|         resolve(this.conn); |         resolve(this.conn); | ||||||
|  | @ -58,7 +58,7 @@ export class LiveSrv { | ||||||
|     return this.initPromise; |     return this.initPromise; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   handleMessage(message) { |   handleMessage(message: any) { | ||||||
|     message = JSON.parse(message); |     message = JSON.parse(message); | ||||||
| 
 | 
 | ||||||
|     if (!message.stream) { |     if (!message.stream) { | ||||||
|  | @ -83,38 +83,38 @@ export class LiveSrv { | ||||||
| 
 | 
 | ||||||
|     console.log('LiveSrv: Reconnecting'); |     console.log('LiveSrv: Reconnecting'); | ||||||
| 
 | 
 | ||||||
|     this.getConnection().then(conn => { |     this.getConnection().then((conn: any) => { | ||||||
|       _.each(this.observers, (value, key) => { |       _.each(this.observers, (value, key) => { | ||||||
|         this.send({ action: 'subscribe', stream: key }); |         this.send({ action: 'subscribe', stream: key }); | ||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   send(data) { |   send(data: any) { | ||||||
|     this.conn.send(JSON.stringify(data)); |     this.conn.send(JSON.stringify(data)); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   addObserver(stream, observer) { |   addObserver(stream: any, observer: any) { | ||||||
|     this.observers[stream] = observer; |     this.observers[stream] = observer; | ||||||
| 
 | 
 | ||||||
|     this.getConnection().then(conn => { |     this.getConnection().then((conn: any) => { | ||||||
|       this.send({ action: 'subscribe', stream: stream }); |       this.send({ action: 'subscribe', stream: stream }); | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   removeObserver(stream, observer) { |   removeObserver(stream: any, observer: any) { | ||||||
|     console.log('unsubscribe', stream); |     console.log('unsubscribe', stream); | ||||||
|     delete this.observers[stream]; |     delete this.observers[stream]; | ||||||
| 
 | 
 | ||||||
|     this.getConnection().then(conn => { |     this.getConnection().then((conn: any) => { | ||||||
|       this.send({ action: 'unsubscribe', stream: stream }); |       this.send({ action: 'unsubscribe', stream: stream }); | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   subscribe(streamName) { |   subscribe(streamName: string) { | ||||||
|     console.log('LiveSrv.subscribe: ' + streamName); |     console.log('LiveSrv.subscribe: ' + streamName); | ||||||
| 
 | 
 | ||||||
|     return Observable.create(observer => { |     return Observable.create((observer: any) => { | ||||||
|       this.addObserver(streamName, observer); |       this.addObserver(streamName, observer); | ||||||
| 
 | 
 | ||||||
|       return () => { |       return () => { | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ export const initialState: NavIndex = buildInitialState(); | ||||||
| export const navIndexReducer = (state = initialState, action: Action): NavIndex => { | export const navIndexReducer = (state = initialState, action: Action): NavIndex => { | ||||||
|   switch (action.type) { |   switch (action.type) { | ||||||
|     case ActionTypes.UpdateNavIndex: |     case ActionTypes.UpdateNavIndex: | ||||||
|       const newPages = {}; |       const newPages: NavIndex = {}; | ||||||
|       const payload = action.payload; |       const payload = action.payload; | ||||||
| 
 | 
 | ||||||
|       for (const node of payload.children) { |       for (const node of payload.children) { | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
| export const getRouteParamsId = state => state.routeParams.id; | import { LocationState } from 'app/types'; | ||||||
| 
 | 
 | ||||||
| export const getRouteParamsPage = state => state.routeParams.page; | export const getRouteParamsId = (state: LocationState) => state.routeParams.id; | ||||||
|  | export const getRouteParamsPage = (state: LocationState) => state.routeParams.page; | ||||||
|  |  | ||||||
|  | @ -3,16 +3,16 @@ import coreModule from 'app/core/core_module'; | ||||||
| import _ from 'lodash'; | import _ from 'lodash'; | ||||||
| 
 | 
 | ||||||
| export interface AngularComponent { | export interface AngularComponent { | ||||||
|   destroy(); |   destroy(): void; | ||||||
|   digest(); |   digest(): void; | ||||||
|   getScope(); |   getScope(): any; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class AngularLoader { | export class AngularLoader { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $compile, private $rootScope) {} |   constructor(private $compile: any, private $rootScope: any) {} | ||||||
| 
 | 
 | ||||||
|   load(elem, scopeProps, template): AngularComponent { |   load(elem: any, scopeProps: any, template: string): AngularComponent { | ||||||
|     const scope = this.$rootScope.$new(); |     const scope = this.$rootScope.$new(); | ||||||
| 
 | 
 | ||||||
|     _.assign(scope, scopeProps); |     _.assign(scope, scopeProps); | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ import config from 'app/core/config'; | ||||||
| 
 | 
 | ||||||
| export class Analytics { | export class Analytics { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $rootScope, private $location) {} |   constructor(private $rootScope: any, private $location: any) {} | ||||||
| 
 | 
 | ||||||
|   gaInit() { |   gaInit() { | ||||||
|     $.ajax({ |     $.ajax({ | ||||||
|  | @ -35,7 +35,7 @@ export class Analytics { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @ngInject */ | /** @ngInject */ | ||||||
| function startAnalytics(googleAnalyticsSrv) { | function startAnalytics(googleAnalyticsSrv: Analytics) { | ||||||
|   if ((config as any).googleAnalyticsId) { |   if ((config as any).googleAnalyticsId) { | ||||||
|     googleAnalyticsSrv.init(); |     googleAnalyticsSrv.init(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -3,13 +3,20 @@ import appEvents from 'app/core/app_events'; | ||||||
| import { store } from 'app/store/store'; | import { store } from 'app/store/store'; | ||||||
| import locationUtil from 'app/core/utils/location_util'; | import locationUtil from 'app/core/utils/location_util'; | ||||||
| import { updateLocation } from 'app/core/actions'; | import { updateLocation } from 'app/core/actions'; | ||||||
|  | import { ITimeoutService, ILocationService, IWindowService, IRootScopeService } from 'angular'; | ||||||
| 
 | 
 | ||||||
| // Services that handles angular -> redux store sync & other react <-> angular sync
 | // Services that handles angular -> redux store sync & other react <-> angular sync
 | ||||||
| export class BridgeSrv { | export class BridgeSrv { | ||||||
|   private fullPageReloadRoutes; |   private fullPageReloadRoutes: string[]; | ||||||
| 
 | 
 | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $location, private $timeout, private $window, private $rootScope, private $route) { |   constructor( | ||||||
|  |     private $location: ILocationService, | ||||||
|  |     private $timeout: ITimeoutService, | ||||||
|  |     private $window: IWindowService, | ||||||
|  |     private $rootScope: IRootScopeService, | ||||||
|  |     private $route: any | ||||||
|  |   ) { | ||||||
|     this.fullPageReloadRoutes = ['/logout']; |     this.fullPageReloadRoutes = ['/logout']; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -55,7 +62,7 @@ export class BridgeSrv { | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     appEvents.on('location-change', payload => { |     appEvents.on('location-change', (payload: any) => { | ||||||
|       const urlWithoutBase = locationUtil.stripBaseFromUrl(payload.href); |       const urlWithoutBase = locationUtil.stripBaseFromUrl(payload.href); | ||||||
|       if (this.fullPageReloadRoutes.indexOf(urlWithoutBase) > -1) { |       if (this.fullPageReloadRoutes.indexOf(urlWithoutBase) > -1) { | ||||||
|         this.$window.location.href = payload.href; |         this.$window.location.href = payload.href; | ||||||
|  |  | ||||||
|  | @ -44,7 +44,7 @@ export class ContextSrv { | ||||||
|     this.hasEditPermissionInFolders = this.user.hasEditPermissionInFolders; |     this.hasEditPermissionInFolders = this.user.hasEditPermissionInFolders; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   hasRole(role) { |   hasRole(role: string) { | ||||||
|     return this.user.orgRole === role; |     return this.user.orgRole === role; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,9 +3,9 @@ import coreModule from '../core_module'; | ||||||
| 
 | 
 | ||||||
| class DynamicDirectiveSrv { | class DynamicDirectiveSrv { | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $compile) {} |   constructor(private $compile: angular.ICompileService) {} | ||||||
| 
 | 
 | ||||||
|   addDirective(element, name, scope) { |   addDirective(element: any, name: string, scope: any) { | ||||||
|     const child = angular.element(document.createElement(name)); |     const child = angular.element(document.createElement(name)); | ||||||
|     this.$compile(child)(scope); |     this.$compile(child)(scope); | ||||||
| 
 | 
 | ||||||
|  | @ -13,7 +13,7 @@ class DynamicDirectiveSrv { | ||||||
|     element.append(child); |     element.append(child); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   link(scope, elem, attrs, options) { |   link(scope: any, elem: JQLite, attrs: any, options: any) { | ||||||
|     const directiveInfo = options.directive(scope); |     const directiveInfo = options.directive(scope); | ||||||
|     if (!directiveInfo || !directiveInfo.fn) { |     if (!directiveInfo || !directiveInfo.fn) { | ||||||
|       elem.empty(); |       elem.empty(); | ||||||
|  | @ -28,13 +28,13 @@ class DynamicDirectiveSrv { | ||||||
|     this.addDirective(elem, directiveInfo.name, scope); |     this.addDirective(elem, directiveInfo.name, scope); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   create(options) { |   create(options: any) { | ||||||
|     const directiveDef = { |     const directiveDef = { | ||||||
|       restrict: 'E', |       restrict: 'E', | ||||||
|       scope: options.scope, |       scope: options.scope, | ||||||
|       link: (scope, elem, attrs) => { |       link: (scope: any, elem: JQLite, attrs: any) => { | ||||||
|         if (options.watchPath) { |         if (options.watchPath) { | ||||||
|           let childScope = null; |           let childScope: any = null; | ||||||
|           scope.$watch(options.watchPath, () => { |           scope.$watch(options.watchPath, () => { | ||||||
|             if (childScope) { |             if (childScope) { | ||||||
|               childScope.$destroy(); |               childScope.$destroy(); | ||||||
|  |  | ||||||
|  | @ -5,8 +5,8 @@ import config from 'app/core/config'; | ||||||
| export class ImpressionSrv { | export class ImpressionSrv { | ||||||
|   constructor() {} |   constructor() {} | ||||||
| 
 | 
 | ||||||
|   addDashboardImpression(dashboardId) { |   addDashboardImpression(dashboardId: number) { | ||||||
|     const impressionsKey = this.impressionKey(config); |     const impressionsKey = this.impressionKey(); | ||||||
|     let impressions = []; |     let impressions = []; | ||||||
|     if (store.exists(impressionsKey)) { |     if (store.exists(impressionsKey)) { | ||||||
|       impressions = JSON.parse(store.get(impressionsKey)); |       impressions = JSON.parse(store.get(impressionsKey)); | ||||||
|  | @ -28,7 +28,7 @@ export class ImpressionSrv { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getDashboardOpened() { |   getDashboardOpened() { | ||||||
|     let impressions = store.get(this.impressionKey(config)) || '[]'; |     let impressions = store.get(this.impressionKey()) || '[]'; | ||||||
| 
 | 
 | ||||||
|     impressions = JSON.parse(impressions); |     impressions = JSON.parse(impressions); | ||||||
| 
 | 
 | ||||||
|  | @ -39,7 +39,7 @@ export class ImpressionSrv { | ||||||
|     return impressions; |     return impressions; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   impressionKey(config) { |   impressionKey() { | ||||||
|     return 'dashboard_impressions-' + config.bootData.user.orgId; |     return 'dashboard_impressions-' + config.bootData.user.orgId; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ import { store } from 'app/store/store'; | ||||||
| import Mousetrap from 'mousetrap'; | import Mousetrap from 'mousetrap'; | ||||||
| import 'mousetrap-global-bind'; | import 'mousetrap-global-bind'; | ||||||
| import { ContextSrv } from './context_srv'; | import { ContextSrv } from './context_srv'; | ||||||
|  | import { ILocationService, ITimeoutService } from 'angular'; | ||||||
| 
 | 
 | ||||||
| export class KeybindingSrv { | export class KeybindingSrv { | ||||||
|   helpModal: boolean; |   helpModal: boolean; | ||||||
|  | @ -17,11 +18,11 @@ export class KeybindingSrv { | ||||||
| 
 | 
 | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor( |   constructor( | ||||||
|     private $rootScope, |     private $rootScope: any, | ||||||
|     private $location, |     private $location: ILocationService, | ||||||
|     private $timeout, |     private $timeout: ITimeoutService, | ||||||
|     private datasourceSrv, |     private datasourceSrv: any, | ||||||
|     private timeSrv, |     private timeSrv: any, | ||||||
|     private contextSrv: ContextSrv |     private contextSrv: ContextSrv | ||||||
|   ) { |   ) { | ||||||
|     // clear out all shortcuts on route change
 |     // clear out all shortcuts on route change
 | ||||||
|  | @ -114,10 +115,10 @@ export class KeybindingSrv { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   bind(keyArg, fn) { |   bind(keyArg: string | string[], fn: () => void) { | ||||||
|     Mousetrap.bind( |     Mousetrap.bind( | ||||||
|       keyArg, |       keyArg, | ||||||
|       evt => { |       (evt: any) => { | ||||||
|         evt.preventDefault(); |         evt.preventDefault(); | ||||||
|         evt.stopPropagation(); |         evt.stopPropagation(); | ||||||
|         evt.returnValue = false; |         evt.returnValue = false; | ||||||
|  | @ -127,10 +128,10 @@ export class KeybindingSrv { | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   bindGlobal(keyArg, fn) { |   bindGlobal(keyArg: string, fn: () => void) { | ||||||
|     Mousetrap.bindGlobal( |     Mousetrap.bindGlobal( | ||||||
|       keyArg, |       keyArg, | ||||||
|       evt => { |       (evt: any) => { | ||||||
|         evt.preventDefault(); |         evt.preventDefault(); | ||||||
|         evt.stopPropagation(); |         evt.stopPropagation(); | ||||||
|         evt.returnValue = false; |         evt.returnValue = false; | ||||||
|  | @ -149,14 +150,14 @@ export class KeybindingSrv { | ||||||
|     this.$location.search(search); |     this.$location.search(search); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setupDashboardBindings(scope, dashboard) { |   setupDashboardBindings(scope: any, dashboard: any) { | ||||||
|     this.bind('mod+o', () => { |     this.bind('mod+o', () => { | ||||||
|       dashboard.graphTooltip = (dashboard.graphTooltip + 1) % 3; |       dashboard.graphTooltip = (dashboard.graphTooltip + 1) % 3; | ||||||
|       appEvents.emit('graph-hover-clear'); |       appEvents.emit('graph-hover-clear'); | ||||||
|       dashboard.startRefresh(); |       dashboard.startRefresh(); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     this.bind('mod+s', e => { |     this.bind('mod+s', () => { | ||||||
|       scope.appEvent('save-dashboard'); |       scope.appEvent('save-dashboard'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  | @ -272,7 +273,7 @@ export class KeybindingSrv { | ||||||
|       dashboard.expandRows(); |       dashboard.expandRows(); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     this.bind('d n', e => { |     this.bind('d n', () => { | ||||||
|       this.$location.url('/dashboard/new'); |       this.$location.url('/dashboard/new'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,20 +1,21 @@ | ||||||
| import _ from 'lodash'; | import _ from 'lodash'; | ||||||
| import coreModule from 'app/core/core_module'; | import coreModule from 'app/core/core_module'; | ||||||
|  | import { ITimeoutService } from 'angular'; | ||||||
| 
 | 
 | ||||||
| // This service really just tracks a list of $timeout promises to give us a
 | // This service really just tracks a list of $timeout promises to give us a
 | ||||||
| // method for canceling them all when we need to
 | // method for canceling them all when we need to
 | ||||||
| export class Timer { | export class Timer { | ||||||
|   timers = []; |   timers: Array<angular.IPromise<any>> = []; | ||||||
| 
 | 
 | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor(private $timeout) {} |   constructor(private $timeout: ITimeoutService) {} | ||||||
| 
 | 
 | ||||||
|   register(promise) { |   register(promise: angular.IPromise<any>) { | ||||||
|     this.timers.push(promise); |     this.timers.push(promise); | ||||||
|     return promise; |     return promise; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   cancel(promise) { |   cancel(promise: angular.IPromise<any>) { | ||||||
|     this.timers = _.without(this.timers, promise); |     this.timers = _.without(this.timers, promise); | ||||||
|     this.$timeout.cancel(promise); |     this.$timeout.cancel(promise); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| import { TimeSrv } from './TimeSrv'; |  | ||||||
| import moment from 'moment'; | import moment from 'moment'; | ||||||
|  | import { TimeSrv } from './TimeSrv'; | ||||||
|  | import { ContextSrvStub } from 'test/specs/helpers'; | ||||||
| 
 | 
 | ||||||
| describe('timeSrv', () => { | describe('timeSrv', () => { | ||||||
|   const rootScope = { |   const rootScope = { | ||||||
|  | @ -26,7 +27,7 @@ describe('timeSrv', () => { | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   beforeEach(() => { |   beforeEach(() => { | ||||||
|     timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() }); |     timeSrv = new TimeSrv(rootScope as any, jest.fn() as any, location as any, timer, new ContextSrvStub() as any); | ||||||
|     timeSrv.init(_dashboard); |     timeSrv.init(_dashboard); | ||||||
|     _dashboard.refresh = false; |     _dashboard.refresh = false; | ||||||
|   }); |   }); | ||||||
|  | @ -56,7 +57,7 @@ describe('timeSrv', () => { | ||||||
|         })), |         })), | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() }); |       timeSrv = new TimeSrv(rootScope as any, jest.fn() as any, location as any, timer, new ContextSrvStub() as any); | ||||||
|       timeSrv.init(_dashboard); |       timeSrv.init(_dashboard); | ||||||
|       const time = timeSrv.timeRange(); |       const time = timeSrv.timeRange(); | ||||||
|       expect(time.raw.from).toBe('now-2d'); |       expect(time.raw.from).toBe('now-2d'); | ||||||
|  | @ -71,7 +72,7 @@ describe('timeSrv', () => { | ||||||
|         })), |         })), | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() }); |       timeSrv = new TimeSrv(rootScope as any, jest.fn() as any, location as any, timer, new ContextSrvStub() as any); | ||||||
| 
 | 
 | ||||||
|       timeSrv.init(_dashboard); |       timeSrv.init(_dashboard); | ||||||
|       const time = timeSrv.timeRange(); |       const time = timeSrv.timeRange(); | ||||||
|  | @ -87,7 +88,7 @@ describe('timeSrv', () => { | ||||||
|         })), |         })), | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() }); |       timeSrv = new TimeSrv(rootScope as any, jest.fn() as any, location as any, timer, new ContextSrvStub() as any); | ||||||
| 
 | 
 | ||||||
|       // dashboard saved with refresh on
 |       // dashboard saved with refresh on
 | ||||||
|       _dashboard.refresh = true; |       _dashboard.refresh = true; | ||||||
|  | @ -104,7 +105,7 @@ describe('timeSrv', () => { | ||||||
|         })), |         })), | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() }); |       timeSrv = new TimeSrv(rootScope as any, jest.fn() as any, location as any, timer, new ContextSrvStub() as any); | ||||||
| 
 | 
 | ||||||
|       timeSrv.init(_dashboard); |       timeSrv.init(_dashboard); | ||||||
|       const time = timeSrv.timeRange(); |       const time = timeSrv.timeRange(); | ||||||
|  | @ -120,7 +121,7 @@ describe('timeSrv', () => { | ||||||
|         })), |         })), | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() }); |       timeSrv = new TimeSrv(rootScope as any, jest.fn() as any, location as any, timer, new ContextSrvStub() as any); | ||||||
| 
 | 
 | ||||||
|       timeSrv.init(_dashboard); |       timeSrv.init(_dashboard); | ||||||
|       const time = timeSrv.timeRange(); |       const time = timeSrv.timeRange(); | ||||||
|  | @ -136,7 +137,7 @@ describe('timeSrv', () => { | ||||||
|         })), |         })), | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       timeSrv = new TimeSrv(rootScope, jest.fn(), location, timer, { isGrafanaVisibile: jest.fn() }); |       timeSrv = new TimeSrv(rootScope as any, jest.fn() as any, location as any, timer, new ContextSrvStub() as any); | ||||||
| 
 | 
 | ||||||
|       _dashboard.time.from = 'now-6h'; |       _dashboard.time.from = 'now-6h'; | ||||||
|       timeSrv.init(_dashboard); |       timeSrv.init(_dashboard); | ||||||
|  |  | ||||||
|  | @ -8,19 +8,28 @@ import coreModule from 'app/core/core_module'; | ||||||
| import * as dateMath from 'app/core/utils/datemath'; | import * as dateMath from 'app/core/utils/datemath'; | ||||||
| 
 | 
 | ||||||
| // Types
 | // Types
 | ||||||
| import { TimeRange } from '@grafana/ui'; | import { TimeRange, RawTimeRange } from '@grafana/ui'; | ||||||
|  | import { ITimeoutService, ILocationService } from 'angular'; | ||||||
|  | import { ContextSrv } from 'app/core/services/context_srv'; | ||||||
|  | import { DashboardModel } from '../state/DashboardModel'; | ||||||
| 
 | 
 | ||||||
| export class TimeSrv { | export class TimeSrv { | ||||||
|   time: any; |   time: any; | ||||||
|   refreshTimer: any; |   refreshTimer: any; | ||||||
|   refresh: boolean; |   refresh: any; | ||||||
|   oldRefresh: boolean; |   oldRefresh: boolean; | ||||||
|   dashboard: any; |   dashboard: Partial<DashboardModel>; | ||||||
|   timeAtLoad: any; |   timeAtLoad: any; | ||||||
|   private autoRefreshBlocked: boolean; |   private autoRefreshBlocked: boolean; | ||||||
| 
 | 
 | ||||||
|   /** @ngInject */ |   /** @ngInject */ | ||||||
|   constructor($rootScope, private $timeout, private $location, private timer, private contextSrv) { |   constructor( | ||||||
|  |     $rootScope: any, | ||||||
|  |     private $timeout: ITimeoutService, | ||||||
|  |     private $location: ILocationService, | ||||||
|  |     private timer: any, | ||||||
|  |     private contextSrv: ContextSrv | ||||||
|  |   ) { | ||||||
|     // default time
 |     // default time
 | ||||||
|     this.time = { from: '6h', to: 'now' }; |     this.time = { from: '6h', to: 'now' }; | ||||||
| 
 | 
 | ||||||
|  | @ -35,7 +44,7 @@ export class TimeSrv { | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   init(dashboard) { |   init(dashboard: Partial<DashboardModel>) { | ||||||
|     this.timer.cancelAll(); |     this.timer.cancelAll(); | ||||||
| 
 | 
 | ||||||
|     this.dashboard = dashboard; |     this.dashboard = dashboard; | ||||||
|  | @ -63,7 +72,7 @@ export class TimeSrv { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private parseUrlParam(value) { |   private parseUrlParam(value: any) { | ||||||
|     if (value.indexOf('now') !== -1) { |     if (value.indexOf('now') !== -1) { | ||||||
|       return value; |       return value; | ||||||
|     } |     } | ||||||
|  | @ -121,7 +130,7 @@ export class TimeSrv { | ||||||
|     return this.timeAtLoad && (this.timeAtLoad.from !== this.time.from || this.timeAtLoad.to !== this.time.to); |     return this.timeAtLoad && (this.timeAtLoad.from !== this.time.from || this.timeAtLoad.to !== this.time.to); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setAutoRefresh(interval) { |   setAutoRefresh(interval: any) { | ||||||
|     this.dashboard.refresh = interval; |     this.dashboard.refresh = interval; | ||||||
|     this.cancelNextRefresh(); |     this.cancelNextRefresh(); | ||||||
| 
 | 
 | ||||||
|  | @ -153,7 +162,7 @@ export class TimeSrv { | ||||||
|     this.dashboard.timeRangeUpdated(this.timeRange()); |     this.dashboard.timeRangeUpdated(this.timeRange()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private startNextRefreshTimer(afterMs) { |   private startNextRefreshTimer(afterMs: number) { | ||||||
|     this.cancelNextRefresh(); |     this.cancelNextRefresh(); | ||||||
|     this.refreshTimer = this.timer.register( |     this.refreshTimer = this.timer.register( | ||||||
|       this.$timeout(() => { |       this.$timeout(() => { | ||||||
|  | @ -171,7 +180,7 @@ export class TimeSrv { | ||||||
|     this.timer.cancel(this.refreshTimer); |     this.timer.cancel(this.refreshTimer); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setTime(time, fromRouteUpdate?) { |   setTime(time: RawTimeRange, fromRouteUpdate?: boolean) { | ||||||
|     _.extend(this.time, time); |     _.extend(this.time, time); | ||||||
| 
 | 
 | ||||||
|     // disable refresh if zoom in or zoom out
 |     // disable refresh if zoom in or zoom out
 | ||||||
|  | @ -224,7 +233,7 @@ export class TimeSrv { | ||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   zoomOut(e, factor) { |   zoomOut(e: any, factor: number) { | ||||||
|     const range = this.timeRange(); |     const range = this.timeRange(); | ||||||
| 
 | 
 | ||||||
|     const timespan = range.to.valueOf() - range.from.valueOf(); |     const timespan = range.to.valueOf() - range.from.valueOf(); | ||||||
|  | @ -237,7 +246,7 @@ export class TimeSrv { | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| let singleton; | let singleton: TimeSrv; | ||||||
| 
 | 
 | ||||||
| export function setTimeSrv(srv: TimeSrv) { | export function setTimeSrv(srv: TimeSrv) { | ||||||
|   singleton = srv; |   singleton = srv; | ||||||
|  |  | ||||||
|  | @ -126,7 +126,7 @@ export class TeamPages extends PureComponent<Props, State> { | ||||||
| function mapStateToProps(state) { | function mapStateToProps(state) { | ||||||
|   const teamId = getRouteParamsId(state.location); |   const teamId = getRouteParamsId(state.location); | ||||||
|   const pageName = getRouteParamsPage(state.location) || 'members'; |   const pageName = getRouteParamsPage(state.location) || 'members'; | ||||||
|   const teamLoadingNav = getTeamLoadingNav(pageName); |   const teamLoadingNav = getTeamLoadingNav(pageName as string); | ||||||
|   const navModel = getNavModel(state.navIndex, `team-${pageName}-${teamId}`, teamLoadingNav); |   const navModel = getNavModel(state.navIndex, `team-${pageName}-${teamId}`, teamLoadingNav); | ||||||
|   const team = getTeam(state.team, teamId); |   const team = getTeam(state.team, teamId); | ||||||
|   const members = getTeamMembers(state.team); |   const members = getTeamMembers(state.team); | ||||||
|  |  | ||||||
|  | @ -172,6 +172,8 @@ export class TimeSrvStub { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class ContextSrvStub { | export class ContextSrvStub { | ||||||
|  |   isGrafanaVisibile = jest.fn(); | ||||||
|  | 
 | ||||||
|   hasRole() { |   hasRole() { | ||||||
|     return true; |     return true; | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue