Crestron Components Lib - Showcase App

ch5-template in template

Emulator Scenario (click to expand)
{
  "cues": [
    {
      "type": "boolean",
      "event": "trigger.toggle_template_visibility",
      "trigger": true,
      "actions": [
        {
          "state": "toggle.template.visibility",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "trigger.template.visibility.for.second.ch5.template",
      "trigger": true,
      "actions": [
        {
          "state": "toggle.template.visibility.for.second.ch5.template",
          "type": "b",
          "logic": "toggle"
        }
      ]
    }
  ],
  "onStart": [
    {
      "state": "trigger.toggle_template_visibility",
      "type": "b",
      "value": true
    },
    {
      "state": "toggle.template.visibility.for.second.ch5.template",
      "type": "b",
      "value": true
    }
  ]
}

Press the Load button to load the scenario.

Press the Run button to run the scenario. You only need to do this if the scenario (the json) has an onStart key.

The Emulator Scenario JSON contains an array of cues and an optional array onStart A cue is defined by: type:string, signal:string, trigger:boolean|string|number, actions:array. An action is defined by: type:string, signal:string, logic:string ... plus other fields ( depending on type)

type for cue or for action can be the string:

  • b or boolean - for a boolean signal
  • n or number or numeric - for a number signal
  • s or string - for a string signal
  • o or object - for an object signal

signal for cue or for action is a string representing the name of the signal:

trigger can be either a fixed value of the same type as the signal, or the string "&change". If it is a fixed value then, when the emulator detects that the signal has changed to the value given in trigger then it also executes the actions for that signal. If the value is the string "&change", regardless of signal type, then the actions are executed on any change in the value of the signal.

logic can be:

  • link - passes the value received on the incoming join through to the outgoing join. Using this between incompatible join types will attempt to cast the value. In the event of a cast failure the value will be set to false, 0 or "" (empty string)
  • set - assigns a specific value to the join. This requires a 5th key of 'value' and the specific value to assign. ie. {"signal":"light_level", "type":"n", "logic": "set","value":5}. If the 5th key is omitted, the default value will be sent (false, 0, "" or {})
  • toggle - (boolean Only) reads the current state and changes it to the opposite state
  • pulse - (boolean Only) value goes high and then low.
  • increment - (Numeric Only) reads the current value of the analog and adds an offset. This logic accepts an optional 5th key of 'offset which determines how many to incrementby. ie. {"signal":"volume_level","type":"n", "logic":"increment","offset":5}. If this 5th key is omitted, the default offset of 1 will be applied.
  • decrement - (Numeric Only) reads the current value of the analog and subtracts an offset. This logic accepts an optional 5th key of 'offset which determines how many to decrement by. ie. {"signal":"volume_level","type":"n", "logic":"decrement","offset":5}. If this 5th key is omitted, the default offset of 1 will be applied.

RCB logic can be accomplished by defining an action containing an object signal of RCB type:
{ "rcb":{ "value": numeric_value, "time": duration_in_ms } }
Scenario example:


    {
      "cues": [
        {
          "type": "boolean",
          "signal": "trigger",
          "trigger": true,
          "actions": [
            {
              "signal": "action1",
              "type": "boolean",
              "logic": "toggle"
            },
            {
                "signal": "rcb_signal",
                "type": "object",
                "logic": "set",
                "value": {
                    "rcb":{
                        "value": 101,
                        "time": 1500
                    }
                }
            }
          ]
        }
      ],
      "onStart": [
      ]
    }
    

Ch5-template inside other templates

The following example shows a ch5-list using a ch5-template. The template used then contains another ch5-template "Content from the second ch5-template" and a ch5-button.

Hide main ch5-template using the "receiveStateShow" attribute.


Hide the second ch5-template (used in all 3 examples here) using the "receiveStateShow" attribute.


    <p>The following example shows a <b>ch5-list</b> using a <b>ch5-template</b>. The template used then contains
        another
        <b>ch5-template</b> <i>"Content from the second ch5-template"</i> and a <b>ch5-button</b>.</p>
    <template id="template-2">
        <p>Content from the second ch5-template</p>
    </template>

    <template id="template-1">
        <ch5-template receiveStateShow="toggle.template.visibility.for.second.ch5.template"
                      templateid="template-2" context="OSTUFF:original.ostuff"></ch5-template>
        <ch5-button type="info" label="original.label From first ch5-template" sendSignalOnClick="original.click"
                    receiveSignalSelected="original.selected"></ch5-button>
    </template>

    <ch5-list size="15" maxHeight="150px" indexId="idx" receiveSignalSize="numXYZ">
        <template>
            <ch5-template templateid="template-1"
                          context="original:xyz_{{idx}}"></ch5-template>
        </template>
    </ch5-list>

    <p>Hide main ch5-template using the <i><b>"receiveStateShow"</b></i> attribute.</p>

    <ch5-toggle value=false sendEventOnClick="trigger.toggle_template_visibility"
                labelOn="Show"
                labelOff="Hide"
                handleShape="rectangle"
                label="Toggle the visibility of the first ch5-template"
                receiveStateValue="toggle.template.visibility"></ch5-toggle>
    <br/>

    <ch5-list size="15" maxHeight="150px" indexId="idx" receiveSignalSize="numXYZ">
        <template>
            <ch5-template receiveStateShow="toggle.template.visibility" templateid="template-1"
                          context="original:xyz_{{idx}}"></ch5-template>
        </template>
    </ch5-list>

    <p>Hide the second ch5-template (used in all 3 examples here) using the <i><b>"receiveStateShow"</b></i>
        attribute.</p>

    <ch5-toggle sendEventOnClick="trigger.template.visibility.for.second.ch5.template"
                labelOn="Show"
                labelOff="Hide"
                handleShape="rectangle"
                receiveStateValue="toggle.template.visibility.for.second.ch5.template"
                label="Toggle the visibility of the second ch5-template"></ch5-toggle>
    <br/>

    <ch5-list size="15" maxHeight="150px" indexId="idx" receiveSignalSize="numXYZ">
        <template>
            <ch5-template templateid="template-1"
                          context="original:xyz_{{idx}}"></ch5-template>
        </template>
    </ch5-list>