[Time Conductor] Refactored time of interest as optional generic behavior of MctTable

This commit is contained in:
Henry 2016-10-07 14:51:59 -07:00
parent dfbbc3b0c5
commit 51a95575f7
6 changed files with 58 additions and 44 deletions

View File

@ -2,6 +2,7 @@
ng-class="{'loading': loading}"> ng-class="{'loading': loading}">
<mct-table <mct-table
headers="headers" headers="headers"
time-columns="timeColumns"
rows="rows" rows="rows"
enableFilter="true" enableFilter="true"
enableSort="true" enableSort="true"

View File

@ -52,7 +52,7 @@
<!--ng-class="{ 'l-toi pinned': false }"--> <!--ng-class="{ 'l-toi pinned': false }"-->
<!--ng-click="dummyUnpin()" --> <!--ng-click="dummyUnpin()" -->
<tr ng-repeat="visibleRow in visibleRows track by visibleRow.rowIndex" <tr ng-repeat="visibleRow in visibleRows track by visibleRow.rowIndex"
class="{{visibleRow.contents.cssClass}}" ng-class="{ 'l-toi pinned': visibleRow.rowIndex === toiRowIndex }"
ng-click="table.onRowClick($event, visibleRow.contents)" ng-click="table.onRowClick($event, visibleRow.contents)"
ng-style="{ ng-style="{
top: visibleRow.offsetY + 'px', top: visibleRow.offsetY + 'px',

View File

@ -36,7 +36,7 @@ define(
* @param telemetryFormatter * @param telemetryFormatter
* @constructor * @constructor
*/ */
function HistoricalTableController($scope, telemetryHandler, telemetryFormatter, $timeout, conductor) { function HistoricalTableController($scope, telemetryHandler, telemetryFormatter, $timeout) {
var self = this; var self = this;
this.$timeout = $timeout; this.$timeout = $timeout;
@ -49,7 +49,7 @@ define(
} }
}); });
TableController.call(this, $scope, telemetryHandler, telemetryFormatter, conductor); TableController.call(this, $scope, telemetryHandler, telemetryFormatter);
} }
HistoricalTableController.prototype = Object.create(TableController.prototype); HistoricalTableController.prototype = Object.create(TableController.prototype);
@ -59,7 +59,6 @@ define(
* @private * @private
*/ */
HistoricalTableController.prototype.doneProcessing = function (rowData) { HistoricalTableController.prototype.doneProcessing = function (rowData) {
//Set table rows to formatted data;
this.$scope.rows = rowData; this.$scope.rows = rowData;
this.$scope.loading = false; this.$scope.loading = false;
}; };
@ -110,9 +109,8 @@ define(
//Process rows in a batch with size not exceeding a maximum length //Process rows in a batch with size not exceeding a maximum length
for (; i < end; i++) { for (; i < end; i++) {
var datum = this.handle.makeDatum(telemetryObject, series, i); rowData.push(this.table.getRowValues(telemetryObject,
this.data.push(datum); this.handle.makeDatum(telemetryObject, series, i)));
rowData.push(this.table.getRowValues(telemetryObject, datum));
} }
//Done processing all rows for this object. //Done processing all rows for this object.
@ -134,7 +132,7 @@ define(
if (this.timeoutHandle) { if (this.timeoutHandle) {
this.$timeout.cancel(this.timeoutHandle); this.$timeout.cancel(this.timeoutHandle);
} }
this.data = [];
this.timeoutHandle = this.$timeout(this.processTelemetryObjects.bind(this, this.handle.getTelemetryObjects(), 0, 0, [])); this.timeoutHandle = this.$timeout(this.processTelemetryObjects.bind(this, this.handle.getTelemetryObjects(), 0, 0, []));
}; };

View File

@ -12,7 +12,7 @@ define(
* @param element * @param element
* @constructor * @constructor
*/ */
function MCTTableController($scope, $timeout, element, exportService) { function MCTTableController($scope, $timeout, element, exportService, formatService, conductor) {
var self = this; var self = this;
this.$scope = $scope; this.$scope = $scope;
@ -24,6 +24,9 @@ define(
this.thead = element.find('thead'); this.thead = element.find('thead');
this.tbody = element.find('tbody'); this.tbody = element.find('tbody');
this.$scope.sizingRow = {}; this.$scope.sizingRow = {};
this.conductor = conductor;
this.toiFormatter = undefined;
this.formatService = formatService;
//Bind all class functions to 'this' //Bind all class functions to 'this'
Object.keys(MCTTableController.prototype).filter(function (key) { Object.keys(MCTTableController.prototype).filter(function (key) {
@ -77,6 +80,7 @@ define(
$scope.sortDirection = undefined; $scope.sortDirection = undefined;
} }
self.setRows($scope.rows); self.setRows($scope.rows);
self.setTimeOfInterest(self.conductor.timeOfInterest());
}; };
/* /*
@ -99,7 +103,28 @@ define(
*/ */
$scope.resize = this.setElementSizes.bind(this); $scope.resize = this.setElementSizes.bind(this);
// Time conductor integration
if (this.$scope.timeColumns) {
this.conductor.on('timeSystem', this.changeTimeSystem);
this.conductor.on('timeOfInterest', this.setTimeOfInterest);
$scope.$on('$destroy', function () {
this.conductor.off('timeSystem', this.changeTimeSystem);
this.conductor.off('timeOfInterest', this.setTimeOfInterest);
}.bind(this));
// If time system defined, set initially
if (conductor.timeSystem()) {
this.changeTimeSystem(conductor.timeSystem());
} }
}
}
MCTTableController.prototype.changeTimeSystem = function () {
var format = this.conductor.timeSystem().formats()[0];
this.toiFormatter = this.formatService.getFormat(format);
};
/** /**
* If auto-scroll is enabled, this function will scroll to the * If auto-scroll is enabled, this function will scroll to the
@ -308,7 +333,7 @@ define(
return min; // Element is not in array, min gives direction return min; // Element is not in array, min gives direction
} }
switch (this.sortComparator(searchElement[this.$scope.sortColumn].text, switch (this.sortComparator(searchElement,
searchArray[sampleAt][this.$scope.sortColumn].text)) { searchArray[sampleAt][this.$scope.sortColumn].text)) {
case -1: case -1:
return this.binarySearch(searchArray, searchElement, min, return this.binarySearch(searchArray, searchElement, min,
@ -332,7 +357,7 @@ define(
index = array.length; index = array.length;
} else { } else {
//Sort is enabled, perform binary search to find insertion point //Sort is enabled, perform binary search to find insertion point
index = this.binarySearch(array, element, 0, array.length - 1); index = this.binarySearch(array, element[this.$scope.sortColumn].text, 0, array.length - 1);
} }
if (index === -1) { if (index === -1) {
array.unshift(element); array.unshift(element);
@ -496,11 +521,6 @@ define(
this.resize(newRows).then(this.setVisibleRows.bind(this)); this.resize(newRows).then(this.setVisibleRows.bind(this));
}; };
MCTTableController.prototype.onRowClick = function (event, row) {
var index = this.$scope.rows.indexOf(row);
this.$scope.onRowClick({event: event, rowIndex:index, sortColumn: this.$scope.sortColumn, sortDirection: this.$scope.sortDirection});
};
/** /**
* 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.
@ -538,6 +558,20 @@ define(
return rowsToFilter.filter(matchRow.bind(null, filters)); return rowsToFilter.filter(matchRow.bind(null, filters));
}; };
/**
* Update rows with new data. If filtering is enabled, rows
* will be sorted before display.
*/
MCTTableController.prototype.setTimeOfInterest = function (newTOI) {
if (this.$scope.timeColumns.indexOf(this.$scope.sortColumn) !== -1) {
var formattedTOI = this.toiFormatter.format(newTOI);
var rowsLength = this.$scope.displayRows.length;
// searchElement, min, max
this.$scope.toiRowIndex = this.binarySearch(this.$scope.displayRows, formattedTOI, 0, rowsLength);
} else {
this.$scope.toiRowIndex = -1;
}
};
return MCTTableController; return MCTTableController;
} }

View File

@ -26,10 +26,9 @@
*/ */
define( define(
[ [
'../TableConfiguration', '../TableConfiguration'
'../DomainColumn'
], ],
function (TableConfiguration, DomainColumn) { function (TableConfiguration) {
/** /**
* The TableController is responsible for getting data onto the page * The TableController is responsible for getting data onto the page
@ -57,7 +56,6 @@ define(
telemetryFormatter); telemetryFormatter);
this.changeListeners = []; this.changeListeners = [];
this.conductor = conductor; this.conductor = conductor;
this.data = [];
$scope.rows = []; $scope.rows = [];
@ -67,28 +65,13 @@ define(
self.registerChangeListeners(); self.registerChangeListeners();
}); });
this.destroy = this.destroy.bind(this);
// Unsubscribe when the plot is destroyed // Unsubscribe when the plot is destroyed
this.$scope.$on("$destroy", this.destroy); this.$scope.$on("$destroy", this.destroy);
this.$scope.timeColumns = ['Time'];
} }
TelemetryTableController.prototype.onRowClick = function (event, rowIndex, sortBy, sortOrder) {
var datum = this.data[rowIndex];
if (event.altKey) {
console.log("selected: " + this.$scope.rows[rowIndex]);
//Is column one that we can use to set time of interest?
var domainColumn = this.table.columns.filter(function (column) {
return column instanceof DomainColumn &&
column.getTitle() === sortBy;
})[0];
if (domainColumn) {
var timeOfInterest = datum[domainColumn.domainMetadata.key];
this.conductor.timeOfInterest(timeOfInterest);
}
}
};
/** /**
* @private * @private
*/ */
@ -210,10 +193,6 @@ define(
}); });
}; };
TelemetryTableController.prototype.changeTimeOfInterest = function (toi) {
}
return TelemetryTableController; return TelemetryTableController;
} }
); );

View File

@ -86,6 +86,8 @@ define(
'$timeout', '$timeout',
'$element', '$element',
'exportService', 'exportService',
'formatService',
'timeConductor',
MCTTableController MCTTableController
], ],
controllerAs: "table", controllerAs: "table",
@ -95,7 +97,7 @@ define(
enableFilter: "=?", enableFilter: "=?",
enableSort: "=?", enableSort: "=?",
autoScroll: "=?", autoScroll: "=?",
onRowClick: "&" timeColumns: "=?"
} }
}; };
} }