[Tables] Changed the way that new rows are added to table

Fixed failing tests
This commit is contained in:
Henry
2016-03-13 19:37:08 -07:00
parent ea0b86fe72
commit c5de90a951
7 changed files with 68 additions and 63 deletions

View File

@ -1,9 +0,0 @@
<div ng-controller="RTTelemetryTableController">
<mct-table
headers="headers"
rows="rows"
enableFilter="true"
enableSort="true"
auto-scroll="true">
</mct-table>
</div>

View File

@ -73,7 +73,7 @@ define(
/* /*
* Listen for rows added individually (eg. for real-time tables) * Listen for rows added individually (eg. for real-time tables)
*/ */
$scope.$on('addRow', this.newRow.bind(this)); $scope.$on('add:row', this.newRow.bind(this));
} }
/** /**
@ -98,19 +98,13 @@ define(
* `addRow` broadcast event. * `addRow` broadcast event.
* @private * @private
*/ */
MCTTableController.prototype.newRow = function (event, row) { MCTTableController.prototype.newRow = function (event, rowIndex) {
var row = this.$scope.rows[rowIndex];
//Add row to the filtered, sorted list of all rows //Add row to the filtered, sorted list of all rows
if (this.filterRows([row]).length > 0) { if (this.filterRows([row]).length > 0) {
this.insertSorted(this.$scope.displayRows, row); this.insertSorted(this.$scope.displayRows, row);
} }
//Keep 'rows' synchronized as it provides the unsorted,
// unfiltered model for this view
if (!this.$scope.rows) {
this.$scope.rows = [];
}
this.$scope.rows.push(row);
this.$timeout(this.setElementSizes.bind(this)) this.$timeout(this.setElementSizes.bind(this))
.then(this.scrollToBottom.bind(this)); .then(this.scrollToBottom.bind(this));
}; };
@ -354,7 +348,7 @@ define(
return rowsToSort; return rowsToSort;
} }
return rowsToSort.slice(0).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
@ -447,7 +441,7 @@ define(
} }
if (this.$scope.enableSort) { if (this.$scope.enableSort) {
displayRows = this.sortRows(displayRows); displayRows = this.sortRows(displayRows.slice(0));
} }
this.$scope.displayRows = displayRows; this.$scope.displayRows = displayRows;
}; };
@ -467,15 +461,15 @@ define(
return; return;
} }
//Apply filters and sort a copy of the the new rows this.filterAndSort(newRows || []);
this.filterAndSort((newRows || []).slice(0));
//Resize columns appropriately
this.resize(); this.resize();
}; };
/** /**
* Applies user defined filters to rows. These filters are based on * Applies user defined filters to rows. These filters are based on
* the text entered in the search areas in each column * the text entered in the search areas in each column.
* @param rowsToFilter {Object[]} The rows to apply filters to
* @returns {Object[]} A filtered copy of the supplied rows
*/ */
MCTTableController.prototype.filterRows = function(rowsToFilter) { MCTTableController.prototype.filterRows = function(rowsToFilter) {
var filters = {}, var filters = {},

View File

@ -83,12 +83,19 @@ define(
} }
function updateData(){ function updateData(){
var datum; var datum,
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) {
var rowValue = self.table.getRowValues(telemetryObject, datum); row = self.table.getRowValues(telemetryObject, datum);
self.$scope.$broadcast('addRow', rowValue); self.$scope.rows = self.$scope.rows || [];
if (!self.$scope.rows){
self.$scope.rows = [row];
} else {
self.$scope.rows.push(row);
self.$scope.$broadcast('add:row', self.$scope.rows.length - 1);
}
} }
}); });

View File

