Facility Control

 View Only
  • 1.  Table from Rest API Webservice

    Posted 08-08-2019 18:29

    Hello All, 

    I am working through learning Dashboard. I am a beginner programmer, but committed to learning. 

    I ultimately wish to build an Xpression op assist panel that will retrieve StatCrew, Dak All-Sport5000, and Excel data and present it in an easy to use interface. So far, I have a sql database that contains my rosters and season stats. I also have a php web api that retrieves the data in a json format. That part was pretty easy.

    Right now, I am trying to understand how to populate a table using json. I started with the example in the thread here -API From Rundwon Creator- https://support.rossvideo.com/hc/en-us/community/posts/360040041991-API-from-Rundwon-Creator
    I can not get the table to populate and I'm still not sure why after hours of searching and reading. Below is my grid and a sample of the data follows. 
    Can anyone point me in a direction?

    <abs contexttype="opengear">
    <meta>
    <params>
    <param access="1" constrainttype="INT_NULL" name="Jersey Number" oid="params.Jersey" precision="0" stateless="true" type="INT16_ARRAY" value="1" widget="default"/>
    <param access="1" maxlength="0" name="First Name" oid="params.FirstName" precision="0" stateless="true" type="STRING_ARRAY" value=" " widget="default">
    <value/>
    </param>
    <param access="1" constrainttype="STRING_CHOICE" name="Table" oid="params.table" precision="0" stateless="true" type="INT16" value="1" widget="table">
    <constraint>params.Jersey</constraint>
    <constraint>params.FirstName</constraint>
    </param>
    </params>
    </meta>
    <meta>
    <api immediate="true">function handleResults(resultData)
    {
    if (resultData == null)
    {
    ogscript.debug("NO DATA");
    }
    else
    {
    ogscript.debug("Data Found");
    var resultsAsObject = JSON.parse(resultData);
    //ogscript.debug(resultData);
    var jerseys = [];
    var firstnames = [];
    for (var i = 0; i &lt; resultsAsObject.length; i++)
    {
    jerseys.push(resultsAsObject[i]["jersey"]);
    //ogscript.debug(resultsAsObject[i]["jersey"]);
    firstnames.push(resultsAsObject[i]["fName"]);
    //ogscript.debug(resultsAsObject[i]["fName"]);
    }

    //We need to make sure we always have at least one element in a parameter
    if (jerseys.length == 0)
    {
    jerseys.push("");
    firstnames.push("");
    ogscript.debug("Jersey Length= " +jerseys.length)
    }

    ogscript.debug("Setting All Values...");
    ogscript.debug(jerseys);
    ogscript.debug(firstnames);
    params.setAllValues('params.Jersey', jerseys);
    params.setAllValues('params.FirstName', firstnames);
    }
    }

    function fetchRoster()
    {
    ogscript.asyncPost('http://192.168.1.137:8080/read.php', null, handleResults);
    }</api>
    <ogscript handles="onload">/*! block id=1000 !*/
    fetchRoster()
    /*!!
    &lt;block id="1000" type="function_fetchRoster" x="10" y="100" w="243" /&gt;
    !!*/
    /*!!&lt;checksum&gt;97f7d234533212934b6c5e069b1d31b0&lt;/checksum&gt;!!*/</ogscript>
    </meta>
    <button buttontype="push" height="81" left="15" name="Refresh" top="17" width="172">
    <task tasktype="ogscript">/*! block id=1001 !*/
    fetchRoster()
    /*!!
    &lt;block id="1001" type="function_fetchRoster" x="10" y="100" w="243" /&gt;
    !!*/
    /*!!&lt;checksum&gt;2cd1be6cfe34db06a453cd5214acd084&lt;/checksum&gt;!!*/</task>
    </button>
    <param expand="true" height="209" left="17" oid="params.table" showlabel="false" top="117" width="488"/>
    </abs>

    Sample Data- 

    [{"id":"1","jersey":"1","fName":"Harry","lName":"Harris","Positions1":"RB","Gr":"Sr."},{"id":"2","jersey":"1","fName":"Harry","lName":"Harris","Positions1":"DE","Gr":"Sr."},{"id":"3","jersey":"2","fName":"Julius","lName":"Jones","Positions1":"WR","Gr":"Sr."},{"id":"4","jersey":"3","fName":"Kai","lName":"Gordon","Positions1":"WR","Gr":"Sr."},{"id":"5","jersey":"3","fName":"Mehki","lName":"Gordon","Positions1":"WR","Gr":"Sr."},{"id":"6","jersey":"4","fName":"Robby","lName":"Levak (C)","Positions1":"QB","Gr":"Sr."},{"id":"7","jersey":"5","fName":"Jordan","lName":"Jones","Positions1":"WR","Gr":"Sr."},{"id":"8","jersey":"6","fName":"Jon","lName":"Henderson","Positions1":"WR","Gr":"Fr."},{"id":"9","jersey":"6","fName":"Jon","lName":"Henderson","Positions1":"WR","Gr":"Fr."},{"id":"10","jersey":"7","fName":"Aidan","lName":"Bell","Positions1":"DE","Gr":"Sr."},{"id":"11","jersey":"8","fName":"Jason","lName":"Tuttle","Positions1":"WR","Gr":"Jr."},{"id":"12","jersey":"9","fName":"Jason","lName":"Tuttle","Positions1":"QB","Gr":"Jr."},{"id":"13","jersey":"9","fName":"Jahdon","lName":"Wimbush","Positions1":"WR","Gr":"So."},{"id":"14","jersey":"10","fName":"Joel","lName":"Jones","Positions1":"WR","Gr":"So."},{"id":"15","jersey":"11","fName":"Cody","lName":"Pestino","Positions1":"WR","Gr":"Sr."},{"id":"16","jersey":"12","fName":"Billy","lName":"Levak","Positions1":"QB","Gr":"So."},{"id":"17","jersey":"13","fName":"Collin","lName":"Flynn","Positions1":"OLB","Gr":"Sr."},{"id":"18","jersey":"13","fName":"Matthew","lName":"Hayes","Positions1":"WR","Gr":"Fr."},{"id":"19","jersey":"14","fName":"Jacob","lName":"Kraus","Positions1":"QB","Gr":"Sr."},{"id":"20","jersey":"15","fName":"Ricky","lName":"McLeod","Positions1":"QB","Gr":"So."},{"id":"21","jersey":"16","fName":"Brendan","lName":"O'donnell (C)","Positions1":"WR","Gr":"Sr."},{"id":"22","jersey":"16","fName":"Cooper","lName":"Rusk","Positions1":"WR","Gr":"Fr."},{"id":"23","jersey":"17","fName":"Deandre","lName":"Love","Positions1":"WR","Gr":"Jr."}]

     

    Thanks for looking!

    -Chris

     



  • 2.  RE: Table from Rest API Webservice

    Posted 08-09-2019 19:10

    The following is a demo panel that can read different json files and put the data in a table.

    Here is some sample data you can put in a file:

    [{
        "team":"Eagles",
        "sport":"Flight",
        "players": [
            "Eddie",
            "Sam",
            "Steagle"
        ]
     },
     {
        "team":"Dogs",
        "sport":"Fetch",
        "players": [
            "Rover",
            "Fido",
            "Rex"
        ]
     }]

    Once you have that data in the file, make a panel with the following code.   Put the file name in the top entry box, and this code will read it and display it in a table.

     

     

    <?xml version="1.0" encoding="UTF-8"?><abs contexttype="opengear" id="_top">
    <meta>
    <params>
    <param access="1" maxlength="0" name="Data URL" oid="Data_URL" stateless="true" type="STRING" value="" widget="text"/>
    <param access="1" name="Structured Data" oid="struct-data" stateless="true" type="STRUCT_ARRAY" widget="table">
    <value>
    <subparam access="1" maxlength="0" name="name" suboid="team" type="STRING" value="" widget="default"/>
    </value>
    </param>
    </params>
    </meta>
    <param expand="true" height="61" left="18" oid="Data_URL" right="17" top="20">
    <task tasktype="ogscript">function callback(resultStr)
    {
    if (resultStr != null)
    {
    var json = JSON.parse(resultStr);
    var a = null;
    if (Array.isArray(json))
    {
    a = json;
    }
    else
    {
    a = [];
    a.push(json);
    }
    params.setAllValues('struct-data', a);
    }
    }
    params.resetAllValues('struct-data');
    ogscript.asyncPost(params.getValue('Data_URL', 0), null, callback);</task>
    </param>


    <param bottom="10" expand="true" left="19" oid="struct-data" right="9" showlabel="false" top="94"/>
    </abs>

     

     

    Here is some sample data you can put in a file


    #DashBoard