100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Improved client startup procedure, added loader busy indicator
Christian Bauer74b16f5269bc
diff --git a/client/src/main/java/org/openremote/app/client/AppEntryPoint.java b/client/src/main/java/org/openremote/app/client/AppEntryPoint.javaindex 3970cfa4b..200f05740 100644--- a/client/src/main/java/org/openremote/app/client/AppEntryPoint.java+++ b/client/src/main/java/org/openremote/app/client/AppEntryPoint.java@@ -21,30 +21,41 @@ package org.openremote.app.client;import com.google.gwt.core.client.GWT;-import java.util.logging.Logger;-public class AppEntryPoint implements com.google.gwt.core.client.EntryPoint {- private static final Logger LOG = Logger.getLogger(AppEntryPoint.class.getName());-protected final ManagerGinjector injector = GWT.create(ManagerGinjector.class);- @Override- public void onModuleLoad() {- LOG.info("App GWT module loaded");- dispatchLoadedEvent();- }-protected void startManager() {injector.getAppController().start();}- public native void dispatchLoadedEvent() /*-{- $wnd.addEventListener("StartManager", function() {- [email protected]::startManager()();- }.bind(this));+ protected void stopManager() {+ injector.getAppController().stop();+ }+ @Override+ public native void onModuleLoad() /*-{+ console.log("App GWT module loaded")++ // Add a one-time event listener that starts the manager+ var startEventListener = function(e) {+ if (!$wnd.openremote.INSTANCE.error) {+ [email protected]::startManager()();+ }+ e.currentTarget.removeEventListener("StartManager", startEventListener);+ }.bind(this);+ $wnd.addEventListener("StartManager", startEventListener);++ // Add a one-time event listener that stops the manager+ var stopEventListener = function(e) {+ [email protected]::stopManager()();+ e.currentTarget.removeEventListener("AppError", stopEventListener);+ }.bind(this);+ $wnd.addEventListener("AppError", stopEventListener);++ // Let others know jsinterop components are loaded$wnd.dispatchEvent(new CustomEvent("AppLoaded"));}-*/;+}diff --git a/client/src/main/java/org/openremote/app/client/app/AppController.java b/client/src/main/java/org/openremote/app/client/app/AppController.javaindex 2440d2d0d..75878145e 100644--- a/client/src/main/java/org/openremote/app/client/app/AppController.java+++ b/client/src/main/java/org/openremote/app/client/app/AppController.java@@ -26,4 +26,6 @@ public interface AppController {void goTo(Place place);void start();++ void stop();}diff --git a/client/src/main/java/org/openremote/app/client/app/AppControllerImpl.java b/client/src/main/java/org/openremote/app/client/app/AppControllerImpl.javaindex 99a3c94fa..6afe6401a 100644--- a/client/src/main/java/org/openremote/app/client/app/AppControllerImpl.java+++ b/client/src/main/java/org/openremote/app/client/app/AppControllerImpl.java@@ -21,9 +21,9 @@ package org.openremote.app.client.app;import com.google.gwt.place.shared.Place;import com.google.gwt.place.shared.PlaceHistoryHandler;-import com.google.gwt.user.client.Window;import com.google.gwt.user.client.ui.RootPanel;import com.google.inject.Provider;+import elemental2.dom.DomGlobal;import org.openremote.app.client.Environment;import org.openremote.app.client.event.ShowFailureEvent;import org.openremote.app.client.event.ShowInfoEvent;@@ -31,11 +31,15 @@ import org.openremote.app.client.event.ShowSuccessEvent;import org.openremote.app.client.event.SubscriptionFailureEvent;import org.openremote.app.client.toast.Toast;import org.openremote.app.client.toast.Toasts;+import org.openremote.model.event.bus.EventListener;import javax.inject.Inject;+import java.util.logging.Logger;public class AppControllerImpl implements AppController, AppView.Presenter {+ private static final Logger LOG = Logger.getLogger(AppControllerImpl.class.getName());+protected final AppView appView;protected final Environment environment;protected final PlaceHistoryHandler placeHistoryHandler;@@ -103,9 +107,15 @@ public class AppControllerImpl implements AppController, AppView.Presenter {@Overridepublic void start() {- Window.setTitle("OpenRemote Manager");- RootPanel.get().add(appView);+ LOG.info("Starting manager");appView.setPresenter(this);+ RootPanel.get().add(appView);placeHistoryHandler.handleCurrentHistory();}++ @Override+ public void stop() {+ LOG.info("Stopping manager");+ RootPanel.get().remove(appView);+ }}diff --git a/client/src/main/java/org/openremote/app/client/app/AppViewImpl.java b/client/src/main/java/org/openremote/app/client/app/AppViewImpl.javaindex 8318d786a..b8d94bac1 100644--- a/client/src/main/java/org/openremote/app/client/app/AppViewImpl.java+++ b/client/src/main/java/org/openremote/app/client/app/AppViewImpl.java@@ -61,7 +61,6 @@ public class AppViewImpl extends Composite implements AppView {@Injectpublic AppViewImpl() {initWidget(ui.createAndBindUi(this));-}@Overridediff --git a/client/src/main/java/org/openremote/app/client/app/FooterViewImpl.ui.xml b/client/src/main/java/org/openremote/app/client/app/FooterViewImpl.ui.xmlindex 9b8d9c333..efec9cd39 100644--- a/client/src/main/java/org/openremote/app/client/app/FooterViewImpl.ui.xml+++ b/client/src/main/java/org/openremote/app/client/app/FooterViewImpl.ui.xml@@ -17,7 +17,7 @@}.logo {- height: 30px;+ margin-right: 1em;}.brand {@@ -40,17 +40,6 @@<g:HTMLPanel styleName="{style.logoItem}"><g:HTMLPanel styleName="layout horizontal center {style.logo}">-<!--- <svg style="pointer-events: none; display: block; height: 100%;" viewBox="0 0 24 24"- preserveAspectRatio="xMidYMid meet">- <path fill="#C4D600"- d="M11.93,21.851c-5.551,0-10.066-4.515-10.066-10.065h2.108c0,4.388,3.57,7.958,7.958,7.958 c4.387,0,7.958-3.57,7.958-7.958c0-4.388-3.57-7.958-7.958-7.958V1.72c5.55,0,10.066,4.517,10.066,10.066 C21.996,17.336,17.48,21.851,11.93,21.851L11.93,21.851z"/>- <path fill="#4E9D2D"- d="M10.406,19.088c-1.95-0.406-3.626-1.549-4.717-3.215s-1.469-3.66-1.062-5.61 c0.407-1.951,1.55-3.626,3.217-4.718c1.667-1.092,3.659-1.469,5.61-1.062c4.027,0.84,6.62,4.799,5.779,8.825l-2.063-0.429 c0.603-2.889-1.257-5.73-4.147-6.333c-1.4-0.292-2.829-0.022-4.025,0.762C7.802,8.091,6.982,9.293,6.69,10.693 c-0.291,1.398-0.021,2.828,0.762,4.024c0.783,1.196,1.985,2.016,3.385,2.307L10.406,19.088L10.406,19.088z"/>- <path fill="#1D5632"- d="M11.936,16.622c-0.082,0-0.164-0.001-0.245-0.004c-1.29-0.065-2.478-0.628-3.346-1.585 c-0.868-0.958-1.31-2.195-1.246-3.487l2.104,0.105c-0.036,0.728,0.214,1.427,0.704,1.967c0.488,0.54,1.16,0.858,1.888,0.894 c0.725,0.033,1.426-0.213,1.966-0.703c0.541-0.489,0.858-1.159,0.895-1.887c0.075-1.503-1.088-2.787-2.591-2.862l0.105-2.104 c2.664,0.132,4.724,2.406,4.592,5.07c-0.064,1.291-0.628,2.478-1.585,3.345C14.28,16.183,13.137,16.622,11.936,16.622L11.936,16.622 z"/>- </svg>---><div class="{widgetStyle.Hyperlink} {style.brand}"><g:Anchor href="https://openremote.com/">OpenRemote Inc.</g:Anchor></div>diff --git a/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java b/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.javaindex a78ab5d6f..df380aef8 100644--- a/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java+++ b/client/src/main/java/org/openremote/app/client/i18n/ManagerMessages.java@@ -29,8 +29,6 @@ public interface ManagerMessages extends Messages {String logout();- String sessionTimedOut();-String map();String assets();diff --git a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.propertiesindex 29808aa86..4442a867f 100644--- a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties+++ b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties@@ -67,7 +67,6 @@ roleLabel[write-rules]=Write rulesets (NOTE: effectively super-user access!)noteRolesAfterCreate=You can assign access roles after creating the user.showMoreAssets=Show more assetsemptyAsset=No assets found.-sessionTimedOut=Your session timed out. Please close or reload this browser window.description=DescriptionunsupportedAttributeType=Not implemented attribute type: {0}unsupportedMetaItemType=Not implemented meta item type : {0}diff --git a/client/src/main/webapp/index.html b/client/src/main/webapp/index.htmlindex 44107d0c0..da2f76ce4 100644--- a/client/src/main/webapp/index.html+++ b/client/src/main/webapp/index.html@@ -33,11 +33,11 @@app.set("error", e);});});-</script>+</head>-<body class="layout vertical" style="visibility:hidden;">+<body class="layout vertical"><or-app login="true"></or-app><or-toast></or-toast>diff --git a/client/src/main/webapp/src/or-app/or-app-security.html b/client/src/main/webapp/src/or-app/or-app-security.htmlindex 65dcb1a05..e683a4cbb 100644--- a/client/src/main/webapp/src/or-app/or-app-security.html+++ b/client/src/main/webapp/src/or-app/or-app-security.html@@ -140,8 +140,8 @@/*** Name of the OpenRemote tenant realm this app wants to connect to- * and possibly login and authenticate with. The realm can be overridden with an- * attribute, otherwise try to get it from URL path, first segment.+ * and login and authenticate with. The realm can be overridden with an+ * attribute, otherwise it will be obtained from the URL path, first segment.*/realm: {type: String,@@ -171,14 +171,14 @@ready() {super.ready();- // If we don't have a tenant realm, get it from the URL path- if (!this.realm) {+ // If login is required, and we don't have a realm, get it from the URL path+ if (this.login && !this.realm) {if (!window.location.pathname || window.location.pathname.length <= 1) {this.set("error", "No tenant realm configured and URL doesn't have any path elements");return;}let realm = window.location.pathname.split('/')[1];- console.log("No tenant realm configured, using: " + realm);+ console.log("No tenant realm configured, using first URL path segment: " + realm);this.set("realm", realm);}}diff --git a/client/src/main/webapp/src/or-app/or-app.html b/client/src/main/webapp/src/or-app/or-app.htmlindex 7123fed99..5f045c754 100644--- a/client/src/main/webapp/src/or-app/or-app.html+++ b/client/src/main/webapp/src/or-app/or-app.html@@ -13,8 +13,52 @@<template><style include="or-style">++ /* Children of or-app might be hidden, some have to be visible */+ #loader,+ #errorView {+ visibility: visible !important;+ }++ #loader {+ z-index: 9999;+ position: fixed;+ bottom: 0.8em;+ right: 0.4em;+ pointer-events: none;+ width: 0.8em;+ height: 0.8em;+ border: 2px solid var(--theme-lightgreen);+ border-top-color: var(--theme-black);+ border-radius: 50%;+ -webkit-animation: loadingspin 1s linear infinite;+ animation: loaderSpin 1s linear infinite;+ }++ @-webkit-keyframes loaderSpin {+ 100% {+ -webkit-transform: rotate(360deg);+ transform: rotate(360deg);+ }+ }++ @keyframes loaderSpin {+ 100% {+ -webkit-transform: rotate(360deg);+ transform: rotate(360deg);+ }+ }++ #errorView {+ padding: 1em;+ }++ #errorView h1 {+ color: var(--theme-darkgrey);+ }++ /* Slots are not shown until we are ready */#slots {- /* Hide the slotted children by default */display: none;}@@ -23,9 +67,10 @@border: 1px solid var(--theme-red);*/}-</style>+ <div id="loader"></div>+<or-shell-native id="shellNative"></or-shell-native><or-app-security id="appSecurity"@@ -36,9 +81,9 @@error="{{error}}"></or-app-security><template is="dom-if" if="[[error]]">- <div style="padding:1em;">- <h1 style="color: var(--theme-darkgrey);">[[defaultErrorMessage]]</h1>- <h5><span>[[error]]</span></h5>+ <div id="errorView">+ <h1>[[defaultErrorMessage]]</h1>+ <h5>[[error]]</h5></div></template>@@ -92,6 +137,20 @@/*** Singleton per window/document, registers itself as window.openremote.INSTANCE.+ *+ * When this component is used, the following startup procedure runs:+ *+ * 1a. If authentication is required, perform authentication, then fire AppInit.+ * 1b. If no authentication is required, fire AppInit.+ *+ * 2. Any element registered with defineAppElement() will be set in the openremote namespace+ * so its class is available in GWT jsinterop.+ *+ * 3. The GWT jsinterop components will be loaded, then fire AppLoaded.+ *+ * 4. This component will finish its initialization, then fire AppReady.+ *+ * 5. Any element registered with defineAppElement() will be finally defined/started.*/class OpenRemoteApp extends Polymer.Element {@@ -280,7 +339,9 @@}initialize() {- // This event is usually used to load other application resources which are not components, from the main document+ // This event is usually used to load other application resources which are not+ // components, from the main document. We also use it to set registered element+ // classes/types in the "openremote" namespace.console.log("Application init, loading components");window.dispatchEvent(new CustomEvent("AppInit", {detail: {app: this}}));@@ -309,30 +370,50 @@// Remove all slotted children, effectively disabling the appthis.$.slot.assignedNodes({flatten: false}).forEach((node) => {node.parentElement.removeChild(node);- })+ });++ // Disable login/token refresh+ this.set("login", false);+ // TODO Close websocket?// Hide the slotsthis.$.slots.style.display = "none";- // Disable login/token refresh- this.set("login", false);+ // Hide the loader+ this.hideLoader();- // Show the document body- window.document.body.style.visibility = "visible";+ // Fire an event so others can react to an error+ window.dispatchEvent(new CustomEvent("AppError", {detail: {app: this, error: error}}));}showApp() {console.debug("Showing application");- // The slotted children are hidden by default (this will set display: flex)+ // The children of or-app, the slots, and the slotted elements may be hidden, show them+ document.querySelectorAll("or-app > *").forEach((node) => {+ if (node.style) {+ node.style.visibility = "visible";+ }+ });this.$.slots.style.display = "inherit";-// Safari bug, this will trigger another repaint, the first stops in some weird half-rendered statethis.$.slots.style.webkitTransform = 'scale(1)';+ this.$.slot.assignedNodes({flatten: false}).forEach((node) => {+ if (node.style) {+ node.style.visibility = "visible";+ }+ });++ // Hide the loader+ this.hideLoader();+ }++ hideLoader() {+ this.$.loader.style.display = "none";+ }- // Show the document body as late as possible, this hides the application- // of custom-style, which flickers in Firefox- window.document.body.style.visibility = "visible";+ showLoader() {+ this.$.loader.style.display = "inherit";}registerWidgetStyle() {@@ -374,6 +455,13 @@this.webSocket.onopen = () => {console.log("Connected to event service: " + serviceUrl);this.set("status", "CONNECTED");++ // Close explicitly on unload/refresh of page, otherwise close code will be 1001+ window.addEventListener("beforeunload", () => {+ console.log("Page unloaded, closing event service connection");+ // TODO Should also cancel all subscriptions with the server+ this.webSocket.close();+ });};this.webSocket.onerror = () => {@@ -386,7 +474,9 @@this.set("webSocket", undefined);this.set("status", "DISCONNECTED");if (!this.error) {- if (e.code === 1001) {+ if (e.code === 1000) {+ // Do nothing, we closed the socket on page unload+ } else if (e.code === 1001) {this.set("error", "Server closed connection to event service: " + serviceUrl);} else {let msg = e.reason ? e.reason : serviceUrl;@@ -426,23 +516,12 @@}}- // Bit of a hack, we must detect if GWT superdev compilation failed, then show the- // document (without this, you won't see the failure message written by GWT dev mode- // into the main doc)- window.checkGwtSuperDevCompilationFailureInterval = window.setInterval(function() {- if (document.querySelectorAll("a[target='gwt_dev_mode_log']").length > 0) {- window.document.body.style.visibility = "visible";- }- }, 100);-// Upgrade immediately, so you can't use jsinterop in this class!customElements.define(OpenRemoteApp.is, OpenRemoteApp);// This is fired after jsinterop components are loaded/started, finalize initializationwindow.addEventListener('AppLoaded', function () {- window.clearInterval(window.checkGwtSuperDevCompilationFailureInterval);-openremote.INSTANCE.registerRequestService();openremote.INSTANCE.registerWidgetStyle();@@ -484,7 +563,7 @@// This is fired after jsinterop components are loaded/started and after we have done any other// initialization (see above). Now the actual web component elements can be defined/upgraded,- // this is when component constructors etc. lifecycle starts+ // this is when component constructors etc. lifecycle starts.window.addEventListener('AppReady', function () {console.log("Upgrading element: " + is);customElements.define(is, element);diff --git a/deployment/manager/consoles/customerA/index.html b/deployment/manager/consoles/customerA/index.htmlindex ceb2334aa..a5a74579f 100644--- a/deployment/manager/consoles/customerA/index.html+++ b/deployment/manager/consoles/customerA/index.html@@ -47,8 +47,13 @@})</script>- <!-- Optional: Create some styles only for your app --><style type="text/css">+ /* Recommended: Avoid flickering during loading/styling by hiding children of or-app */+ or-app > * {+ visibility: hidden;+ }++ /* Optional: Create some styles only for your app */.myAppHeadline {display: block;text-decoration: none;@@ -61,8 +66,8 @@</head>-<!-- Optional: Make your body hidden by default, so it will be visible only when authenticated -->-<body class="layout vertical" style="visibility:hidden;">+<!-- Optional: You should use flexbox layout classes everywhere, starting with the body -->+<body class="layout vertical"><!-- Optional: A component can handle ShowInfo and ShowError events for you with a simple toast display--><or-toast></or-toast>diff --git a/keycloak/theme/account/template.ftl b/keycloak/theme/account/template.ftlindex 0e901043d..28be2f5b2 100644--- a/keycloak/theme/account/template.ftl+++ b/keycloak/theme/account/template.ftl@@ -20,9 +20,15 @@<link rel="import" href="/static/src/or-app/or-app.html">+ <style type="text/css">+ or-app > * {+ visibility: hidden;+ }+ </style>+</head>-<body class="layout horizontal" style="visibility: hidden;">+<body class="layout horizontal"><or-app>diff --git a/keycloak/theme/login/template.ftl b/keycloak/theme/login/template.ftlindex 6c665889d..ca018f991 100755--- a/keycloak/theme/login/template.ftl+++ b/keycloak/theme/login/template.ftl@@ -20,9 +20,15 @@<link rel="import" href="/static/src/or-app/or-app.html">+ <style type="text/css">+ or-app > * {+ visibility: hidden;+ }+ </style>+</head>-<body class="layout vertical" style="visibility: hidden;">+<body class="layout vertical"><or-app>