From 9955638c4e0175813736ad435e3351d8454d9a00 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Wed, 26 Feb 2014 16:51:37 -0700 Subject: [PATCH] Refactor into isolate scope, add params object, add add/remove. Skeleton for panel directive --- src/kibana/apps/dashboard/index.html | 11 +- src/kibana/apps/dashboard/index.js | 164 +++++++++++++++++---------- 2 files changed, 110 insertions(+), 65 deletions(-) diff --git a/src/kibana/apps/dashboard/index.html b/src/kibana/apps/dashboard/index.html index 7bbb44417387f2..94f5edcf070f71 100644 --- a/src/kibana/apps/dashboard/index.html +++ b/src/kibana/apps/dashboard/index.html @@ -1,14 +1,17 @@
-
    +
      \ No newline at end of file diff --git a/src/kibana/apps/dashboard/index.js b/src/kibana/apps/dashboard/index.js index 5042a74726dea7..c3a42bccc9bb10 100644 --- a/src/kibana/apps/dashboard/index.js +++ b/src/kibana/apps/dashboard/index.js @@ -11,77 +11,104 @@ define(function (require) { var app = angular.module('app/dashboard', []); app.controller('dashboard', function ($scope) { - $scope.gridSettings = { + $scope.gridControl = {}; + + $scope.dashboard = { + title: 'Logstash Dashboard', + panels: [ + { + col: 1, + row: 1, + size_x: 5, + size_y: 2, + params: { type: 'line' } + }, + { + col: 6, + row: 1, + size_x: 4, + size_y: 2, + params: { type: 'bar' } + }, + { + col: 10, + row: 1, + size_x: 3, + size_y: 1, + params: { type: 'table' } + }, + { + col: 10, + row: 2, + size_x: 3, + size_y: 1, + params: { type: 'pie' } + }, + { + col: 1, + row: 3, + size_x: 3, + size_y: 1, + params: { type: 'scatter' } + }, + { + col: 4, + row: 3, + size_x: 3, + size_y: 1, + params: { type: 'map' } + }, + { + col: 7, + row: 3, + size_x: 3, + size_y: 1, + params: { type: 'sparkline' } + }, + { + col: 10, + row: 3, + size_x: 3, + size_y: 1, + params: { type: 'heatmap' } + } + ] }; - $scope.panels = [ - { - col: 1, - row: 1, - size_x: 5, - size_y: 2 - }, - { - col: 6, - row: 1, - size_x: 4, - size_y: 2 - }, - { - col: 10, - row: 1, - size_x: 3, - size_y: 1 - }, - { - col: 10, - row: 2, - size_x: 3, - size_y: 1 - }, - { - col: 1, - row: 3, - size_x: 3, - size_y: 1 - }, - { - col: 4, - row: 3, - size_x: 3, - size_y: 1 - }, - { - col: 7, - row: 3, - size_x: 3, - size_y: 1 - }, - { - col: 10, - row: 3, - size_x: 3, - size_y: 1 - } - ]; - $scope.serializeGrid = function () { - console.log($scope.gridster.serialize()); + }); + + app.directive('dashboardPanel', function () { + return { + template: '
    • ' }; }); app.directive('dashboardGrid', function () { return { restrict: 'A', + scope : { + grid: '=', + control: '=' + }, link: function ($scope, elem) { - var width; + var width, gridster; elem.addClass('gridster'); width = elem.width(); - $scope.gridster = elem.gridster({ + $scope.control.serializeGrid = function () { + console.log(gridster.serialize()); + return gridster.serialize(); + }; + + $scope.control.addWidget = function () { + gridster.add_widget('
    • ', 3, 2); + }; + + gridster = elem.gridster({ widget_margins: [5, 5], widget_base_dimensions: [((width - 80) / 12), 100], min_cols: 12, @@ -89,16 +116,31 @@ define(function (require) { resize: { enabled: true, stop: function (event, ui, widget) { - console.log(widget.height()); - widget.children('.content').text('height: ' + widget.height() + ' / width: ' + widget.width()); + console.log(widget.height(), widget.width()); } + }, + serialize_params: function (el, wgd) { + return { + col: wgd.col, + row: wgd.row, + size_x: wgd.size_x, + size_y: wgd.size_y, + params: el.data('params') + }; } }).data('gridster'); - _.each($scope.panels, function (panel, i) { - $scope.gridster.add_widget('
    • ' + - i + - '

    • ', panel.size_x, panel.size_y, panel.col, panel.row); + _.each($scope.grid, function (panel) { + console.log(panel); + var wgd = gridster.add_widget('
    • ', + panel.size_x, panel.size_y, panel.col, panel.row); + wgd.html(panel.params.type + ' '); + wgd.data('params', panel.params); + }); + + elem.on('click', 'li i.remove', function (event) { + var target = event.target.parentNode; + gridster.remove_widget(event.target.parentNode); }); } };