grafana/src/app/controllers/dash.js

116 lines
3.2 KiB
JavaScript
Raw Normal View History

2013-12-02 13:43:39 -06:00
/** @scratch /index/0
* = Kibana
*
* // Why can't I have a preamble here?
*
* == Introduction
*
* Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for
* ElasticSearch. Kibana is a snap to setup and start using. Written entirely in HTML and Javascript
* it requires only a plain webserver, Kibana requires no fancy server side components.
* Kibana strives to be easy to get started with, while also being flexible and powerful, just like
* Elasticsearch.
*
* include::configuration/config.js.asciidoc[]
*
* include::panels.asciidoc[]
*
*/
2013-09-13 15:52:13 -05:00
define([
'angular',
'jquery',
2013-09-13 15:52:13 -05:00
'config',
'underscore',
'services/all',
'services/dashboard/all'
2013-09-13 15:52:13 -05:00
],
function (angular, $, config, _) {
2013-09-13 15:52:13 -05:00
"use strict";
var module = angular.module('kibana.controllers');
2014-06-08 07:40:44 -05:00
module.controller('DashCtrl', function($scope, $rootScope, dashboardKeybindings) {
2014-06-08 07:40:44 -05:00
$scope.editor = { index: 0 };
2013-09-13 15:52:13 -05:00
$scope.init = function() {
$scope.reset_row();
2014-06-08 07:40:44 -05:00
dashboardKeybindings.shortcuts();
};
$scope.isPanel = function(obj) {
if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) {
return true;
} else {
return false;
}
};
$scope.add_row = function(dash, row) {
2013-09-13 15:52:13 -05:00
dash.rows.push(row);
};
$scope.add_row_default = function() {
$scope.reset_row();
$scope.row.title = 'New row';
2014-06-07 14:00:05 -05:00
$scope.add_row($scope.dashboard, $scope.row);
};
2013-09-13 15:52:13 -05:00
$scope.reset_row = function() {
$scope.row = {
title: '',
2014-06-06 09:05:56 -05:00
height: '250px',
2013-09-13 15:52:13 -05:00
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.colors = [
"#7EB26D","#EAB839","#6ED0E0","#EF843C","#E24D42","#1F78C1","#BA43A9","#705DA0", //1
"#508642","#CCA300","#447EBC","#C15C17","#890F02","#0A437C","#6D1F62","#584477", //2
"#B7DBAB","#F4D598","#70DBED","#F9BA8F","#F29191","#82B5D8","#E5A8E2","#AEA2E0", //3
"#629E51","#E5AC0E","#64B0C8","#E0752D","#BF1B00","#0A50A1","#962D82","#614D93", //4
"#9AC48A","#F2C96D","#65C5DB","#F9934E","#EA6460","#5195CE","#D683CE","#806EB7", //5
"#3F6833","#967302","#2F575E","#99440A","#58140C","#052B51","#511749","#3F2B5B", //6
"#E0F9D7","#FCEACA","#CFFAFF","#F9E2D2","#FCE2DE","#BADFF4","#F9D9F9","#DEDAF7" //7
];
2013-09-13 15:52:13 -05:00
$scope.init();
});
});