2

The Widgets Development Guide of ThingsBoard describes how to develop widgets with JavaScript hooked to the Widget API.

For the development of reusable widget component, I'd like to develop TypeScript Angular components that can be used within widgets, similarly to how Angular components are used in built-in (default) widgets.

For example, here is the template+controller of the Entities hierarchy widget:

<tb-entities-hierarchy-widget 
    [ctx]="ctx">
</tb-entities-hierarchy-widget>
self.onInit = function() {
}

self.onDataUpdated = function() {
    self.ctx.$scope.entitiesHierarchyWidget.onDataUpdated();
}

self.typeParameters = function() {
    return {
        dataKeysOptional: true
    };
}

self.actionSources = function() {
    return {
        'nodeSelected': {
            name: 'widget-action.node-selected',
            multiple: false
        }
    };
}

self.onDestroy = function() {
}

In this widget, everything is delegated to an entitiesHierarchyWidget Angular component with a tb-entities-hierarchy-widget selector.

It seems that the thingsboard-extensions repository can be used for this purpose but the process is largely undocumented.

How can I create a new Angular component and use it within a custom ThingsBoard widget?

DurandA
  • 1,095
  • 1
  • 17
  • 35

1 Answers1

0

I was able to use "extension" Angular components using the following steps:

  • install OpenJDK (tested with v11), Maven and Node.js (I used NVM with Node 16)
  • git clone https://github.com/thingsboard/thingsboard-extensions.git
  • cd thingsboard-extensions
  • build and serve the default included widgets using mvn clean install -P yarn-start

Now the widgets are served from http://localhost:5000/static/widgets/thingsboard-extension-widgets.js and can be included in a normal (ThingsBoard UI) widget. Add http://localhost:5000/static/widgets/thingsboard-extension-widgets.js in resources tab and check Is module. The widget can be included using the angular selector (e.g. <tb-example></tb-example> for the example component).

In order to create your own component, you could use the example component as a starting point.

To customize default ThingsBoard components, it should be possible to copy their source code to things-board and adapt the various imports accordingly. However there were still some import issues after a successful build that I was not able to solve.

DurandA
  • 1,095
  • 1
  • 17
  • 35