Files
grafana/public/app/features/panel/query_editor_row.ts

110 lines
2.5 KiB
TypeScript
Raw Normal View History

2017-12-20 12:33:33 +01:00
import angular from 'angular';
2018-08-26 20:19:23 +02:00
const module = angular.module('grafana.directives');
export class QueryRowCtrl {
collapsedText: string;
canCollapse: boolean;
getCollapsedText: any;
target: any;
queryCtrl: any;
panelCtrl: any;
panel: any;
collapsed: any;
hideRowButtons: boolean;
constructor() {
this.panelCtrl = this.queryCtrl.panelCtrl;
this.target = this.queryCtrl.target;
this.panel = this.panelCtrl.panel;
this.hideRowButtons = this.panelCtrl.hideRowButtons;
2016-04-27 10:16:04 +02:00
if (!this.target.refId) {
this.target.refId = this.panelCtrl.dashboard.getNextQueryLetter(this.panel);
2016-04-27 10:16:04 +02:00
}
2016-04-27 10:16:04 +02:00
this.toggleCollapse(true);
if (this.target.isNew) {
delete this.target.isNew;
this.toggleCollapse(false);
}
if (this.panel.targets.length < 4) {
this.collapsed = false;
}
}
toggleHideQuery() {
this.target.hide = !this.target.hide;
this.panelCtrl.refresh();
}
toggleCollapse(init) {
if (!this.canCollapse) {
return;
}
if (!this.panelCtrl.__collapsedQueryCache) {
this.panelCtrl.__collapsedQueryCache = {};
}
if (init) {
this.collapsed = this.panelCtrl.__collapsedQueryCache[this.target.refId] !== false;
} else {
this.collapsed = !this.collapsed;
this.panelCtrl.__collapsedQueryCache[this.target.refId] = this.collapsed;
}
try {
this.collapsedText = this.queryCtrl.getCollapsedText();
} catch (e) {
2018-08-26 20:19:23 +02:00
const err = e.message || e.toString();
2017-12-20 12:33:33 +01:00
this.collapsedText = 'Error: ' + err;
}
}
toggleEditorMode() {
2016-04-27 10:16:04 +02:00
if (this.canCollapse && this.collapsed) {
this.collapsed = false;
}
this.queryCtrl.toggleEditorMode();
}
removeQuery() {
if (this.panelCtrl.__collapsedQueryCache) {
delete this.panelCtrl.__collapsedQueryCache[this.target.refId];
}
this.panelCtrl.removeQuery(this.target);
}
duplicateQuery() {
2018-08-26 20:19:23 +02:00
const clone = angular.copy(this.target);
this.panelCtrl.addQuery(clone);
}
moveQuery(direction) {
this.panelCtrl.moveQuery(this.target, direction);
}
}
/** @ngInject */
function queryEditorRowDirective() {
return {
2017-12-20 12:33:33 +01:00
restrict: 'E',
controller: QueryRowCtrl,
bindToController: true,
2017-12-20 12:33:33 +01:00
controllerAs: 'ctrl',
templateUrl: 'public/app/features/panel/partials/query_editor_row.html',
transclude: true,
scope: {
2017-12-20 12:33:33 +01:00
queryCtrl: '=',
canCollapse: '=',
hasTextEditMode: '=',
},
};
}
2017-12-20 12:33:33 +01:00
module.directive('queryEditorRow', queryEditorRowDirective);