From b349b3ef5574a797d69cb28d9023aa1e98ba0b8b Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Wed, 13 Sep 2017 16:29:53 +0900 Subject: [PATCH] provide ace editor for external datasource plugin (#9224) --- .../app/core/components/code_editor/code_editor.ts | 13 +++++++++---- .../datasource/prometheus}/mode-prometheus.js | 0 .../prometheus/partials/query.editor.html | 2 +- .../datasource/prometheus}/snippets/prometheus.js | 0 4 files changed, 10 insertions(+), 5 deletions(-) rename public/app/{core/components/code_editor => plugins/datasource/prometheus}/mode-prometheus.js (100%) rename public/app/{core/components/code_editor => plugins/datasource/prometheus}/snippets/prometheus.js (100%) diff --git a/public/app/core/components/code_editor/code_editor.ts b/public/app/core/components/code_editor/code_editor.ts index 7c41eb3b3a2..61ebb17d9b3 100644 --- a/public/app/core/components/code_editor/code_editor.ts +++ b/public/app/core/components/code_editor/code_editor.ts @@ -40,11 +40,11 @@ const DEFAULT_MAX_LINES = 10; const DEFAULT_TAB_SIZE = 2; const DEFAULT_BEHAVIOURS = true; -const GRAFANA_MODULES = ['mode-prometheus', 'snippets-prometheus', 'theme-grafana-dark']; +const GRAFANA_MODULES = ['theme-grafana-dark']; const GRAFANA_MODULE_BASE = "public/app/core/components/code_editor/"; // Trick for loading additional modules -function setModuleUrl(moduleType, name) { +function setModuleUrl(moduleType, name, pluginBaseUrl = null) { let baseUrl = ACE_SRC_BASE; let aceModeName = `ace/${moduleType}/${name}`; let moduleName = `${moduleType}-${name}`; @@ -54,6 +54,10 @@ function setModuleUrl(moduleType, name) { baseUrl = GRAFANA_MODULE_BASE; } + if (pluginBaseUrl) { + baseUrl = pluginBaseUrl + '/'; + } + if (moduleType === 'snippets') { componentName = `${moduleType}/${name}.js`; } @@ -159,8 +163,8 @@ function link(scope, elem, attrs) { function setLangMode(lang) { let aceModeName = `ace/mode/${lang}`; - setModuleUrl("mode", lang); - setModuleUrl("snippets", lang); + setModuleUrl("mode", lang, scope.datasource.meta.baseUrl || null); + setModuleUrl("snippets", lang, scope.datasource.meta.baseUrl || null); editorSession.setMode(aceModeName); ace.config.loadModule("ace/ext/language_tools", (language_tools) => { @@ -210,6 +214,7 @@ export function codeEditorDirective() { template: editorTemplate, scope: { content: "=", + datasource: "=", codeEditorFocus: "<", onChange: "&", getCompleter: "&" diff --git a/public/app/core/components/code_editor/mode-prometheus.js b/public/app/plugins/datasource/prometheus/mode-prometheus.js similarity index 100% rename from public/app/core/components/code_editor/mode-prometheus.js rename to public/app/plugins/datasource/prometheus/mode-prometheus.js diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index a34a752bd95..9b06d4116f4 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -1,7 +1,7 @@
-
diff --git a/public/app/core/components/code_editor/snippets/prometheus.js b/public/app/plugins/datasource/prometheus/snippets/prometheus.js similarity index 100% rename from public/app/core/components/code_editor/snippets/prometheus.js rename to public/app/plugins/datasource/prometheus/snippets/prometheus.js