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
UI updates: code styling and Edge bug fixes
Rich Turner1f13527eeb6b
diff --git a/ui/component/or-smart-notify/src/index.ts b/ui/component/or-smart-notify/src/index.tsindex c5b739682..b8d1a33d9 100644--- a/ui/component/or-smart-notify/src/index.ts+++ b/ui/component/or-smart-notify/src/index.ts@@ -1,17 +1,120 @@-import {html, LitElement, property, customElement, PropertyValues} from 'lit-element';+import {html, LitElement, property, customElement, PropertyValues} from "lit-element";-import moment from 'moment';+import moment from "moment";-import {icon} from '@fortawesome/fontawesome-svg-core'-import {faClock} from '@fortawesome/free-regular-svg-icons';-import {faTimes} from '@fortawesome/free-solid-svg-icons';+import {icon} from "@fortawesome/fontawesome-svg-core";+import {faClock} from "@fortawesome/free-regular-svg-icons";+import {faTimes} from "@fortawesome/free-solid-svg-icons";import REST from "@openremote/rest";import {AssetQuery, BaseAssetQueryInclude} from "@openremote/model";import openremote from "@openremote/core";-@customElement('or-smart-notify')+@customElement("or-smart-notify")class OrSmartNotify extends LitElement {+ // default function on smartyNotify+ @property({type: Function})+ private onChange: any;++ // if smart notify popup is visible+ @property({type: Boolean})+ private isVisible: boolean = false;++ // If smart notify is active+ @property({type: Boolean})+ private isActive: boolean = false;++ // If smart notify is active+ @property({type: Boolean})+ private isDisabled: boolean = false;++ // If smart notify is active+ @property({type: Object})+ private smartNotify: any = {};++ // default function on smartyNotify+ @property({type: String})+ private currentTime: string = "-";++ constructor() {+ super();+ const self: any = this;+ this.currentTime = moment().format("HH:mm");++ setInterval(function() {+ self.currentTime = moment().format("HH:mm");+ }, 500);+ }++ public getSmartNotify() {+ const self: any = this;+ return new Promise((resolve: any, reject: any) => {+ const smartNotifyQuery: AssetQuery = {+ name: {predicateType: "string", value: "SMART_NOTIFY_ASSET"},+ select: {include: BaseAssetQueryInclude.ALL_EXCEPT_PATH}+ };+ REST.api.AssetResource.queryAssets(smartNotifyQuery).then((response: any) => {+ console.log("Setting Smart Notify");+ if (response.data) {+ self.smartNotify = response.data[0];+ self.isActive = self.smartNotify.attributes.SMART_NOTIFY_ENABLED.value;+ self.onChange();+ resolve(response);+ }++ }).catch((reason: any) => {+ reject(Error("Error:" + reason));+ console.log("Error:" + reason);+ });++ });+ }++ public checkSmartNotifyMarkers() {+ const self: any = this;+ if (this.isActive && this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers && this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers.length > 0) {+ } else if (this.isActive && this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers.length === 0) {+ this.getSmartNotify().then(() => {+ setTimeout(() => {+ self.checkSmartNotifyMarkers();+ }, 3000);+ });+ }+ }++ public setSmartNotify(e: any) {+ const isChecked = e.target.checked;+ if (isChecked) {+ this.smartNotify.attributes.SMART_NOTIFY_ENABLED.value = moment();+ this.smartNotify.attributes.SMART_NOTIFY_ENABLED.valueTimestamp = moment();+ this.isActive = true;+ } else {+ this.smartNotify.attributes.SMART_NOTIFY_ENABLED.value = null;+ this.isActive = false;+ }+ REST.api.AssetResource.update(this.smartNotify.id, this.smartNotify).then((response: any) => {+ console.log("Setting Smart Notify");+ this.smartNotify.version = this.smartNotify.version + 1;+ if (isChecked) {+ this.checkSmartNotifyMarkers();+ } else {++ // Clear the smart notify markers and smart notify in frontend+ this.smartNotify.attributes.SMART_NOTIFY_ENABLED.value = false;+ this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers = [];+ this.onChange();+ }++ }).catch((reason: any) => console.log("Error:" + reason));+ }++ public close() {+ this.isVisible = false;+ }++ public toggleVisibility() {+ this.isVisible = !this.isVisible;+ }protected render() {// language=HTMLreturn html`@@ -211,7 +314,7 @@ class OrSmartNotify extends LitElement {${this.isActive ? html`<div class="layout horizontal"><div style="background-color: var(--app-lightgrey-color, #dedede);" class="flex padding-10">Starttijd</div>- <div class="flex t-center">${this.isActive ? moment(this.smartNotify.attributes.SMART_NOTIFY_ENABLED.valueTimestamp).format('HH:mm') : "-"}</div>+ <div class="flex t-center">${this.isActive ? moment(this.smartNotify.attributes.SMART_NOTIFY_ENABLED.valueTimestamp).format("HH:mm") : "-"}</div></div>` : ``}</div>@@ -225,116 +328,10 @@ class OrSmartNotify extends LitElement {`;}- // default function on smartyNotify- @property({type: Function})- private onChange: any;-- // if smart notify popup is visible- @property({type: Boolean})- private isVisible: boolean = false;-- // If smart notify is active- @property({type: Boolean})- private isActive: boolean = false;-- // If smart notify is active- @property({type: Boolean})- private isDisabled: boolean = false;-- // If smart notify is active- @property({type: Object})- private smartNotify: any = {};-- // default function on smartyNotify- @property({type: String})- private currentTime: string = '-';-protected firstUpdated(_changedProperties: PropertyValues): void {super.firstUpdated(_changedProperties);this.isDisabled = !openremote.hasRole("write:assets");}- getSmartNotify() {- const self:any = this;- return new Promise(function(resolve: any, reject: any) {- const smartNotifyQuery: AssetQuery = {- name: {predicateType: "string", value: "SMART_NOTIFY_ASSET"},- select: {include: BaseAssetQueryInclude.ALL_EXCEPT_PATH}- };- REST.api.AssetResource.queryAssets(smartNotifyQuery).then((response: any) => {- console.log("Setting Smart Notify");- if (response.data) {- self.smartNotify = response.data[0];- self.isActive = self.smartNotify.attributes.SMART_NOTIFY_ENABLED.value ? true : false;- self.onChange();- resolve(response);- }-- }).catch((reason:any) => {- reject(Error("Error:" + reason));- console.log("Error:" + reason)- });-- });- }-- checkSmartNotifyMarkers() {- const self:any = this;- if(this.isActive && this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers && this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers.length > 0) {- } else if (this.isActive && this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers.length === 0) {- this.getSmartNotify().then(()=> {- setTimeout(function(){- self.checkSmartNotifyMarkers();- }.bind(this), 3000);- });- }- }-- setSmartNotify(e:any) {- const isChecked = e.target.checked;- if (isChecked == true) {- this.smartNotify.attributes.SMART_NOTIFY_ENABLED.value = moment();- this.smartNotify.attributes.SMART_NOTIFY_ENABLED.valueTimestamp = moment();- this.isActive = true;- } else {- this.smartNotify.attributes.SMART_NOTIFY_ENABLED.value = null;- this.isActive = false;- }- REST.api.AssetResource.update(this.smartNotify.id, this.smartNotify).then((response:any) => {- console.log("Setting Smart Notify");- this.smartNotify.version = this.smartNotify.version+1;- if(isChecked == true){- this.checkSmartNotifyMarkers();- } else {-- // Clear the smartnotify markers and smart notify in frontend- this.smartNotify.attributes.SMART_NOTIFY_ENABLED.value = false;- this.smartNotify.attributes.SMART_NOTIFY_RESULT.value.markers = [];- this.onChange();- }-- }).catch((reason:any) => console.log("Error:" + reason));- }-- close() {- this.isVisible = false;- }-- toggleVisibility() {- this.isVisible = !this.isVisible;- }-- constructor() {- super();- const self:any = this;- this.currentTime = moment().format('HH:mm');-- setInterval(function(){- self.currentTime = moment().format('HH:mm');- }, 500);- }--}-diff --git a/ui/component/or-timeline/src/index.ts b/ui/component/or-timeline/src/index.tsindex f5261b3fb..e91364638 100644--- a/ui/component/or-timeline/src/index.ts+++ b/ui/component/or-timeline/src/index.ts@@ -1,17 +1,94 @@-import {html, LitElement, property} from 'lit-element';--import moment from 'moment';+import {html, LitElement, property, customElement} from "lit-element";+import moment from "moment";+@customElement("or-timeline")class OrTimeline extends LitElement {- protected render() {- if(this.shadowRoot){- const range:any = this.shadowRoot.getElementById('or-timeline-slider');- if(range) {- range.value = Math.round(this.current);- this.moveBubble(range);++ // default value in minutes+ @property({type: Number})+ public current: number = 0;++ @property({type: Function})+ public onChange: any;++ // default value in minutes+ @property({type: Number})+ public value: number = 0;++ // maxRange in minutes+ @property({type: Number})+ public maxRange: number = 360;++ // minRange in minutes+ @property({type: Number})+ public minRange: number = 0;++ // Steps in minutes+ @property({type: Number})+ public step: number = 5;++ constructor() {+ super();+ }++ public moveBubble(e: any= null, value: string|null= null) {+ let el;+ if (e) {+ el = e.target;+ } else {+ if (this.shadowRoot) {+ el = this.shadowRoot.getElementById("or-timeline-slider");+ }+ }++ if (el) {+ if (value) {+ this.current = parseInt(value);+ } else {+ this.current = parseInt(el.value);+ }+ // Measure width of range input+ const width = el.offsetWidth;+ const v = this.current;++ // Figure out placement percentage between left and right of input+ const newPoint = v / this.maxRange;+ // Janky value to get pointer to line up better+ const offset = 15;+ let newPlace;++ // Prevent bubble from going beyond left or right (unsupported browsers)+ if (newPoint < 0) {+ newPlace = 0;+ } else if (newPoint > 1) {+ newPlace = width - offset;+ } else {+ newPlace = (width - offset) * newPoint;++ if (newPlace < 0 ) {+ newPlace = 0;+ }++ }++ // Move bubble+ if (this.shadowRoot) {+ const range: HTMLElement | null = this.shadowRoot.getElementById("range-value");+ if (range) {+ range.style.left = newPlace + "px";+ }}}+ }++ public valueChange(e: any) {+ this.moveBubble(e);+ this.onChange();+ }++ protected render() {+return html`<style>:host {@@ -30,16 +107,16 @@ class OrTimeline extends LitElement {}.slidecontainer {position: relative;- margin: -5px 50px 0 30px;+ margin: -5px 44px 0 19px;}/* The slider itself */.slider {+ color: var(--timeline-accent, #1D5632);box-sizing: border-box;-webkit-appearance: none;outline: none;- width: 102%;- margin-left: -15px;+ width: 100%;}.slider::-webkit-slider-runnable-track {cursor: pointer;@@ -54,7 +131,7 @@ class OrTimeline extends LitElement {border-radius: 50%;cursor: pointer;-webkit-appearance: none;- background-color: var(--timeline-accent, blue); /* Green background */+ background-color: var(--timeline-accent, #1D5632); /* Green background */pointer-events: all;margin-top: -2px;}@@ -73,7 +150,7 @@ class OrTimeline extends LitElement {border-radius: 50%;cursor: pointer;-webkit-appearance: none;- background-color: var(--timeline-accent, blue); /* Green background */+ background-color: var(--timeline-accent, #1D5632); /* Green background */pointer-events: all;margin-top: -2px;}@@ -92,7 +169,7 @@ class OrTimeline extends LitElement {border-radius: 50%;cursor: pointer;-webkit-appearance: none;- background-color: var(--timeline-accent, blue); /* Green background */+ background-color: var(--timeline-accent, currentColor); /* Bug in Edge set colour on slider itself */pointer-events: all;margin-top: -2px;}@@ -140,7 +217,7 @@ class OrTimeline extends LitElement {#range-value {position: absolute;- background-color: var(--timeline-accent, blue);+ background-color: var(--timeline-accent, #1D5632);height: 30px;width: 60px;margin-left: -30px;@@ -164,111 +241,26 @@ class OrTimeline extends LitElement {<div class="time-value-container">- <div id="range-value">${this.current === 0 ? 'LIVE' : moment().add(this.current, 'minutes').format('HH:mm')}</div>+ <div id="range-value">${this.current === 0 ? "LIVE" : moment().add(this.current, "minutes").format("HH:mm")}</div></div><div class="timeline-container"><div id="timelineHourMarkers" class="layout horizontal justified style-scope controller-timeline">- ${new Array((this.maxRange/60)+1).fill(0).map((_, idx) => {+ ${new Array((this.maxRange / 60) + 1).fill(0).map((_, idx) => {return html`${idx === 0 ? html`<div class="timelineHourMark style-scope controller-timeline">Nu</div>` : html`<div class="timelineHourMark style-scope controller-timeline">+${idx}u</div>`}- `})}+ `; })}</div><div class="slidecontainer">- <input id="or-timeline-slider" class="slider" type="range" @input="${this.moveBubble}" @change="${this.valueChange}" value="${this.current}" min="${this.minRange}" max="${this.maxRange}" step="${this.step}">+ <input id="or-timeline-slider" class="slider" type="range" @input="${this.moveBubble}" @change="${this.valueChange}" value="${this.current}" min="${this.minRange}" max="${this.maxRange}" step="${this.step}"></div></div>`;}- @property({type: Function})- private onChange: any;-- // default value in minutes- @property({type: Number})- private value: number = 0;-- // default value in minutes- @property({type: Number})- public current: number = 0;-- // maxRange in minutes- @property({type: Number})- private maxRange: number = 360;-- // minRange in minutes- @property({type: Number})- private minRange: number = 0;-- // Steps in minutes- @property({type: Number})- private step: number = 5;-- moveBubble(e:any=null, value:string|null=null) {- let el;- if(e){- el = e.target;- } else {- if(this.shadowRoot){- el = this.shadowRoot.getElementById('or-timeline-slider');- }- }-- if(el) {- if(value){- this.current = parseInt(value);- } else {- this.current = parseInt(el.value);- }- // Measure width of range input- const width = el.offsetWidth;- const v = this.current;-- // Figure out placement percentage between left and right of input- const newPoint = v / this.maxRange;- // Janky value to get pointer to line up better- let offset = 15;- let newPlace;-- // Prevent bubble from going beyond left or right (unsupported browsers)- if (newPoint < 0) {- newPlace = 0;- } else if (newPoint > 1) {- newPlace = width - offset;- } else {- newPlace = (width - offset) * newPoint;-- if(newPlace < 0 ) {- newPlace = 0;- }-- }-- // Move bubble- if(this.shadowRoot) {- const range:HTMLElement | null = this.shadowRoot.getElementById('range-value');- if(range){- range.style.left = newPlace + "px";- }- }- }-- }-- valueChange (e:any) {- this.moveBubble(e);- this.onChange();- }-- constructor() {- super();- }-}--window.customElements.define('or-timeline', OrTimeline);