Crestron Components Lib - Showcase App

ch5-template in template with ch5-list

Emulator Scenario (click to expand)
{
  "cues": [
    {
      "type": "boolean",
      "event": "xyz_0.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_0 button clicked"
        },
        {
          "state": "receive.stop_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_1.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_1 button clicked"
        },
        {
          "state": "receive.prevtrack_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_2.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_2 button clicked"
        },
        {
          "state": "receive.play_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_3.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_3 button clicked"
        },
        {
          "state": "receive.nexttrack_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_4.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_4 button clicked"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_5.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_5 button clicked"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_6.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_6 button clicked"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_7.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_7 button clicked"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_8.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_8 button clicked"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_9.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_9 button clicked"
        }
      ]
    },
    {
      "type": "boolean",
      "event": "xyz_10.click",
      "trigger": true,
      "actions": [
        {
          "state": "selected_button_from_list",
          "type": "s",
          "logic": "set",
          "value": "xyz_10 button clicked"
        }
      ]
    },
    {
      "type": "b",
      "event": "4",
      "trigger": true,
      "actions": [
        {
          "state": "4",
          "type": "s",
          "logic": "set",
          "value": "25 degrees Celsius"
        }
      ]
    }
  ],
  "onStart": [
    {
      "state": "selected_button_from_list",
      "type": "s",
      "value": "No buttons from ch5-list have been clicked"
    },
    {
      "state": "numXYZ",
      "type": "n",
      "value": 10
    }
  ]
}

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 used inside of a ch5-list
Ch5-template used with a ch5-list.

The sizes of all lists are received via the numXYZ signal.

DIV: Testing ch5-template inside ch5-list

Ch5-list used inside of a ch5-template
    <h6> Ch5-template used with a ch5-list.</h6>
    <p>The sizes of all lists are received via the numXYZ signal.</p>
    <template id="viewXYZ">
        <ch5-button label="original.label"
                    sendEventOnClick="original.click"
                    receiveStateSelected="original.selected"></ch5-button>
    </template>
    <ch5-list
            maxWidth="300px"
            receiveStateSize="numXYZ"
            orientation="horizontal"
            indexId="idx">
        <template>
            <ch5-template templateid="viewXYZ"
                          context="original:xyz_{{idx}}">
            </ch5-template>
        </template>
    </ch5-list>

    <div id="textcontent" class="b-red"
         data-ch5-textcontent="selected_button_from_list">
        DIV: Testing ch5-template inside ch5-list
    </div>

    <br>
    <h6> Ch5-list used inside of a ch5-template</h6>
    <ch5-template templateid="viewXYZ2"
                  context="original:idx">
    </ch5-template>

    <template id="viewXYZ2">
        <ch5-list
                maxWidth="300px"
                receiveStateSize="numXYZ"
                orientation="horizontal"
                indexId="original">
            <template>
                <div class="xyz">
                    <ch5-button label="xyz_{{original}}.label"
                                sendEventOnClick="xyz_{{original}}.click"
                                receiveStateSelected="xyz_{{original}}.selected"></ch5-button>
                </div>
            </template>
        </ch5-list>
    </template>

ch5-list using a ch5-template which contains another ch5-template with a data-ch5-textcontent attribute
The next example showcases a ch5-list using a ch5-template which contains another ch5-template and a data-ch5-textcontent attribute.

Update content of the third element using data-ch5-textcontent.

    <h6>The next example showcases a ch5-list using a ch5-template which contains another ch5-template and a
        <i>data-ch5-textcontent</i> attribute.</h6>

    <template id="viewOtherStuff">
        <div class="otherStuff"><h4 data-ch5-textcontent="OSTUFF"></h4></div>
    </template>


    <template id="viewXYZ3">
        <div class="xyz">
            <ch5-template templateid="viewOtherStuff" context="OSTUFF:INST"></ch5-template>
            <ch5-button label="xyz_INST.label" sendEventOnClick="xyz_INST.click"
                        receiveStateSelected="xyz_INST.selected"></ch5-button>
        </div>
    </template>

    <div>
        <p>Update content of the <b>third element</b> using data-ch5-textcontent.</p>
        <ch5-button type="info" label="Update content"
                    sendEventOnClick="4"></ch5-button>
    </div>
    <div>
        <ch5-list indexId="idx" receiveStateSize="numXYZ" maxHeight="300px">
            <template>
                <ch5-template templateid="viewXYZ3" context="INST:{{idx}}"></ch5-template>
            </template>
        </ch5-list>
    </div>