2016-04-17 12:14:25 -04:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
2017-05-19 21:32:23 +02:00
|
|
|
import {DashboardModel} from '../dashboard/model';
|
2016-04-17 12:14:25 -04:00
|
|
|
|
2017-05-19 21:32:23 +02:00
|
|
|
export class MetricsTabCtrl {
|
2016-04-17 12:14:25 -04:00
|
|
|
dsName: string;
|
2017-05-19 21:32:23 +02:00
|
|
|
panel: any;
|
2016-04-17 12:14:25 -04:00
|
|
|
panelCtrl: any;
|
|
|
|
|
datasources: any[];
|
|
|
|
|
current: any;
|
2017-05-19 21:32:23 +02:00
|
|
|
nextRefId: string;
|
|
|
|
|
dashboard: DashboardModel;
|
2017-06-14 19:42:45 -04:00
|
|
|
panelDsValue: any;
|
|
|
|
|
addQueryDropdown: any;
|
2016-04-17 12:14:25 -04:00
|
|
|
|
|
|
|
|
/** @ngInject */
|
2017-06-14 19:42:45 -04:00
|
|
|
constructor($scope, private uiSegmentSrv, private datasourceSrv) {
|
2017-05-19 21:32:23 +02:00
|
|
|
this.panelCtrl = $scope.ctrl;
|
|
|
|
|
$scope.ctrl = this;
|
|
|
|
|
|
|
|
|
|
this.panel = this.panelCtrl.panel;
|
|
|
|
|
this.dashboard = this.panelCtrl.dashboard;
|
2016-04-17 12:14:25 -04:00
|
|
|
this.datasources = datasourceSrv.getMetricSources();
|
2017-06-14 19:42:45 -04:00
|
|
|
this.panelDsValue = this.panelCtrl.panel.datasource || null;
|
2016-04-28 10:13:18 +02:00
|
|
|
|
2016-04-17 12:14:25 -04:00
|
|
|
for (let ds of this.datasources) {
|
2017-06-14 19:42:45 -04:00
|
|
|
if (ds.value === this.panelDsValue) {
|
2016-04-17 12:14:25 -04:00
|
|
|
this.current = ds;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 19:42:45 -04:00
|
|
|
this.addQueryDropdown = {text: 'Add Query', value: null, fake: true};
|
2017-05-20 10:14:41 +02:00
|
|
|
// update next ref id
|
|
|
|
|
this.panelCtrl.nextRefId = this.dashboard.getNextQueryLetter(this.panel);
|
2017-05-17 17:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-19 02:17:24 +09:00
|
|
|
getOptions(includeBuiltin) {
|
|
|
|
|
return Promise.resolve(this.datasources.filter(value => {
|
|
|
|
|
return includeBuiltin || !value.meta.builtIn;
|
2017-06-14 19:42:45 -04:00
|
|
|
}).map(ds => {
|
|
|
|
|
return {value: ds.value, text: ds.name, datasource: ds};
|
2016-04-17 12:14:25 -04:00
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 19:42:45 -04:00
|
|
|
datasourceChanged(option) {
|
|
|
|
|
if (!option) {
|
|
|
|
|
return;
|
2016-04-17 12:14:25 -04:00
|
|
|
}
|
|
|
|
|
|
2017-06-14 19:42:45 -04:00
|
|
|
this.current = option.datasource;
|
|
|
|
|
this.panelCtrl.setDatasource(option.datasource);
|
|
|
|
|
}
|
2017-06-13 18:31:43 -04:00
|
|
|
|
2017-06-14 19:42:45 -04:00
|
|
|
addMixedQuery(option) {
|
|
|
|
|
if (!option) {
|
|
|
|
|
return;
|
2016-04-17 12:14:25 -04:00
|
|
|
}
|
2017-06-13 18:31:43 -04:00
|
|
|
|
2017-06-14 19:42:45 -04:00
|
|
|
var target: any = {isNew: true};
|
|
|
|
|
this.panelCtrl.addQuery({isNew: true, datasource: option.datasource.name});
|
|
|
|
|
this.addQueryDropdown = {text: 'Add Query', value: null, fake: true};
|
2017-02-19 02:17:24 +09:00
|
|
|
}
|
2016-04-17 12:14:25 -04:00
|
|
|
|
2017-05-20 10:14:41 +02:00
|
|
|
addQuery() {
|
|
|
|
|
this.panelCtrl.addQuery({isNew: true});
|
2016-04-17 12:14:25 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 21:32:23 +02:00
|
|
|
/** @ngInject **/
|
|
|
|
|
export function metricsTabDirective() {
|
|
|
|
|
'use strict';
|
2016-04-17 12:14:25 -04:00
|
|
|
return {
|
|
|
|
|
restrict: 'E',
|
2017-05-19 21:32:23 +02:00
|
|
|
scope: true,
|
2017-05-20 18:21:41 +02:00
|
|
|
templateUrl: 'public/app/features/panel/partials/metrics_tab.html',
|
2017-05-19 21:32:23 +02:00
|
|
|
controller: MetricsTabCtrl,
|
2016-04-17 12:14:25 -04:00
|
|
|
};
|
2017-05-19 21:32:23 +02:00
|
|
|
}
|
2017-05-20 18:21:41 +02:00
|
|
|
|