Skip to content

Commit

Permalink
Added support for clicking row to set TOI
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Oct 8, 2016
1 parent b995a8b commit 70c4ce2
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
ng-class="{ 'pinned': toi.pinned, 'val-to-right': toi.left < 20 }"
ng-style="{'left': toi.left + '%'}">
<div class="l-toi">
<a class="t-button-unpin icon-button" ng-click="toi.pinned = false"></a>
<a class="t-button-unpin icon-button"
ng-click="toi.dismiss()"></a>
<span class="l-toi-val">{{toi.toiText}}</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ define(
}
};

ConductorTOIController.prototype.dismiss = function () {
this.conductor.timeOfInterest(undefined);
};

ConductorTOIController.prototype.resize = function () {
//Do something?
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ng-class="{'loading': loading}">
<mct-table
headers="headers"
time-columns="timeColumns"
time-columns="tableController.timeColumns"
rows="rows"
enableFilter="true"
enableSort="true"
Expand Down
2 changes: 1 addition & 1 deletion platform/features/table/res/templates/mct-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<!--ng-click="dummyUnpin()" -->
<tr ng-repeat="visibleRow in visibleRows track by visibleRow.rowIndex"
ng-class="{ 'l-toi pinned': visibleRow.rowIndex === toiRowIndex }"
ng-click="table.onRowClick($event, visibleRow.contents)"
ng-click="table.onRowClick($event, visibleRow.rowIndex)"
ng-style="{
top: visibleRow.offsetY + 'px',
}">
Expand Down
69 changes: 53 additions & 16 deletions platform/features/table/src/controllers/MCTTableController.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,29 @@ define(
*/
$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());
$scope.$watch("timeColumns", function (timeColumns){
if (timeColumns) {
this.destroyConductorListeners();

this.conductor.on('timeSystem', this.changeTimeSystem);
this.conductor.on('timeOfInterest', this.setTimeOfInterest);

// If time system defined, set initially
if (conductor.timeSystem()) {
this.changeTimeSystem(conductor.timeSystem());
}
}
}
}.bind(this));

$scope.$on('$destroy', this.destroyConductorListeners);
}

MCTTableController.prototype.destroyConductorListeners = function () {
this.conductor.off('timeSystem', this.changeTimeSystem);
this.conductor.off('timeOfInterest', this.setTimeOfInterest);
};

MCTTableController.prototype.changeTimeSystem = function () {
var format = this.conductor.timeSystem().formats()[0];
this.toiFormatter = this.formatService.getFormat(format);
Expand Down Expand Up @@ -558,18 +563,50 @@ define(
return rowsToFilter.filter(matchRow.bind(null, filters));
};

MCTTableController.prototype.scrollToRow = function (displayRowIndex) {

var visible = this.$scope.visibleRows.reduce(function (exists, row) {
return exists || (row.rowIndex === displayRowIndex)
}, false);

if (!visible) {
var scrollTop = displayRowIndex * this.$scope.rowHeight
+ this.$scope.headerHeight
- (this.scrollable[0].offsetHeight / 2);
this.scrollable[0].scrollTop = scrollTop;
this.setVisibleRows();
}
};

/**
* 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) {
this.$scope.toiRowIndex = -1;
if (this.$scope.timeColumns.indexOf(this.$scope.sortColumn) !== -1
&& newTOI
&& this.$scope.displayRows.length > 0) {
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;
this.scrollToRow(this.$scope.toiRowIndex);
}
};

MCTTableController.prototype.onRowClick = function (event, rowIndex) {
if (this.$scope.timeColumns.indexOf(this.$scope.sortColumn) !== -1) {
if (rowIndex === this.$scope.toiRowIndex) {
this.conductor.timeOfInterest(undefined);
} else {
var selectedTime = this.$scope.displayRows[rowIndex][this.$scope.sortColumn].text;
if (selectedTime
&& this.toiFormatter.validate(selectedTime)
&& event.altKey) {
this.conductor.timeOfInterest(this.toiFormatter.parse(selectedTime));
}
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define(

// Unsubscribe when the plot is destroyed
this.$scope.$on("$destroy", this.destroy);
this.$scope.timeColumns = ['Time'];
this.$scope.timeColumns = [];
}

/**
Expand Down Expand Up @@ -153,20 +153,32 @@ define(
this.setup();
};

TelemetryTableController.prototype.populateColumns = function (telemetryMetadata) {
this.table.populateColumns(telemetryMetadata);

//Identify time columns
telemetryMetadata.forEach(function (metadatum) {
//Push domains first
(metadatum.domains || []).forEach(function (domainMetadata) {
this.timeColumns.push(domainMetadata.name);
}.bind(this));
}.bind(this));
};

/**
* Setup table columns based on domain object metadata
*/
TelemetryTableController.prototype.setup = function () {
var handle = this.handle,
table = this.table,
self = this;

if (handle) {
this.timeColumns = [];
handle.promiseTelemetryObjects().then(function () {
self.$scope.headers = [];
self.$scope.rows = [];
table.populateColumns(handle.getMetadata());

self.populateColumns(handle.getMetadata());
self.filterColumns();

// When table column configuration changes, (due to being
Expand Down

0 comments on commit 70c4ce2

Please sign in to comment.