source: issm/oecreview/Archive/20545-21336/ISSM-20822-20823.diff@ 21337

Last change on this file since 21337 was 21337, checked in by Mathieu Morlighem, 8 years ago

CHG: added Archive/20545-21336

File size: 16.8 KB
RevLine 
[21337]1Index: ../trunk-jpl/src/m/classes/clusters/generic.js
2===================================================================
3--- ../trunk-jpl/src/m/classes/clusters/generic.js (revision 20822)
4+++ ../trunk-jpl/src/m/classes/clusters/generic.js (revision 20823)
5@@ -45,18 +45,18 @@
6 fprintf(fid,'mpiexec -np %i %s/%s %s %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,executable,EnumToString(solution),cluster.executionpath+'/'+dirname,modelname,modelname,modelname);
7 fclose(fid);
8 } //}}}
9- this.UploadAndRun = function (md,callbackfunction,fid,toolkitsstring,solutionstring,name,runtimename) { //{{{
10+ this.UploadAndRun = function (md,callbackfunction,callbackid,fid,toolkitsstring,solutionstring,name,runtimename) { //{{{
11
12 var request = new XMLHttpRequest();
13- $(".run-button").html(sprintf("%-16s", "CONNECTING...")).prop("disabled", true);
14+ $(callbackid).html(sprintf("%-16s", "CONNECTING...")).prop("disabled", true);
15 request.position = 0; //Keep track of current parsing position in repsonseText
16 request.timeout = 30000;
17 request.ontimeout = function (event) { //{{{
18- $(".run-button").html(sprintf("%-16s", "RUN")).prop("disabled", false);
19+ $(callbackid).html(sprintf("%-16s", "RUN")).prop("disabled", false);
20 } //}}}
21 request.upload.onprogress = function(event) { //{{{
22 var progress = (event.loaded / event.total * 100).toFixed(0);
23- $(".run-button").html(sprintf("%-20s", "UPLOADING: " + progress + "%"));
24+ $(callbackid).html(sprintf("%-20s", "UPLOADING: " + progress + "%"));
25 } //}}}
26 request.onprogress = function (event) { //{{{
27 //Receive updates by parsing message length as a 32-bit hex string of form 0x*09ABCDEF))
28@@ -67,11 +67,11 @@
29 startIndex = endIndex;
30 endIndex = startIndex + chunkSize;
31 if (chunkSize >= 1024) { //Arbitrary maximium size of message (Must be below minimium size of model results)
32- $(".run-button").html(sprintf("%-20s", "DOWNLOADING: " + ((request.responseText.length - request.position) / chunkSize * 100).toFixed(0) + "%")).prop("disabled", true);
33+ $(callbackid).html(sprintf("%-20s", "DOWNLOADING: " + ((request.responseText.length - request.position) / chunkSize * 100).toFixed(0) + "%")).prop("disabled", true);
34 }
35 else if (request.responseText.length >= endIndex) { //Ensure entire chunk is loaded
36 var responseChunk = request.responseText.slice(startIndex, endIndex);
37- $(".run-button").html(responseChunk);
38+ $(callbackid).html(responseChunk);
39 request.position = endIndex;
40 }
41 }
42@@ -95,7 +95,7 @@
43 catch (e) {
44 console.log(e);
45 }
46- $(".run-button").html(sprintf("%-16s", "RUN")).prop("disabled", false);
47+ $(callbackid).html(sprintf("%-16s", "RUN")).prop("disabled", false);
48 callbackfunction();
49 }; //}}}
50
51Index: ../trunk-jpl/src/m/plot/slider.js
52===================================================================
53--- ../trunk-jpl/src/m/plot/slider.js (revision 20822)
54+++ ../trunk-jpl/src/m/plot/slider.js (revision 20823)
55@@ -1,143 +1,179 @@
56-function slider() {
57- //SLIDER - Slider bar with initial value, callback on change, unique name, min/max value range, description message, fill color, widht/height, value precision, value step, and the id of the div to create the slider in.
58- //
59- // Usage:
60- // slider('value',0,'callback',function(value){PlotGreenland(value,0);PlotSlr()},'name','greenland','min',0,'max',100,'message',['Remove ice: ','%'],'color','#BBBBBB','width','100%','height','24px','precision',2,'step',5,'slidersdiv','greenland-sliders');
61+/*
62+ Name:
63+ sliderInit
64+
65+ Description:
66+ Initialize slider corresponding to passed selector with passed value,
67+ minimum and maximum values, step (which is the increment for the
68+ slider), and callback function (which is called when slider is changed).
69+
70+ Options are passed as pairs to the function according to the usage
71+ example below.
72+
73+ Usage:
74+ sliderInit(
75+ 'selector', #some-element,
76+ 'value', 0,
77+ 'min', -1,
78+ 'max', 1,
79+ 'step', 0.1,
80+ 'callback', function(value){someEngineFunction(value)}
81+ );
82+
83+ NOTE: jQuery Mobile will reflect changes to slider in its input "label"
84+ based on the width of the slider. For example, step might be set to
85+ 0.1, but if the width of the slider is too narrow, changes to the
86+ slider will only be reflected in whole numeral increments in the
87+ slider' label. That said, *all* sliders can be adjusted via the
88+ "up" and "down" keys by whatever increment step is set to.
89+*/
90+function sliderInit(){
91+
92+ // Convert arguments to options
93+ var args = Array.prototype.slice.call(arguments);
94+ var options = new pairoptions(args.slice());
95
96- //Convert arguments to options
97- var args = Array.prototype.slice.call(arguments);
98- var options = new pairoptions(args.slice());
99+ // Recover option values
100+ var selector = options.getfieldvalue('selector', '');
101+ var value = options.getfieldvalue('value', 0);
102+ var callback = options.getfieldvalue('callback', function(event, ui){});
103+ var min = options.getfieldvalue('min', 0.6 * value);
104+ var max = options.getfieldvalue('max', 1.4 * value);
105+ var step = options.getfieldvalue('step', 1);
106
107- //Recover option values:
108- var value = options.getfieldvalue('value',0);
109- var callback = options.getfieldvalue('callback',function(){});
110- var name = options.getfieldvalue('name','');
111- var min = options.getfieldvalue('min',0.6*value);
112- var max = options.getfieldvalue('max',1.4*value);
113- var width = options.getfieldvalue('width','auto');
114- var height = options.getfieldvalue('height',32);
115- var message = options.getfieldvalue('message','');
116- var startmessage = options.getfieldvalue('startmessage',message);
117- var middlemessage = options.getfieldvalue('middlemessage',message);
118- var endmessage = options.getfieldvalue('endmessage',message);
119- var color = options.getfieldvalue('color','#bbbbbb');
120- var precision = options.getfieldvalue('precision',3);
121- var step = options.getfieldvalue('step',1);
122- var slidersdiv = options.getfieldvalue('slidersdiv','slidersdiv');
123+ /*
124+ Update slider attributes.
125+
126+ NOTE: Although slider has already been created, need to call slider()
127+ in order to avoid:
128+
129+ Error: cannot call methods on slider prior to
130+ initialization; attempted to call method 'refresh'
131+
132+ Attempted all other methods for intialization of slider widget
133+ from jQuery Mobile, and this is the only one that seemed to work
134+ (see index.php for related markup).
135+ */
136+ $(selector).slider();
137+ $(selector).val(value);
138+ $(selector).attr('min', min);
139+ $(selector).attr('max', max);
140+ $(selector).attr('step', step);
141+ $(selector).on('slidestop', function(event, ui){
142+ callback(parseFloat($(selector).val()));
143+ });
144
145- $('<div class="'+name+'-slider"></div>').appendTo('#'+slidersdiv);
146- $('<div class="info'+name+'">'+startmessage[0]+value.toFixed(precision)+startmessage[1]+'</div>').appendTo('#'+slidersdiv);
147- var info=$('.info'+name);
148- $('.'+name+'-slider').slider({
149- range:'min',
150- value:value,
151- min:min,
152- max:max,
153- step:step,
154- slide:function(event,ui){
155- info.text(middlemessage[0]+ui.value.toFixed(precision)+middlemessage[1]);
156- },
157- stop:function(event,ui){
158- info.text(middlemessage[0]+ui.value.toFixed(precision)+middlemessage[1]);
159- callback(ui.value);
160- info.text(endmessage[0]+ui.value.toFixed(precision)+endmessage[1]);
161- }
162- });
163- $('.'+name+'-slider.ui-slider').css({
164- width:'auto',
165- height:height,
166- background:color,
167- margin:'8px'
168- });
169- $('.'+name+'-slider .ui-slider-handle').css({
170- background:color,
171- height:parseInt(height)+8
172- });
173- $('.'+name+'-slider .ui-slider-range').css({
174- background:color
175- });
176+ /*
177+ NOTE: Slider must be "refreshed" after any JavaScript change to it, as
178+ it is an AJAX object.
179+ */
180+ $(selector).slider('refresh');
181 }
182+/* exported sliderInit, refreshErrorMessages */
183
184-function progress() {
185- //PROGRESS - Progress bar with initial value, unique name, width/height, and the id of the div to create the slider in. One progress per canvas, value/label updated by node transient runs in plot_unit.
186- //
187- // Usage:
188- // progress('value',0,'name','hma','width','100%','height',sliderheight,'progressdiv','hma-progressdiv');
189- //
190- // See also: PLOT_UNIT
191+
192+/*
193+ Name:
194+ sliderMoveInput
195
196- //Convert arguments to options
197- var args = Array.prototype.slice.call(arguments);
198- var options = new pairoptions(args.slice());
199+ Description:
200+ Appends a jQuery Mobile slider input to an element whose selector
201+ adheres to the following protocol,
202+
203+ destination = sliderSelector + '-value'
204+
205+ Usage:
206+ sliderMoveInput('#someSliderSelector');
207+
208+ NOTE: Destination element must, obviously, be hardcoded into markup for a
209+ call to this function to work as expected.
210+*/
211+function sliderMoveInput(selector){
212
213- var value = options.getfieldvalue('value',0);
214- var name = options.getfieldvalue('name','hma');
215- var min = options.getfieldvalue('min',0.6*value);
216- var max = options.getfieldvalue('max',1.4*value);
217- var width = options.getfieldvalue('width','auto');
218- var height = options.getfieldvalue('height',32);
219- var color = options.getfieldvalue('color','#bbbbbb');
220- var progressdiv = options.getfieldvalue('progressdiv','progressdiv');
221+ $(selector).appendTo(selector + '-value');
222+ $(selector).slider('refresh');
223+}
224+
225+/*
226+ value/label updated by node transient runs in plot_unit.
227+*/
228+function progressInit(){
229
230- var canvas = $('#'+name)[0];
231- var progressbar = $('#'+name+'-progressbar');
232- var playbutton = $('#'+name+'-playbutton');
233- var reversebutton = $('#'+name+'-reversebutton');
234- var timelabel = $('#'+name+'-timelabel');
235+ // Convert arguments to options.
236+ var args = Array.prototype.slice.call(arguments);
237+ var options = new pairoptions(args.slice());
238+
239+ // Recover option values
240+ var sim = options.getfieldvalue('sim', '');
241+
242+ var canvas = $(sim + '-canvas')[0];
243+ var progressBar = $(sim + '-controls-slider-progress');
244+ var playButton = $(sim + '-controls-button-play');
245+ var reverseButton = $(sim + '-controls-button-reverse');
246+ var timeText = $(sim + '-controls-text-time');
247+
248+ /*
249+ Update progress bar slider attributes.
250+
251+ NOTE: Although slider has already been created, need to call slider()
252+ in order to avoid:
253+
254+ Error: cannot call methods on slider prior to
255+ initialization; attempted to call method 'refresh'
256+
257+ Attempted all other methods for intialization of slider widget
258+ from jQuery Mobile, and this is the only one that seemed to work
259+ (see index.php for related markup).
260+ */
261+ $(progressBar).slider();
262+ $(progressBar).val(value);
263+ $(progressBar).attr('min', 0);
264+ $(progressBar).attr('max', 1);
265+ $(progressBar).attr('step', 1);
266+ $(progressBar).on('slidestop', function(event, ui){
267+ canvas.movieIncrement = true;
268+ canvas.movieFrame = parseInt($(progressBar).val());
269+ });
270+ $(progressBar).on('change', function(event, ui){
271+ canvas.movieFrame = parseInt($(progressBar).val());
272+ });
273+ $(progressBar).on('slidestart', function(event, ui){
274+ canvas.movieIncrement = false;
275+ canvas.movieFrame = parseInt($(progressBar).val());
276+ });
277
278+ /*
279+ NOTE: Slider must be "refreshed" after any JavaScript change to it, as
280+ it is an AJAX object.
281+ */
282+ $(progressBar).slider('refresh');
283
284- playbutton.click(function() {
285+ // Attach progress bar slider to simulation.
286+ canvas.progressBar = progressBar;
287+
288+ playButton.click(function(){
289 canvas.moviePlay = !canvas.moviePlay;
290- if (canvas.moviePlay) {
291- $("#playButton").html("&#10074&#10074");
292+ if (canvas.moviePlay){
293+ playButton.find("span").removeClass("fa-play");
294+ playButton.find("span").addClass("fa-pause");
295 }
296- else {
297- $("#playButton").html("&#9654");
298+ else{
299+ playButton.find("span").removeClass("fa-pause");
300+ playButton.find("span").addClass("fa-play");
301 }
302 });
303- reversebutton.click(function() {
304+
305+ reverseButton.click(function(){
306 canvas.movieReverse = !canvas.movieReverse;
307 if (canvas.movieReverse) {
308- reversebutton.html("&#9664&#9664");
309+ reverseButton.find("span").removeClass("fa-backward");
310+ reverseButton.find("span").addClass("fa-forward");
311 }
312 else {
313- reversebutton.html("&#9654&#9654");
314+ reverseButton.find("span").removeClass("fa-forward");
315+ reverseButton.find("span").addClass("fa-backward");
316 }
317 });
318- canvas.timeLabel = timelabel;
319
320- $('<div class="'+name+'-progressbar bordered margin-8 padding-8"></div>').prependTo('#'+progressdiv);
321- $('.'+name+'-progressbar').slider({
322- range:'min',
323- value:0,
324- min:0,
325- max:1,
326- step:1,
327- start:function(event,ui){
328- canvas.movieFrame = ui.value;
329- canvas.movieIncrement = false;
330- },
331- slide:function(event,ui){
332- canvas.movieFrame = ui.value;
333- },
334- stop:function(event,ui){
335- canvas.movieFrame = ui.value;
336- canvas.movieIncrement = true;
337- }
338- });
339- $('.'+name+'-progressbar.ui-slider').css({
340- width:'auto',
341- height:height,
342- background:color,
343- margin:'8px'
344- });
345- $('.'+name+'-progressbar .ui-slider-handle').css({
346- background:color,
347- height:parseInt(height)+8
348- });
349- $('.'+name+'-progressbar .ui-slider-range').css({
350- background:'red'
351- });
352-
353- canvas.progressBar = $('.'+name+'-progressbar');
354-}
355+ canvas.timeLabel = timeText;
356+}
357\ No newline at end of file
358Index: ../trunk-jpl/src/m/plot/plot_unit.js
359===================================================================
360--- ../trunk-jpl/src/m/plot/plot_unit.js (revision 20822)
361+++ ../trunk-jpl/src/m/plot/plot_unit.js (revision 20823)
362@@ -245,7 +245,7 @@
363 if (canvas["movieHandler"]) clearInterval(canvas["movieHandler"]);
364 canvas["movieHandler"] = setInterval(function () {
365 node["movieFrame"] = canvas["movieFrame"];
366- if (canvas["moviePlay"]) {
367+ if (canvas["moviePlay"] && canvas["movieIncrement"]) {
368 if (canvas["movieReverse"]) {
369 node["movieFrame"] = (((node["movieFrame"] - 1) % node["movieLength"]) + node["movieLength"]) % node["movieLength"]; //Handle negative modulus
370 }
371@@ -253,15 +253,21 @@
372 node["movieFrame"] = (((node["movieFrame"] + 1) % node["movieLength"]) + node["movieLength"]) % node["movieLength"]; //Handle negative modulus
373 }
374 }
375- if (canvas["timeLabel"]) canvas["timeLabel"].html(node["movieTimestamps"][node["movieFrame"]].toFixed(0) + " " + options.getfieldvalue("movietimeunit","yr"));
376- if (canvas["progressBar"]) canvas["progressBar"].slider("value", node["movieFrame"]);
377+ if (canvas["timeLabel"]) {
378+ canvas["timeLabel"].html(node["movieTimestamps"][node["movieFrame"]].toFixed(0) + " " + options.getfieldvalue("movietimeunit","yr"));
379+ }
380+ if (canvas["progressBar"]) {
381+ canvas["progressBar"].val(node["movieFrame"]);
382+ canvas["progressBar"].slider('refresh');
383+ }
384 node["buffers"] = initBuffers(gl,[node["arrays"][0],node["arrays"][1][node["movieFrame"]],node["arrays"][2]]);
385 canvas["movieFrame"] = node["movieFrame"];
386 }, node["movieInterval"]);
387 if (canvas["progressBar"]) {
388 canvas["movieFrame"] = 0;
389- canvas["progressBar"].slider("value", 0);
390- canvas["progressBar"].slider("option", {max: node["movieLength"]-1});
391+ canvas["progressBar"].val(0);
392+ canvas["progressBar"].attr('max', node["movieLength"]-1);
393+ canvas["progressBar"].slider('refresh');
394 }
395 }
396
397Index: ../trunk-jpl/src/m/solve/solve.js
398===================================================================
399--- ../trunk-jpl/src/m/solve/solve.js (revision 20822)
400+++ ../trunk-jpl/src/m/solve/solve.js (revision 20823)
401@@ -102,10 +102,16 @@
402 toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
403
404 //callback function:
405- function callbackfunction(){}; //default, do nothing if no callback requested.
406- if (options.getfieldvalue('callback',false)){
407- callbackfunction=options.getfieldvalue('callback');
408+ function callbackfunction(){}; //default, do nothing if no callback function requested.
409+ if (options.getfieldvalue('callbackfunction',false)){
410+ callbackfunction=options.getfieldvalue('callbackfunction');
411 }
412+
413+ //callback id:
414+ var callbackid = '.run-button'; //default, update .run-button elements with progress updates.
415+ if (options.getfieldvalue('callbackid',false)){
416+ callbackid=options.getfieldvalue('callbackid');
417+ }
418
419 if (cluster.classname() == 'local'){ //{{{
420
421@@ -130,7 +136,7 @@
422 else { //{{{
423
424 /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
425- cluster.UploadAndRun(md,callbackfunction,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
426+ cluster.UploadAndRun(md,callbackfunction,callbackid,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
427
428 return md;
429
Note: See TracBrowser for help on using the repository browser.