| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  | import angular from 'angular'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-09 15:37:16 +08:00
										 |  |  | import coreModule from './core_module'; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  | function tip($compile: any) { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     restrict: 'E', | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |     link: (scope: any, elem: any, attrs: any) => { | 
					
						
							| 
									
										
										
										
											2018-08-30 15:03:11 +08:00
										 |  |  |       let _t = | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         '<i class="grafana-tip fa fa-' + | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         (attrs.icon || 'question-circle') + | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         '" bs-tooltip="\'' + | 
					
						
							| 
									
										
										
										
											2021-11-05 21:18:42 +08:00
										 |  |  |         // here we double-html-encode any special characters in the source string
 | 
					
						
							|  |  |  |         // this is needed so that the final html contains the encoded entities as they
 | 
					
						
							|  |  |  |         // will be decoded when _t is parsed by angular
 | 
					
						
							|  |  |  |         elem.text().replace(/[\'\"\\{}<>&]/g, (m: string) => '&#' + m.charCodeAt(0) + ';') + | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         '\'"></i>'; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |       elem.replaceWith($compile(angular.element(_t))(scope)); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  | function compile($compile: any) { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     restrict: 'A', | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |     link: (scope: any, element: any, attrs: any) => { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |       scope.$watch( | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |         (scope: any) => { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |           return scope.$eval(attrs.compile); | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |         (value: any) => { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |           element.html(value); | 
					
						
							|  |  |  |           $compile(element.contents())(scope); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function watchChange() { | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     scope: { onchange: '&watchChange' }, | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |     link: (scope: any, element: any) => { | 
					
						
							| 
									
										
										
										
											2018-09-04 23:02:32 +08:00
										 |  |  |       element.on('input', () => { | 
					
						
							|  |  |  |         scope.$apply(() => { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |           scope.onchange({ inputValue: element.val() }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  | function editorOptBool($compile: any) { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     restrict: 'E', | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |     link: (scope: any, elem: any, attrs: any) => { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |       const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : ''; | 
					
						
							|  |  |  |       const tip = attrs.tip ? ' <tip>' + attrs.tip + '</tip>' : ''; | 
					
						
							|  |  |  |       const showIf = attrs.showIf ? ' ng-show="' + attrs.showIf + '" ' : ''; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |       const template = | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         '<div class="editor-option gf-form-checkbox text-center"' + | 
					
						
							|  |  |  |         showIf + | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         '>' + | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         ' <label for="' + | 
					
						
							|  |  |  |         attrs.model + | 
					
						
							|  |  |  |         '" class="small">' + | 
					
						
							|  |  |  |         attrs.text + | 
					
						
							|  |  |  |         tip + | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         '</label>' + | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         '<input class="cr1" id="' + | 
					
						
							|  |  |  |         attrs.model + | 
					
						
							|  |  |  |         '" type="checkbox" ' + | 
					
						
							|  |  |  |         '       ng-model="' + | 
					
						
							|  |  |  |         attrs.model + | 
					
						
							|  |  |  |         '"' + | 
					
						
							|  |  |  |         ngchange + | 
					
						
							|  |  |  |         '       ng-checked="' + | 
					
						
							|  |  |  |         attrs.model + | 
					
						
							|  |  |  |         '"></input>' + | 
					
						
							|  |  |  |         ' <label for="' + | 
					
						
							|  |  |  |         attrs.model + | 
					
						
							|  |  |  |         '" class="cr1"></label>'; | 
					
						
							|  |  |  |       elem.replaceWith($compile(angular.element(template))(scope)); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  | function editorCheckbox($compile: any, $interpolate: any) { | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     restrict: 'E', | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |     link: (scope: any, elem: any, attrs: any) => { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |       const text = $interpolate(attrs.text)(scope); | 
					
						
							|  |  |  |       const model = $interpolate(attrs.model)(scope); | 
					
						
							|  |  |  |       const ngchange = attrs.change ? ' ng-change="' + attrs.change + '"' : ''; | 
					
						
							|  |  |  |       const tip = attrs.tip ? ' <tip>' + attrs.tip + '</tip>' : ''; | 
					
						
							|  |  |  |       const label = '<label for="' + scope.$id + model + '" class="checkbox-label">' + text + tip + '</label>'; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-30 15:03:11 +08:00
										 |  |  |       let template = | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         '<input class="cr1" id="' + | 
					
						
							|  |  |  |         scope.$id + | 
					
						
							|  |  |  |         model + | 
					
						
							|  |  |  |         '" type="checkbox" ' + | 
					
						
							|  |  |  |         '       ng-model="' + | 
					
						
							|  |  |  |         model + | 
					
						
							|  |  |  |         '"' + | 
					
						
							|  |  |  |         ngchange + | 
					
						
							|  |  |  |         '       ng-checked="' + | 
					
						
							|  |  |  |         model + | 
					
						
							|  |  |  |         '"></input>' + | 
					
						
							|  |  |  |         ' <label for="' + | 
					
						
							|  |  |  |         scope.$id + | 
					
						
							|  |  |  |         model + | 
					
						
							|  |  |  |         '" class="cr1"></label>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       template = template + label; | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       elem.addClass('gf-form-checkbox'); | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |       elem.html($compile(angular.element(template))(scope)); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  | function gfDropdown($parse: any, $compile: any, $timeout: any) { | 
					
						
							|  |  |  |   function buildTemplate(items: any, placement?: any) { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |     const upclass = placement === 'top' ? 'dropup' : ''; | 
					
						
							|  |  |  |     const ul = ['<ul class="dropdown-menu ' + upclass + '" role="menu" aria-labelledby="drop1">', '</ul>']; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (let index = 0; index < items.length; index++) { | 
					
						
							| 
									
										
										
										
											2018-08-26 23:14:40 +08:00
										 |  |  |       const item = items[index]; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (item.divider) { | 
					
						
							|  |  |  |         ul.splice(index + 1, 0, '<li class="divider"></li>'); | 
					
						
							|  |  |  |         continue; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-30 15:03:11 +08:00
										 |  |  |       let li = | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         '<li' + | 
					
						
							| 
									
										
										
										
											2017-12-21 15:39:31 +08:00
										 |  |  |         (item.submenu && item.submenu.length ? ' class="dropdown-submenu"' : '') + | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         '>' + | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         '<a tabindex="-1" ng-href="' + | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         (item.href || '') + | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         '"' + | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         (item.click ? ' ng-click="' + item.click + '"' : '') + | 
					
						
							|  |  |  |         (item.target ? ' target="' + item.target + '"' : '') + | 
					
						
							|  |  |  |         (item.method ? ' data-method="' + item.method + '"' : '') + | 
					
						
							|  |  |  |         '>' + | 
					
						
							|  |  |  |         (item.text || '') + | 
					
						
							|  |  |  |         '</a>'; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (item.submenu && item.submenu.length) { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         li += buildTemplate(item.submenu).join('\n'); | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       li += '</li>'; | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |       ul.splice(index + 1, 0, li); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ul; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |     restrict: 'EA', | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |     scope: true, | 
					
						
							| 
									
										
										
										
											2019-04-28 15:58:12 +08:00
										 |  |  |     link: function postLink(scope: any, iElement: any, iAttrs: any) { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |       const getter = $parse(iAttrs.gfDropdown), | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         items = getter(scope); | 
					
						
							| 
									
										
										
										
											2018-09-04 23:02:32 +08:00
										 |  |  |       $timeout(() => { | 
					
						
							| 
									
										
										
										
											2018-08-29 20:26:50 +08:00
										 |  |  |         const placement = iElement.data('placement'); | 
					
						
							|  |  |  |         const dropdown = angular.element(buildTemplate(items, placement).join('')); | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |         dropdown.insertAfter(iElement); | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |         $compile(iElement.next('ul.dropdown-menu'))(scope); | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  |       iElement.addClass('dropdown-toggle').attr('data-toggle', 'dropdown'); | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2017-11-23 21:53:23 +08:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 19:33:33 +08:00
										 |  |  | coreModule.directive('tip', tip); | 
					
						
							|  |  |  | coreModule.directive('compile', compile); | 
					
						
							|  |  |  | coreModule.directive('watchChange', watchChange); | 
					
						
							|  |  |  | coreModule.directive('editorOptBool', editorOptBool); | 
					
						
							|  |  |  | coreModule.directive('editorCheckbox', editorCheckbox); | 
					
						
							|  |  |  | coreModule.directive('gfDropdown', gfDropdown); |