Repository navigation
Developer Guide: UI apps and components
Front end applications are webcomponent based using the lit library and Material Design for styling. Our We use a combination of Polymer LIT, Material Design and our own OpenRemote elements. The UI components are published on NPM. The applications themselves are composed of our re-usable modular UI components which can be found in the code base in the ui/component folder, these are also published to NPM.
To work on an app for example the Manager UI then cd into the app/manager app and run the following npm scripts at the same time:
-
npm run modelWatch- Starts a gradle task to watch the modeljavacode for changes and auto generates themodelandrestclienttypescript files and compiles them -
npm run watch- Watches typescript files (including referenced typescript projects) for changes and auto transpiles to javascript -
npm run serve- Starts webpack dev server and serves the web app which can then be accessed athttp://localhost:9000/manager/(NOTE: trailing/is required)
Components are published as ES6 modules (for use in bundlers like webpack) and are also pre-bundled for direct consumption.
This is a quick example of consuming the or-header component.
npm i -S @openremote/or-headerimport '@openremote/or-header';
<or-header logo="${logoImage}">
<div slot="desktop-left">
<a href="/map">Map</a>
<a href="/overview">Overview</a>
</div>
<div slot="desktop-right">
<a>Logout</a>
</div>
<div slot="mobile-top">
<a href="/map">Map</a>
<a>Logout</a>
</div>
<div slot="mobile-bottom">
</div>
</or-header>
Doing development on the UI means working on any of:
- Front end applications
- Front end components and their demos, shared between applications
- Keycloak theme(s) used in authentication screens
You will need the standard tool chain (see Preparing the environment) to be able to build and run the components and apps. Working on the web applications and/or components will also generally require backend services to interact with, you can either:
- Run a Manager instance in an IDE (refer to Setting up an IDE)
- Deploy the Manager using a Docker container (refer to UI Development profile)
If you want to create a new component or app then simply copy an existing one as a template (when creating a component then you may need to create a corresponding demo which acts as a development harness that can be served by webpack dev server - one demo may act as harness for multiple components).
All UI components and apps are located in the ui directory; here you can find the standard OpenRemote web UI components and apps using a monorepo architecture. The code is divided into categories by directory:
-
component- Base OpenRemote JS modules and web components (built using Polymer) these are written as ES6 modules -
app- Built-in OpenRemote web applications (applications can be built with whatever frameworks/libraries are desired) -
demo- Demos of each web component (provides a development harness for developers working on the components)
Typescript is used to provide static typing with the OpenRemote model available in the @openremote/model component package; the components are published to npm under the @openremote scope; see the README in each component for information about each specific component.
Yarn workspaces are used to symlink the OpenRemote packages into a root node_modules directory (refer to the Yarn documentation for more details). Yarn acts as an alternative to npm so please use it.
NPM scripts are used for build and development purposes (the main build tool for the entire code base is gradle so there are gradle tasks that launch NPM scripts - these gradle tasks have the prefix npm followed by the NPM script name e.g. npmBuild).
The following standard NPM scripts are used throughout the components and apps for consistency:
-
clean- Cleans up any build artefacts (typically uses theshxpackage) -
build- Build the component/app ready for publishing/deployment -
test- Run any automated tests -
modelWatch- Starts agradletask to watch thejavamodel code and to run thetypescriptgenerator when changes are detected, the generatedmodelandrestclienttypescript code is then transpiled tojavascript -
modelBuild- Similar tomodelWatchbut just does a onetime build rather than watching for changes -
serve- Startswebpack dev servertypically onhttp://localhost:9000/[app|demo]/ -
watch- Runs the typescript compiler in watch mode with project references (e.g.npx tsc -b -w) to compiletypescriptcode on changes
The above script names should be used in package.json files and then appropriate build.gradle files should be added, see existing components, apps, demos for examples. Typically only the apps need to be built by gradle tasks as typescript should follow project references and compile any dependent components.
Components can be developed and tested in isolation (with dependencies on other components and/or public npm modules as required). Some components have no visuals and provide standard OpenRemote functionality e.g. @openremote/core, whilst others provide visuals that allow interaction with the Manager backend.
If you are working on a map component then please refer to the working on maps.
Apps bring together components and/or public NPM modules and can be written using any framework/library etc that is compatible with web components (see here).
These are apps for development purposes Generally a 1-1 mapping between components and demos; they provide a simple harness for the components that can be used during development and optionally can be deployed to offer component demos.
Source · Documentation · Forum · Issues · Docker Images · OpenRemote Inc.