Facility Control

 View Only
  • 1.  dashboard csv

    Posted 04-16-2019 09:20

    i have a dashboard project that have a button to read csv file and replace a parameter constrain. the csv file contain name and head shot image of reporter. i want to change headshot when i change name in dropdown in dashboard. so in xpression it update headshot according to my name. can anybody help in it iam not familiar with scripting . you find csv file in attachment

     

    https://drive.google.com/file/d/1UbLeRbNJH3MDWSUw1khbZz9hLmMF8Na-/view?usp=sharing 

     

    thank you for your help ..



  • 2.  RE: dashboard csv

    Posted 04-17-2019 19:41

    Hi Sunil.

    There are a number of ways to achieve this.  You will basically want to

    • read your CSV file
    • build-up your list of names in an array
    • create a choice constraint out of the array
    • replace the constraint in your drop-down list with your new one
    • store any other  CSV data you want (either as parameters or as a JSON object)
    • add a task to your drop-down parameter to grab the photo path out of your stored data
    • set a parameter for your 'photo path' to the value from your stored data

     

    Attached is an example that does this with your CSV schema and uses the approach where all of the CSV data is stored as an object.

     

    <abs contexttype="opengear" dblinqport="2222" id="_top">
    <meta>
    <params>
    <param access="1" maxlength="0" name="Selected Photo" oid="Selected_Photo" stateless="true" type="STRING" value="" widget="label"/>
    <param access="1" constrainttype="INT_CHOICE" name="Selected Index" oid="Selected_Index" precision="0" stateless="true" type="INT32" value="-1" widget="combo">
    <constraint key="-1">Nothing Loaded</constraint>
    </param>
    </params>
    </meta>
    <param expand="true" height="39" left="26" oid="Selected_Index" top="29" width="238">
    <task tasktype="ogscript">if (this.getValue() &gt;= 0)
    {
    var csvData = ogscript.getObject('csv-data');
    if (csvData != null &amp;&amp; csvData.length &gt; this.getValue())
    {

    var rowData = csvData[this.getValue()];
    params.setValue('Selected_Photo', 0, rowData.photo);
    }
    }</task>
    </param>
    <param expand="true" height="38" left="22" oid="Selected_Photo" style="size:Small;bg#dark;fg#panelfg;" top="99" width="643">
    <task tasktype="ogscript">//To show a preview, we need to turn the file system path into a URL
    var filePath = this.getValue();
    filePath = filePath.split('\\').join('/');
    filePath = filePath.split(' ').join('%20');
    filePath = 'file:/' + filePath;
    ogscript.setStyle('photo-preview', 'bg-u:' + filePath);</task>
    </param>
    <abs height="115" id="photo-preview" left="673" style="bg-fill:fit;bg#dark;bdr:shadow;" top="22" width="151"/>
    <button buttontype="push" height="44" left="270" name="Load" top="27" width="94">
    <task tasktype="ogscript">function processCSV(fileContent)
    {
    if (fileContent == null)
    {
    ogscript.debug("CAN'T LOAD FILE");
    return;
    }

    var allCSVData = [];
    var nameList = [];

    var rows = fileContent.split('\n');
    var dataByColumn = []; //It is more efficient if we only call "SET" on the parameters once

    for (var r = 1; r &lt; rows.length; r++)
    {
    var cols = rows[r].trim().split(',');
    var csvRow = {};
    csvRow.name = cols[0];
    csvRow.photo = cols[1];
    csvRow.place = cols[2];
    csvRow.place_image = cols[3];
    if (csvRow.name.length &gt; 0)
    {
    allCSVData.push(csvRow);
    nameList.push(csvRow.name);
    }
    }

    ogscript.putObject('csv-data', allCSVData);
    params.replaceConstraint('Selected_Index', params.createIntChoiceConstraint(nameList));
    ogscript.debug("NAMES: " + nameList.length);

    }

    ogscript.asyncPost('Employee_Photo.csv', null, processCSV);</task>
    </button>
    </abs>

    #DashBoard


  • 3.  RE: dashboard csv

    Posted 04-18-2019 05:46

    Very Much Thank you. 


    #DashBoard


  • 4.  RE: dashboard csv

    Posted 04-18-2019 06:52

    hello its working for some time but sometime image field is not updating .... i tried a lot sometime it update in image field but sometime its not any solution 

     


    #DashBoard


  • 5.  RE: dashboard csv

    Posted 04-18-2019 08:03

    thank you its working :) 


    #DashBoard


  • 6.  RE: dashboard csv

    Posted 04-19-2019 07:35

    can i contact with you for further works. if yes how can i contact you :)


    #DashBoard


  • 7.  RE: dashboard csv

    Posted 04-22-2019 13:23

    @sunil

    This forum in the community is our preferred method of contact. We try to respond to the questions here as quickly as possible and the archive if past questions has proven to be quite helpful for new and current users to get the most out of DashBoard.

    Cheers

    James


    #DashBoard