@@ -7,21 +7,37 @@ let diagnosticCount = 0;
77/* --- End dashboard parameters --- */
88
99$ ( document ) . ready ( function ( ) {
10- var data_table = $ ( '#log' ) . DataTable ( {
11- "createdRow" : function ( row , data , index ) {
12- $ ( 'td' , row ) . eq ( 0 ) . attr ( 'id' , `${ data [ 0 ] } _label` ) ;
13- $ ( 'td' , row ) . eq ( 1 ) . attr ( 'id' , `${ data [ 0 ] } _value` ) ;
14- $ ( 'td' , row ) . eq ( 2 ) . attr ( 'id' , `${ data [ 0 ] } _num` ) ;
15- $ ( 'td' , row ) . eq ( 3 ) . attr ( 'id' , `${ data [ 0 ] } _freq` ) ;
16- }
17- } ) ;
18-
1910 updateDashboardParameters ( ) ;
11+ searchTable ( )
12+
13+ var f_sl = 1 ;
14+ var f_nm = 1 ;
15+ $ ( "#sn" ) . click ( function ( ) {
16+ f_sl *= - 1 ;
17+ var n = $ ( this ) . prevAll ( ) . length ;
18+ sortTable ( f_sl , n ) ;
19+ } ) ;
20+ $ ( "#sv" ) . click ( function ( ) {
21+ f_nm *= - 1 ;
22+ var n = $ ( this ) . prevAll ( ) . length ;
23+ sortTable ( f_nm , n ) ;
24+ } ) ;
25+ $ ( "#sr" ) . click ( function ( ) {
26+ f_nm *= - 1 ;
27+ var n = $ ( this ) . prevAll ( ) . length ;
28+ sortTable ( f_nm , n ) ;
29+ } ) ;
30+ $ ( "#sf" ) . click ( function ( ) {
31+ f_nm *= - 1 ;
32+ var n = $ ( this ) . prevAll ( ) . length ;
33+ sortTable ( f_nm , n ) ;
34+ } ) ;
35+
2036
21- namespace = '' ;
22- var socket = io ( namespace ) ;
23- socket . on ( 'vehicle data' , function ( msg , cb ) {
24- // console.log(msg);
37+ namespace = '' ;
38+ var socket = io ( namespace ) ;
39+ socket . on ( 'vehicle data' , function ( msg , cb ) {
40+ // console.log(msg);
2541
2642 if ( ! msg . hasOwnProperty ( 'command_response' ) ) {
2743 if ( msg . hasOwnProperty ( 'success' ) ) {
@@ -33,12 +49,12 @@ $(document).ready(function() {
3349 if ( ! msg . hasOwnProperty ( 'name' ) ) {
3450 msg . name = 'Raw-' + msg . bus + '-0x' + msg . id . toString ( 16 ) ;
3551 msg . value = msg . data ;
36- }
37-
52+ }
53+
3854 if ( msg . hasOwnProperty ( 'event' ) ) {
39- msg . value = msg . value + ': ' + msg . event
55+ msg . value = msg . value + ': ' + msg . event
4056 }
41-
57+
4258 if ( ! ( msg . name in dataPoints ) ) {
4359 dataPoints [ msg . name ] = {
4460 current_data : undefined ,
@@ -50,27 +66,17 @@ $(document).ready(function() {
5066 last_update_time : undefined ,
5167 average_time_since_update : undefined
5268 } ;
53-
54- data_table . row . add ( [
55- msg . name ,
56- msg . value ,
57- 0 ,
58- 0
59- ] ) . draw ( ) ;
60-
61- var id = data_table . row ( this ) . id ( ) ;
62- console . log ( id ) ;
6369 }
64-
70+
6571 updateDataPoint ( dataPoints [ msg . name ] , msg ) ;
6672 updateDisplay ( dataPoints [ msg . name ] ) ;
67-
73+
6874 if ( cb ) {
6975 cb ( ) ;
7076 }
7177 }
7278 }
73- } ) ;
79+ } ) ;
7480} ) ;
7581
7682function updateDashboardParameters ( ) {
@@ -83,22 +89,54 @@ function saveSettings(e) {
8389 updateDashboardParameters ( ) ;
8490}
8591
92+ function addToDisplay ( msgName ) {
93+ var added = false ;
94+ if ( ! added ) {
95+ $ ( '<tr/>' , {
96+ id : msgName
97+ } ) . appendTo ( '#log' ) ;
98+ }
99+
100+ $ ( '<td/>' , {
101+ id : msgName + '_label' ,
102+ text : msgName
103+ } ) . appendTo ( '#' + msgName ) ;
104+
105+ $ ( '<td/>' , {
106+ id : msgName + '_value'
107+ } ) . appendTo ( '#' + msgName ) ;
108+
109+ $ ( '<td/>' , {
110+ id : msgName + '_num' ,
111+ class : 'metric'
112+ } ) . appendTo ( '#' + msgName ) ;
113+
114+ $ ( '<td/>' , {
115+ id : msgName + '_freq' ,
116+ class : 'metric'
117+ } ) . appendTo ( '#' + msgName ) ;
118+ }
119+
86120function updateDisplay ( dataPoint ) {
87121 msg = dataPoint . current_data
88122
89- $ ( '#' + msg . name + '_value' ) . text ( msg . value ) ;
90- highlightCell ( '#' + msg . name + '_value' ) ;
123+ if ( ! ( $ ( '#' + msg . name ) . length > 0 ) ) {
124+ addToDisplay ( msg . name ) ;
125+ }
126+
127+ $ ( '#' + msg . name + '_value' ) . text ( msg . value ) ;
128+ highlightCell ( '#' + msg . name + '_value' ) ;
91129
92- $ ( '#' + msg . name + '_num' ) . text ( dataPoint . messages_received ) ;
93- $ ( '#' + msg . name + '_freq' ) . text ( Math . ceil ( 1 / dataPoint . average_time_since_update ) ) ;
130+ $ ( '#' + msg . name + '_num' ) . text ( dataPoint . messages_received ) ;
131+ $ ( '#' + msg . name + '_freq' ) . text ( Math . ceil ( 1 / dataPoint . average_time_since_update ) ) ;
94132}
95133
96134function highlightCell ( cellId ) {
97135 $ ( cellId ) . stop ( true ) ;
98- $ ( cellId ) . css ( { 'background' : '#1338F0' , 'color' : 'white' } ) ;
99- $ ( cellId ) . animate ( { backgroundColor : '#949494' } , valueChangedTimer , function ( ) {
100- $ ( this ) . animate ( { backgroundColor : '#FFFFFF' , color : 'black' } , valueRecentlyChangedTimer ) ;
101- } ) ;
136+ $ ( cellId ) . css ( { 'background' : '#1338F0' , 'color' : 'white' } ) ;
137+ $ ( cellId ) . animate ( { backgroundColor : '#949494' } , valueChangedTimer , function ( ) {
138+ $ ( this ) . animate ( { backgroundColor : '#FFFFFF' , color : 'black' } , valueRecentlyChangedTimer ) ;
139+ } ) ;
102140}
103141
104142function validateSettingsForm ( ) {
@@ -124,7 +162,7 @@ function validateSettingsForm() {
124162
125163function validateTimerInput ( input , errors ) {
126164 let inputVal = input . val ( ) ;
127-
165+
128166 if ( isNaN ( inputVal ) || inputVal < 0 ) {
129167 errors . push ( { id : input [ 0 ] . id , msg : 'Input must be a positive number' } ) ;
130168 }
@@ -138,7 +176,7 @@ function updateDataPoint(dataPoint, measurement) {
138176 let update_time = ( new Date ( ) ) . getTime ( ) / 1000 ;
139177
140178 if ( dataPoint . last_update_time !== undefined ) {
141- dataPoint . average_time_since_update =
179+ dataPoint . average_time_since_update =
142180 calculateAverageTimeSinceUpdate ( update_time , dataPoint ) ;
143181 }
144182
@@ -152,16 +190,56 @@ function updateDataPoint(dataPoint, measurement) {
152190function calculateAverageTimeSinceUpdate ( updateTime , dataPoint ) {
153191 let time_since_update = updateTime - dataPoint . last_update_time ;
154192
155- return ( dataPoint . average_time_since_update === undefined )
193+ return ( dataPoint . average_time_since_update === undefined )
156194 ? time_since_update
157195 : ( 0.1 * time_since_update ) + ( 0.9 * dataPoint . average_time_since_update ) ;
158196}
159197
198+ function sortTable ( f , n ) {
199+ var rows = $ ( '#log tbody tr' ) . get ( ) ;
200+
201+ rows . sort ( function ( a , b ) {
202+
203+ var A = getVal ( a ) ;
204+ var B = getVal ( b ) ;
205+
206+ if ( A < B ) {
207+ return - 1 * f ;
208+ }
209+ if ( A > B ) {
210+ return 1 * f ;
211+ }
212+ return 0 ;
213+ } ) ;
214+
215+ function getVal ( elm ) {
216+ var v = $ ( elm ) . children ( 'td' ) . eq ( n ) . text ( ) . toUpperCase ( ) ;
217+ if ( $ . isNumeric ( v ) ) {
218+ v = parseInt ( v , 10 ) ;
219+ }
220+ return v ;
221+ }
222+
223+ $ . each ( rows , function ( index , row ) {
224+ $ ( '#log' ) . children ( 'tbody' ) . append ( row ) ;
225+ } ) ;
226+ console . log ( "jamez test" ) ;
227+ }
228+
229+ function searchTable ( ) {
230+ $ ( "#myInput" ) . on ( "keyup" , function ( ) {
231+ var value = $ ( this ) . val ( ) . toLowerCase ( ) ;
232+ $ ( "#log tr" ) . filter ( function ( ) {
233+ $ ( this ) . toggle ( $ ( this ) . text ( ) . toLowerCase ( ) . indexOf ( value ) > - 1 )
234+ } ) ;
235+ } ) ;
236+ }
237+
160238function addDiagnosticResponse ( name , message ) {
161239 $ ( '<tr/>' , {
162240 id : name
163241 } ) . appendTo ( '#diagnostic' ) ;
164-
242+
165243 $ ( '<td/>' , {
166244 id : name + '_bus' ,
167245 text : message . bus
0 commit comments