From 04715e94c888a547dc9fcda5ba903969b7ffa513 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Fri, 8 May 2020 17:13:54 +0300 Subject: [PATCH] Chore: remove unused files --- .../datasource-selector.directive.js | 57 -------- src/panel-triggers/module.js | 5 +- src/panel-triggers/partials/triggers_tab.html | 104 -------------- src/panel-triggers/triggers_tab.js | 131 ------------------ 4 files changed, 2 insertions(+), 295 deletions(-) delete mode 100644 src/panel-triggers/datasource-selector.directive.js delete mode 100644 src/panel-triggers/partials/triggers_tab.html delete mode 100644 src/panel-triggers/triggers_tab.js diff --git a/src/panel-triggers/datasource-selector.directive.js b/src/panel-triggers/datasource-selector.directive.js deleted file mode 100644 index 0d55483..0000000 --- a/src/panel-triggers/datasource-selector.directive.js +++ /dev/null @@ -1,57 +0,0 @@ -import angular from 'angular'; -import _ from 'lodash'; - -const template = ` - - -`; - -angular -.module('grafana.directives') -.directive('datasourceSelector', () => { - return { - scope: { - datasources: "=", - options: "=", - onChange: "&" - }, - controller: DatasourceSelectorCtrl, - controllerAs: 'ctrl', - template: template - }; -}); - -class DatasourceSelectorCtrl { - - /** @ngInject */ - constructor($scope) { - this.scope = $scope; - let datasources = $scope.datasources; - let options = $scope.options; - this.dsOptions = { - multi: true, - current: {value: datasources, text: datasources.join(" + ")}, - options: _.map(options, (ds) => { - return {text: ds, value: ds, selected: _.includes(datasources, ds)}; - }) - }; - // Fix for Grafana 6.0 - // https://github.com/grafana/grafana/blob/v6.0.0/public/app/core/directives/value_select_dropdown.ts#L291 - this.dashboard = { - on: () => {} - }; - } - - onChange(updatedOptions) { - let newDataSources = updatedOptions.current.value; - this.scope.datasources = newDataSources; - - // Run after model was changed - this.scope.$$postDigest(() => { - this.scope.onChange(); - }); - } -} diff --git a/src/panel-triggers/module.js b/src/panel-triggers/module.js index 2ea2c17..a6f7f15 100644 --- a/src/panel-triggers/module.js +++ b/src/panel-triggers/module.js @@ -11,9 +11,8 @@ * Licensed under the Apache License, Version 2.0 */ -import {TriggerPanelCtrl} from './triggers_panel_ctrl'; -import {loadPluginCss} from 'grafana/app/plugins/sdk'; -import './datasource-selector.directive'; +import { TriggerPanelCtrl } from './triggers_panel_ctrl'; +import { loadPluginCss } from 'grafana/app/plugins/sdk'; loadPluginCss({ dark: 'plugins/alexanderzobnin-zabbix-app/css/grafana-zabbix.dark.css', diff --git a/src/panel-triggers/partials/triggers_tab.html b/src/panel-triggers/partials/triggers_tab.html deleted file mode 100644 index e7df9fe..0000000 --- a/src/panel-triggers/partials/triggers_tab.html +++ /dev/null @@ -1,104 +0,0 @@ -
-
-
-
- -
-
- - -
-
-
-
- -
-
-
{{ target.datasource }}
-
-
- - -
-
- - -
-
- - -
-
- -
-
- - -
-
- - -
-
- - -
-
-
-
diff --git a/src/panel-triggers/triggers_tab.js b/src/panel-triggers/triggers_tab.js deleted file mode 100644 index 9b3032b..0000000 --- a/src/panel-triggers/triggers_tab.js +++ /dev/null @@ -1,131 +0,0 @@ -import _ from 'lodash'; -import * as utils from '../datasource-zabbix/utils'; -import { getDefaultTarget } from './triggers_panel_ctrl'; - -class TriggersTabCtrl { - - /** @ngInject */ - constructor($scope, $rootScope, uiSegmentSrv, templateSrv) { - $scope.editor = this; - this.panelCtrl = $scope.ctrl; - this.panel = this.panelCtrl.panel; - this.templateSrv = templateSrv; - this.datasources = {}; - - // Load scope defaults - var scopeDefaults = { - getGroupNames: {}, - getHostNames: {}, - getApplicationNames: {}, - getProxyNames: {}, - oldTarget: _.cloneDeep(this.panel.targets) - }; - _.defaultsDeep(this, scopeDefaults); - this.selectedDatasources = this.getSelectedDatasources(); - - this.initDatasources(); - this.panelCtrl.refresh(); - } - - initDatasources() { - return this.panelCtrl.initDatasources() - .then((datasources) => { - _.each(datasources, (datasource) => { - this.datasources[datasource.name] = datasource; - this.bindSuggestionFunctions(datasource); - }); - }); - } - - bindSuggestionFunctions(datasource) { - // Map functions for bs-typeahead - let ds = datasource.name; - this.getGroupNames[ds] = _.bind(this.suggestGroups, this, datasource); - this.getHostNames[ds] = _.bind(this.suggestHosts, this, datasource); - this.getApplicationNames[ds] = _.bind(this.suggestApps, this, datasource); - this.getProxyNames[ds] = _.bind(this.suggestProxies, this, datasource); - } - - getSelectedDatasources() { - return _.compact(this.panel.targets.map(target => target.datasource)); - } - - suggestGroups(datasource, query, callback) { - return datasource.zabbix.getAllGroups() - .then(groups => { - return _.map(groups, 'name'); - }) - .then(callback); - } - - suggestHosts(datasource, query, callback) { - const target = this.panel.targets.find(t => t.datasource === datasource.name); - let groupFilter = datasource.replaceTemplateVars(target.group.filter); - return datasource.zabbix.getAllHosts(groupFilter) - .then(hosts => { - return _.map(hosts, 'name'); - }) - .then(callback); - } - - suggestApps(datasource, query, callback) { - const target = this.panel.targets.find(t => t.datasource === datasource.name); - let groupFilter = datasource.replaceTemplateVars(target.group.filter); - let hostFilter = datasource.replaceTemplateVars(target.host.filter); - return datasource.zabbix.getAllApps(groupFilter, hostFilter) - .then(apps => { - return _.map(apps, 'name'); - }) - .then(callback); - } - - suggestProxies(datasource, query, callback) { - return datasource.zabbix.getProxies() - .then(proxies => _.map(proxies, 'host')) - .then(callback); - } - - datasourcesChanged() { - const newTargets = []; - _.each(this.selectedDatasources, (ds) => { - const dsTarget = this.panel.targets.find((target => target.datasource === ds)); - if (dsTarget) { - newTargets.push(dsTarget); - } else { - const newTarget = getDefaultTarget(this.panel.targets); - newTarget.datasource = ds; - newTargets.push(newTarget); - } - this.panel.targets = newTargets; - }); - this.parseTarget(); - } - - parseTarget() { - this.initDatasources() - .then(() => { - var newTarget = _.cloneDeep(this.panel.targets); - if (!_.isEqual(this.oldTarget, newTarget)) { - this.oldTarget = newTarget; - this.panelCtrl.refresh(); - } - }); - } - - isRegex(str) { - return utils.isRegex(str); - } - - isVariable(str) { - return utils.isTemplateVariable(str, this.templateSrv.variables); - } -} - -export function triggerPanelTriggersTab() { - return { - restrict: 'E', - scope: true, - templateUrl: 'public/plugins/alexanderzobnin-zabbix-app/panel-triggers/partials/triggers_tab.html', - controller: TriggersTabCtrl, - }; -}