Skip to content

Commit 0327f04

Browse files
committed
Add copy to clipboard button
Fixes #55
1 parent f9f67c5 commit 0327f04

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

InteractiveHtmlBom/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def set_from_args(self, args):
208208

209209
# Extra
210210
self.netlist_file = args.netlist_file
211-
self.extra_fields = args.extra_fields.split(',')
211+
self.extra_fields = [f for f in args.extra_fields.split(',') if f]
212212
self.board_variant_field = args.variant_field
213213
self.board_variant_whitelist = args.variants_whitelist
214214
self.board_variant_blacklist = args.variants_blacklist

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def main(pcb, config):
511511

512512
# Get extra field data
513513
extra_fields = None
514-
if os.path.isfile(config.netlist_file):
514+
if config.netlist_file and os.path.isfile(config.netlist_file):
515515
extra_fields = parse_schematic_data(config.netlist_file)
516516
need_extra_fields = \
517517
config.extra_fields or config.board_variant_whitelist or config.dnp_field

InteractiveHtmlBom/ibom.css

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ button#bom-btn {
7171
background-repeat: no-repeat;
7272
}
7373

74+
button#copy {
75+
background-image: url("data:image/svg+xml,%3Csvg height='48' viewBox='0 0 48 48' width='48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h48v48h-48z' fill='none'/%3E%3Cpath d='M32 2h-24c-2.21 0-4 1.79-4 4v28h4v-28h24v-4zm6 8h-22c-2.21 0-4 1.79-4 4v28c0 2.21 1.79 4 4 4h22c2.21 0 4-1.79 4-4v-28c0-2.21-1.79-4-4-4zm0 32h-22v-28h22v28z'/%3E%3C/svg%3E");
76+
background-position: 6px 6px;
77+
background-repeat: no-repeat;
78+
background-size: 26px 26px;
79+
border-radius: 6px;
80+
height: 40px;
81+
width: 40px;
82+
margin: 10px 5px;
83+
}
84+
85+
button#copy:active {
86+
box-shadow: inset 0px 0px 5px #6c6c6c;
87+
}
88+
7489
.left-most-button {
7590
border-right: 0;
7691
border-top-left-radius: 6px;
@@ -329,7 +344,7 @@ canvas:active {
329344
}
330345

331346
.filter {
332-
width: calc(60% - 10px);
347+
width: calc(60% - 64px);
333348
}
334349

335350
.reflookup {

InteractiveHtmlBom/ibom.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
oninput="updateRefLookup(this.value)">
120120
<input id="filter" class="searchbox filter hideonprint" type="text" placeholder="Filter"
121121
oninput="updateFilter(this.value)">
122+
<div class="button-container hideonprint" style="float: left">
123+
<button id="copy" title="Copy bom table to clipboard"
124+
onclick="copyToClipboard()"></button>
125+
</div>
122126
</div>
123127
<div id="dbg"></div>
124128
<table class="bom">

InteractiveHtmlBom/ibom.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,55 @@ function updateRefLookup(input) {
507507
populateBomTable();
508508
}
509509

510+
function copyToClipboard() {
511+
var text = '';
512+
for (var node of bomhead.childNodes[0].childNodes) {
513+
if (node.firstChild) {
514+
text = text + node.firstChild.nodeValue;
515+
}
516+
if (node != bomhead.childNodes[0].lastChild) {
517+
text += '\t';
518+
}
519+
}
520+
text += '\n';
521+
for (var row of bombody.childNodes) {
522+
for (var cell of row.childNodes) {
523+
for (var node of cell.childNodes) {
524+
if (node.nodeName == "INPUT") {
525+
if (node.checked) {
526+
text = text + '✓';
527+
}
528+
} else if (node.nodeName == "MARK") {
529+
text = text + node.firstChild.nodeValue;
530+
} else {
531+
text = text + node.nodeValue;
532+
}
533+
}
534+
if (cell != row.lastChild) {
535+
text += '\t';
536+
}
537+
}
538+
text += '\n';
539+
}
540+
var textArea = document.createElement("textarea");
541+
textArea.classList.add('clipboard-temp');
542+
textArea.value = text;
543+
544+
document.body.appendChild(textArea);
545+
textArea.focus();
546+
textArea.select();
547+
548+
try {
549+
if (document.execCommand('copy')) {
550+
console.log('Bom copied to clipboard.');
551+
}
552+
} catch (err) {
553+
console.log('Can not copy to clipboard.');
554+
}
555+
556+
document.body.removeChild(textArea);
557+
}
558+
510559
function silkscreenVisible(visible) {
511560
if (visible) {
512561
allcanvas.front.silk.style.display = "";

0 commit comments

Comments
 (0)