@ -122,10 +122,20 @@ define(
true // Lossless true // Lossless
); );
function getHistoricalData(){ this.handle.request({}).then(this.addHistoricalData.bind(this));
var rowData = [];
self.handle.getTelemetryObjects().forEach(function(telemetryObject){ this.setup();
};
/**
* Populates historical data on scope when it becomes available
* @private
*/
TelemetryTableController.prototype.addHistoricalData = function() {
var rowData = [],
self = this;
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;
@ -135,24 +145,7 @@ define(
} }
}); });
self.$scope.rows = rowData; this.$scope.rows = rowData;
}
this.handle.request({}).then(getHistoricalData);
this.setup();
};
/**
* Add any historical data available
* @private
*/
TelemetryTableController.prototype.addHistoricalData = function(domainObject, series) {
var i,
newRows = [];
for (i=0; i < series.getPointCount(); i++) {
this.$scope.rows.push(this.table.getRowValues(domainObject, this.handle.makeDatum(domainObject, series, i)));
}
}; };
/** /**

View File

@ -95,6 +95,7 @@ define(
'col3': {'text': 'row3 col3'} 'col3': {'text': 'row3 col3'}
} }
]; ];
mockScope.rows = testRows;
}); });
it('Filters results based on filter input', function() { it('Filters results based on filter input', function() {
@ -128,7 +129,8 @@ define(
}; };
controller.updateRows(testRows); controller.updateRows(testRows);
expect(mockScope.displayRows.length).toBe(3); expect(mockScope.displayRows.length).toBe(3);
addRowFunc(row4); testRows.push(row4);
addRowFunc(3);
expect(mockScope.displayRows.length).toBe(4); expect(mockScope.displayRows.length).toBe(4);
}); });
@ -194,17 +196,23 @@ define(
mockScope.sortColumn = 'col2'; mockScope.sortColumn = 'col2';
mockScope.sortDirection = 'desc'; mockScope.sortDirection = 'desc';
mockScope.displayRows = controller.sortRows(testRows); mockScope.displayRows = controller.sortRows(testRows.slice(0));
controller.newRow(undefined, row4); mockScope.rows.push(row4);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows[0].col2.text).toEqual('xyz'); expect(mockScope.displayRows[0].col2.text).toEqual('xyz');
controller.newRow(undefined, row5);
mockScope.rows.push(row5);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows[4].col2.text).toEqual('aaa'); expect(mockScope.displayRows[4].col2.text).toEqual('aaa');
controller.newRow(undefined, row6);
mockScope.rows.push(row6);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows[2].col2.text).toEqual('ggg'); expect(mockScope.displayRows[2].col2.text).toEqual('ggg');
//Add a duplicate row //Add a duplicate row
controller.newRow(undefined, row6); mockScope.rows.push(row6);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows[2].col2.text).toEqual('ggg'); expect(mockScope.displayRows[2].col2.text).toEqual('ggg');
expect(mockScope.displayRows[3].col2.text).toEqual('ggg'); expect(mockScope.displayRows[3].col2.text).toEqual('ggg');
}); });
@ -216,14 +224,16 @@ define(
mockScope.filters = {'col2': 'a'};//Include only mockScope.filters = {'col2': 'a'};//Include only
// rows with 'a' // rows with 'a'
mockScope.displayRows = controller.sortRows(testRows); mockScope.displayRows = controller.sortRows(testRows.slice(0));
mockScope.displayRows = controller.filterRows(testRows); mockScope.displayRows = controller.filterRows(testRows);
controller.newRow(undefined, row5); mockScope.rows.push(row5);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows.length).toBe(2); expect(mockScope.displayRows.length).toBe(2);
expect(mockScope.displayRows[1].col2.text).toEqual('aaa'); expect(mockScope.displayRows[1].col2.text).toEqual('aaa');
controller.newRow(undefined, row6); mockScope.rows.push(row6);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows.length).toBe(2); expect(mockScope.displayRows.length).toBe(2);
//Row was not added because does not match filter //Row was not added because does not match filter
}); });
@ -234,11 +244,14 @@ define(
mockScope.sortDirection = undefined; mockScope.sortDirection = undefined;
mockScope.filters = {}; mockScope.filters = {};
mockScope.displayRows = testRows; mockScope.displayRows = testRows.slice(0);
controller.newRow(undefined, row5); mockScope.rows.push(row5);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows[3].col2.text).toEqual('aaa'); expect(mockScope.displayRows[3].col2.text).toEqual('aaa');
controller.newRow(undefined, row6);
mockScope.rows.push(row6);
controller.newRow(undefined, mockScope.rows.length-1);
expect(mockScope.displayRows[4].col2.text).toEqual('ggg'); expect(mockScope.displayRows[4].col2.text).toEqual('ggg');
}); });

View File

@ -132,7 +132,7 @@ define(
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('addRow', mockTableRow); expect(mockScope.$broadcast).toHaveBeenCalledWith('add:row', 0);
}); });
it('enables autoscroll for event telemetry', function() { it('enables autoscroll for event telemetry', function() {

View File

@ -94,11 +94,15 @@ define(
mockTelemetryHandle = jasmine.createSpyObj('telemetryHandle', [ mockTelemetryHandle = jasmine.createSpyObj('telemetryHandle', [
'request', 'request',
'promiseTelemetryObjects', 'promiseTelemetryObjects',
'getTelemetryObjects',
'getMetadata', 'getMetadata',
'getSeries',
'unsubscribe', 'unsubscribe',
'makeDatum' 'makeDatum'
]); ]);
mockTelemetryHandle.promiseTelemetryObjects.andReturn(promise(undefined)); mockTelemetryHandle.promiseTelemetryObjects.andReturn(promise(undefined));
mockTelemetryHandle.request.andReturn(promise(undefined));
mockTelemetryHandle.getTelemetryObjects.andReturn([]);
mockTelemetryHandler = jasmine.createSpyObj('telemetryHandler', [ mockTelemetryHandler = jasmine.createSpyObj('telemetryHandler', [
'handle' 'handle'
@ -159,6 +163,9 @@ define(
return mockRow; return mockRow;
}); });
mockTable.getRowValues.andReturn(mockRow); mockTable.getRowValues.andReturn(mockRow);
mockTelemetryHandle.getTelemetryObjects.andReturn([mockDomainObject]);
mockTelemetryHandle.getSeries.andReturn(mockSeries);
controller.addHistoricalData(mockDomainObject, mockSeries); controller.addHistoricalData(mockDomainObject, mockSeries);
expect(controller.$scope.rows.length).toBe(5); expect(controller.$scope.rows.length).toBe(5);