diff --git a/InteractiveHtmlBom/core/config.py b/InteractiveHtmlBom/core/config.py index 605a40bc..55371e0e 100644 --- a/InteractiveHtmlBom/core/config.py +++ b/InteractiveHtmlBom/core/config.py @@ -39,7 +39,7 @@ class Config: 'dark_mode', 'show_pads', 'show_fabrication', 'show_silkscreen', 'highlight_pin1', 'redraw_on_drag', 'board_rotation', 'checkboxes', 'bom_view', 'layer_view', 'offset_back_rotation', - 'kicad_text_formatting', 'mark_when_checked' + 'kicad_text_formatting', 'mark_when_checked', 'custom_metadata' ] default_show_group_fields = ["Value", "Footprint"] @@ -494,6 +494,10 @@ def add_options(cls, parser, version): help='Name of the extra field that indicates ' 'do not populate status. Components with ' 'this field not empty will be excluded.') + parser.add_argument('--custom-metadata', default='', + help='Custom metadata. Gets attached to ' + 'the BOM and can be accessed in ' + 'the user customization files.') def get_ini_defaults(self): # type: () -> dict | None @@ -645,6 +649,7 @@ def set_from_args(self, args): self.board_variant_whitelist = self._split(args.variants_whitelist) self.board_variant_blacklist = self._split(args.variants_blacklist) self.dnp_field = args.dnp_field + self.custom_metadata = args.custom_metadata def get_html_config(self): import json diff --git a/InteractiveHtmlBom/web/user-file-examples/user.js b/InteractiveHtmlBom/web/user-file-examples/user.js index 4cffc3b1..4a3a3933 100644 --- a/InteractiveHtmlBom/web/user-file-examples/user.js +++ b/InteractiveHtmlBom/web/user-file-examples/user.js @@ -2,3 +2,23 @@ // Event argument will always be {eventType, args} dict EventHandler.registerCallback(IBOM_EVENT_TYPES.ALL, (e) => console.log(e)); + +// Example custom metadata (use with userheader.html) +window.addEventListener("load", function () { + var meta = {}; + try { + console.log(typeof config.custom_metadata); + console.log(JSON.stringify(config.custom_metadata)); + meta = JSON.parse(config.custom_metadata || "{}"); + } catch (e) { + console.error("custom_metadata is no valid JSON string:", e); + } + + var element = document.getElementById("custom-metadata"); + if (!element) return; + + var text = "Drawing: " + (meta.drawing || "-") + + " | Customer: " + (meta.customer || "-"); + + element.textContent = text; +}); diff --git a/InteractiveHtmlBom/web/user-file-examples/userheader.html b/InteractiveHtmlBom/web/user-file-examples/userheader.html index bb597c57..e721c5ea 100644 --- a/InteractiveHtmlBom/web/user-file-examples/userheader.html +++ b/InteractiveHtmlBom/web/user-file-examples/userheader.html @@ -2,4 +2,7 @@