Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Libraries - initial implementation #1225

Merged
merged 11 commits into from
Dec 12, 2021
Merged

Block Libraries - initial implementation #1225

merged 11 commits into from
Dec 12, 2021

Conversation

ghys
Copy link
Member

@ghys ghys commented Dec 10, 2021

This adds a new UI component namespace (ui:blocks) allowing to define user-defined Blockly libraries declaratively using the component/config/slots paradigm and templating for code generation, and ultimately to share them on the Marketplace.
Also adds a dedicated editor for them in the developer tools.

image

Example YAML
uid: blocklibrary_1e0855d1e4
tags: []
props:
  parameters: []
  parameterGroups: []
timestamp: Dec 10, 2021, 4:07:34 AM
component: BlockLibrary
config:
  name: Block Library 2
slots:
  blocks:
    - component: BlockType
      config:
        type: block1
        message0: Do %1 with %2 %3
        args0:
          - type: field_dropdown
            name: OPTION1
            options:
              - - something
                - do_something
              - - something else
                - do_something_else
          - type: field_input
            name: TEXT1
            text: text value
          - type: input_value
            name: NAME
        colour: 180
        previousStatement: ""
        nextStatement: ""
        tooltip: ""
        helpUrl: ""
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{field:OPTION1}}('{{field:TEXT1}}', {{input:NAME:ORDER_NONE}});"
    - component: BlockType
      config:
        type: radius
        message0: area of circle with radius %1
        args0:
          - type: input_value
            name: RADIUS
            check: Number
        colour: 70
        output: ""
        tooltip: Returns the circumference of a circle given its radius
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: 2 * Math.PI * {{input:RADIUS:ORDER_MULTIPLICATION}}
              order: ORDER_MULTIPLICATION
    - component: BlockType
      config:
        type: arc_length
        message0: arc length with angle %1 and radius %2
        args0:
          - type: field_angle
            name: ANGLE
            angle: 45
          - type: input_value
            name: RADIUS
            check: Number
        colour: 50
        output: ""
        tooltip: Returns the length of a arc given its radius and angle
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{function:degrees_to_radians}}({{field:ANGLE:ORDER_ATOMIC}}) * {{input:RADIUS}}"
              order: ORDER_MULTIPLICATION
    - component: BlockType
      config:
        type: only_before_noon
        message0: only before noon do %1 %2
        args0:
          - type: input_dummy
          - type: input_statement
            name: CODE
        colour: 240
        previousStatement: ""
        nextStatement: ""
        tooltip: ""
        helpUrl: ""
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: >-
                if (new Date().getHours() < 12) {
                  {{statements:CODE}}
                }
  functions:
    - component: UtilityFunction
      config:
        name: degrees_to_radians
        code: >-
          function {{name}}(degrees) {
            var pi = Math.PI;
            return degrees * (pi/180);
          }

image

Generated code:
image

ghys added 5 commits December 9, 2021 22:22
Signed-off-by: Yannick Schaus <github@schaus.net>
Signed-off-by: Yannick Schaus <github@schaus.net>
Also adds Block Libraries in the left sidebar menu under Developer Tools
and in the Developer Sidebar.

Signed-off-by: Yannick Schaus <github@schaus.net>
Signed-off-by: Yannick Schaus <github@schaus.net>
Signed-off-by: Yannick Schaus <github@schaus.net>
@relativeci
Copy link

relativeci bot commented Dec 10, 2021

Job #279: Bundle Size — 10.62MB (-6.47%).

861f883 vs 67320e2

Changed metrics (2/8)
Metric Current Baseline
Cache Invalidation 20.96% 15.44%
Modules 1534(-0.13%) 1536
Changed assets by type (1/7)
            Current     Baseline
JS 8.57MB (-7.9%) 9.3MB

View Job #279 report on app.relative-ci.com

ghys added a commit to ghys/openhab-core that referenced this pull request Dec 10, 2021
Related to openhab/openhab-webui#1225.

This add-on handler supports installing block libraries in the
UIComponentRegistry, `ui:blocks` namespace.

It is very similar to the CommunityUIWidgetAddonHandler, as the format
is the same, so are the features and implementation, the only
differences being:

- Supported content type: `application/vnd.openhab.uicomponent;type=blocks`
  (vs. `application/vnd.openhab.uicomponent;type=widget`)
- Discourse category nb.: 76 (vs. 75)
- Inferred Add-on type: "automation" (vs. "ui")

Signed-off-by: Yannick Schaus <github@schaus.net>
@ghys ghys changed the title Blockly Libraries - initial implementation Block Libraries - initial implementation Dec 10, 2021
Allow referencing other utilities in utility functions

Signed-off-by: Yannick Schaus <github@schaus.net>
kaikreuzer pushed a commit to openhab/openhab-core that referenced this pull request Dec 10, 2021
Related to openhab/openhab-webui#1225.

This add-on handler supports installing block libraries in the
UIComponentRegistry, `ui:blocks` namespace.

It is very similar to the CommunityUIWidgetAddonHandler, as the format
is the same, so are the features and implementation, the only
differences being:

- Supported content type: `application/vnd.openhab.uicomponent;type=blocks`
  (vs. `application/vnd.openhab.uicomponent;type=widget`)
- Discourse category nb.: 76 (vs. 75)
- Inferred Add-on type: "automation" (vs. "ui")

Signed-off-by: Yannick Schaus <github@schaus.net>
ghys added 4 commits December 12, 2021 14:15
Signed-off-by: Yannick Schaus <github@schaus.net>
Signed-off-by: Yannick Schaus <github@schaus.net>
Signed-off-by: Yannick Schaus <github@schaus.net>
Signed-off-by: Yannick Schaus <github@schaus.net>
@ghys ghys marked this pull request as ready for review December 12, 2021 14:33
@ghys ghys requested a review from a team as a code owner December 12, 2021 14:33
Signed-off-by: Yannick Schaus <github@schaus.net>
@ghys ghys merged commit 5bf193d into openhab:main Dec 12, 2021
@ghys ghys added enhancement New feature or request main ui Main UI labels Dec 12, 2021
@ghys ghys added this to the 3.2 milestone Dec 12, 2021
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
Related to openhab/openhab-webui#1225.

This add-on handler supports installing block libraries in the
UIComponentRegistry, `ui:blocks` namespace.

It is very similar to the CommunityUIWidgetAddonHandler, as the format
is the same, so are the features and implementation, the only
differences being:

- Supported content type: `application/vnd.openhab.uicomponent;type=blocks`
  (vs. `application/vnd.openhab.uicomponent;type=widget`)
- Discourse category nb.: 76 (vs. 75)
- Inferred Add-on type: "automation" (vs. "ui")

Signed-off-by: Yannick Schaus <github@schaus.net>
GitOrigin-RevId: f641d1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request main ui Main UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant