As an additional comment ... I keep getting a null response from bname26 - I have no idea why. I added a debug statement to report the bstate value of bname26 and it returns a value of "1" when toggled on ??
Also, 1 step forward 5 steps back...
When I add the suggested code for updating values from a function instead of what I was doing - I thought everything was great. Then I realized a day or two later that the values I loaded to a table (Btable) from the Board Member csv file loads the data and updates the button labels ... it also put the same data to the table (Stable) for the Staff Member list. I know I have a collision of data being read to variables but for the life of me, I can't figure out how to separate the two tables (with each respective table getting data from a separate csv file). I've included the current .grid and csv files for reference.
Once this is all done, I'll be happy to share the results. The project is growing because of the help I've received.
Original Message:
Sent: 11-25-2024 10:43
From: Jerry Burianyk
Subject: Updating variables with getValue and setValue
Hi Richard
Thanks so much, your state example works as suggested. I have run into another issue when I restore the state(s). In this dashboard, all commands are being sent to the application's web server. As such, it is really easy to bombard (hence overload) the server and have commands get ignored/lost (a lot of " Server returned HTTP response code: 503 for URL: http://localhost:5201"). This is definitely the case when I restore the states of the dashboard buttons which in turn, sends commands to the application.
So, the question is...
When I insert a pause in the for loop like this.....
<task tasktype="pause">5000</task>
it doesn't really do anything predictable.
Would it be better to use:
function runLater()
ogscript.asyncExec(runLater, 5000);
TIA
------------------------------
JerryB
Original Message:
Sent: 11-22-2024 09:05
From: Richard Crutwell
Subject: Updating variables with getValue and setValue
To save all the button states I would do this:
var buttonStates = {};for (var i = 1; i <= 18; i++) { var buttonName = 'bname' + i; buttonStates[buttonName] = params.getValue(buttonName, 0); }ogscript.putObject('buttonStates', buttonStates);ogscript.debug(JSON.stringify(buttonStates));
To recall them again:
var buttonStates = ogscript.getObject('buttonStates');for (var i = 1; i <= 18; i++) { var buttonName = 'bname' + i; var savedState = buttonStates[buttonName] || 0; ogscript.debug(typeof savedState); params.setValue(buttonName, 0, savedState);}ogscript.debug("Button states recalled:", buttonStates);
Wayne is here, will pass on the hellos
------------------------------
Richard Crutwell
Ross Video UK
Original Message:
Sent: 11-21-2024 20:41
From: Jerry Burianyk
Subject: Updating variables with getValue and setValue
Brilliant Richard !!!
Thanks - after getting rid of all my typos, I got it to work and kind of follow what's going on. I never really looked at functions before so this was a great lesson. The only thing that puzzles me a bit is the last line - it seems counter intuitive to put the asyncPost at "the end"??
Also, is there a really efficient way to get all the button "states" and save them in a way that I can 'rebuild' after I use the clear button?
TIA
(p.s. you can tell me I've reached my be nice threshold for the last question ... also, if you happen to run across Wayne Davis, say hi from me)
------------------------------
JerryB
Original Message:
Sent: 11-21-2024 06:24
From: Richard Crutwell
Subject: Updating variables with getValue and setValue
Hi Jerry,
The first press of the load button calls the asyncPost
function that creates a separate process to read the file, the calls for param.setValue
continues executing before file processing finishes. Any function that starts with async
in Dashboard will create a separate process whilst other processes continue. The second button press simply updates the params.setValue
with the data from the first call of asyncPost
.
A quick fix however, just place all the calls inside a function that calls after the file has been processed.
Neat looking panel. (^///^)
/*function processCSV(fileContent){if (fileContent == null){ogscript.debug("CAN'T LOAD FILE");return;}var rows = fileContent.split('\n');var dataByColumn = []; //It is more efficient if we only call "SET" on the parameters oncefor (var r = 0; r < rows.length; r++){var cols = rows[r].trim().split(';');for (var c = 0; c < cols.length; c++){if (c >= dataByColumn.length){dataByColumn.push([]); //Add a new column if it wasn't already created}dataByColumn[c][r] = cols[c].trim(); //Push the cell's value into the array of column data at row "r"}}//Now that we have collected all of the data for each column into an array, we can call setAllValues for the array parameterfor (var c = 0; c < dataByColumn.length; c++){params.setAllValues('cols.' + c, dataByColumn[c]); //Set all of the values in the column}}ogscript.asyncPost(params.getValue("filename",0), null, processCSV);; params.setValue('name1', 0, params.getValue('cols.0', 0) + " " + params.getValue('cols.1', 0)); params.setValue('title1', 0, params.getValue('cols.2', 0)); params.setValue('name2', 0, params.getValue('cols.0', 1) + " " + params.getValue('cols.1', 1)); params.setValue('title2', 0, params.getValue('cols.2', 1)); params.setValue('name3', 0, params.getValue('cols.0', 2) + " " + params.getValue('cols.1', 2)); params.setValue('title3', 0, params.getValue('cols.2', 2)); params.setValue('name4', 0, params.getValue('cols.0', 3) + " " + params.getValue('cols.1', 3)); params.setValue('title4', 0, params.getValue('cols.2', 3)); params.setValue('name5', 0, params.getValue('cols.0', 4) + " " + params.getValue('cols.1', 4)); params.setValue('title5', 0, params.getValue('cols.2', 4)); params.setValue('name6', 0, params.getValue('cols.0', 5) + " " + params.getValue('cols.1', 5)); params.setValue('title6', 0, params.getValue('cols.2', 5)); params.setValue('name7', 0, params.getValue('cols.0', 6) + " " + params.getValue('cols.1', 6)); params.setValue('title7', 0, params.getValue('cols.2', 6)); params.setValue('name8', 0, params.getValue('cols.0', 7) + " " + params.getValue('cols.1', 7)); params.setValue('title8', 0, params.getValue('cols.2', 7)); params.setValue('name9', 0, params.getValue('cols.0', 8) + " " + params.getValue('cols.1', 8)); params.setValue('title9', 0, params.getValue('cols.2', 8)); params.setValue('name10', 0, params.getValue('cols.0', 9) + " " + params.getValue('cols.1', 9)); params.setValue('title10', 0, params.getValue('cols.2', 9));; params.setValue('name11', 0, params.getValue('cols.0', 10) + " " + params.getValue('cols.1', 10)); params.setValue('title11', 0, params.getValue('cols.2', 10));; params.setValue('name12', 0, params.getValue('cols.0', 11) + " " + params.getValue('cols.1', 11)); params.setValue('title12', 0, params.getValue('cols.2', 11));; params.setValue('name13', 0, params.getValue('cols.0', 12) + " " + params.getValue('cols.1', 12)); params.setValue('title13', 0, params.getValue('cols.2', 12));; params.setValue('name14', 0, params.getValue('cols.0', 13) + " " + params.getValue('cols.1', 13)); params.setValue('title14', 0, params.getValue('cols.2', 13));; params.setValue('name15', 0, params.getValue('cols.0', 14) + " " + params.getValue('cols.1', 14)); params.setValue('title15', 0, params.getValue('cols.2', 14));; params.setValue('name16', 0, params.getValue('cols.0', 15) + " " + params.getValue('cols.1', 15)); params.setValue('title16', 0, params.getValue('cols.2', 15));; params.setValue('name17', 0, params.getValue('cols.0', 16) + " " + params.getValue('cols.1', 16)); params.setValue('title17', 0, params.getValue('cols.2', 16));; params.setValue('name18', 0, params.getValue('cols.0', 17) + " " + params.getValue('cols.1', 17)); params.setValue('title18', 0, params.getValue('cols.2', 17));; var isRemote1 = params.getValue('cols.2', 0);*/ function processCSV(fileContent) { if (fileContent == null) { ogscript.debug("CAN'T LOAD FILE"); return; } var rows = fileContent.split('\n'); var dataByColumn = []; for (var r = 0; r < rows.length; r++) { var cols = rows[r].trim().split(';'); for (var c = 0; c < cols.length; c++) { if (c >= dataByColumn.length) { dataByColumn.push([]); } dataByColumn[c][r] = cols[c].trim(); } } for (var c = 0; c < dataByColumn.length; c++) { params.setAllValues('cols.' + c, dataByColumn[c]); } updateValues();}function updateValues() { params.setValue('name1', 0, params.getValue('cols.0', 0) + " " + params.getValue('cols.1', 0)); params.setValue('title1', 0, params.getValue('cols.2', 0)); params.setValue('name2', 0, params.getValue('cols.0', 1) + " " + params.getValue('cols.1', 1)); params.setValue('title2', 0, params.getValue('cols.2', 1)); params.setValue('name3', 0, params.getValue('cols.0', 2) + " " + params.getValue('cols.1', 2)); params.setValue('title3', 0, params.getValue('cols.2', 2)); params.setValue('name4', 0, params.getValue('cols.0', 3) + " " + params.getValue('cols.1', 3)); params.setValue('title4', 0, params.getValue('cols.2', 3)); params.setValue('name5', 0, params.getValue('cols.0', 4) + " " + params.getValue('cols.1', 4)); params.setValue('title5', 0, params.getValue('cols.2', 4)); params.setValue('name6', 0, params.getValue('cols.0', 5) + " " + params.getValue('cols.1', 5)); params.setValue('title6', 0, params.getValue('cols.2', 5)); params.setValue('name7', 0, params.getValue('cols.0', 6) + " " + params.getValue('cols.1', 6)); params.setValue('title7', 0, params.getValue('cols.2', 6)); params.setValue('name8', 0, params.getValue('cols.0', 7) + " " + params.getValue('cols.1', 7)); params.setValue('title8', 0, params.getValue('cols.2', 7)); params.setValue('name9', 0, params.getValue('cols.0', 8) + " " + params.getValue('cols.1', 8)); params.setValue('title9', 0, params.getValue('cols.2', 8)); params.setValue('name10', 0, params.getValue('cols.0', 9) + " " + params.getValue('cols.1', 9)); params.setValue('title10', 0, params.getValue('cols.2', 9));; params.setValue('name11', 0, params.getValue('cols.0', 10) + " " + params.getValue('cols.1', 10)); params.setValue('title11', 0, params.getValue('cols.2', 10));; params.setValue('name12', 0, params.getValue('cols.0', 11) + " " + params.getValue('cols.1', 11)); params.setValue('title12', 0, params.getValue('cols.2', 11));; params.setValue('name13', 0, params.getValue('cols.0', 12) + " " + params.getValue('cols.1', 12)); params.setValue('title13', 0, params.getValue('cols.2', 12));; params.setValue('name14', 0, params.getValue('cols.0', 13) + " " + params.getValue('cols.1', 13)); params.setValue('title14', 0, params.getValue('cols.2', 13));; params.setValue('name15', 0, params.getValue('cols.0', 14) + " " + params.getValue('cols.1', 14)); params.setValue('title15', 0, params.getValue('cols.2', 14));; params.setValue('name16', 0, params.getValue('cols.0', 15) + " " + params.getValue('cols.1', 15)); params.setValue('title16', 0, params.getValue('cols.2', 15));; params.setValue('name17', 0, params.getValue('cols.0', 16) + " " + params.getValue('cols.1', 16)); params.setValue('title17', 0, params.getValue('cols.2', 16));; params.setValue('name18', 0, params.getValue('cols.0', 17) + " " + params.getValue('cols.1', 17)); params.setValue('title18', 0, params.getValue('cols.2', 17));; var isRemote1 = params.getValue('cols.2', 0);}ogscript.asyncPost(params.getValue("filename", 0), null, processCSV);
------------------------------
Richard Crutwell
Ross Video UK
Original Message:
Sent: 11-20-2024 17:22
From: Jerry Burianyk
Subject: Updating variables with getValue and setValue
Hi Richard - thanks for the sample.
I see (kind of ....) what you are doing here. I'm doing something similar but loading the csv into a 3 column table and then getting the values from the table. So let me study this for a bit before I throw in the towel. I'll upload the .grid file so you can take a look and just shake your head about how badly and inefficiently the coding is ¯\_(ツ)_/¯
(change the ext to .grid)
I'm mostly happy with how the function of the panel is working but I know there are massive inefficiencies all through. I've cobbled this together with examples and help from others and just keep trying to improve my understanding of Dashboard.
Cheers,
(p.s. Be gentle, I know not what I'm doing here)
------------------------------
JerryB
Original Message:
Sent: 11-20-2024 08:06
From: Richard Crutwell
Subject: Updating variables with getValue and setValue
Can you send your code over an I'll take a look?
Here is an example for loading a CSV and populating labels: https://public.3.basecamp.com/p/GLoyYciCMDvs1NGtwnfZZmfN
<abs contexttype="opengear" id="_top" keepalive="false"> <meta> <params> <param access="1" maxlength="0" name="Flie Path" oid="file.path" type="STRING" value="avangers.csv" widget="file-picker"/> <param access="1" maxlength="0" name="Label 1" oid="label.1" type="STRING" value="Iron Man" widget="label"/> <param access="1" maxlength="0" name="Label 2" oid="label.2" type="STRING" value="Tony " widget="label"/> <param access="1" maxlength="0" name="Label 3" oid="label.3" type="STRING" value="Stark" widget="label"/> </params> </meta> <meta> <color id="color.1" value="#000B58"/> <color id="color.2" value="#003161"/> <color id="color.3" value="#006A67"/> <color id="color.4" value="#FFF4B7"/> <style id="btn.style.1" value="fg#color.4;t:bg#selectbg;f:bg#color.2;"/> <style id="bkgnd.1" value="bg#color.1;bdr:round;bdr#color.1;"/> <style id="bkgnd.2" value="bg#color.2;bdr:round;bdr#color.2;"/> <style id="bkgnd.3" value="bg#color.3;bdr:round;bdr#color.3;"/> <style id="bkgnd.4" value="bg#color.4;bdr:round;bdr#color.4;"/> <style id="text.1" value="bdr:round;bdr#color.3;fg#color.4;size:Big;"/> </meta> <meta> <api>function loadFromCsv(fileContent) { if (fileContent == null) { ogscript.debug("CAN'T LOAD FILE"); return; } ogscript.debug(fileContent); var rows = fileContent.split('\n'); var cols = rows[1].trim().split(','); params.setValue('label.1', 0, cols[0]); params.setValue('label.2', 0, cols[1]); params.setValue('label.3', 0, cols[2]);}</api> </meta> <abs height="447" left="20" style="style:bkgnd.1;" top="20" width="640"> <abs height="404" left="20" style="style:bkgnd.2;" top="19" width="600"> <param expand="true" height="63" left="22" oid="file.path" showlabel="false" style="style:text.1;" top="18" width="561"> <config key="w.remove">false</config> <config key="w.save">false</config> <config key="w.filetypes">csv,.csv</config> <config key="w.absolute">false</config> <task tasktype="ogscript">//var filepath = params.getValue('file.path', 0);//var file = ogscript.asyncPost(filepath, null, loadFromCsv);</task> </param> <simplegrid cols="2" height="205" hspace="5" left="18" rows="3" top="98" vspace="5" width="564"> <label name="Label 1" style="style:text.1;txt-align:center;"/> <param expand="true" oid="label.1" showlabel="false" style="style:text.1;"/> <label name="Label 2" style="style:text.1;txt-align:center;"/> <param expand="true" oid="label.2" showlabel="false" style="style:text.1;"/> <label name="Label 3" style="style:text.1;txt-align:center;"/> <param expand="true" oid="label.3" showlabel="false" style="style:text.1;"/> </simplegrid> <button buttontype="push" height="63" left="16" name="Pull Labels from CSV" style="bg#color.3;bdr:round;size:Big;font:bold;fg#color.4;" top="316" width="567"> <task tasktype="ogscript">var filepath = params.getValue('file.path', 0);var file = ogscript.asyncPost(filepath, null, loadFromCsv);</task> </button> </abs> </abs></abs>
------------------------------
Richard Crutwell
Ross Video UK
Original Message:
Sent: 11-19-2024 16:10
From: Jerry Burianyk
Subject: Updating variables with getValue and setValue
I'll try and describe this as best as possible:
Generally,
I have a Button that will load a table from a csv file (based off the example samples) ....
Under the ogscript task, the csv file is processed ...
the name list params are set by the
ogscript.asyncPost(params.getValue("filename",0), null, processCSV);;
params.setValue('name1', 0, params.getValue('cols.0', 0) + " " + params.getValue('cols.1', 0));
etc..
Now here's where problems sometimes (mostly) occur ....
elsewhere in the coding ... I take the result of the setValue and then send/assign it to a label on the dashboard panel.
The problem....
Sometimes (actually almost all the time) ... it takes 2 (two) button pushes to do this.
Visually, it loads the table on the first hit of the button ... then, if I hit the button a second time, I see the Label(s) get populated with the content.
I expect that I'm doing something wrong in the order of things but is there a way to ensure that I need to only click the "Load" button once?
Rename the labels under the same Task ??
TIA for any hints
------------------------------
JerryB
------------------------------