diff --git a/platform/features/table/bundle.js b/platform/features/table/bundle.js index b598ec1200..2cc4bce38a 100644 --- a/platform/features/table/bundle.js +++ b/platform/features/table/bundle.js @@ -23,17 +23,15 @@ define([ "./src/directives/MCTTable", - "./src/controllers/TableController", + "./src/controllers/TelemetryTableController", "./src/controllers/TableOptionsController", - "./src/controllers/MCTTableController", '../../commonUI/regions/src/Region', '../../commonUI/browse/src/InspectorRegion', "legacyRegistry" ], function ( MCTTable, - TableController, + TelemetryTableController, TableOptionsController, - MCTTableController, Region, InspectorRegion, legacyRegistry @@ -84,19 +82,14 @@ define([ ], "controllers": [ { - "key": "TableController", - "implementation": TableController, + "key": "TelemetryTableController", + "implementation": TelemetryTableController, "depends": ["$scope", "telemetryHandler", "telemetryFormatter"] }, { "key": "TableOptionsController", "implementation": TableOptionsController, "depends": ["$scope"] - }, - { - "key": "MCTTableController", - "implementation": MCTTableController, - "depends": ["$scope", "$timeout", "$element"] } ], diff --git a/platform/features/table/res/templates/mct-data-table.html b/platform/features/table/res/templates/mct-data-table.html index 42753a8a7b..9726d18d5c 100644 --- a/platform/features/table/res/templates/mct-data-table.html +++ b/platform/features/table/res/templates/mct-data-table.html @@ -1,13 +1,10 @@
- @@ -52,7 +49,7 @@
+
1){ + self.addColumn(new NameColumn(), 0); + } + metadata.forEach(function (metadatum) { //Push domains first metadatum.domains.forEach(function (domainMetadata) { @@ -72,7 +77,7 @@ define( * @param {Number} [index] Where the column should appear (will be * affected by column filtering) */ - Table.prototype.addColumn = function (column, index) { + TableConfiguration.prototype.addColumn = function (column, index) { if (typeof index === 'undefined') { this.columns.push(column); } else { @@ -85,7 +90,7 @@ define( * @param column * @returns {*|string} */ - Table.prototype.getColumnTitle = function (column) { + TableConfiguration.prototype.getColumnTitle = function (column) { return column.getTitle(); }; @@ -93,7 +98,7 @@ define( * Get a simple list of column titles * @returns {Array} The titles of the columns */ - Table.prototype.getHeaders = function() { + TableConfiguration.prototype.getHeaders = function() { var self = this; return this.columns.map(function (column){ return self.getColumnTitle(column); @@ -108,7 +113,7 @@ define( * @returns {Object} Key value pairs where the key is the column * title, and the value is the formatted value from the provided datum. */ - Table.prototype.getRowValues = function(telemetryObject, datum) { + TableConfiguration.prototype.getRowValues = function(telemetryObject, datum) { var self = this; return this.columns.reduce(function(rowObject, column){ var columnTitle = self.getColumnTitle(column), @@ -130,10 +135,22 @@ define( /** * @private */ - Table.prototype.defaultColumnConfiguration = function () { + TableConfiguration.prototype.defaultColumnConfiguration = function () { return ((this.domainObject.getModel().configuration || {}).table || {}).columns || {}; }; + /** + * Set the established configuration on the domain object + * @private + */ + TableConfiguration.prototype.saveColumnConfig = function (columnConfig) { + this.domainObject.useCapability('mutation', function (model) { + model.configuration = model.configuration || {}; + model.configuration.table = model.configuration.table || {}; + model.configuration.table.columns = columnConfig; + }); + }; + /** * As part of the process of building the table definition, extract * configuration from column definitions. @@ -141,7 +158,7 @@ define( * pairs where the key is the column title, and the value is a * boolean indicating whether the column should be shown. */ - Table.prototype.getColumnConfiguration = function() { + TableConfiguration.prototype.getColumnConfig = function() { var configuration = {}, //Use existing persisted config, or default it defaultConfig = this.defaultColumnConfiguration(); @@ -158,6 +175,6 @@ define( return configuration; }; - return Table; + return TableConfiguration; } ); diff --git a/platform/features/table/src/controllers/MCTTableController.js b/platform/features/table/src/controllers/MCTTableController.js index 63a5aa5036..45614bc9d1 100644 --- a/platform/features/table/src/controllers/MCTTableController.js +++ b/platform/features/table/src/controllers/MCTTableController.js @@ -287,7 +287,7 @@ define( } ]; - this.$timeout(this.setElementSizes.bind(this), 0); + this.$timeout(this.setElementSizes.bind(this)); }; /** diff --git a/platform/features/table/src/controllers/TableController.js b/platform/features/table/src/controllers/TelemetryTableController.js similarity index 76% rename from platform/features/table/src/controllers/TableController.js rename to platform/features/table/src/controllers/TelemetryTableController.js index 577b79b1ca..b28f87ba21 100644 --- a/platform/features/table/src/controllers/TableController.js +++ b/platform/features/table/src/controllers/TelemetryTableController.js @@ -27,10 +27,9 @@ */ define( [ - '../Table', - '../NameColumn' + '../TableConfiguration' ], - function (Table, NameColumn) { + function (TableConfiguration) { "use strict"; /** @@ -43,7 +42,7 @@ define( * @param telemetryFormatter * @constructor */ - function TableController( + function TelemetryTableController( $scope, telemetryHandler, telemetryFormatter @@ -55,7 +54,7 @@ define( this.handle = undefined; //this.pending = false; this.telemetryHandler = telemetryHandler; - this.table = new Table($scope.domainObject, telemetryFormatter); + this.table = new TableConfiguration($scope.domainObject, telemetryFormatter); this.changeListeners = []; $scope.rows = []; @@ -73,7 +72,7 @@ define( this.$scope.$on("$destroy", this.destroy.bind(this)); } - TableController.prototype.registerChangeListeners = function() { + TelemetryTableController.prototype.registerChangeListeners = function() { //Defer registration of change listeners until domain object is // available in order to avoid race conditions @@ -93,7 +92,7 @@ define( /** * Release the current subscription (called when scope is destroyed) */ - TableController.prototype.destroy = function () { + TelemetryTableController.prototype.destroy = function () { if (this.handle) { this.handle.unsubscribe(); this.handle = undefined; @@ -103,13 +102,7 @@ define( /** Create a new subscription. This is called when */ - TableController.prototype.subscribe = function() { - var self = this; - - /*if (this.pending){ - return; - }*/ - //this.pending = true; + TelemetryTableController.prototype.subscribe = function() { if (this.handle) { this.handle.unsubscribe(); @@ -119,7 +112,6 @@ define( //Noop because not supporting realtime data right now function noop(){ - //self.pending = false; } this.handle = this.$scope.domainObject && this.telemetryHandler.handle( @@ -136,43 +128,25 @@ define( /** * Add any historical data available */ - TableController.prototype.addHistoricalData = function(domainObject, series) { + TelemetryTableController.prototype.addHistoricalData = function(domainObject, series) { var i; - //this.pending = false; for (i=0; i < series.getPointCount(); i++) { this.updateRows(domainObject, this.handle.makeDatum(domainObject, series, i)); } }; - /** - * Set the established configuration on the domain object - * @private - */ - TableController.prototype.writeConfigToModel = function (configuration) { - this.$scope.domainObject.useCapability('mutation', function (model) { - model.configuration = model.configuration || {}; - model.configuration.table = model.configuration.table || {}; - model.configuration.table.columns = configuration; - }); - }; - /** * Setup table columns based on domain object metadata */ - TableController.prototype.setup = function() { + TelemetryTableController.prototype.setup = function() { var handle = this.handle, table = this.table, - self = this, - configuration; + self = this; if (handle) { handle.promiseTelemetryObjects().then(function (objects) { table.buildColumns(handle.getMetadata()); - if (objects && objects.length > 1){ - table.addColumn(new NameColumn(), 0); - } - self.filterColumns(); // When table column configuration changes, (due to being @@ -191,7 +165,7 @@ define( * be composed of multiple objects) * @param datum The data received from the telemetry source */ - TableController.prototype.updateRows = function (object, datum) { + TelemetryTableController.prototype.updateRows = function (object, datum) { this.$scope.rows.push(this.table.getRowValues(object, datum)); }; @@ -199,16 +173,17 @@ define( * When column configuration changes, update the visible headers * accordingly. */ - TableController.prototype.filterColumns = function () { - var config = this.table.getColumnConfiguration(); - - this.writeConfigToModel(config); + TelemetryTableController.prototype.filterColumns = function (columnConfig) { + if (!columnConfig){ + columnConfig = this.table.getColumnConfig(); + this.table.saveColumnConfig(columnConfig); + } //Populate headers with visible columns (determined by configuration) - this.$scope.headers = Object.keys(config).filter(function(column) { - return config[column]; + this.$scope.headers = Object.keys(columnConfig).filter(function(column) { + return columnConfig[column]; }); }; - return TableController; + return TelemetryTableController; } ); diff --git a/platform/features/table/src/directives/MCTTable.js b/platform/features/table/src/directives/MCTTable.js index 1e3eec6111..17ca12b141 100644 --- a/platform/features/table/src/directives/MCTTable.js +++ b/platform/features/table/src/directives/MCTTable.js @@ -1,21 +1,21 @@ /*global define*/ define( - [], - function () { + ["../controllers/MCTTableController"], + function (MCTTableController) { "use strict"; function MCTTable($timeout) { return { restrict: "E", templateUrl: "platform/features/table/res/templates/mct-data-table.html", - controller: 'MCTTableController', + controller: ['$scope', '$timeout', '$element', MCTTableController], scope: { headers: "=", rows: "=", enableFilter: "=?", enableSort: "=?" - } + }, }; }