[Table] #670 Addressed comments from code review

This commit is contained in:
Henry 2016-03-02 21:40:56 -08:00
parent b9a7ee423a
commit 55e00baeaf
7 changed files with 61 additions and 79 deletions

View File

@ -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"]
}
],

View File

@ -1,13 +1,10 @@
<div class="l-view-section scrolling"
ng-style="overrideRowPositioning ?
{'overflow': 'auto'} :
{'overflow': 'scroll'}
"
style="overflow: auto;"
>
<table class="filterable" ng-style="overrideRowPositioning && {
<table class="filterable"
ng-style="overrideRowPositioning && {
height: totalHeight + 'px',
'table-layout': overrideRowPositioning ? 'fixed' : 'auto',
'box-sizing': 'border-box'
'table-layout': overrideRowPositioning ? 'fixed' : 'auto'
}">
<thead>
<tr>
@ -52,7 +49,7 @@
<td ng-repeat="header in displayHeaders"
ng-style="overrideRowPositioning && {
width: columnWidths[$index] + 'px',
'white-space': 'nowrap',
'max-width': columnWidths[$index] + 'px',
overflow: 'hidden',
'box-sizing': 'border-box'

View File

@ -1,4 +1,4 @@
<div ng-controller="TableController">
<div ng-controller="TelemetryTableController">
<mct-table
headers="headers"
rows="rows"

View File

@ -36,7 +36,7 @@ define(
* @param domainObject
* @constructor
*/
function Table(domainObject, telemetryFormatter) {
function TableConfiguration(domainObject, telemetryFormatter) {
this.domainObject = domainObject;
this.columns = [];
this.telemetryFormatter = telemetryFormatter;
@ -45,14 +45,19 @@ define(
/**
* Build column definitions based on supplied telemetry metadata
* @param metadata Metadata describing the domains and ranges available
* @returns {Table} This object
* @returns {TableConfiguration} This object
*/
Table.prototype.buildColumns = function(metadata) {
TableConfiguration.prototype.buildColumns = function(metadata) {
var self = this;
this.columns = [];
if (metadata) {
if (metadata.length > 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;
}
);

View File

@ -287,7 +287,7 @@ define(
}
];
this.$timeout(this.setElementSizes.bind(this), 0);
this.$timeout(this.setElementSizes.bind(this));
};
/**

View File

@ -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;
}
);

View File

@ -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: "=?"
}
},
};
}