From 7ef83d01a6808e8713561384cc737950ae727b0d Mon Sep 17 00:00:00 2001 From: JuMiSanAr Date: Wed, 6 Dec 2023 11:55:15 +0100 Subject: [PATCH 1/2] shopfloor_mobile_base: force nav item counter update --- shopfloor_mobile_base/static/wms/src/main.js | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/shopfloor_mobile_base/static/wms/src/main.js b/shopfloor_mobile_base/static/wms/src/main.js index 76379add59..78a7ddac25 100644 --- a/shopfloor_mobile_base/static/wms/src/main.js +++ b/shopfloor_mobile_base/static/wms/src/main.js @@ -77,6 +77,7 @@ new Vue({ global_state_key: "", loading: false, loading_msg_custom: "", + loadingMenu: false, appconfig: null, }; _.merge(data, config_registry.generare_data_keys()); @@ -122,6 +123,9 @@ new Vue({ }); event_hub.$emit("app:mounted", self, false); }, + beforeUpdate: function () { + this.loadMenu(true); + }, computed: { ...config_registry.generate_computed_properties(), app_info: function () { @@ -231,9 +235,20 @@ new Vue({ "SERVICE-CTX-PROFILE-ID": this.profile.id, }, }); - return odoo.call("menu").then(function (result) { - self.appmenu = result.data; - }); + if (!this.loadingMenu) { + // TODO: this is added to make sure to always have + // up-to-date counter in the navigation drawer items. + // It is not an ideal solution though, as it will be called + // whenever the component is updated (there's no easy way + // to refresh the counters only when needed, + // as each scenario has a different implementation). + // That being said, this call is very small so it's not that costly. + this.loadingMenu = true; + return odoo.call("menu").then((result) => { + self.appmenu = result.data; + this.loadingMenu = false; + }); + } }, login: function (evt, data) { evt.preventDefault(); From 9510682e03ada60f462a8b6b5b0d05fca1fc9582 Mon Sep 17 00:00:00 2001 From: JuMiSanAr Date: Mon, 18 Dec 2023 16:15:46 +0100 Subject: [PATCH 2/2] shopfloor_mobile_base: improve nav item counter update --- shopfloor_mobile_base/static/wms/src/main.js | 24 +++++-------------- .../static/wms/src/scenario/mixins.js | 3 +++ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/shopfloor_mobile_base/static/wms/src/main.js b/shopfloor_mobile_base/static/wms/src/main.js index 78a7ddac25..be38599f9c 100644 --- a/shopfloor_mobile_base/static/wms/src/main.js +++ b/shopfloor_mobile_base/static/wms/src/main.js @@ -77,7 +77,6 @@ new Vue({ global_state_key: "", loading: false, loading_msg_custom: "", - loadingMenu: false, appconfig: null, }; _.merge(data, config_registry.generare_data_keys()); @@ -121,11 +120,11 @@ new Vue({ self.profile = profile; self.loadMenu(true); }); + event_hub.$on("menu_drawer:update", function () { + self.loadMenu(true); + }); event_hub.$emit("app:mounted", self, false); }, - beforeUpdate: function () { - this.loadMenu(true); - }, computed: { ...config_registry.generate_computed_properties(), app_info: function () { @@ -235,20 +234,9 @@ new Vue({ "SERVICE-CTX-PROFILE-ID": this.profile.id, }, }); - if (!this.loadingMenu) { - // TODO: this is added to make sure to always have - // up-to-date counter in the navigation drawer items. - // It is not an ideal solution though, as it will be called - // whenever the component is updated (there's no easy way - // to refresh the counters only when needed, - // as each scenario has a different implementation). - // That being said, this call is very small so it's not that costly. - this.loadingMenu = true; - return odoo.call("menu").then((result) => { - self.appmenu = result.data; - this.loadingMenu = false; - }); - } + return odoo.call("menu").then(function (result) { + self.appmenu = result.data; + }); }, login: function (evt, data) { evt.preventDefault(); diff --git a/shopfloor_mobile_base/static/wms/src/scenario/mixins.js b/shopfloor_mobile_base/static/wms/src/scenario/mixins.js index b3b68f6850..d342446db4 100644 --- a/shopfloor_mobile_base/static/wms/src/scenario/mixins.js +++ b/shopfloor_mobile_base/static/wms/src/scenario/mixins.js @@ -357,6 +357,9 @@ export var ScenarioBaseMixin = { // Move to new state, data will be refreshed right after. this.state_to(state_key); } + // Make sure the counters and all the data from the navigation drawer menu + // is up to date after new data from the backend is received. + event_hub.$emit("menu_drawer:update"); }, on_call_error: function (result) { alert(result.status + " " + result.error);