Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI updates: move realm change into app state (away from individual components)

Rich Turner0c47ff5c645c
diff --git a/ui/app/manager/src/pages/page-assets.ts b/ui/app/manager/src/pages/page-assets.ts
index c47b2421d..043be9f5b 100644
--- a/ui/app/manager/src/pages/page-assets.ts
+++ b/ui/app/manager/src/pages/page-assets.ts
@@ -19,13 +19,14 @@ import {
OrAssetTreeRequestSelectionEvent,
OrAssetTreeSelectionEvent
} from "@openremote/or-asset-tree";
-import {DefaultBoxShadow, Util} from "@openremote/core";
+import manager, {DefaultBoxShadow, Util} from "@openremote/core";
import {AppStateKeyed, Page, PageProvider, router} from "@openremote/or-app";
import {EnhancedStore} from "@reduxjs/toolkit";
import {showOkCancelDialog} from "@openremote/or-mwc-components/or-mwc-dialog";
import i18next from "i18next";
import {AssetEventCause, WellknownAssets} from "@openremote/model";
import "@openremote/or-json-forms";
+import {createSelector} from "reselect";
export interface PageAssetsConfig {
viewer?: ViewerConfig;
@@ -132,11 +133,21 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
protected _viewer!: OrAssetViewer;
protected _addedAssetId?: string;
+ protected _realmSelector = (state: S) => state.app.realm || manager.displayRealm;
get name(): string {
return "assets";
}
+ protected getRealmState = createSelector(
+ [this._realmSelector],
+ async (realm) => {
+ if (this._tree) {
+ this._tree.refresh();
+ }
+ }
+ )
+
constructor(store: EnhancedStore<S>) {
super(store);
this.addEventListener(OrAssetTreeRequestSelectionEvent.NAME, this._onAssetSelectionRequested);
@@ -159,6 +170,7 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
// State is only utilised for initial loading
this._editMode = !!(state.app.params && state.app.params.editMode === "true");
this._assetIds = state.app.params && state.app.params.id ? [state.app.params.id as string] : undefined;
+ this.getRealmState(state);
}
protected _onAssetSelectionRequested(event: OrAssetTreeRequestSelectionEvent) {
diff --git a/ui/app/manager/src/pages/page-map.ts b/ui/app/manager/src/pages/page-map.ts
index 11c09835c..818606b27 100644
--- a/ui/app/manager/src/pages/page-map.ts
+++ b/ui/app/manager/src/pages/page-map.ts
@@ -50,10 +50,10 @@ const pageMapSlice = createSlice({
return state;
},
attributeEventReceived(state: MapState, action: PayloadAction<AttributeEvent>) {
- let assets = state.assets;
+ const assets = state.assets;
const assetId = action.payload.attributeState.ref.id;
const index = assets.findIndex((asst) => asst.id === assetId);
- let asset = index >= 0 ? assets[index] : null;
+ const asset = index >= 0 ? assets[index] : null;
if (!asset) {
return state;
@@ -157,14 +157,12 @@ export class PageMap<S extends MapStateKeyed> extends Page<S> {
protected _assetSelector = (state: S) => state.map.assets;
protected _paramsSelector = (state: S) => state.app.params;
- protected subscribedRealm?: string;
+ protected _realmSelector = (state: S) => state.app.realm || manager.displayRealm;
+
protected assetSubscriptionId: string;
protected attributeSubscriptionId: string;
- protected subscribeAssets = (): ThunkAction<void, MapStateKeyed, unknown, Action<string>> => async (dispatch) => {
-
- const realm = manager.displayRealm;
- this.subscribedRealm = realm;
+ protected subscribeAssets = async (realm: string) => {
try {
const result = await manager.rest.api.AssetResource.queryAssets({
@@ -207,25 +205,21 @@ export class PageMap<S extends MapStateKeyed> extends Page<S> {
}
});
- if (realm !== this.subscribedRealm) {
- // Realm has changed
- return;
- }
-
- if (!this.isConnected) {
+ if (!this.isConnected || realm !== this._realmSelector(this._store.getState())) {
+ // No longer connected or realm has changed
return;
}
if (result.data) {
const assets = result.data;
- dispatch(setAssets(assets));
+ this._store.dispatch(setAssets(assets));
const assetSubscriptionId = await manager.events.subscribeAssetEvents(undefined, false, undefined, (event) => {
- dispatch(assetEventReceived(event));
+ this._store.dispatch(assetEventReceived(event));
});
- if (!this.isConnected || realm !== this.subscribedRealm) {
+ if (!this.isConnected || realm !== this._realmSelector(this._store.getState())) {
manager.events.unsubscribe(assetSubscriptionId);
return;
}
@@ -233,10 +227,11 @@ export class PageMap<S extends MapStateKeyed> extends Page<S> {
this.assetSubscriptionId = assetSubscriptionId;
const attributeSubscriptionId = await manager.events.subscribeAttributeEvents(undefined, false, (event) => {
- dispatch(attributeEventReceived(event));
+ this._store.dispatch(attributeEventReceived(event));
});
- if (!this.isConnected || realm !== this.subscribedRealm) {
+ if (!this.isConnected || realm !== this._realmSelector(this._store.getState())) {
+ this.assetSubscriptionId = undefined;
manager.events.unsubscribe(assetSubscriptionId);
manager.events.unsubscribe(attributeSubscriptionId);
return;
@@ -249,7 +244,7 @@ export class PageMap<S extends MapStateKeyed> extends Page<S> {
}
};
- protected unsubscribeAssets = (): ThunkAction<void, MapStateKeyed, unknown, Action<string>> => (dispatch, getState) => {
+ protected unsubscribeAssets = () => {
if (this.assetSubscriptionId) {
manager.events.unsubscribe(this.assetSubscriptionId);
this.assetSubscriptionId = undefined;
@@ -260,6 +255,22 @@ export class PageMap<S extends MapStateKeyed> extends Page<S> {
}
};
+ protected getRealmState = createSelector(
+ [this._realmSelector],
+ async (realm) => {
+ if (this._assets.length > 0) {
+ // Clear existing assets
+ this._assets = [];
+ }
+ this.unsubscribeAssets();
+ this.subscribeAssets(realm);
+
+ if (this._map) {
+ this._map.refresh();
+ }
+ }
+ )
+
protected _getMapAssets = createSelector(
[this._assetSelector],
(assets) => {
@@ -313,30 +324,19 @@ export class PageMap<S extends MapStateKeyed> extends Page<S> {
super.connectedCallback();
this.addEventListener(OrMapMarkerClickedEvent.NAME, this.onMapMarkerClick);
this.addEventListener(OrMapClickedEvent.NAME, this.onMapClick);
- manager.addListener(this.onManagerEvent);
- this._store.dispatch(this.subscribeAssets());
}
public disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener(OrMapMarkerClickedEvent.NAME, this.onMapMarkerClick);
this.removeEventListener(OrMapClickedEvent.NAME, this.onMapClick);
- manager.removeListener(this.onManagerEvent);
- this._store.dispatch(this.unsubscribeAssets());
- }
-
- protected onManagerEvent = (event: OREvent) => {
- switch (event) {
- case OREvent.DISPLAY_REALM_CHANGED:
- this._store.dispatch(this.unsubscribeAssets());
- this._store.dispatch(this.subscribeAssets());
- break;
- }
+ this.unsubscribeAssets();
}
stateChanged(state: S) {
this._assets = this._getMapAssets(state);
this._currentAsset = this._getCurrentAsset(state);
+ this.getRealmState(state);
}
protected onMapMarkerClick(e: OrMapMarkerClickedEvent) {
diff --git a/ui/app/manager/src/pages/page-rules.ts b/ui/app/manager/src/pages/page-rules.ts
index 420987e84..6a7e8b0cd 100644
--- a/ui/app/manager/src/pages/page-rules.ts
+++ b/ui/app/manager/src/pages/page-rules.ts
@@ -1,11 +1,13 @@
import {css, html} from "lit";
-import {customElement, property} from "lit/decorators.js";
+import {customElement, property, query} from "lit/decorators.js";
import "@openremote/or-rules";
-import {ActionTargetType, RulesConfig} from "@openremote/or-rules";
+import {ActionTargetType, OrRules, RulesConfig} from "@openremote/or-rules";
import {NotificationTargetType, RulesetLang, WellknownAssets} from "@openremote/model";
import {EnhancedStore} from "@reduxjs/toolkit";
import {Page, PageProvider} from "@openremote/or-app";
import {AppStateKeyed} from "@openremote/or-app";
+import manager from "@openremote/core";
+import {createSelector} from "reselect";
export interface PageRulesConfig {
rules: RulesConfig;
@@ -76,6 +78,20 @@ class PageRules<S extends AppStateKeyed> extends Page<S> {
@property()
public config?: PageRulesConfig;
+ @query("#rules")
+ protected _orRules!: OrRules;
+
+ protected _realmSelector = (state: S) => state.app.realm || manager.displayRealm;
+
+ protected getRealmState = createSelector(
+ [this._realmSelector],
+ async (realm) => {
+ if (this._orRules) {
+ this._orRules.refresh();
+ }
+ }
+ )
+
get name(): string {
return "rules";
}
@@ -86,10 +102,11 @@ class PageRules<S extends AppStateKeyed> extends Page<S> {
protected render() {
return html`
- <or-rules .config="${this.config && this.config.rules ? this.config.rules : PAGE_RULES_CONFIG_DEFAULT.rules}"></or-rules>
+ <or-rules id="rules" .config="${this.config && this.config.rules ? this.config.rules : PAGE_RULES_CONFIG_DEFAULT.rules}"></or-rules>
`;
}
public stateChanged(state: S) {
+ this.getRealmState(state);
}
}
diff --git a/ui/component/or-app/src/app.ts b/ui/component/or-app/src/app.ts
index 3a5c2c346..b375dcad4 100644
--- a/ui/component/or-app/src/app.ts
+++ b/ui/component/or-app/src/app.ts
@@ -7,6 +7,7 @@ export interface AppState {
resolved: boolean,
drawerOpened: boolean;
scrollTop: number;
+ realm?: string;
}
export interface AppStateKeyed {
@@ -20,6 +21,7 @@ const INITIAL_STATE: AppState = {
resolved: false,
drawerOpened: false,
scrollTop: 0,
+ realm: undefined
};
export interface PageAndParams {
@@ -49,9 +51,15 @@ const appSlice = createSlice({
...state,
scrollTop: action.payload
};
+ },
+ updateRealm(state, action: PayloadAction<string>) {
+ return {
+ ...state,
+ realm: action.payload
+ }
}
}
});
-export const {updatePage, updateDrawer, scrollToTop} = appSlice.actions;
+export const {updatePage, updateDrawer, scrollToTop, updateRealm} = appSlice.actions;
export const appReducer = appSlice.reducer;
diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.ts
index 59fe14465..36c9d0d84 100644
--- a/ui/component/or-app/src/index.ts
+++ b/ui/component/or-app/src/index.ts
@@ -22,7 +22,7 @@ import {DialogConfig, OrMwcDialog, showErrorDialog, showDialog} from "@openremot
import {OrMwcSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";
import {AnyAction, EnhancedStore, Unsubscribe} from "@reduxjs/toolkit";
import {ThunkMiddleware} from "redux-thunk";
-import {AppStateKeyed, updatePage} from "./app";
+import {AppStateKeyed, updatePage, updateRealm} from "./app";
import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";
import { ORError } from "@openremote/core";
@@ -165,6 +165,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
protected _onManagerEvent = (event: OREvent) => {
switch (event) {
case OREvent.DISPLAY_REALM_CHANGED:
+ this._store.dispatch(updateRealm(manager.displayRealm));
const config = this._getConfig(manager.displayRealm);
if (!config) {
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index 806d83c7c..605d635f0 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -262,13 +262,11 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
public connectedCallback() {
super.connectedCallback();
- manager.addListener(this.onManagerEvent);
}
public disconnectedCallback() {
super.disconnectedCallback();
this.requestUpdate();
- manager.removeListener(this.onManagerEvent);
}
public refresh() {
@@ -276,14 +274,6 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
this._nodes = undefined;
}
- protected onManagerEvent = (event: OREvent) => {
- switch (event) {
- case OREvent.DISPLAY_REALM_CHANGED:
- this._nodes = undefined;
- break;
- }
- }
-
public isAncestorSelected(node: UiAssetTreeNode) {
if (!this.selectedIds || !node.parent) {
return false;
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 2da2b5047..a500b1475 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -1083,6 +1083,25 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
}
+ if (changedProperties.has("assetId")) {
+ this.asset = undefined;
+ if (this.assetId) {
+ this._loading = true;
+ super.assetIds = [this.assetId];
+ } else {
+ this._loading = false;
+ super.assetIds = undefined;
+ }
+ } else if (changedProperties.has("editMode") && !this.editMode) {
+ this.reloadAsset();
+ }
+
+ this.onCompleted().then(() => {
+ onRenderComplete.startCallbacks().then(() => {
+ OrAssetViewer.generateGrid(this.shadowRoot);
+ });
+ });
+
return super.shouldUpdate(changedProperties);
}
@@ -1163,29 +1182,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
`;
}
- protected updated(_changedProperties: PropertyValues) {
- super.updated(_changedProperties);
-
- if (_changedProperties.has("assetId")) {
- this.asset = undefined;
- if (this.assetId) {
- this._loading = true;
- super.assetIds = [this.assetId];
- } else {
- this._loading = false;
- super.assetIds = undefined;
- }
- } else if (_changedProperties.has("editMode") && !this.editMode) {
- this.reloadAsset();
- }
-
- this.onCompleted().then(() => {
- onRenderComplete.startCallbacks().then(() => {
- OrAssetViewer.generateGrid(this.shadowRoot);
- });
- });
- }
-
public reloadAsset() {
this.asset = undefined;
this._assetModified = false;
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.ts
index eb2d00333..8a652713a 100644
--- a/ui/component/or-map/src/index.ts
+++ b/ui/component/or-map/src/index.ts
@@ -375,25 +375,6 @@ export class OrMap extends LitElement {
this.loadMap();
}
}
-
- protected onManagerEvent = (event: OREvent) => {
- switch (event) {
- case OREvent.READY:
- if (manager.ready) {
- this.loadMap();
- }
- break;
- case OREvent.DISPLAY_REALM_CHANGED:
- if(this._map){
- this._map.loadViewSettings().then(()=> {
- if(!this._map) return
- this._map.setCenter()
- this._map.flyTo();
- });
- }
- break;
- }
- }
public get markers(): OrMapMarker[] {
return this._markers;
@@ -401,7 +382,6 @@ export class OrMap extends LitElement {
public connectedCallback() {
super.connectedCallback();
- manager.addListener(this.onManagerEvent);
}
public disconnectedCallback() {
@@ -409,7 +389,6 @@ export class OrMap extends LitElement {
if (this._observer) {
this._observer.disconnect();
}
- manager.removeListener(this.onManagerEvent);
}
protected render() {
@@ -432,9 +411,14 @@ export class OrMap extends LitElement {
}
}
- public reloadMap() {
- this._loaded = false;
- this.loadMap();
+ public refresh() {
+ if (this._map) {
+ this._map.loadViewSettings().then(() => {
+ if (!this._map) return;
+ this._map.setCenter();
+ this._map.flyTo();
+ });
+ }
}
public loadMap() {
diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.ts
index 8a5073f90..dd686d11c 100644
--- a/ui/component/or-map/src/mapwidget.ts
+++ b/ui/component/or-map/src/mapwidget.ts
@@ -153,6 +153,7 @@ export class MapWidget {
}
public async loadViewSettings() {
+
let settingsResponse;
if (this._type === MapType.RASTER) {
settingsResponse = await manager.rest.api.MapResource.getSettingsJs();
@@ -164,8 +165,7 @@ export class MapWidget {
// Load options for current realm or fallback to default if exist
const realmName = manager.displayRealm || "default";
this._viewSettings = settings.options ? settings.options[realmName] ? settings.options[realmName] : settings.options.default : null;
- return settings
-
+ return settings;
}
public async load(): Promise<void> {
diff --git a/ui/component/or-rules/src/index.ts b/ui/component/or-rules/src/index.ts
index b2926a652..bd877c73a 100644
--- a/ui/component/or-rules/src/index.ts
+++ b/ui/component/or-rules/src/index.ts
@@ -588,6 +588,10 @@ export class OrRules extends translate(i18next)(LitElement) {
`;
}
+ public refresh() {
+ this._rulesList.refresh();
+ }
+
protected isReadonly(): boolean {
return this.readonly || !manager.hasRole(ClientRole.WRITE_RULES);
}
diff --git a/ui/component/or-rules/src/or-rule-list.ts b/ui/component/or-rules/src/or-rule-list.ts
index bc71553d3..2fb664a32 100644
--- a/ui/component/or-rules/src/or-rule-list.ts
+++ b/ui/component/or-rules/src/or-rule-list.ts
@@ -144,14 +144,10 @@ export class OrRuleList extends translate(i18next)(LitElement) {
}
public async refresh() {
+ this._nodes = undefined;
await this._loadRulesets();
}
- public disconnectedCallback() {
- super.disconnectedCallback();
- manager.removeListener(this.onManagerEvent);
- }
-
protected get _allowedLanguages(): RulesetLang[] | undefined {
const languages = this.config && this.config.controls && this.config.controls.allowedLanguages ? [...this.config.controls.allowedLanguages] : OrRuleList.DEFAULT_ALLOWED_LANGUAGES;
const groovyIndex = languages.indexOf(RulesetLang.GROOVY);
@@ -183,25 +179,11 @@ export class OrRuleList extends translate(i18next)(LitElement) {
protected firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);
- manager.addListener(this.onManagerEvent);
if (manager.ready) {
this._onReady();
}
}
- protected onManagerEvent = (event: OREvent) => {
- switch (event) {
- case OREvent.READY:
- if (!manager.ready) {
- this._onReady();
- }
- break;
- case OREvent.DISPLAY_REALM_CHANGED:
- this._nodes = undefined;
- break;
- }
- }
-
public shouldUpdate(_changedProperties: PropertyValues): boolean {
const result = super.shouldUpdate(_changedProperties);
@@ -624,7 +606,7 @@ export class OrRuleList extends translate(i18next)(LitElement) {
this._nodes = [];
} else {
- let nodes = rulesets.map((ruleset) => {
+ const nodes = rulesets.map((ruleset) => {
return {
ruleset: ruleset
} as RulesetNode;
diff --git a/ui/component/or-survey-results/src/index.ts b/ui/component/or-survey-results/src/index.ts
index 6e75bc6bc..0972cf363 100644
--- a/ui/component/or-survey-results/src/index.ts
+++ b/ui/component/or-survey-results/src/index.ts
@@ -2,7 +2,7 @@ import {html, LitElement, PropertyValues} from "lit";
import {customElement, property} from "lit/decorators.js";
import {Asset, AssetQuery} from "@openremote/model";
import {surveyResultStyle} from "./style";
-import manager, { OREvent, EventCallback } from "@openremote/core";
+import manager from "@openremote/core";
export interface ProcessedResultAnswer {
name: string,
@@ -37,24 +37,6 @@ class OrSurveyResults extends LitElement {
@property({type: Number})
public maxAmount?: number;
- protected _initCallback?: EventCallback;
-
- protected firstUpdated(_changedProperties: PropertyValues): void {
- super.firstUpdated(_changedProperties);
-
- if (!manager.ready) {
- // Defer until openremote is initialised
- this._initCallback = (initEvent: OREvent) => {
- if (initEvent === OREvent.READY) {
- this.getSurvey();
- manager.removeListener(this._initCallback!);
- }
- };
- manager.addListener(this._initCallback);
- } else {
- }
- }
-
updated(_changedProperties: PropertyValues) {
if(_changedProperties.has('surveyId')) {
this.getSurvey();
diff --git a/ui/component/or-survey/src/index.ts b/ui/component/or-survey/src/index.ts
index 2f1fd54ac..34ddce627 100644
--- a/ui/component/or-survey/src/index.ts
+++ b/ui/component/or-survey/src/index.ts
@@ -7,7 +7,7 @@ import get from "lodash-es/get";
import orderBy from "lodash-es/orderBy";
import * as momentImported from 'moment';
-import manager, {EventCallback, OREvent} from "@openremote/core";
+import manager, {EventCallback} from "@openremote/core";
import filter from "lodash-es/filter";
import "@openremote/or-translate";
@@ -202,19 +202,7 @@ class OrSurvey extends LitElement {
protected firstUpdated(_changedProperties: PropertyValues): void {
super.firstUpdated(_changedProperties);
-
- if (!manager.ready) {
- // Defer until openremote is initialised
- this._initCallback = (initEvent: OREvent) => {
- if (initEvent === OREvent.READY) {
- this.getSurvey();
- manager.removeListener(this._initCallback!);
- }
- };
- manager.addListener(this._initCallback);
- } else {
- this.getSurvey();
- }
+ this.getSurvey();
}
protected updated(_changedProperties: PropertyValues): void {
@@ -291,7 +279,7 @@ class OrSurvey extends LitElement {
this.previousButton = false;
}
- if (this.questionIndex + 1 == this.questions.length) {
+ if (this.questionIndex + 1 === this.questions.length) {
this.nextButtonLabel= 'Send';
} else {
this.nextButtonLabel= 'Next';
@@ -302,7 +290,7 @@ class OrSurvey extends LitElement {
if (this.survey.attributes && this.survey.attributes.published.value && this.saveanswers) {
localStorage.setItem('survey'+this.survey.id, "set");
- var xhttp = new XMLHttpRequest();
+ const xhttp = new XMLHttpRequest();
const url = manager.config.managerUrl ? manager.config.managerUrl+"/rest/survey/" : window.location.origin+"/rest/survey/";
xhttp.open("POST", url + this.survey.id, true);
xhttp.setRequestHeader("Content-type", "application/json");
@@ -349,13 +337,13 @@ class OrSurvey extends LitElement {
return;
}
const target = e.currentTarget;
- let surveyAnswers = this.surveyAnswers;
- let currQuestion:Asset = this.questions[this.questionIndex];
+ const surveyAnswers = this.surveyAnswers;
+ const currQuestion = this.questions[this.questionIndex];
if (this.getType(currQuestion.type) === "singleSelect" || this.getType(currQuestion.type) === "rating") {
if (!(target instanceof HTMLButtonElement) && !(target instanceof HTMLLabelElement)) {
return;
}
- if (target && target.dataset.autoforward == "true") {
+ if (target && target.dataset.autoforward === "true") {
this.nextQuestion();
} else {
if(currQuestion && currQuestion.id && surveyAnswers){
@@ -367,11 +355,11 @@ class OrSurvey extends LitElement {
}
else if (this.getType(currQuestion.type) === "text") {
- let id = this.questions[this.questionIndex].id;
+ const id = this.questions[this.questionIndex].id;
if(this.shadowRoot && id) {
- const element = (<HTMLInputElement>this.shadowRoot.getElementById(id));
+ const element = this.shadowRoot.getElementById(id) as HTMLInputElement;
if (element && currQuestion && currQuestion.id && surveyAnswers) {
- let value = element.value;
+ const value = element.value;
surveyAnswers[currQuestion.id] = value;
}
}
@@ -382,7 +370,7 @@ class OrSurvey extends LitElement {
return;
}
- if (target.dataset.autoforward == "true") {
+ if (target.dataset.autoforward === "true") {
this.nextQuestion();
} else {
if(currQuestion && currQuestion.id && surveyAnswers && target instanceof HTMLLabelElement) {
@@ -391,12 +379,12 @@ class OrSurvey extends LitElement {
}
const array = surveyAnswers[currQuestion.id];
if(this.shadowRoot && Array.isArray(array)) {
- let input = (<HTMLInputElement>this.shadowRoot.getElementById(target.htmlFor));
+ const input = this.shadowRoot.getElementById(target.htmlFor) as HTMLInputElement;
if (!input.checked) {
array.push(answer.value);
} else {
// Delete answer from array
- let index = surveyAnswers[currQuestion.id].indexOf(answer.value);
+ const index = surveyAnswers[currQuestion.id].indexOf(answer.value);
array.splice(index, 1);
}
this.surveyAnswers = surveyAnswers;
@@ -408,7 +396,7 @@ class OrSurvey extends LitElement {
getSurvey() {
let surveyId: string;
- if (location.hash.indexOf('survey') != -1) {
+ if (location.hash.indexOf('survey') !== -1) {
surveyId = location.hash.split('/')[1];
if(!surveyId) {
this.checkButtons();