From 88b374349ef7d3ad8a440389d6a36f1232456c55 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 14 Sep 2023 17:37:50 +0200 Subject: [PATCH 1/7] Add debug logging to Vuex action for loading semantic tags Signed-off-by: Florian Hotze --- .../org.openhab.ui/web/src/js/store/modules/semantics.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js b/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js index a263fcdbae..f41ad9dc5a 100644 --- a/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js +++ b/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js @@ -17,6 +17,7 @@ const getters = { const actions = { loadSemantics () { + console.debug('Loading semantic tags ...') if (this.getters.apiEndpoint('tags')) { return api.get('/rest/tags') .then((tags) => { @@ -32,9 +33,14 @@ const actions = { // Save as i18n messages i18n.mergeLocaleMessage(i18n.locale, state.Labels) + console.debug('Successfully loaded semantic tags.') return Promise.resolve() }) - .catch((e) => Promise.reject(e)) + .catch((e) => { + console.error('Failed to load semantic tags:') + console.error(e) + Promise.reject('Failed to load semantic tags: ' + e) + }) } else { return Promise.resolve() } From 11e4cd3df46b8b5262ea72926cd7c92d5f788850 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 14 Sep 2023 17:38:14 +0200 Subject: [PATCH 2/7] Clear existing labels when loading semantic tags Signed-off-by: Florian Hotze --- bundles/org.openhab.ui/web/src/js/store/modules/semantics.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js b/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js index f41ad9dc5a..3b2f37a7fa 100644 --- a/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js +++ b/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js @@ -26,6 +26,7 @@ const actions = { state.Points = tags.filter(t => t.uid.startsWith('Point')).map(t => t.name) state.Properties = tags.filter(t => t.uid.startsWith('Property')).map(t => t.name) // Store i18n labels + state.Labels = {} // Clear existing labels for (const i in tags) { const t = tags[i] state.Labels[t.name] = t.label || t.name From 672eff370dec32ddd788487d1edff4f7626725b9 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 14 Sep 2023 17:39:10 +0200 Subject: [PATCH 3/7] Load semantic tags in parallel with other data on app init Signed-off-by: Florian Hotze --- bundles/org.openhab.ui/web/src/components/app.vue | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/components/app.vue b/bundles/org.openhab.ui/web/src/components/app.vue index 3f41b2883b..df47cbd844 100644 --- a/bundles/org.openhab.ui/web/src/components/app.vue +++ b/bundles/org.openhab.ui/web/src/components/app.vue @@ -498,7 +498,8 @@ export default { ...this.$store.getters.apiEndpoint('ui') ? [this.$oh.api.get('/rest/ui/components/ui:page'), this.$oh.api.get('/rest/ui/components/ui:widget')] : [Promise.resolve([]), Promise.resolve([])], - dayjsLocalePromise + dayjsLocalePromise, + this.$store.dispatch('loadSemantics') ]) }).then((data) => { // store the pages & widgets @@ -513,11 +514,9 @@ export default { if (data[2]) dayjs.locale(data[2].key) - // load the Semantic tags - this.$store.dispatch('loadSemantics').then(() => { - this.ready = true - return Promise.resolve() - }) + // finished with loading + this.ready = true + return Promise.resolve() }) }, pageIsVisible (page) { @@ -705,7 +704,6 @@ export default { if (refreshToken) { this.refreshAccessToken().then(() => { this.loggedIn = true - // this.loadData() this.init = true }).catch((err) => { console.warn('Error while using the stored refresh_token to get a new access_token: ' + err + '. Logging out & cleaning session.') From e3fdec91439824757085079ebc43eebcf6711081 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 14 Sep 2023 18:13:20 +0200 Subject: [PATCH 4/7] Use mutation to set semantic tags from within action Signed-off-by: Florian Hotze --- .../web/src/js/store/modules/semantics.js | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js b/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js index 3b2f37a7fa..0e08a04e17 100644 --- a/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js +++ b/bundles/org.openhab.ui/web/src/js/store/modules/semantics.js @@ -15,25 +15,30 @@ const getters = { } } +const mutations = { + setSemantics (state, { tags }) { + state.Locations = tags.filter(t => t.uid.startsWith('Location')).map(t => t.name) + state.Equipment = tags.filter(t => t.uid.startsWith('Equipment')).map(t => t.name) + state.Points = tags.filter(t => t.uid.startsWith('Point')).map(t => t.name) + state.Properties = tags.filter(t => t.uid.startsWith('Property')).map(t => t.name) + // Store i18n labels + state.Labels = {} // Clear existing labels + for (const i in tags) { + const t = tags[i] + state.Labels[t.name] = t.label || t.name + } + // Save as i18n messages + i18n.mergeLocaleMessage(i18n.locale, state.Labels) + } +} + const actions = { - loadSemantics () { + loadSemantics (context) { console.debug('Loading semantic tags ...') if (this.getters.apiEndpoint('tags')) { return api.get('/rest/tags') .then((tags) => { - state.Locations = tags.filter(t => t.uid.startsWith('Location')).map(t => t.name) - state.Equipment = tags.filter(t => t.uid.startsWith('Equipment')).map(t => t.name) - state.Points = tags.filter(t => t.uid.startsWith('Point')).map(t => t.name) - state.Properties = tags.filter(t => t.uid.startsWith('Property')).map(t => t.name) - // Store i18n labels - state.Labels = {} // Clear existing labels - for (const i in tags) { - const t = tags[i] - state.Labels[t.name] = t.label || t.name - } - // Save as i18n messages - i18n.mergeLocaleMessage(i18n.locale, state.Labels) - + context.commit('setSemantics', { tags }) console.debug('Successfully loaded semantic tags.') return Promise.resolve() }) @@ -48,11 +53,9 @@ const actions = { } } -const mutations = {} - export default { state, getters, - actions, - mutations + mutations, + actions } From 270354751d394504db0f41b520ec51a44aa715c4 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 14 Sep 2023 18:13:52 +0200 Subject: [PATCH 5/7] Add debug logging to homecards-mixin loadModel Signed-off-by: Florian Hotze --- bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js b/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js index de47e6ccc0..ddf87e1261 100644 --- a/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js +++ b/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js @@ -114,6 +114,7 @@ export default { item.children.forEach(child => this.sortModel(child)) }, loadModel (page) { + console.debug('Loading semantic model and building semantic homepages ...') this.$oh.api.get('/rest/items?staticDataOnly=true&metadata=semantics,listWidget,widgetOrder') .then((data) => { this.items = data @@ -167,6 +168,7 @@ export default { this.model.equipment = Object.keys(equipment).sort((a, b) => this.$t(a).localeCompare(this.$t(b))).map(k => this.buildModelCard('equipment', equipment[k], k, page)) this.model.properties = Object.keys(properties).sort((a, b) => this.$t(a).localeCompare(this.$t(b))).map(k => this.buildModelCard('property', properties[k], k, page)) this.modelReady = true + console.debug('Successfully loaded semantic model and build semantic homepages.') }) .catch((err) => { console.log('Error while loading model: ' + err) From 1cf5e47ef8d25f066415fd52d86e998e2cbe3023 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 14 Sep 2023 18:14:33 +0200 Subject: [PATCH 6/7] Reload semantic model & Rebuilt pages on semantic tags store mutation Signed-off-by: Florian Hotze --- bundles/org.openhab.ui/web/src/pages/home.vue | 6 ++++++ .../org.openhab.ui/web/src/pages/home/homecards-mixin.js | 1 + 2 files changed, 7 insertions(+) diff --git a/bundles/org.openhab.ui/web/src/pages/home.vue b/bundles/org.openhab.ui/web/src/pages/home.vue index 8c30f03e2d..7450cfe874 100644 --- a/bundles/org.openhab.ui/web/src/pages/home.vue +++ b/bundles/org.openhab.ui/web/src/pages/home.vue @@ -175,6 +175,12 @@ export default { this.$store.dispatch('stopTrackingStates') }, onPageInit () { + this.$store.subscribe((mutation, state) => { + if (mutation.type === 'setSemantics') { + this.loadModel() + } + }) + if (window.OHApp) { if (window.OHApp.pinToHome) this.showPinToHome = true if (window.OHApp.exitToApp) this.showExitToApp = true diff --git a/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js b/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js index ddf87e1261..c546f2360f 100644 --- a/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js +++ b/bundles/org.openhab.ui/web/src/pages/home/homecards-mixin.js @@ -114,6 +114,7 @@ export default { item.children.forEach(child => this.sortModel(child)) }, loadModel (page) { + this.modelReady = false console.debug('Loading semantic model and building semantic homepages ...') this.$oh.api.get('/rest/items?staticDataOnly=true&metadata=semantics,listWidget,widgetOrder') .then((data) => { From be484b15030834c72817e6f00bf4d886c8536037 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 14 Sep 2023 18:17:22 +0200 Subject: [PATCH 7/7] Only load semantic model & Rebuilt pages on semantic tags store mutation Signed-off-by: Florian Hotze --- bundles/org.openhab.ui/web/src/pages/home.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/bundles/org.openhab.ui/web/src/pages/home.vue b/bundles/org.openhab.ui/web/src/pages/home.vue index 7450cfe874..67b96e788e 100644 --- a/bundles/org.openhab.ui/web/src/pages/home.vue +++ b/bundles/org.openhab.ui/web/src/pages/home.vue @@ -156,7 +156,6 @@ export default { watch: { ready (val, oldVal) { if (val && !oldVal) { - this.loadModel() this.$store.dispatch('startTrackingStates') } }