[Tables] #733 Made code style changes for conformance with style guide

This commit is contained in:
Henry
2016-03-14 11:25:26 -07:00
parent c5de90a951
commit fc08df4f6f
7 changed files with 122 additions and 92 deletions

View File

@ -47,7 +47,7 @@ define(
* @param metadata Metadata describing the domains and ranges available * @param metadata Metadata describing the domains and ranges available
* @returns {TableConfiguration} This object * @returns {TableConfiguration} This object
*/ */
TableConfiguration.prototype.buildColumns = function(metadata) { TableConfiguration.prototype.buildColumns = function (metadata) {
var self = this; var self = this;
this.columns = []; this.columns = [];
@ -57,10 +57,12 @@ define(
metadata.forEach(function (metadatum) { metadata.forEach(function (metadatum) {
//Push domains first //Push domains first
(metadatum.domains || []).forEach(function (domainMetadata) { (metadatum.domains || []).forEach(function (domainMetadata) {
self.addColumn(new DomainColumn(domainMetadata, self.telemetryFormatter)); self.addColumn(new DomainColumn(domainMetadata,
self.telemetryFormatter));
}); });
(metadatum.ranges || []).forEach(function (rangeMetadata) { (metadatum.ranges || []).forEach(function (rangeMetadata) {
self.addColumn(new RangeColumn(rangeMetadata, self.telemetryFormatter)); self.addColumn(new RangeColumn(rangeMetadata,
self.telemetryFormatter));
}); });
}); });
@ -98,7 +100,7 @@ define(
* Get a simple list of column titles * Get a simple list of column titles
* @returns {Array} The titles of the columns * @returns {Array} The titles of the columns
*/ */
TableConfiguration.prototype.getHeaders = function() { TableConfiguration.prototype.getHeaders = function () {
var self = this; var self = this;
return this.columns.map(function (column, i){ return this.columns.map(function (column, i){
return self.getColumnTitle(column) || 'Column ' + (i + 1); return self.getColumnTitle(column) || 'Column ' + (i + 1);
@ -113,9 +115,9 @@ define(
* @returns {Object} Key value pairs where the key is the column * @returns {Object} Key value pairs where the key is the column
* title, and the value is the formatted value from the provided datum. * title, and the value is the formatted value from the provided datum.
*/ */
TableConfiguration.prototype.getRowValues = function(telemetryObject, datum) { TableConfiguration.prototype.getRowValues = function (telemetryObject, datum) {
var self = this; var self = this;
return this.columns.reduce(function(rowObject, column, i){ return this.columns.reduce(function (rowObject, column, i){
var columnTitle = self.getColumnTitle(column) || 'Column ' + (i + 1), var columnTitle = self.getColumnTitle(column) || 'Column ' + (i + 1),
columnValue = column.getValue(telemetryObject, datum); columnValue = column.getValue(telemetryObject, datum);
@ -125,7 +127,9 @@ define(
// Don't replace something with nothing. // Don't replace something with nothing.
// This occurs when there are multiple columns with the // This occurs when there are multiple columns with the
// column title // column title
if (rowObject[columnTitle] === undefined || rowObject[columnTitle].text === undefined || rowObject[columnTitle].text.length === 0) { if (rowObject[columnTitle] === undefined ||
rowObject[columnTitle].text === undefined ||
rowObject[columnTitle].text.length === 0) {
rowObject[columnTitle] = columnValue; rowObject[columnTitle] = columnValue;
} }
return rowObject; return rowObject;
@ -136,7 +140,8 @@ define(
* @private * @private
*/ */
TableConfiguration.prototype.defaultColumnConfiguration = function () { TableConfiguration.prototype.defaultColumnConfiguration = function () {
return ((this.domainObject.getModel().configuration || {}).table || {}).columns || {}; return ((this.domainObject.getModel().configuration || {}).table ||
{}).columns || {};
}; };
/** /**
@ -158,7 +163,7 @@ define(
* pairs where the key is the column title, and the value is a * pairs where the key is the column title, and the value is a
* boolean indicating whether the column should be shown. * boolean indicating whether the column should be shown.
*/ */
TableConfiguration.prototype.getColumnConfiguration = function() { TableConfiguration.prototype.getColumnConfiguration = function () {
var configuration = {}, var configuration = {},
//Use existing persisted config, or default it //Use existing persisted config, or default it
defaultConfig = this.defaultColumnConfiguration(); defaultConfig = this.defaultColumnConfiguration();
@ -168,8 +173,10 @@ define(
* specifying whether the column is visible or not. Default to * specifying whether the column is visible or not. Default to
* existing (persisted) configuration if available * existing (persisted) configuration if available
*/ */
this.getHeaders().forEach(function(columnTitle) { this.getHeaders().forEach(function (columnTitle) {
configuration[columnTitle] = typeof defaultConfig[columnTitle] === 'undefined' ? true : defaultConfig[columnTitle]; configuration[columnTitle] =
typeof defaultConfig[columnTitle] === 'undefined' ? true :
defaultConfig[columnTitle];
}); });
return configuration; return configuration;

View File

@ -81,13 +81,13 @@ define(
* bottom of the page * bottom of the page
* @private * @private
*/ */
MCTTableController.prototype.scrollToBottom = function() { MCTTableController.prototype.scrollToBottom = function () {
var self = this; var self = this;
//Use timeout to defer execution until next digest when any //Use timeout to defer execution until next digest when any
// pending UI changes have completed, eg. a new row in the table. // pending UI changes have completed, eg. a new row in the table.
if (this.$scope.autoScroll) { if (this.$scope.autoScroll) {
this.$timeout(function(){ this.$timeout(function (){
self.scrollable[0].scrollTop = self.scrollable[0].scrollHeight; self.scrollable[0].scrollTop = self.scrollable[0].scrollHeight;
}); });
} }
@ -115,8 +115,9 @@ define(
MCTTableController.prototype.onScroll = function (event) { MCTTableController.prototype.onScroll = function (event) {
//If user scrolls away from bottom, disable auto-scroll. //If user scrolls away from bottom, disable auto-scroll.
// Auto-scroll will be re-enabled if user scrolls to bottom again. // Auto-scroll will be re-enabled if user scrolls to bottom again.
if (this.scrollable[0].scrollTop < (this.scrollable[0].scrollHeight - this.scrollable[0].offsetHeight)) { if (this.scrollable[0].scrollTop <
this.$scope.autoScroll = false; (this.scrollable[0].scrollHeight - this.scrollable[0].offsetHeight)) {
this.$scope.autoScroll = false;
} else { } else {
this.$scope.autoScroll = true; this.$scope.autoScroll = true;
} }
@ -144,7 +145,8 @@ define(
if (this.$scope.displayRows.length < this.maxDisplayRows) { if (this.$scope.displayRows.length < this.maxDisplayRows) {
//Check whether need to resynchronize visible with display //Check whether need to resynchronize visible with display
// rows (if data added) // rows (if data added)
if (this.$scope.visibleRows.length != this.$scope.displayRows.length){ if (this.$scope.visibleRows.length !=
this.$scope.displayRows.length){
start = 0; start = 0;
end = this.$scope.displayRows.length; end = this.$scope.displayRows.length;
} else { } else {
@ -159,11 +161,13 @@ define(
firstVisible = 0; firstVisible = 0;
} else { } else {
firstVisible = Math.floor( firstVisible = Math.floor(
(topScroll - this.$scope.headerHeight) / this.$scope.rowHeight (topScroll - this.$scope.headerHeight) /
this.$scope.rowHeight
); );
} }
lastVisible = Math.ceil( lastVisible = Math.ceil(
(bottomScroll - this.$scope.headerHeight) / this.$scope.rowHeight (bottomScroll - this.$scope.headerHeight) /
this.$scope.rowHeight
); );
totalVisible = lastVisible - firstVisible; totalVisible = lastVisible - firstVisible;
@ -173,12 +177,14 @@ define(
if (start < 0) { if (start < 0) {
start = 0; start = 0;
end = Math.min(this.maxDisplayRows, this.$scope.displayRows.length); end = Math.min(this.maxDisplayRows,
this.$scope.displayRows.length);
} else if (end >= this.$scope.displayRows.length) { } else if (end >= this.$scope.displayRows.length) {
end = this.$scope.displayRows.length; end = this.$scope.displayRows.length;
start = end - this.maxDisplayRows + 1; start = end - this.maxDisplayRows + 1;
} }
if (this.$scope.visibleRows[0] && this.$scope.visibleRows[0].rowIndex === start && if (this.$scope.visibleRows[0] &&
this.$scope.visibleRows[0].rowIndex === start &&
this.$scope.visibleRows[this.$scope.visibleRows.length - 1] this.$scope.visibleRows[this.$scope.visibleRows.length - 1]
.rowIndex === end) { .rowIndex === end) {
@ -187,7 +193,7 @@ define(
} }
//Set visible rows from display rows, based on calculated offset. //Set visible rows from display rows, based on calculated offset.
this.$scope.visibleRows = this.$scope.displayRows.slice(start, end) this.$scope.visibleRows = this.$scope.displayRows.slice(start, end)
.map(function(row, i) { .map(function (row, i) {
return { return {
rowIndex: start + i, rowIndex: start + i,
offsetY: ((start + i) * self.$scope.rowHeight) + offsetY: ((start + i) * self.$scope.rowHeight) +
@ -213,9 +219,10 @@ define(
} }
// Reset column sort information unless the new headers // Reset column sort information unless the new headers
// contain the column currently sorted on. // contain the column currently sorted on.
if (this.$scope.enableSort && newHeaders.indexOf(this.$scope.sortColumn) === -1) { if (this.$scope.enableSort &&
this.$scope.sortColumn = undefined; newHeaders.indexOf(this.$scope.sortColumn) === -1) {
this.$scope.sortDirection = undefined; this.$scope.sortColumn = undefined;
this.$scope.sortDirection = undefined;
} }
this.updateRows(this.$scope.rows); this.updateRows(this.$scope.rows);
}; };
@ -234,7 +241,8 @@ define(
rowHeight = 20, rowHeight = 20,
columnWidth, columnWidth,
tableWidth = 0, tableWidth = 0,
overallHeight = headerHeight + (rowHeight * (this.$scope.displayRows ? this.$scope.displayRows.length - 1 : 0)); overallHeight = headerHeight + (rowHeight *
(this.$scope.displayRows ? this.$scope.displayRows.length - 1 : 0));
this.$scope.columnWidths = []; this.$scope.columnWidths = [];
@ -248,18 +256,20 @@ define(
this.$scope.rowHeight = rowHeight; this.$scope.rowHeight = rowHeight;
this.$scope.totalHeight = overallHeight; this.$scope.totalHeight = overallHeight;
this.setVisibleRows(); this.setVisibleRows();
this.$scope.overrideRowPositioning = true;
if (tableWidth > 0) { if (tableWidth > 0) {
this.$scope.totalWidth = tableWidth + 'px'; this.$scope.totalWidth = tableWidth + 'px';
} else { } else {
this.$scope.totalWidth = 'none'; this.$scope.totalWidth = 'none';
} }
this.$scope.overrideRowPositioning = true;
}; };
/** /**
* @private * @private
*/ */
MCTTableController.prototype.insertSorted = function(array, element) { MCTTableController.prototype.insertSorted = function (array, element) {
var index = -1, var index = -1,
self = this, self = this,
sortKey = this.$scope.sortColumn; sortKey = this.$scope.sortColumn;
@ -272,16 +282,22 @@ define(
return min; // Element is not in array, min gives direction return min; // Element is not in array, min gives direction
} }
valA = isNaN(searchElement[sortKey].text) ? searchElement[sortKey].text : parseFloat(searchElement[sortKey].text); valA = isNaN(searchElement[sortKey].text) ?
valB = isNaN(searchArray[sampleAt][sortKey].text) ? searchArray[sampleAt][sortKey].text : searchArray[sampleAt][sortKey].text; searchElement[sortKey].text :
parseFloat(searchElement[sortKey].text);
valB = isNaN(searchArray[sampleAt][sortKey].text) ?
searchArray[sampleAt][sortKey].text :
searchArray[sampleAt][sortKey].text;
switch(self.sortComparator(valA, valB)) { switch(self.sortComparator(valA, valB)) {
case -1: case -1:
return binarySearch(searchArray, searchElement, min, sampleAt - 1); return binarySearch(searchArray, searchElement, min,
sampleAt - 1);
case 0 : case 0 :
return sampleAt; return sampleAt;
case 1 : case 1 :
return binarySearch(searchArray, searchElement, sampleAt + 1, max); return binarySearch(searchArray, searchElement,
sampleAt + 1, max);
} }
} }
@ -309,7 +325,7 @@ define(
* *
* @private * @private
*/ */
MCTTableController.prototype.sortComparator = function(a, b) { MCTTableController.prototype.sortComparator = function (a, b) {
var result = 0, var result = 0,
sortDirectionMultiplier; sortDirectionMultiplier;
@ -340,7 +356,7 @@ define(
* *
* Does not modify the array that was passed in. * Does not modify the array that was passed in.
*/ */
MCTTableController.prototype.sortRows = function(rowsToSort) { MCTTableController.prototype.sortRows = function (rowsToSort) {
var self = this, var self = this,
sortKey = this.$scope.sortColumn; sortKey = this.$scope.sortColumn;
@ -348,12 +364,14 @@ define(
return rowsToSort; return rowsToSort;
} }
return rowsToSort.sort(function(a, b) { return rowsToSort.sort(function (a, b) {
//If the values to compare can be compared as //If the values to compare can be compared as
// numbers, do so. String comparison of number // numbers, do so. String comparison of number
// values can cause inconsistencies // values can cause inconsistencies
var valA = isNaN(a[sortKey].text) ? a[sortKey].text : parseFloat(a[sortKey].text), var valA = isNaN(a[sortKey].text) ? a[sortKey].text :
valB = isNaN(b[sortKey].text) ? b[sortKey].text : parseFloat(b[sortKey].text); parseFloat(a[sortKey].text),
valB = isNaN(b[sortKey].text) ? b[sortKey].text :
parseFloat(b[sortKey].text);
return self.sortComparator(valA, valB); return self.sortComparator(valA, valB);
}); });
@ -365,7 +383,7 @@ define(
* pre-calculate optimal column sizes without having to render * pre-calculate optimal column sizes without having to render
* every row. * every row.
*/ */
MCTTableController.prototype.findLargestRow = function(rows) { MCTTableController.prototype.findLargestRow = function (rows) {
var largestRow = rows.reduce(function (largestRow, row) { var largestRow = rows.reduce(function (largestRow, row) {
Object.keys(row).forEach(function (key) { Object.keys(row).forEach(function (key) {
var currentColumn = row[key].text, var currentColumn = row[key].text,
@ -390,7 +408,7 @@ define(
// Pad with characters to accomodate variable-width fonts, // Pad with characters to accomodate variable-width fonts,
// and remove characters that would allow word-wrapping. // and remove characters that would allow word-wrapping.
Object.keys(largestRow).forEach(function(key) { Object.keys(largestRow).forEach(function (key) {
var padCharacters, var padCharacters,
i; i;
@ -424,7 +442,7 @@ define(
//Wait a timeout to allow digest of previous change to visible //Wait a timeout to allow digest of previous change to visible
// rows to happen. // rows to happen.
this.$timeout(function() { this.$timeout(function () {
//Remove temporary padding row used for setting column widths //Remove temporary padding row used for setting column widths
self.$scope.visibleRows = []; self.$scope.visibleRows = [];
self.setElementSizes(); self.setElementSizes();
@ -434,7 +452,7 @@ define(
/** /**
* @priate * @priate
*/ */
MCTTableController.prototype.filterAndSort = function(rows) { MCTTableController.prototype.filterAndSort = function (rows) {
var displayRows = rows; var displayRows = rows;
if (this.$scope.enableFilter) { if (this.$scope.enableFilter) {
displayRows = this.filterRows(displayRows); displayRows = this.filterRows(displayRows);
@ -471,7 +489,7 @@ define(
* @param rowsToFilter {Object[]} The rows to apply filters to * @param rowsToFilter {Object[]} The rows to apply filters to
* @returns {Object[]} A filtered copy of the supplied rows * @returns {Object[]} A filtered copy of the supplied rows
*/ */
MCTTableController.prototype.filterRows = function(rowsToFilter) { MCTTableController.prototype.filterRows = function (rowsToFilter) {
var filters = {}, var filters = {},
self = this; self = this;
@ -479,7 +497,7 @@ define(
* Returns true if row matches all filters. * Returns true if row matches all filters.
*/ */
function matchRow(filters, row) { function matchRow(filters, row) {
return Object.keys(filters).every(function(key) { return Object.keys(filters).every(function (key) {
if (!row[key]) { if (!row[key]) {
return false; return false;
} }
@ -492,7 +510,7 @@ define(
return rowsToFilter; return rowsToFilter;
} }
Object.keys(this.$scope.filters).forEach(function(key) { Object.keys(this.$scope.filters).forEach(function (key) {
if (!self.$scope.filters[key]) { if (!self.$scope.filters[key]) {
return; return;
} }

View File

@ -56,7 +56,7 @@ define(
return range.format === 'string'; return range.format === 'string';
}); });
} }
$scope.$watch('domainObject', function(domainObject) { $scope.$watch('domainObject', function (domainObject) {
//When a domain object becomes available, check whether the //When a domain object becomes available, check whether the
// view should auto-scroll to the bottom. // view should auto-scroll to the bottom.
if (domainObject && hasStringTelemetry(domainObject)){ if (domainObject && hasStringTelemetry(domainObject)){
@ -71,10 +71,10 @@ define(
Override the subscribe function defined on the parent controller in Override the subscribe function defined on the parent controller in
order to handle realtime telemetry instead of historical. order to handle realtime telemetry instead of historical.
*/ */
RTTelemetryTableController.prototype.subscribe = function() { RTTelemetryTableController.prototype.subscribe = function () {
var self = this; var self = this;
self.$scope.rows = undefined; self.$scope.rows = undefined;
(this.subscriptions || []).forEach(function(unsubscribe){ (this.subscriptions || []).forEach(function (unsubscribe){
unsubscribe(); unsubscribe();
}); });
@ -85,7 +85,7 @@ define(
function updateData(){ function updateData(){
var datum, var datum,
row; row;
self.handle.getTelemetryObjects().forEach(function(telemetryObject){ self.handle.getTelemetryObjects().forEach(function (telemetryObject){
datum = self.handle.getDatum(telemetryObject); datum = self.handle.getDatum(telemetryObject);
if (datum) { if (datum) {
row = self.table.getRowValues(telemetryObject, datum); row = self.table.getRowValues(telemetryObject, datum);
@ -94,7 +94,8 @@ define(
self.$scope.rows = [row]; self.$scope.rows = [row];
} else { } else {
self.$scope.rows.push(row); self.$scope.rows.push(row);
self.$scope.$broadcast('add:row', self.$scope.rows.length - 1); self.$scope.$broadcast('add:row',
self.$scope.rows.length - 1);
} }
} }
}); });

View File

@ -58,9 +58,9 @@ define(
self.populateForm(model); self.populateForm(model);
}); });
$scope.$watchCollection('configuration.table.columns', function(columns){ $scope.$watchCollection('configuration.table.columns', function (columns){
if (columns){ if (columns){
self.domainObject.useCapability('mutation', function(model) { self.domainObject.useCapability('mutation', function (model) {
model.configuration.table.columns = columns; model.configuration.table.columns = columns;
}); });
self.domainObject.getCapability('persistence').persist(); self.domainObject.getCapability('persistence').persist();

View File

@ -54,7 +54,8 @@ define(
this.handle = undefined; this.handle = undefined;
//this.pending = false; //this.pending = false;
this.telemetryHandler = telemetryHandler; this.telemetryHandler = telemetryHandler;
this.table = new TableConfiguration($scope.domainObject, telemetryFormatter); this.table = new TableConfiguration($scope.domainObject,
telemetryFormatter);
this.changeListeners = []; this.changeListeners = [];
$scope.rows = undefined; $scope.rows = undefined;
@ -77,17 +78,19 @@ define(
* available in order to avoid race conditions * available in order to avoid race conditions
* @private * @private
*/ */
TelemetryTableController.prototype.registerChangeListeners = function() { TelemetryTableController.prototype.registerChangeListeners = function () {
this.changeListeners.forEach(function (listener) { this.changeListeners.forEach(function (listener) {
return listener && listener(); return listener && listener();
}); });
this.changeListeners = []; this.changeListeners = [];
// When composition changes, re-subscribe to the various // When composition changes, re-subscribe to the various
// telemetry subscriptions // telemetry subscriptions
this.changeListeners.push(this.$scope.$watchCollection('domainObject.getModel().composition', this.subscribe.bind(this))); this.changeListeners.push(this.$scope.$watchCollection(
'domainObject.getModel().composition', this.subscribe.bind(this)));
//Change of bounds in time conductor //Change of bounds in time conductor
this.changeListeners.push(this.$scope.$on('telemetry:display:bounds', this.subscribe.bind(this))); this.changeListeners.push(this.$scope.$on('telemetry:display:bounds',
this.subscribe.bind(this)));
}; };
/** /**
@ -105,7 +108,7 @@ define(
change default behaviour (which is to retrieve historical telemetry change default behaviour (which is to retrieve historical telemetry
only). only).
*/ */
TelemetryTableController.prototype.subscribe = function() { TelemetryTableController.prototype.subscribe = function () {
var self = this; var self = this;
if (this.handle) { if (this.handle) {
@ -131,17 +134,18 @@ define(
* Populates historical data on scope when it becomes available * Populates historical data on scope when it becomes available
* @private * @private
*/ */
TelemetryTableController.prototype.addHistoricalData = function() { TelemetryTableController.prototype.addHistoricalData = function () {
var rowData = [], var rowData = [],
self = this; self = this;
this.handle.getTelemetryObjects().forEach(function(telemetryObject){ this.handle.getTelemetryObjects().forEach(function (telemetryObject){
var series = self.handle.getSeries(telemetryObject) || {}, var series = self.handle.getSeries(telemetryObject) || {},
pointCount = series.getPointCount ? series.getPointCount() : 0, pointCount = series.getPointCount ? series.getPointCount() : 0,
i = 0; i = 0;
for (; i < pointCount; i++) { for (; i < pointCount; i++) {
rowData.push(self.table.getRowValues(telemetryObject, self.handle.makeDatum(telemetryObject, series, i))); rowData.push(self.table.getRowValues(telemetryObject,
self.handle.makeDatum(telemetryObject, series, i)));
} }
}); });
@ -151,13 +155,13 @@ define(
/** /**
* Setup table columns based on domain object metadata * Setup table columns based on domain object metadata
*/ */
TelemetryTableController.prototype.setup = function() { TelemetryTableController.prototype.setup = function () {
var handle = this.handle, var handle = this.handle,
table = this.table, table = this.table,
self = this; self = this;
if (handle) { if (handle) {
handle.promiseTelemetryObjects().then(function (objects) { handle.promiseTelemetryObjects().then(function () {
table.buildColumns(handle.getMetadata()); table.buildColumns(handle.getMetadata());
self.filterColumns(); self.filterColumns();
@ -193,7 +197,7 @@ define(
this.table.saveColumnConfiguration(columnConfig); this.table.saveColumnConfiguration(columnConfig);
} }
//Populate headers with visible columns (determined by configuration) //Populate headers with visible columns (determined by configuration)
this.$scope.headers = Object.keys(columnConfig).filter(function(column) { this.$scope.headers = Object.keys(columnConfig).filter(function (column) {
return columnConfig[column]; return columnConfig[column];
}); });
}; };

View File

@ -28,7 +28,7 @@ define(
function (TableController) { function (TableController) {
"use strict"; "use strict";
describe('The real-time table controller', function() { describe('The real-time table controller', function () {
var mockScope, var mockScope,
mockTelemetryHandler, mockTelemetryHandler,
mockTelemetryHandle, mockTelemetryHandle,
@ -48,7 +48,7 @@ define(
}; };
} }
beforeEach(function() { beforeEach(function () {
watches = {}; watches = {};
mockTableRow = {'col1': 'val1', 'col2': 'row2'}; mockTableRow = {'col1': 'val1', 'col2': 'row2'};
@ -58,13 +58,13 @@ define(
'$watchCollection', '$watchCollection',
'$broadcast' '$broadcast'
]); ]);
mockScope.$on.andCallFake(function(expression, callback){ mockScope.$on.andCallFake(function (expression, callback){
watches[expression] = callback; watches[expression] = callback;
}); });
mockScope.$watch.andCallFake(function(expression, callback){ mockScope.$watch.andCallFake(function (expression, callback){
watches[expression] = callback; watches[expression] = callback;
}); });
mockScope.$watchCollection.andCallFake(function(expression, callback){ mockScope.$watchCollection.andCallFake(function (expression, callback){
watches[expression] = callback; watches[expression] = callback;
}); });
@ -94,7 +94,7 @@ define(
mockDomainObject.getModel.andReturn({}); mockDomainObject.getModel.andReturn({});
mockDomainObject.getCapability.andReturn( mockDomainObject.getCapability.andReturn(
{ {
getMetadata: function(){ getMetadata: function (){
return {ranges: [{format: 'string'}]}; return {ranges: [{format: 'string'}]};
} }
}); });
@ -124,18 +124,18 @@ define(
controller.handle = mockTelemetryHandle; controller.handle = mockTelemetryHandle;
}); });
it('registers for streaming telemetry', function() { it('registers for streaming telemetry', function () {
controller.subscribe(); controller.subscribe();
expect(mockTelemetryHandler.handle).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function), true); expect(mockTelemetryHandler.handle).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function), true);
}); });
it('updates table with new streaming telemetry', function() { it('updates table with new streaming telemetry', function () {
controller.subscribe(); controller.subscribe();
mockTelemetryHandler.handle.mostRecentCall.args[1](); mockTelemetryHandler.handle.mostRecentCall.args[1]();
expect(mockScope.$broadcast).toHaveBeenCalledWith('add:row', 0); expect(mockScope.$broadcast).toHaveBeenCalledWith('add:row', 0);
}); });
it('enables autoscroll for event telemetry', function() { it('enables autoscroll for event telemetry', function () {
controller.subscribe(); controller.subscribe();
mockScope.$watch.mostRecentCall.args[1](mockDomainObject); mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
expect(mockScope.autoScroll).toBe(true); expect(mockScope.autoScroll).toBe(true);

View File

@ -28,7 +28,7 @@ define(
function (TableController) { function (TableController) {
"use strict"; "use strict";
describe('The Table Controller', function() { describe('The Table Controller', function () {
var mockScope, var mockScope,
mockTelemetryHandler, mockTelemetryHandler,
mockTelemetryHandle, mockTelemetryHandle,
@ -47,7 +47,7 @@ define(
}; };
} }
beforeEach(function() { beforeEach(function () {
watches = {}; watches = {};
mockScope = jasmine.createSpyObj('scope', [ mockScope = jasmine.createSpyObj('scope', [
'$on', '$on',
@ -55,13 +55,13 @@ define(
'$watchCollection' '$watchCollection'
]); ]);
mockScope.$on.andCallFake(function(expression, callback){ mockScope.$on.andCallFake(function (expression, callback){
watches[expression] = callback; watches[expression] = callback;
}); });
mockScope.$watch.andCallFake(function(expression, callback){ mockScope.$watch.andCallFake(function (expression, callback){
watches[expression] = callback; watches[expression] = callback;
}); });
mockScope.$watchCollection.andCallFake(function(expression, callback){ mockScope.$watchCollection.andCallFake(function (expression, callback){
watches[expression] = callback; watches[expression] = callback;
}); });
@ -114,28 +114,28 @@ define(
controller.handle = mockTelemetryHandle; controller.handle = mockTelemetryHandle;
}); });
it('subscribes to telemetry handler for telemetry updates', function() { it('subscribes to telemetry handler for telemetry updates', function () {
controller.subscribe(); controller.subscribe();
expect(mockTelemetryHandler.handle).toHaveBeenCalled(); expect(mockTelemetryHandler.handle).toHaveBeenCalled();
expect(mockTelemetryHandle.request).toHaveBeenCalled(); expect(mockTelemetryHandle.request).toHaveBeenCalled();
}); });
it('Unsubscribes from telemetry when scope is destroyed',function() { it('Unsubscribes from telemetry when scope is destroyed',function () {
controller.handle = mockTelemetryHandle; controller.handle = mockTelemetryHandle;
watches.$destroy(); watches.$destroy();
expect(mockTelemetryHandle.unsubscribe).toHaveBeenCalled(); expect(mockTelemetryHandle.unsubscribe).toHaveBeenCalled();
}); });
describe('the controller makes use of the table', function() { describe('the controller makes use of the table', function () {
it('to create column definitions from telemetry' + it('to create column definitions from telemetry' +
' metadata', function() { ' metadata', function () {
controller.setup(); controller.setup();
expect(mockTable.buildColumns).toHaveBeenCalled(); expect(mockTable.buildColumns).toHaveBeenCalled();
}); });
it('to create column configuration, which is written to the' + it('to create column configuration, which is written to the' +
' object model', function() { ' object model', function () {
var mockModel = {}; var mockModel = {};
controller.setup(); controller.setup();
@ -144,22 +144,22 @@ define(
}); });
}); });
it('updates the rows on scope when historical telemetry is received', function(){ it('updates the rows on scope when historical telemetry is received', function (){
var mockSeries = { var mockSeries = {
getPointCount: function() { getPointCount: function () {
return 5; return 5;
}, },
getDomainValue: function() { getDomainValue: function () {
return 'Domain Value'; return 'Domain Value';
}, },
getRangeValue: function() { getRangeValue: function () {
return 'Range Value'; return 'Range Value';
} }
}, },
mockRow = {'domain': 'Domain Value', 'range': 'Range' + mockRow = {'domain': 'Domain Value', 'range': 'Range' +
' Value'}; ' Value'};
mockTelemetryHandle.makeDatum.andCallFake(function(){ mockTelemetryHandle.makeDatum.andCallFake(function (){
return mockRow; return mockRow;
}); });
mockTable.getRowValues.andReturn(mockRow); mockTable.getRowValues.andReturn(mockRow);
@ -172,7 +172,7 @@ define(
expect(controller.$scope.rows[0]).toBe(mockRow); expect(controller.$scope.rows[0]).toBe(mockRow);
}); });
it('filters the visible columns based on configuration', function(){ it('filters the visible columns based on configuration', function (){
controller.filterColumns(); controller.filterColumns();
expect(controller.$scope.headers.length).toBe(3); expect(controller.$scope.headers.length).toBe(3);
expect(controller.$scope.headers[2]).toEqual('domain1'); expect(controller.$scope.headers[2]).toEqual('domain1');
@ -183,14 +183,14 @@ define(
expect(controller.$scope.headers[2]).toBeUndefined(); expect(controller.$scope.headers[2]).toBeUndefined();
}); });
describe('creates event listeners', function(){ describe('creates event listeners', function (){
beforeEach(function() { beforeEach(function () {
spyOn(controller,'subscribe'); spyOn(controller,'subscribe');
spyOn(controller, 'filterColumns'); spyOn(controller, 'filterColumns');
}); });
it('triggers telemetry subscription update when domain' + it('triggers telemetry subscription update when domain' +
' object changes', function() { ' object changes', function () {
controller.registerChangeListeners(); controller.registerChangeListeners();
//'watches' object is populated by fake scope watch and //'watches' object is populated by fake scope watch and
// watchCollection functions defined above // watchCollection functions defined above
@ -200,7 +200,7 @@ define(
}); });
it('triggers telemetry subscription update when domain' + it('triggers telemetry subscription update when domain' +
' object composition changes', function() { ' object composition changes', function () {
controller.registerChangeListeners(); controller.registerChangeListeners();
expect(watches['domainObject.getModel().composition']).toBeDefined(); expect(watches['domainObject.getModel().composition']).toBeDefined();
watches['domainObject.getModel().composition'](); watches['domainObject.getModel().composition']();
@ -208,7 +208,7 @@ define(
}); });
it('triggers telemetry subscription update when time' + it('triggers telemetry subscription update when time' +
' conductor bounds change', function() { ' conductor bounds change', function () {
controller.registerChangeListeners(); controller.registerChangeListeners();
expect(watches['telemetry:display:bounds']).toBeDefined(); expect(watches['telemetry:display:bounds']).toBeDefined();
watches['telemetry:display:bounds'](); watches['telemetry:display:bounds']();
@ -216,7 +216,7 @@ define(
}); });
it('triggers refiltering of the columns when configuration' + it('triggers refiltering of the columns when configuration' +
' changes', function() { ' changes', function () {
controller.setup(); controller.setup();
expect(watches['domainObject.getModel().configuration.table.columns']).toBeDefined(); expect(watches['domainObject.getModel().configuration.table.columns']).toBeDefined();
watches['domainObject.getModel().configuration.table.columns'](); watches['domainObject.getModel().configuration.table.columns']();