forked from OCA/wms
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shopfloor_mobile_base: add actions registry
Makes easier to plug in actions from external modules w/o having to override the top bar component.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
shopfloor_mobile_base/static/wms/src/services/actions_registry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright 2023 Camptocamp SA | ||
* @author Simone Orsi <simahawk@gmail.com> | ||
* 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(); |