grafana/src/app/controllers/dash.js

104 lines
2.5 KiB
JavaScript
Raw Normal View History

2013-09-13 15:52:13 -05:00
define([
'angular',
'config',
'underscore',
'services/all'
],
function (angular, config, _) {
"use strict";
var module = angular.module('kibana.controllers');
module.controller('DashCtrl', function(
$scope, $route, ejsResource, fields, dashboard, alertSrv, panelMove, esVersion) {
$scope.requiredElasticSearchVersion = ">=0.20.5";
2013-09-13 15:52:13 -05:00
$scope.editor = {
index: 0
};
// For moving stuff around the dashboard.
$scope.panelMoveDrop = panelMove.onDrop;
$scope.panelMoveStart = panelMove.onStart;
$scope.panelMoveStop = panelMove.onStop;
$scope.panelMoveOver = panelMove.onOver;
$scope.panelMoveOut = panelMove.onOut;
2013-09-13 15:52:13 -05:00
$scope.init = function() {
$scope.config = config;
// Make stuff, including underscore.js available to views
2013-09-13 15:52:13 -05:00
$scope._ = _;
$scope.dashboard = dashboard;
$scope.dashAlerts = alertSrv;
$scope.esVersion = esVersion;
// Clear existing alerts
2013-09-13 15:52:13 -05:00
alertSrv.clearAll();
// Provide a global list of all seen fields
2013-09-13 15:52:13 -05:00
$scope.fields = fields;
$scope.reset_row();
$scope.ejs = ejsResource(config.elasticsearch);
};
$scope.isPanel = function(obj) {
if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) {
return true;
} else {
return false;
}
};
2013-09-13 15:52:13 -05:00
$scope.add_row = function(dash,row) {
dash.rows.push(row);
};
$scope.reset_row = function() {
$scope.row = {
title: '',
height: '150px',
editable: true,
};
};
$scope.row_style = function(row) {
return { 'min-height': row.collapse ? '5px' : row.height };
};
2013-11-07 15:25:24 -06:00
$scope.panel_path =function(type) {
2013-09-13 15:52:13 -05:00
if(type) {
2013-11-07 15:25:24 -06:00
return 'app/panels/'+type.replace(".","/");
} else {
return false;
}
};
$scope.edit_path = function(type) {
var p = $scope.panel_path(type);
if(p) {
return p+'/editor.html';
2013-09-13 15:52:13 -05:00
} else {
return false;
}
};
$scope.setEditorTabs = function(panelMeta) {
$scope.editorTabs = ['General','Panel'];
if(!_.isUndefined(panelMeta.editorTabs)) {
$scope.editorTabs = _.union($scope.editorTabs,_.pluck(panelMeta.editorTabs,'title'));
}
return $scope.editorTabs;
};
// This is whoafully incomplete, but will do for now
$scope.parse_error = function(data) {
var _error = data.match("nested: (.*?);");
return _.isNull(_error) ? data : _error[1];
};
$scope.init();
});
});