diff --git a/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel.js b/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel.js deleted file mode 100644 index 38e08660a7fb7..0000000000000 --- a/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel.js +++ /dev/null @@ -1,77 +0,0 @@ -export const DEFAULT_PANEL_WIDTH = 3; -export const DEFAULT_PANEL_HEIGHT = 2; - -/** - * Represents a panel on a grid. Keeps track of position in the grid and what visualization it - * contains. - * - * @param id - Id of the visualization contained in the panel. - * @param type - Type of the visualization in the panel. - * @param panelId - Unique id to represent this panel in the grid. - * @constructor - */ -function Panel(id, type, panelId) { - /** - * A reference to the gridster widget holding this panel. Used to - * update the size and column attributes. - */ - this.$el; - - /** - * Width of the panel. - * @type {number} - */ - this.size_x = DEFAULT_PANEL_WIDTH; - - /** - * Height of the panel. - * @type {number} - */ - this.size_y = DEFAULT_PANEL_HEIGHT; - - /** - * Column index in the grid. - * @type {number} - */ - this.col; - - /** - * Row index of the panel in the grid. - * @type {number} - */ - this.row; - - /** - * Height of the panel. - * @type {number} - */ - this.id = id; - - /** - * Unique identifier for this panel. Guaranteed to be unique among the current - * panels in the grid. - * @type {number} - */ - this.panelId = panelId; - - /** - * Type of visualization this panel contains. - * @type {string} - */ - this.type = type; -} - - -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); - } -} diff --git a/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel_state.js b/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel_state.js new file mode 100644 index 0000000000000..f3b9c137adc51 --- /dev/null +++ b/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel_state.js @@ -0,0 +1,35 @@ +export const DEFAULT_PANEL_WIDTH = 3; +export const DEFAULT_PANEL_HEIGHT = 2; + +/** + * Represents a panel on a grid. Keeps track of position in the grid and what visualization it + * contains. + * + * @typedef PanelState + * @property {number} id - Id of the visualization contained in the panel. + * @property {Element} $el - A reference to the gridster widget holding this panel. Used to + * update the size and column attributes. TODO: move out of panel state as this couples state to ui. + * @property {string} type - Type of the visualization in the panel. + * @property {number} panelId - Unique id to represent this panel in the grid. + * @property {number} size_x - Width of the panel. + * @property {number} size_y - Height of the panel. + * @property {number} col - Column index in the grid. + * @property {number} row - Row index in the grid. + */ + +/** + * Creates and initializes a basic panel state. + * @param {number} id + * @param {string} type + * @param {number} panelId + * @return {PanelState} + */ +export function createPanelState(id, type, panelId) { + return { + size_x: DEFAULT_PANEL_WIDTH, + size_y: DEFAULT_PANEL_HEIGHT, + panelId: panelId, + type: type, + id: id + }; +} diff --git a/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel_utils.js b/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel_utils.js index dc2a80f25e931..2b789179ba322 100644 --- a/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel_utils.js +++ b/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel_utils.js @@ -1,4 +1,4 @@ -import { DEFAULT_PANEL_WIDTH, DEFAULT_PANEL_HEIGHT } from 'plugins/kibana/dashboard/components/panel/lib/panel'; +import { DEFAULT_PANEL_WIDTH, DEFAULT_PANEL_HEIGHT } from 'plugins/kibana/dashboard/components/panel/lib/panel_state'; export class PanelUtils { /** diff --git a/src/core_plugins/kibana/public/dashboard/directives/dashboard_panel_directive.js b/src/core_plugins/kibana/public/dashboard/directives/dashboard_panel.js similarity index 98% rename from src/core_plugins/kibana/public/dashboard/directives/dashboard_panel_directive.js rename to src/core_plugins/kibana/public/dashboard/directives/dashboard_panel.js index bc0abc9799883..ed1736349991d 100644 --- a/src/core_plugins/kibana/public/dashboard/directives/dashboard_panel_directive.js +++ b/src/core_plugins/kibana/public/dashboard/directives/dashboard_panel.js @@ -22,7 +22,7 @@ uiModules /** * Returns a unique id for storing the panel state in the persistent ui. - * @param panel + * @param {PanelState} panel * @returns {string} */ const getPersistedStateId = function (panel) { @@ -46,7 +46,7 @@ uiModules parentUiState: '=', /** * Contains information about this panel. - * @type {Panel} + * @type {PanelState} */ panel: '=', /** diff --git a/src/core_plugins/kibana/public/dashboard/index.js b/src/core_plugins/kibana/public/dashboard/index.js index 08a6cab3de0da..607633f747aff 100644 --- a/src/core_plugins/kibana/public/dashboard/index.js +++ b/src/core_plugins/kibana/public/dashboard/index.js @@ -7,7 +7,7 @@ import 'ui/notify'; import 'ui/typeahead'; import 'ui/share'; import 'plugins/kibana/dashboard/directives/grid'; -import 'plugins/kibana/dashboard/directives/dashboard_panel_directive'; +import 'plugins/kibana/dashboard/directives/dashboard_panel'; import 'plugins/kibana/dashboard/services/saved_dashboards'; import 'plugins/kibana/dashboard/styles/main.less'; import FilterBarQueryFilterProvider from 'ui/filter_bar/query_filter'; @@ -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 { PanelFactory } from 'plugins/kibana/dashboard/components/panel/lib/panel'; +import { createPanelState } from 'plugins/kibana/dashboard/components/panel/lib/panel_state'; require('ui/saved_objects/saved_object_registry').register(savedDashboardRegister); const app = uiModules.get('app/dashboard', [ @@ -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(PanelFactory.create(hit.id, 'visualization', getMaxPanelId())); + $state.panels.push(createPanelState(hit.id, 'visualization', getMaxPanelId())); }; $scope.addSearch = function (hit) { pendingVis++; - $state.panels.push(PanelFactory.create(hit.id, 'search', getMaxPanelId())); + $state.panels.push(createPanelState(hit.id, 'search', getMaxPanelId())); }; // Setup configurable values for config directive, after objects are initialized