Facility Control

 View Only
  • 1.  Lock web HTTP triggers

    Posted 06-30-2020 19:51
    I created a custom panel with 3 buttons. If one off the buttons is triggered the panel locks for 20 seconds. It starts a blank canvas with label “Panel locked”. This works fine in when running the full Dashboard software. The panel will be triggered from another workstation using Web HTTP triggers. The custom panel locks in the full Dashboard when triggered through a web trigger but the buttons in the web browser are staying active. Is there a way to lock the web buttons so they can not be triggered for 20 seconds till the panel unlocks?


  • 2.  RE: Lock web HTTP triggers

    Posted 06-30-2020 19:56

    Here is a panel that has a button that locks itself for 5 seconds:

     

    <abs contexttype="opengear" id="_top" keepalive="false" style="">
    <button buttontype="push" height="63" id="button1" left="153" name="lock for 5" top="146" width="194">
    <task tasktype="ogscript">ogscript.setEnabled("button1", false);


    function runLater()
    {
    ogscript.setEnabled("button1", true);
    }

    ogscript.asyncExec(runLater, 5000);</task>
    </button>
    </abs>

     

     


    #DashBoard


  • 3.  RE: Lock web HTTP triggers

    Posted 06-30-2020 21:40

    It works well in a panel but the button in the web browser doesn't lock for 5 seconds.

     


    #DashBoard


  • 4.  RE: Lock web HTTP triggers

    Posted 07-02-2020 14:30

    I found the answer in the manual. It looks like there is no solution to temporary stop a web button from running the scripts on that button.  

    ----

    Simple Web Page Publishing for a CustomPanel

    Pushing one of these buttons will run all of the scripts that are attached to that button in the CustomPanel.

    Note: This is NOT pushing the button in the DashBoard Custom Panel, it is running the scripts on that button.

    ----

    Thank you Ben Gatien for the option to lock a button. This will work for now! I wrote a script that launches a custom donor panel in fullscreen mode with triggers that sends HTTP requests to the master panel. The buttons on the donor panel lock for 20 seconds after pushing a button. 


    #DashBoard


  • 5.  RE: Lock web HTTP triggers

    Posted 07-02-2020 15:24

    Hi Chiel

    If you need to avoid having a button's tasks run regardless of whether they were executed by the button being pushed in the UI or having it triggered remotely, you can also track the last time the task was executed inside of a variable and check that variable against the current time.

    Here's an example of this:

     

    var lastExecution = ogscript.getObject("last-execution");
    var now = new Date().getTime();
    if (lastExecution == null || (now - lastExecution) > 2000)
    {
    ogscript.putObject("last-execution", now);
    ogscript.debug("RUN TASK");
    }
    else
    {
    ogscript.debug("TOO SOON");
    }

     

    Cheers

    James


    #DashBoard


  • 6.  RE: Lock web HTTP triggers

    Posted 07-03-2020 13:29

    Hi James,

    This is a very helpfull function. Thanks for sharing!

    I try to re-create you're example in Visual logic editor (make's more sense for my brain) so I can extened this function but I didn't succeed. Can you show how this is made in Visual logic and make a screenshot.

    Greets,

    Chiel

     


    #DashBoard


  • 7.  RE: Lock web HTTP triggers

    Posted 07-03-2020 18:30

    Hi Chiel

    This type of behavior goes beyond the normal capabilities of visual logic and requires scripting to achieve. If you would like to use visual logic, I would recommend creating utility functions to update the last execution time and check the last execution time and put them in an <api/> block. You can then use visual logic to call those functions to test how long it has been and visual logic to run your tasks:

    function timeSince(key)
    {
    var time = ogscript.getObject(key);
    if (time == null)
    {
    time = 0;
    }
    return Date.now() - time;
    }

    function updateExecutionTime(key)
    {
    var now = Date.now();
    ogscript.putObject(key, now);
    return now;
    }

     

    Using it in visual logic would look like this (note that we pass "updateExecutionTime" into ogscript.debug - this is to work around an existing visual logic bug when calling user functions).

     

    Here is the whole panel - it shows how you can reuse this code on any number of buttons:

    <abs contexttype="opengear" keepalive="true">
    <meta>
    <api>function timeSince(key)
    {
    var time = ogscript.getObject(key);
    if (time == null)
    {
    time = 0;
    }
    return Date.now() - time;
    }

    function updateExecutionTime(key)
    {
    var now = Date.now();
    ogscript.putObject(key, now);
    return now;
    }
    </api>
    </meta>
    <simplegrid cols="2" height="217" left="44" top="38" width="418">
    <button buttontype="push" height="100" left="89" name="Pause for 2 seconds" top="249" width="217">
    <task tasktype="ogscript">


    /*! block id=1002,1003,1007,1008,1005,1006 !*/
    if (timeSince("button-1") &gt;= 2000)
    {
    ogscript.debug(updateExecutionTime("button-1"));
    ogscript.debug("RUN CODE");
    } else {
    ogscript.debug("TOO SOON");
    }
    /*!!
    &lt;block id="1002" type="if" x="283" y="10" w="268" INPUT1="ID:1003" OPERATION="is bigger or equal to" INPUT2="2000" TRUE="ID:1007" FALSE="ID:1006" IGNORE="" /&gt;
    &lt;block id="1003" type="function_timeSince" x="56" y="12" w="243" key="button-1" /&gt;
    &lt;block id="1007" type="ogscript_debug" x="791" y="57" w="243" MESSAGE="ID:1008" next="ID:1005" /&gt;
    &lt;block id="1008" type="function_updateExecutionTime" x="569" y="59" w="243" key="button-1" /&gt;
    &lt;block id="1005" type="ogscript_debug" x="771" y="183" w="243" MESSAGE="RUN CODE" /&gt;
    &lt;block id="1006" type="ogscript_debug" x="508" y="365" w="243" MESSAGE="TOO SOON" /&gt;
    !!*/
    /*!!&lt;checksum&gt;0bf60a85e8710b0de4927554a166d141&lt;/checksum&gt;!!*/</task>
    </button>
    <button buttontype="push" height="100" left="89" name="Pause for 3 seconds" top="249" width="217">
    <task tasktype="ogscript">


    /*! block id=1002,1003,1007,1008,1005,1006 !*/
    if (timeSince("button-2") &gt;= 3000)
    {
    ogscript.debug(updateExecutionTime("button-2"));
    ogscript.debug("RUN MORE CODE");
    } else {
    ogscript.debug("TOO SOON");
    }
    /*!!
    &lt;block id="1002" type="if" x="283" y="10" w="268" INPUT1="ID:1003" OPERATION="is bigger or equal to" INPUT2="3000" TRUE="ID:1007" FALSE="ID:1006" IGNORE="" /&gt;
    &lt;block id="1003" type="function_timeSince" x="56" y="12" w="243" key="button-2" /&gt;
    &lt;block id="1007" type="ogscript_debug" x="791" y="57" w="243" MESSAGE="ID:1008" next="ID:1005" /&gt;
    &lt;block id="1008" type="function_updateExecutionTime" x="569" y="59" w="243" key="button-2" /&gt;
    &lt;block id="1005" type="ogscript_debug" x="771" y="183" w="243" MESSAGE="RUN MORE CODE" /&gt;
    &lt;block id="1006" type="ogscript_debug" x="508" y="365" w="243" MESSAGE="TOO SOON" /&gt;
    !!*/
    /*!!&lt;checksum&gt;4dc19696b68a84026b4b6c18c94bb7ef&lt;/checksum&gt;!!*/</task>
    </button>
    <button buttontype="push" height="100" left="89" name="Pause for 1 second" top="249" width="217">
    <task tasktype="ogscript">


    /*! block id=1002,1003,1007,1008,1005,1006 !*/
    if (timeSince("button-3") &gt;= 1000)
    {
    ogscript.debug(updateExecutionTime("button-3"));
    ogscript.debug("BUTTON 3");
    } else {
    ogscript.debug("TOO SOON");
    }
    /*!!
    &lt;block id="1002" type="if" x="283" y="10" w="268" INPUT1="ID:1003" OPERATION="is bigger or equal to" INPUT2="1000" TRUE="ID:1007" FALSE="ID:1006" IGNORE="" /&gt;
    &lt;block id="1003" type="function_timeSince" x="56" y="12" w="243" key="button-3" /&gt;
    &lt;block id="1007" type="ogscript_debug" x="791" y="57" w="243" MESSAGE="ID:1008" next="ID:1005" /&gt;
    &lt;block id="1008" type="function_updateExecutionTime" x="569" y="59" w="243" key="button-3" /&gt;
    &lt;block id="1005" type="ogscript_debug" x="771" y="183" w="243" MESSAGE="BUTTON 3" /&gt;
    &lt;block id="1006" type="ogscript_debug" x="508" y="365" w="243" MESSAGE="TOO SOON" /&gt;
    !!*/
    /*!!&lt;checksum&gt;bb408629101e061837f863cfcca863b3&lt;/checksum&gt;!!*/</task>
    </button>
    <button buttontype="push" height="100" left="89" name="NO PAUSE" top="249" width="217">
    <task tasktype="ogscript">


    /*! block id=1005 !*/
    ogscript.debug("JUST DO IT");
    /*!!
    &lt;block id="1005" type="ogscript_debug" x="51" y="54" w="243" MESSAGE="JUST DO IT" /&gt;
    !!*/
    /*!!&lt;checksum&gt;e68eec64effcf3752e978b2d3a8c5bf5&lt;/checksum&gt;!!*/</task>
    </button>
    </simplegrid>
    </abs>

     

    Cheers

    James

     


    #DashBoard