Subversion Repositories f9daq

Rev

Rev 275 | Rev 318 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 275 Rev 302
Line 98... Line 98...
98
function startTask() {
98
function startTask() {
99
       
99
       
100
        var r = document.getElementById('results');
100
        var r = document.getElementById('results');
101
        if ( r.style.display == 'none' ) switchTask();
101
        if ( r.style.display == 'none' ) switchTask();
102
        r.innerHTML = '';
102
        r.innerHTML = '';
103
        document.getElementById('drawing').innerHTML = '';
103
        var btnstart = document.getElementById('btnstart');
-
 
104
        btnstart.value= "Stop Analysis";
104
 
105
       
-
 
106
       
-
 
107
        document.getElementById('drawing').innerHTML = '';
105
 
108
 
106
        Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
109
        Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
107
        var code = Blockly.JavaScript.workspaceToCode(workspace);
110
        var code = Blockly.JavaScript.workspaceToCode(workspace);
108
            code = code.replace(/\(|\)/gi, '');
111
            code = code.replace(/\(|\)/gi, '');
109
               
112
               
110
        addLog(code + '<br>');
113
        addLog(code + '<br>');
111
       //addLog(JSON.stringify(code)+ '<br>');
114
       //addLog(JSON.stringify(code)+ '<br>');
112
        es = new EventSource('runscript.php?code='  + code  );
115
        es = new EventSource('runscript.php?code='  + code  );
113
         
116
         
114
       //a message is received
117
       //a message is received
115
        es.addEventListener('message',EventListener);      
118
        es.addEventListener('message',EventListener);      
116
        es.addEventListener('error', function(e) {
119
        es.addEventListener('error', function(e) {
117
        addLog('Error occurred');
120
        addLog('Error occurred');
-
 
121
        stopTask();
118
        es.close();
122
        //es.close();
119
    });
123
    });
120
}
124
}
121
 
125
 
-
 
126
function startAction() {
-
 
127
   var btnstart = document.getElementById('btnstart');
-
 
128
   if (btnstart.value=== "Stop Analysis"){
-
 
129
     stopTask();
-
 
130
   } else {
-
 
131
     startTask();
-
 
132
   }
-
 
133
}
122
function EventListener(e) {
134
function EventListener(e) {
123
//addLog(JSON.stringify(e) );
135
//addLog(JSON.stringify(e) );
124
 
136
 
125
var result = JSON.parse( e.data );
137
var result = JSON.parse( e.data );
126
 
138
 
127
        if(e.lastEventId == 'CLOSE') {
139
        if(e.lastEventId == 'CLOSE') {
128
            addLog('Received CLOSE closing');
140
            addLog('Received CLOSE closing');
-
 
141
            stopTask();
129
            es.close();
142
//            es.close();
-
 
143
           
130
            var pBar = document.getElementById('progressor');
144
            var pBar = document.getElementById('progressor');
131
            pBar.value = pBar.max; //max out the progress bar
145
            pBar.value = pBar.max; //max out the progress bar
132
            var perc = document.getElementById('percentage');
146
            var perc = document.getElementById('percentage');
133
            perc.innerHTML   =  "100%";
147
            perc.innerHTML   =  "100%";
134
            perc.style.width = (Math.floor(pBar.clientWidth * (0.5)) + 15) + 'px';
148
            perc.style.width = (Math.floor(pBar.clientWidth * (0.5)) + 15) + 'px';
Line 176... Line 190...
176
            var pBar = document.getElementById('progressor');
190
            var pBar = document.getElementById('progressor');
177
            pBar.value = result.progress;
191
            pBar.value = result.progress;
178
            var perc = document.getElementById('percentage');
192
            var perc = document.getElementById('percentage');
179
            perc.innerHTML   = result.progress  + "%";
193
            perc.innerHTML   = result.progress  + "%";
180
            perc.style.width = (Math.floor(pBar.clientWidth * (result.progress/100)) + 15) + 'px';
194
            perc.style.width = (Math.floor(pBar.clientWidth * (result.progress/100)) + 15) + 'px';
181
        }
195
        }
182
}
196
}
183
 
197
 
184
 
198
 
185
 
199
 
186
function stopTask() {
200
function stopTask() {
187
    es.close();
201
    es.close();
188
    addLog('Interrupted');
202
    addLog('Task end');
-
 
203
    var btnstart = document.getElementById('btnstart');
-
 
204
   
-
 
205
    btnstart.value= "Run Analysis";
-
 
206
 
189
}
207
}
190
 
208
 
191
       
209
       
192
/*
210
/*
193
    function switchTask() {
211
    function switchTask() {
194
    var div  = document.getElementById('results');
212
    var div  = document.getElementById('results');
195
    var divs  = document.getElementById('sbar');
213
    var divs  = document.getElementById('sbar');
Line 202... Line 220...
202
    }
220
    }
203
    else {
221
    else {
204
        div.style.display = 'block';
222
        div.style.display = 'block';
205
        divs.style.display = 'block';
223
        divs.style.display = 'block';
206
        div0.style.display = 'none';
224
        div0.style.display = 'none';
207
    }
225
    }
208
 
226
 
209
  }
227
  }
210
*/
228
*/
211
 
