Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion InteractiveHtmlBom/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions InteractiveHtmlBom/web/user-file-examples/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
3 changes: 3 additions & 0 deletions InteractiveHtmlBom/web/user-file-examples/userheader.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<div style="width:100%; height: 50px;">
Hello header
</div>

<!-- custom metadata (use with JSON string passed to --custom_metadata and user.js) -->
<div id="custom-metadata" style="padding: 4px 8px; font-size: small;"></div>
<div style="height: calc(100% - 100px)">