@@ -103,24 +103,29 @@ define(
103
103
*/
104
104
$scope . resize = this . setElementSizes . bind ( this ) ;
105
105
106
-
107
106
// Time conductor integration
108
- if ( this . $scope . timeColumns ) {
109
- this . conductor . on ( 'timeSystem' , this . changeTimeSystem ) ;
110
- this . conductor . on ( 'timeOfInterest' , this . setTimeOfInterest ) ;
111
- $scope . $on ( '$destroy' , function ( ) {
112
- this . conductor . off ( 'timeSystem' , this . changeTimeSystem ) ;
113
- this . conductor . off ( 'timeOfInterest' , this . setTimeOfInterest ) ;
114
- } . bind ( this ) ) ;
115
-
116
- // If time system defined, set initially
117
- if ( conductor . timeSystem ( ) ) {
118
- this . changeTimeSystem ( conductor . timeSystem ( ) ) ;
107
+ $scope . $watch ( " timeColumns" , function ( timeColumns ) {
108
+ if ( timeColumns ) {
109
+ this . destroyConductorListeners ( ) ;
110
+
111
+ this . conductor . on ( 'timeSystem' , this . changeTimeSystem ) ;
112
+ this . conductor . on ( 'timeOfInterest' , this . setTimeOfInterest ) ;
113
+
114
+ // If time system defined, set initially
115
+ if ( conductor . timeSystem ( ) ) {
116
+ this . changeTimeSystem ( conductor . timeSystem ( ) ) ;
117
+ }
119
118
}
120
- }
119
+ } . bind ( this ) ) ;
121
120
121
+ $scope . $on ( '$destroy' , this . destroyConductorListeners ) ;
122
122
}
123
123
124
+ MCTTableController . prototype . destroyConductorListeners = function ( ) {
125
+ this . conductor . off ( 'timeSystem' , this . changeTimeSystem ) ;
126
+ this . conductor . off ( 'timeOfInterest' , this . setTimeOfInterest ) ;
127
+ } ;
128
+
124
129
MCTTableController . prototype . changeTimeSystem = function ( ) {
125
130
var format = this . conductor . timeSystem ( ) . formats ( ) [ 0 ] ;
126
131
this . toiFormatter = this . formatService . getFormat ( format ) ;
@@ -558,18 +563,50 @@ define(
558
563
return rowsToFilter . filter ( matchRow . bind ( null , filters ) ) ;
559
564
} ;
560
565
566
+ MCTTableController . prototype . scrollToRow = function ( displayRowIndex ) {
567
+
568
+ var visible = this . $scope . visibleRows . reduce ( function ( exists , row ) {
569
+ return exists || ( row . rowIndex === displayRowIndex )
570
+ } , false ) ;
571
+
572
+ if ( ! visible ) {
573
+ var scrollTop = displayRowIndex * this . $scope . rowHeight
574
+ + this . $scope . headerHeight
575
+ - ( this . scrollable [ 0 ] . offsetHeight / 2 ) ;
576
+ this . scrollable [ 0 ] . scrollTop = scrollTop ;
577
+ this . setVisibleRows ( ) ;
578
+ }
579
+ } ;
580
+
561
581
/**
562
582
* Update rows with new data. If filtering is enabled, rows
563
583
* will be sorted before display.
564
584
*/
565
585
MCTTableController . prototype . setTimeOfInterest = function ( newTOI ) {
566
- if ( this . $scope . timeColumns . indexOf ( this . $scope . sortColumn ) !== - 1 ) {
586
+ this . $scope . toiRowIndex = - 1 ;
587
+ if ( this . $scope . timeColumns . indexOf ( this . $scope . sortColumn ) !== - 1
588
+ && newTOI
589
+ && this . $scope . displayRows . length > 0 ) {
567
590
var formattedTOI = this . toiFormatter . format ( newTOI ) ;
568
591
var rowsLength = this . $scope . displayRows . length ;
569
592
// searchElement, min, max
570
593
this . $scope . toiRowIndex = this . binarySearch ( this . $scope . displayRows , formattedTOI , 0 , rowsLength ) ;
571
- } else {
572
- this . $scope . toiRowIndex = - 1 ;
594
+ this . scrollToRow ( this . $scope . toiRowIndex ) ;
595
+ }
596
+ } ;
597
+
598
+ MCTTableController . prototype . onRowClick = function ( event , rowIndex ) {
599
+ if ( this . $scope . timeColumns . indexOf ( this . $scope . sortColumn ) !== - 1 ) {
600
+ if ( rowIndex === this . $scope . toiRowIndex ) {
601
+ this . conductor . timeOfInterest ( undefined ) ;
602
+ } else {
603
+ var selectedTime = this . $scope . displayRows [ rowIndex ] [ this . $scope . sortColumn ] . text ;
604
+ if ( selectedTime
605
+ && this . toiFormatter . validate ( selectedTime )
606
+ && event . altKey ) {
607
+ this . conductor . timeOfInterest ( this . toiFormatter . parse ( selectedTime ) ) ;
608
+ }
609
+ }
573
610
}
574
611
} ;
575
612
0 commit comments