Skip to content

Commit

Permalink
namespace panel factory
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
stacey-gammon committed Dec 2, 2016
1 parent 82323be commit 3a09d66
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ function Panel(id, type, panelId) {
this.type = type;
}

/**
* Factory function to create a panel object.
*
* @param id {string} - The id of the visualization this panel contains
* @param type {string} - The type of visualization this panel contains
* @param panelId {number} - A unique identifier for this panel in the grid
* @returns {Panel}
*/
export function createNewPanel(id, type, panelId) {
return new Panel(id, type, panelId);

export class PanelFactory {
/**
* Factory function to create a panel object.
*
* @param id {string} - The id of the visualization this panel contains
* @param type {string} - The type of visualization this panel contains
* @param panelId {number} - A unique identifier for this panel in the grid
* @returns {Panel}
*/
static create(id, type, panelId) {
return new Panel(id, type, panelId);
}
}
6 changes: 6 additions & 0 deletions src/core_plugins/kibana/public/dashboard/directives/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ app.directive('dashboardGrid', function ($compile, Notifier) {
});
};

/**
* Removes the panel with the given id from the $scope.state.panels array. Does not
* remove the ui element from gridster - that is triggered by a watcher that is
* triggered on changes made to $scope.state.panels.
* @param panelId {number}
*/
$scope.getPanelByPanelId = (panelId) => {
return _.find($scope.state.panels, function (panel) {
return panel.panelId === panelId;
Expand Down
6 changes: 3 additions & 3 deletions src/core_plugins/kibana/public/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import uiRoutes from 'ui/routes';
import uiModules from 'ui/modules';
import indexTemplate from 'plugins/kibana/dashboard/index.html';
import { savedDashboardRegister } from 'plugins/kibana/dashboard/services/saved_dashboard_register';
import { createNewPanel } from 'plugins/kibana/dashboard/components/panel/lib/panel';
import { PanelFactory } from 'plugins/kibana/dashboard/components/panel/lib/panel';
require('ui/saved_objects/saved_object_registry').register(savedDashboardRegister);

const app = uiModules.get('app/dashboard', [
Expand Down Expand Up @@ -272,12 +272,12 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter,
// called by the saved-object-finder when a user clicks a vis
$scope.addVis = function (hit) {
pendingVis++;
$state.panels.push(createNewPanel(hit.id, 'visualization', getMaxPanelId()));
$state.panels.push(PanelFactory.create(hit.id, 'visualization', getMaxPanelId()));
};

$scope.addSearch = function (hit) {
pendingVis++;
$state.panels.push(createNewPanel(hit.id, 'search', getMaxPanelId()));
$state.panels.push(PanelFactory.create(hit.id, 'search', getMaxPanelId()));
};

// Setup configurable values for config directive, after objects are initialized
Expand Down

0 comments on commit 3a09d66

Please sign in to comment.