mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ace: minor changes to ace directive
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="gf-form-inline">
|
||||
<div class="gf-form gf-form--grow">
|
||||
<code-editor content="ctrl.target.expr" on-change="ctrl.refreshMetricData()"
|
||||
get-metrics="ctrl.getMetricsAutocomplete" data-mode="prometheus">
|
||||
get-completions="ctrl.getCompletions($query)" data-mode="prometheus">
|
||||
</code-editor>
|
||||
</div>
|
||||
</div>
|
||||
@@ -40,17 +40,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form gf-form--grow">
|
||||
<div class="gf-form-label gf-form-label--grow"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline">
|
||||
<div class="gf-form max-width-26">
|
||||
<label class="gf-form-label width-8">Metric lookup</label>
|
||||
<input type="text" class="gf-form-input" ng-model="ctrl.target.metric" spellcheck='false' bs-typeahead="ctrl.suggestMetrics" placeholder="metric name" data-min-length=0 data-items=100>
|
||||
</div>
|
||||
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label width-6">Format as</label>
|
||||
<div class="gf-form-select-wrapper width-8">
|
||||
@@ -68,4 +57,5 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</query-editor-row>
|
||||
|
||||
@@ -37,28 +37,18 @@ 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();
|
||||
});
|
||||
});
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
getCompletions(query) {
|
||||
console.log(query);
|
||||
return this.datasource.performSuggestQuery(query).then(res => {
|
||||
return res.map(item => {
|
||||
return {word: item, type: 'metric'};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getDefaultFormat() {
|
||||
if (this.panelCtrl.panel.type === 'table') {
|
||||
return 'table';
|
||||
|
||||
Reference in New Issue
Block a user