diff --git a/public/app/core/components/code_editor/code_editor.ts b/public/app/core/components/code_editor/code_editor.ts index 5dbd07ef1c2..19d4f7655fa 100644 --- a/public/app/core/components/code_editor/code_editor.ts +++ b/public/app/core/components/code_editor/code_editor.ts @@ -126,17 +126,16 @@ function link(scope, elem, attrs) { }); let extCompleter = { - getCompletions: getExtCompletions + getCompletions: getCompletions }; - function getExtCompletions(editor, session, pos, prefix, callback) { - scope.getMetrics(prefix).then(results => { - let wordList = results; - callback(null, wordList.map(word => { + function getCompletions(editor, session, pos, prefix, callback) { + scope.getCompletions({$query: prefix}).then(results => { + callback(null, results.map(hit => { return { - caption: word, - value: word, - meta: "metric" + caption: hit.word, + value: hit.word, + meta: hit.type }; })); }); @@ -176,7 +175,7 @@ export function codeEditorDirective() { scope: { content: "=", onChange: "&", - getMetrics: "=" + getCompletions: "&" }, link: link }; diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 52c124da2f4..f9016c2daca 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -2,7 +2,7 @@
+ get-completions="ctrl.getCompletions($query)" data-mode="prometheus">
@@ -40,17 +40,6 @@ -
-
-
- - -
-
- - -
-
@@ -68,4 +57,5 @@
+ diff --git a/public/app/plugins/datasource/prometheus/query_ctrl.ts b/public/app/plugins/datasource/prometheus/query_ctrl.ts index d62350601cd..a3ce097e5f4 100644 --- a/public/app/plugins/datasource/prometheus/query_ctrl.ts +++ b/public/app/plugins/datasource/prometheus/query_ctrl.ts @@ -37,26 +37,16 @@ class PrometheusQueryCtrl extends QueryCtrl { {text: 'Table', value: 'table'}, ]; - $scope.$on('typeahead-updated', () => { - this.$scope.$apply(() => { - this.target.expr += this.target.metric; - this.metric = ''; - this.refreshMetricData(); + this.updateLink(); + } + + getCompletions(query) { + console.log(query); + return this.datasource.performSuggestQuery(query).then(res => { + return res.map(item => { + return {word: item, type: 'metric'}; }); }); - - // called from typeahead so need this - // here in order to ensure this ref - this.suggestMetrics = (query, callback) => { - console.log(this); - this.datasource.performSuggestQuery(query).then(callback); - }; - - this.getMetricsAutocomplete = (query) => { - return this.datasource.performSuggestQuery(query); - }; - - this.updateLink(); } getDefaultFormat() {