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
|
|
|
dsSegment: any;
|
2017-02-19 02:17:24 +09:00
|
|
|
mixedDsSegment: any;
|
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;
|
2016-04-17 12:14:25 -04:00
|
|
|
|
|
|
|
|
/** @ngInject */
|
2017-05-17 17:02:50 +02:00
|
|
|
constructor($scope, private uiSegmentSrv, 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();
|
|
|
|
|
|
2016-04-28 10:13:18 +02:00
|
|
|
var dsValue = this.panelCtrl.panel.datasource || null;
|
|
|
|
|
|
2016-04-17 12:14:25 -04:00
|
|
|
for (let ds of this.datasources) {
|
2016-04-28 10:13:18 +02:00
|
|
|
if (ds.value === dsValue) {
|
2016-04-17 12:14:25 -04:00
|
|
|
this.current = ds;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 19:08:35 +02:00
|
|
|
if (!this.current) {
|
|
|
|
|
this.current = {name: dsValue + ' not found', value: null};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 11:46:16 +02:00
|
|
|
this.dsSegment = uiSegmentSrv.newSegment({value: this.current.name, selectMode: true});
|
2017-05-17 17:02:50 +02:00
|
|
|
this.mixedDsSegment = uiSegmentSrv.newSegment({value: 'Add Query', selectMode: true});
|
2017-05-19 21:32:23 +02:00
|
|
|
this.nextRefId = this.getNextQueryLetter();
|
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;
|
|
|
|
|
}).map(value => {
|
2016-04-17 12:14:25 -04:00
|
|
|
return this.uiSegmentSrv.newSegment(value.name);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datasourceChanged() {
|
2016-09-13 22:10:44 +02:00
|
|
|
var ds = _.find(this.datasources, {name: this.dsSegment.value});
|
2016-04-17 12:14:25 -04:00
|
|
|
if (ds) {
|
|
|
|
|
this.current = ds;
|
|
|
|
|
this.panelCtrl.setDatasource(ds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 02:17:24 +09:00
|
|
|
mixedDatasourceChanged() {
|
2016-04-17 16:43:13 -04:00
|
|
|
var target: any = {isNew: true};
|
2017-02-19 02:17:24 +09:00
|
|
|
var ds = _.find(this.datasources, {name: this.mixedDsSegment.value});
|
|
|
|
|
if (ds) {
|
|
|
|
|
target.datasource = ds.name;
|
|
|
|
|
this.panelCtrl.panel.targets.push(target);
|
|
|
|
|
this.mixedDsSegment.value = '';
|
2016-04-17 12:14:25 -04:00
|
|
|
}
|
2017-02-19 02:17:24 +09:00
|
|
|
}
|
2016-04-17 12:14:25 -04:00
|
|
|
|
2017-05-19 21:32:23 +02:00
|
|
|
getNextQueryLetter() {
|
|
|
|
|
return this.dashboard.getNextQueryLetter(this.panel);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 02:17:24 +09:00
|
|
|
addDataQuery() {
|
2017-05-19 21:32:23 +02:00
|
|
|
var target: any = {
|
|
|
|
|
isNew: true,
|
|
|
|
|
refId: this.getNextQueryLetter()
|
|
|
|
|
};
|
2016-04-17 12:14:25 -04:00
|
|
|
this.panelCtrl.panel.targets.push(target);
|
2017-05-19 21:32:23 +02:00
|
|
|
this.nextRefId = this.getNextQueryLetter();
|
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,
|
|
|
|
|
templateUrl: 'public/app/partials/metrics.html',
|
|
|
|
|
controller: MetricsTabCtrl,
|
2016-04-17 12:14:25 -04:00
|
|
|
};
|
2017-05-19 21:32:23 +02:00
|
|
|
}
|