Crestron Components Lib - Showcase App

ch5-select: multi selection specific attributes

Emulator Scenario (click to expand)
{
  "cues": [
    {
      "type": "boolean",
      "event": "updateSelection",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_selected",
          "type": "boolean",
          "logic": "toggle"
        },
        {
          "state": "option_4_selected",
          "type": "boolean",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_4_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_4_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_1_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_1_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_2_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_2_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_3_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_3_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_4_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_4_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_5_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_5_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_6_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_6_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_7_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_7_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_8_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_8_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_9_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_9_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_10_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_10_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_11_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_11_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_12_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_12_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_13_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_13_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_14_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_14_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    },
    {
      "type": "b",
      "event": "option_2_15_on_click",
      "trigger": true,
      "actions": [
        {
          "state": "option_2_15_selected",
          "type": "b",
          "logic": "toggle"
        }
      ]
    }
  ],
  "onStart": [
    {
      "type": "b",
      "state": "option_2_selected",
      "value": false
    },
    {
      "type": "b",
      "state": "option_4_selected",
      "value": false
    },
    {
      "type": "string",
      "state": "label_signal_0",
      "logic": "set",
      "value": "Option 0"
    },
    {
      "type": "string",
      "state": "label_signal_1",
      "logic": "set",
      "value": "Option 1"
    },
    {
      "type": "string",
      "state": "label_signal_2",
      "logic": "set",
      "value": "Option 2"
    },
    {
      "type": "string",
      "state": "label_signal_3",
      "logic": "set",
      "value": "Option 3"
    },
    {
      "type": "string",
      "state": "label_signal_4",
      "logic": "set",
      "value": "Option 4"
    },
    {
      "type": "string",
      "state": "label_signal_5",
      "logic": "set",
      "value": "Option 5"
    },
    {
      "type": "string",
      "state": "label_signal_6",
      "logic": "set",
      "value": "Option 6"
    },
    {
      "type": "string",
      "state": "label_signal_7",
      "logic": "set",
      "value": "Option 7"
    },
    {
      "type": "string",
      "state": "label_signal_8",
      "logic": "set",
      "value": "Option 8"
    },
    {
      "type": "string",
      "state": "label_signal_9",
      "logic": "set",
      "value": "Option 9"
    },
    {
      "type": "string",
      "state": "label_signal_1",
      "logic": "set",
      "value": "Option 1"
    },
    {
      "type": "string",
      "state": "label_signal_10",
      "logic": "set",
      "value": "Option 10"
    },
    {
      "type": "string",
      "state": "label_signal_11",
      "logic": "set",
      "value": "Option 11"
    },
    {
      "type": "string",
      "state": "label_signal_12",
      "logic": "set",
      "value": "Option 12"
    },
    {
      "type": "string",
      "state": "label_signal_13",
      "logic": "set",
      "value": "Option 13"
    },
    {
      "type": "string",
      "state": "label_signal_14",
      "logic": "set",
      "value": "Option 14"
    },
    {
      "type": "string",
      "state": "label_signal_15",
      "logic": "set",
      "value": "Option 15"
    }
  ]
}

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": [
      ]
    }
    

Component Configuration (click to expand)
{
  "templatevariables": {
    "id": {
      "multi_select_panel": [
          {"label":"Option 0"},
          {"label":"Option 1"},
          {"label":"Option 2"},
          {"label":"Option 3"},
          {"label":"Option 4"}
        ]
    }
  }
}

Press the Load button to load the configuration.

Ch5 components can be preconfigured with default values for attributes and for templatevariables. The configuration can be done using Ch5Config and its methods:

  • loadConfig(config:TCh5Config) loads a new configuration and overrides the existing one.
  • setAttributeForId(elementId:string, attributeName:string, attributeValue:string) sets an attributeValue for an attributeName of the specified HTML elementId
  • setAttributeForComponent(componentName:string, attributeName:string, attributeValue:string) sets an attributeValue for an attributeName of the specified ch5 component (componentName)
  • setTemplateVarsForId(elementId:string, tempVarsItems:any[]) sets the template variables for the ch5 component having the specified elementId
  • getConfig() returns the current configuration object
  • getAttributesForId(elementId:string):TCh5ConfigAttributes returns the configrued attributes for the component having the specified elementId
  • getAttributesForComponent(componentName:string):TCh5ConfigAttributes returns all configured attributes for the component specified in componentName ( for example 'ch5-button')
  • getTemplateVarsForElementById(elementId:string):TCh5ConfigTemplateVars[] returns the configured template variables for the component having the specified elementId
  • getAttributesForElement(cr:Ch5Common):TCh5ConfigAttributes returns all configured attributes for a ch5 component
  • getTemplateVarsForElement(cr:Ch5Common):TCh5ConfigTemplateVars[] returns all configured templatevariables for a ch5 component


type TCh5ConfigAttributes={
    [attrName:string]: string
}
type TCh5ConfigTemplateVars={
    [varName:string]: string
}
type TCh5Config={
    "attributes": {
        "id": {
            [id:string]:TCh5ConfigAttributes
        },
        "component": {
            [component:string]:TCh5ConfigAttributes
        }
    },
    "templatevariables": {
        "id": {
            [id:string]:TCh5ConfigTemplateVars[]
        }
    }
}

ch5-select: multi selection

Attributes used:

  • - multiselect set to true and it can be used only with mode=panel
  • - ch5-select-option.sendEventOnClick used to select options
  • - receiveStateSelected
  • - signalValueSyncTimeout

Note: Each option select/unselect should be confirmed by receiveStateSelected. If selection is confirmed within signalValueSyncTimeout time, the selection will reset to the last confirmed selections.

In the next demo example only option 2 and 4 will receive receiveStateSelected.

Using receiveStateSelected signal, this btn will trigger option 2 and 4 toggle selection

Multiselect in plain mode

<div class="row">
    <p>
        <strong>Note:</strong> Each option select/unselect should be confirmed by receiveStateSelected.
        If selection is confirmed within signalValueSyncTimeout time, the selection will reset to the
        last confirmed selections. <br><br>
        In the next demo example only option 2 and 4 will receive receiveStateSelected.
    </p>
</div>
<div class="row">
    
    <ch5-select id="multi_select_panel" size="5" indexId="Idx" multiselect mode="panel" noneSelectedPrompt="Select">
         <template>
                <ch5-select-option receiveStateSelected="option_{{Idx}}_selected"
                                    sendEventOnClick="option_{{Idx}}_on_click"
                                    receiveStateLabel="label_signal_{{Idx}}">
                    <span>{{label}}</span>
                </ch5-select-option>
         </template>
    </ch5-select>
    
    <p style="margin-top: 24px;">
        Using receiveStateSelected signal, this btn will trigger option 2 and 4 toggle selection
    </p>
    <p><ch5-button label="Toggle 2 and 4 selection" sendEventOnClick="updateSelection"></ch5-button></p>
</div>

<div class="row">
    <p>
        <strong>Multiselect in plain mode</strong>
    </p>
</div>
<div class="row">
    
    <ch5-select id="multi_select_plain" size="15" indexId="Idx"
                 multiselect noneSelectedPrompt="Select option(s)">
         <template>
                <ch5-select-option receiveStateSelected="option_2_{{Idx}}_selected"
                                    sendEventOnClick="option_2_{{Idx}}_on_click"
                                    receiveStateLabel="label_signal_{{Idx}}">
                    <span>Option {{Idx}}</span>
                </ch5-select-option>
         </template>
    </ch5-select>
    
</div>