From 649e10d94fadf8527c4977547c89e746a2f8f7a6 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Mon, 11 Dec 2023 09:18:07 +0100 Subject: [PATCH] shopfloor_mobile_base: add actions registry Makes easier to plug in actions from external modules w/o having to override the top bar component. --- .../static/wms/src/components/screen.js | 26 ++++++++++++- .../wms/src/services/actions_registry.js | 37 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 shopfloor_mobile_base/static/wms/src/services/actions_registry.js diff --git a/shopfloor_mobile_base/static/wms/src/components/screen.js b/shopfloor_mobile_base/static/wms/src/components/screen.js index edfdaa73f62..2c33d4dee77 100644 --- a/shopfloor_mobile_base/static/wms/src/components/screen.js +++ b/shopfloor_mobile_base/static/wms/src/components/screen.js @@ -5,6 +5,7 @@ */ import event_hub from "../services/event_hub.js"; +import {actions_registry} from "../services/actions_registry.js"; /* eslint-disable strict */ Vue.component("Screen", { @@ -333,12 +334,35 @@ Vue.component("nav-items-extra", { Vue.component("app-bar-actions", { template: `
+ +
+ `, + methods: { + actions: function () { + return actions_registry.by_tag("app-bar-actions"); + }, + }, +}); + +// Scan anything action component +Vue.component("app-bar-action-scan-anything", { + template: ` mdi-magnify - `, }); +// Scan anything action registry add +actions_registry.add("app-bar-action-scan-anything", { + render_component: "app-bar-action-scan-anything", + tag: "app-bar-actions", + sequence: 100, +}); Vue.component("app-version-footer", { template: ` diff --git a/shopfloor_mobile_base/static/wms/src/services/actions_registry.js b/shopfloor_mobile_base/static/wms/src/services/actions_registry.js new file mode 100644 index 00000000000..6fc3d21ea28 --- /dev/null +++ b/shopfloor_mobile_base/static/wms/src/services/actions_registry.js @@ -0,0 +1,37 @@ +/** + * Copyright 2023 Camptocamp SA + * @author Simone Orsi + * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + */ + +/** + * Global actions registry. + * + * Register action components to be used by specific UI components. + * + * For an example, check `app-bar-action-scan-anything`. + * + */ +export class ActionsRegistry { + constructor() { + this._data = {}; + } + get(key) { + return this._data[key]; + } + add(key, value) { + _.set(this._data, key, value); + } + /** + * Retrieve all actions matching given tag sorted by sequence. + * + * @param {String} tag: tag to filter with + */ + by_tag(tag) { + return _.filter(this._data, function (x) { + return x.tag == tag; + }).sort((current, next) => current.sequence - next.sequence); + } +} + +export var actions_registry = new ActionsRegistry();