diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ccbb960..57131e7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - The multipart id to references of multipart components others than part 1. - Internal BoM: `no_conflict` option to exclude fields from conflict detection. +- Internal BoM: HTML tables can be sorted selecting a column (Java Script). - Support for KICAD_CONFIG_HOME defined from inside KiCad. - Now layers can be selected using the default KiCad names. - More control over the name of the drill and gerber files. diff --git a/kibot/bom/html_writer.py b/kibot/bom/html_writer.py index fd16ef76..4c6ab1d1 100644 --- a/kibot/bom/html_writer.py +++ b/kibot/bom/html_writer.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2020 Salvador E. Tropea -# Copyright (c) 2020 Instituto Nacional de TecnologĂ­a Industrial +# Copyright (c) 2020-2021 Salvador E. Tropea +# Copyright (c) 2020-2021 Instituto Nacional de TecnologĂ­a Industrial # Copyright (c) 2016-2020 Oliver Henry Walters (@SchrodingersGat) # License: MIT # Project: KiBot (formerly KiPlot) @@ -53,7 +53,15 @@ STYLE_COMMON = (" .cell-title { vertical-align: bottom; }\n" " .color-ref { margin: 25px 0; }\n" " .color-ref th { text-align: left }\n" " .color-ref td { padding: 5px 20px; }\n" - " .head-table { margin-bottom: 2em; }\n") + " .head-table { margin-bottom: 2em; }\n" + # Table sorting cursor. 60% transparent when disabled. Solid white when enabled. + " .tg-sort-header::-moz-selection{background:0 0}\n" + " .tg-sort-header::selection{background:0 0}.tg-sort-header{cursor:pointer}\n" + " .tg-sort-header:after{content:'';float:right;border-width:0 5px 5px;border-style:solid;\n" + " border-color:#ffffff transparent;visibility:hidden;opacity:.6}\n" + " .tg-sort-header:hover:after{visibility:visible}\n" + " .tg-sort-asc:after,.tg-sort-asc:hover:after,.tg-sort-desc:after{visibility:visible;opacity:1}\n" + " .tg-sort-desc:after{border-bottom:none;border-width:5px 5px 0}\n") TABLE_MODERN = """ .content-table { border-collapse: @@ -74,6 +82,124 @@ TABLE_MODERN = """ .content-table tbody tr:last-of-type { border-bottom: 2px solid @bg@; } """ TABLE_CLASSIC = " .content-table, .content-table th, .content-table td { border: 1px solid black; }\n" +# JavaScript table sorter. Is floating around internet, i.e.: +# - Stack Overflow: https://stackoverflow.com/questions/61122696/addeventlistener-after-change-event +# - pimpmykicadbom: https://gitlab.com/antto/pimpmykicadbom +# - Table Generator: https://www.tablesgenerator.com/ +SORT_CODE = ('\n') def cell_class(col): @@ -187,6 +313,8 @@ def write_html(filename, groups, headings, head_names, cfg): head_color = HEAD_COLOR_R style += TABLE_MODERN.replace('@bg@', head_color) else: + # Background is white, so we change the sorting cursor to black + style = style.replace('border-color:#ffffff', 'border-color:#000000') style += TABLE_CLASSIC with open(filename, "w") as html: @@ -264,6 +392,7 @@ def write_html(filename, groups, headings, head_names, cfg): html.write('Empty Fields\n') html.write('\n') + html.write(SORT_CODE) html.write("") return True