artdaq_node_server  v1_00_11
 All Classes Namespaces Files Variables
client.js
1 var partition = -1;
2 var onmonStarted = false;
3 var hpainter;
4 var lastUpdate = 0;
5 
6 function openCanvasWindow( pad,width,height ) {
7  var thisWindow = window.open( "/artdaq-runcontrol/viewer.html?pad=" + pad + "&partition=" + partition,"ROOT Pad Inspector","width=" + width + ", height=" + height );
8 }
9 
10 function openConfigWindow( config ) {
11  var thisWindow = window.open( "/artdaq-configuration/ConfigurationEditor.html?configs=" + config );
12 }
13 
14 function updateGUI() {
15  if ( hpainter == null ) hpainter = new JSROOT.HierarchyPainter( 'root','wd1div' );
16  hpainter.SetDisplay( "grid2x1",'wd0div' );
17 
18  hpainter.OpenRootFile( "/artdaq-runcontrol/P" + partition + "/artdaqdemo_onmon.root",function () {
19  hpainter.displayAll( ["wf0","wf1"] );
20 
21  $( "#wd0div_grid_0" ).click( function () {
22  openCanvasWindow( "wf0",$( this ).width( ),$( this ).height( ) );
23  } );
24  $( "#wd0div_grid_1" ).click( function () {
25  openCanvasWindow( "wf1",$( this ).width( ),$( this ).height( ) );
26  } );
27  } );
28 };
29 
30 function manageButtons( state,running,systemRunning ) {
31  var shutdownActive = $( "#shutdown" ).hasClass( "active" ) ? " active " : "";
32  var startedActive = $( "#started" ).hasClass( "active" ) ? " active" : "";
33  var initializedActive = $( "#initialized" ).hasClass( "active" ) ? " active" : "";
34  var runStartedActive = $( "#runStarted" ).hasClass( "active" ) ? " active" : "";
35  var runPausedActive = $( "#runPaused" ).hasClass( "active" ) ? " active" : "";
36 
37  var color = running ? "yellow" : "green";
38  var sdColor = color;
39  if ( !systemRunning ) { color = "red"; }
40 
41  switch ( state ) {
42  case "Shutdown":
43  color = systemRunning ? "yellow" : "green";
44  $( "#shutdown" ).html( "<span>System Shutdown</span>" ).attr( "class","animated blue visible" );
45  $( "#started" ).html( "<span>Boot System</span>" ).attr( "class","animated visible " + color + startedActive );
46  $( "#initialized" ).html( "<span></span>" ).attr( "class","animated red hidden" );
47  $( "#runStarted" ).html( "<span></span>" ).attr( "class","animated red hidden" );
48  $( "#runPaused" ).html( "<span></span>" ).attr( "class","animated red hidden" );
49  break;
50  case "Started":
51  $( "#shutdown" ).html( "<span>Shutdown System</span>" ).attr( "class","animated visible " + sdColor + shutdownActive );
52  $( "#started" ).html( "<span>System Booted</span>" ).attr( "class","animated blue visible" );
53  $( "#initialized" ).html( "<span>Initialize System</span>" ).attr( "class","animated visible " + color + initializedActive );
54  $( "#runStarted" ).html( "<span></span>" ).attr( "class","animated red hidden" );
55  $( "#runPaused" ).html( "<span></span>" ).attr( "class","animated red hidden" );
56  break;
57  case "Initialized":
58  $( "#shutdown" ).html( "<span>Shutdown System</span>" ).attr( "class","animated visible " + sdColor + shutdownActive );
59  $( "#started" ).html( "<span></span>" ).attr( "class","animated red hidden" );
60  $( "#initialized" ).html( "<span>System Initialized</span>" ).attr( "class","animated blue visible" );
61  $( "#runStarted" ).html( "<span>Start Run</span>" ).attr( "class","animated visible " + color + runStartedActive );
62  $( "#runPaused" ).html( "<span></span>" ).attr( "class","animated red hidden" );
63  break;
64  case "Running":
65  $( "#shutdown" ).html( "<span></span>" ).attr( "class","animated red hidden" );
66  $( "#started" ).html( "<span></span>" ).attr( "class","animated red hidden" );
67  $( "#initialized" ).html( "<span>End Run</span>" ).attr( "class","animated visible " + color + initializedActive );
68  $( "#runStarted" ).html( "<span>Running</span>" ).attr( "class","animated blue visible" );
69  $( "#runPaused" ).html( "<span>Pause Run</span>" ).attr( "class","animated visible " + color + runPausedActive );
70  break;
71  case "Paused":
72  $( "#shutdown" ).html( "<span>Shutdown System</span>" ).attr( "class","animated visible " + sdColor + shutdownActive );
73  $( "#started" ).html( "<span></span>" ).attr( "class","animated red hidden" );
74  $( "#initialized" ).html( "<span>Reinitialize System</span>" ).attr( "class","animated visible " + color + initializedActive );
75  $( "#runStarted" ).html( "<span>Resume Run</span>" ).attr( "class","animated visible " + color + runStartedActive );
76  $( "#runPaused" ).html( "<span>Run Paused</span>" ).attr( "class","animated blue visible" );
77  break;
78  }
79 
80  $( ".green.animated" ).hover( function () {
81  $( this ).addClass( "active" );
82  },function () { $( this ).removeClass( "active" ); } );
83 
84 }
85 
86 function update( dataJSON ) {
87  var data = $.parseJSON( dataJSON );
88  partition = data.partition;
89  $( "#partition" ).val( data.partition );
90  manageButtons( data.state,data.commandRunning,data.systemRunning );
91 
92  $( "#configs" ).val( data.config );
93 
94  var out = $("#systemOut")[0];
95  var err = $("#systemErr")[0];
96  var outAtBottom = out.scrollTop + out.clientHeight >= out.scrollHeight - 10;
97  var errAtBottom = err.scrollTop + err.clientHeight >= err.scrollHeight - 10;
98  $( "#systemOut" ).val( data.systemOutputBuffer );
99  $( "#systemErr" ).val( data.systemErrorBuffer );
100  if(outAtBottom) { out.scrollTop = out.scrollHeight };
101  if(errAtBottom) { err.scrollTop = err.scrollHeight };
102 
103  out = $("#commOut")[0];
104  err = $("#commErr")[0];
105  outAtBottom = out.scrollTop + out.clientHeight >= out.scrollHeight - 10;
106  errAtBottom = err.scrollTop + err.clientHeight >= err.scrollHeight - 10;
107  $( "#commOut" ).val( data.commandOutputBuffer );
108  $( "#commErr" ).val( data.commandErrorBuffer );
109  if(outAtBottom) { out.scrollTop = out.scrollHeight };
110  if(errAtBottom) { err.scrollTop = err.scrollHeight };
111 
112  if ( data.WFPlotsUpdated && $( "#monitoringEnabled" ).is( ":checked" ) ) {
113  var updateDate = data.WFPlotsUpdated;
114  if ( updateDate > lastUpdate ) {
115  updateGUI( );
116  lastUpdate = updateDate;
117  }
118  } else {
119  hpainter = null;
120  $( "#wd0div" ).html( "" );
121  }
122 
123  if((!onmonStarted) && data.okToStartOnMon)
124  {
125  Onmon("#onmonDiv", partition, "artdaq-runcontrol");
126  onmonStarted = true;
127  }
128  }
129 
130 
131 function shutdownSystem() {
132  if ( $( "#shutdown" ).is( ".green" ) ) {
133  AjaxPost( "/artdaq-runcontrol/Shutdown",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update );
134  }
135 }
136 
137 function startSystem() {
138  if ( $( "#started" ).is( ".green" ) ) {
139  AjaxPost( "/artdaq-runcontrol/Start",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update );
140  }
141 }
142 
143 function initSystem() {
144  if ( $( "#initialized" ).is( ".green" ) ) {
145  if ( $( "#started" ).is( ".blue" ) ) {
146  var verbosity = $( "#verbosity" ).is( ":checked" );
147  AjaxPost( "/artdaq-runcontrol/Init",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update );
148  }
149  else {
150  AjaxPost( "/artdaq-runcontrol/End",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update );
151  var number = parseInt( $( "#runNumber" ).val( ) );
152  $( "#runNumber" ).val( number + 1 );
153  }
154  }
155 }
156 
157 function startRun() {
158  if ( $( "#runStarted" ).is( ".green" ) ) {
159  if ( $( "#runPaused" ).is( ".blue" ) ) {
160  AjaxPost( "/artdaq-runcontrol/Resume",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update );
161  } else {
162  AjaxPost( "/artdaq-runcontrol/Run",{ partition: $( "#partition" ).val( ), runNumber: $( "#runNumber" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update );
163  }
164  }
165 }
166 
167 function pauseRun() {
168  if ( $( "#runPaused" ).is( ".green" ) ) {
169  AjaxPost( "/artdaq-runcontrol/Pause",{ partition: $( "#partition" ).val( ), config: $( "#config" ).find( ":selected" ).val( ) },update );
170  }
171 }
172 
173 function getConfigs() {
174  $.get( "/artdaq-configuration/NamedConfigs",function ( result ) {
175  $( "#config" ).html( result );
176  } );
177 }
178 
179 $( document ).ready( function () {
180  $( "#shutdown" ).click( function () {
181  shutdownSystem( );
182  } );
183  $( "#started" ).click( function () {
184  startSystem( );
185  } );
186  $( "#initialized" ).click( function () {
187  initSystem( );
188  } );
189  $( "#runStarted" ).click( function () {
190  startRun( );
191  } );
192  $( "#runPaused" ).click( function () {
193  pauseRun( );
194  } );
195  $( "#monitoringEnabled" ).change( function () {
196  if ( $( "#monitoringEnabled" ).is( ":checked" ) ) {
197  updateGUI( );
198  }
199  } );
200 
201  getConfigs( );
202  $( "#editConfig" ).click( function () {
203  var config = $( "#config" ).find( ":selected" ).val( );
204  openConfigWindow( config );
205  } );
206 
207  $( "#reloadConfigs" ).click( function () {
208  getConfigs( );
209  } );
210 
211  setInterval( function () { AjaxGet( "/artdaq-runcontrol/P" + $( "#partition" ).val( ),update ); },1000 );
212  JSROOT.AssertPrerequisites( '2d;io;',updateGUI );
213 } );
214