229
 
212
 
230
 
213
function togglevisibility( name ) {
231
function togglevisibility( name ) {
214
    var div  = document.getElementById(name);
232
    var div  = document.getElementById(name);
Line 257... Line 275...
257
     }
275
     }
258
  }
276
  }
259
  xhttp.open("GET", url, false); // !!! should be in synchronous mode 
277
  xhttp.open("GET", url, false); // !!! should be in synchronous mode 
260
  xhttp.send();
278
  xhttp.send();
261
  return xhttp.onreadystatechange();
279
  return xhttp.onreadystatechange();
262
}
280
}
263
 
281
 
264
 function showCode() {
282
 function showCode() {
265
      // Generate JavaScript code and display it.
283
      // Generate JavaScript code and display it.
266
      Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
284
      Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
267
      var code = Blockly.JavaScript.workspaceToCode(workspace);
285
      var code = Blockly.JavaScript.workspaceToCode(workspace);
Line 283... Line 301...
283
   
301
   
284
//  var txt=Blockly.Xml.domToPrettyText(Blockly.Xml.workspaceToDom(Blockly.mainWorkspace)); // exports workspace as pretty xml
302
//  var txt=Blockly.Xml.domToPrettyText(Blockly.Xml.workspaceToDom(Blockly.mainWorkspace)); // exports workspace as pretty xml
285
  console.log(txt);
303
  console.log(txt);
286
  var blob = new Blob([txt], {type: "text/xml"});
304
  var blob = new Blob([txt], {type: "text/xml"});
287
  saveAs(blob, "test.blab2");
305
  saveAs(blob, "test.blab2");
288
  }
306
  }
289
 
307
 
290
  function loadBlockly(){
308
  function loadBlockly(){
291
    Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,$("#hiBlocks")[0]); // loads xml from dom into workspace  
309
    Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,$("#hiBlocks")[0]); // loads xml from dom into workspace  
292
  }
310
  }
293
 
311
 
294
    function runCode() {
312
    function runCode() {
295
      // Generate JavaScript code and run it.
313
      // Generate JavaScript code and run it.
296
      window.LoopTrap = 1000;
314
      window.LoopTrap = 1000;
297
      Blockly.JavaScript.INFINITE_LOOP_TRAP =
315
      Blockly.JavaScript.INFINITE_LOOP_TRAP =
Line 301... Line 319...
301
      try {
319
      try {
302
        eval(code);
320
        eval(code);
303
      } catch (e) {
321
      } catch (e) {
304
        alert(e);
322
        alert(e);
305
      }
323
      }
306
    }
324
    }
307
   
325
   
308
 
326
 
309
  </script>
327
  </script>
310
                 
328
                 
311
</head>
329
</head>
312
<body>
330
<body>
313
  <h1>Belle II Masterclass: Describe process &rarr;Run analysis &rarr;Fit results &rarr;Save/load process locally</h1>
331
  <h1>Belle II Masterclass: Describe process &rarr;Run analysis &rarr;Fit results &rarr;Save/load process locally</h1>
314
<!--        <input type="button" onclick="showCode();"  class="mybutton" value="Show JavaScript" /> -->
332
<!--        <input type="button" onclick="showCode();"  class="mybutton" value="Show JavaScript" /> -->
315
        <input type="button" onclick="startTask();"  class="mybutton" value="Run Analysis" />
333
        <input type="button" id="btnstart" onclick="startAction();"  class="mybutton" value="Run Analysis" />
316
        <input type="button" onclick="stopTask();"  class="mybutton" value="Interrupt" />
-
 
-
 
334
     
317
<!--         <input type="button" onclick="switchTask();"  class="mybutton" value="Switch between Diagram and Results" /> -->
335
<!--         <input type="button" onclick="switchTask();"  class="mybutton" value="Switch between Diagram and Results" /> -->
318
        <input type="button" onclick="saveBlockly();"  class="mybutton" value="Save Diagram" />
336
        <input type="button" onclick="saveBlockly();"  class="mybutton" value="Save Diagram" />
319
        <form style="display:inline;"><label for="file-input" class="mybutton" style="">Load Diagram</label>
337
        <form style="display:inline;"><label for="file-input" class="mybutton" style="">Load Diagram</label>
320
        <input type="file" style="visibility:hidden;" id="file-input" onClick="this.form.reset()" data-buttonText="Load Diagram"/></form>
338
        <input type="file" style="visibility:hidden;" id="file-input" onClick="this.form.reset()" data-buttonText="Load Diagram"/></form>
321
        <br/>
339
        <br/>