Hide empty pinout columns (#2783)

* hide empty rows

* refactor

* fix generation error

* show all if not empty

* remove old code
This commit is contained in:
David Holdeman 2021-05-31 09:37:01 -05:00 committed by GitHub
parent baa529e9dd
commit 21264f9cf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 29 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)"/" DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)"/"
TEXT=$(sed -e "/###CSS###/{r ${DIR}style.css" -e 'd}' -e "/###JS###/{r ${DIR}script.js" -e 'd}' ${DIR}pinout.html | sed -e "s/\/\/\/DATA\/\/\//`$(echo ${1//\//\\/} | tr -d '\n')`,\n\/\/\/DATA\/\/\//") TEXT=$(sed -e "/###CSS###/{r ${DIR}style.css" -e 'd}' -e "/###JS###/{r ${DIR}script.js" -e 'd}' ${DIR}pinout.html | sed -e "s/\/\/\/DATA\/\/\//\`$(echo ${1//\//\\/} | tr -d '\n')\`,\n\/\/\/DATA\/\/\//")
echo "$TEXT" > $2 echo "$TEXT" > $2

View File

@ -6,7 +6,6 @@
###CSS### ###CSS###
</style> </style>
<script type="text/javascript" src="yaml.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
###JS### ###JS###
</script> </script>
@ -19,11 +18,11 @@
<template id="table-template"> <template id="table-template">
<tr class="data"> <tr class="data">
<td class="pin-data"></td> <td class="pin-data" data-field="pin"></td>
<td class="ts-data"></td> <td class="ts-data" data-field="ts_name"></td>
<td class="type-data"></td> <td class="type-data" data-field="type"</td>
<td class="function-data"></td> <td class="function-data" data-field="function"></td>
<td class="color-data"></td> <td class="color-data" data-field="color"></td>
</tr> </tr>
</template> </template>
@ -37,11 +36,11 @@
<table class="info-table"> <table class="info-table">
<thead> <thead>
<tr> <tr>
<th class="pin-header">Pin Number</th> <th class="pin-header" data-field="pin">Pin Number</th>
<th class="ts-header">TS Name</th> <th class="ts-header" data-field="ts_name">TS Name</th>
<th class="type-header">Type</th> <th class="type-header" data-field="type">Type</th>
<th class="function-header">Typical Function</th> <th class="function-header" data-field="function">Typical Function</th>
<th class="color-header">Pigtail Color</th> <th class="color-header" data-field="color">Pigtail Color</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -52,11 +51,11 @@
<table class="pinout-table"> <table class="pinout-table">
<thead> <thead>
<tr> <tr>
<th class="pin-header">Pin Number</th> <th class="pin-header" data-field="pin">Pin Number</th>
<th class="ts-header">TS Name</th> <th class="ts-header" data-field="ts_name">TS Name</th>
<th class="type-header">Type</th> <th class="type-header" data-field="type">Type</th>
<th class="function-header">Typical Function</th> <th class="function-header" data-field="function">Typical Function</th>
<th class="color-header">Pigtail Color</th> <th class="color-header" data-field="color">Pigtail Color</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

@ -2,21 +2,38 @@ var connectorData = [
///DATA/// ///DATA///
]; ];
function hideEmptyColumns(table) {
var rows = table.querySelector('tbody').children;
var tableHead = table.querySelector("thead>tr")
var cols = tableHead.children
for (var i = 0; i < cols.length; i++) {
var empty = true;
for (var ii = 0; ii < rows.length; ii++) {
empty = rows[ii].children[i].textContent.length > 0 ? false : empty;
}
if (empty) {
tableHead.querySelectorAll('th')[i].style.display = 'none';
for (var ii = 0; ii < rows.length; ii++) {
rows[ii].children[i].style.display = 'none';
}
} else {
tableHead.querySelectorAll('th')[i].style.display = '';
for (var ii = 0; ii < rows.length; ii++) {
rows[ii].children[i].style.display = '';
}
}
}
}
function addRow(table, pin, pdiv) { function addRow(table, pin, pdiv) {
var template = document.getElementById("table-template"); var template = document.getElementById("table-template");
var clone = template.content.cloneNode(true); var clone = template.content.cloneNode(true);
var row = clone.querySelector(".data"); var row = clone.querySelector(".data");
var pdata = clone.querySelector(".pin-data"); var cells = row.children;
var idata = clone.querySelector(".ts-data"); for (var i = 0; i < cells.length; i++) {
var tdata = clone.querySelector(".type-data"); var cell = cells[i];
var fdata = clone.querySelector(".function-data"); cell.textContent = pin[cell.dataset.field];
var cdata = clone.querySelector(".color-data"); }
pdata.textContent = pin.pin;
pdata.dataset.type = pin.type;
idata.textContent = pin.ts_name;
tdata.textContent = pin.type
fdata.textContent = pin.function;
cdata.textContent = pin.color
if (pdiv) { if (pdiv) {
row.addEventListener('click', function(table, pin, pdiv) { row.addEventListener('click', function(table, pin, pdiv) {
clickPin(table.parentElement.parentElement.parentElement.querySelector(".info-table tbody"), pin, pdiv); clickPin(table.parentElement.parentElement.parentElement.querySelector(".info-table tbody"), pin, pdiv);
@ -25,7 +42,6 @@ function addRow(table, pin, pdiv) {
} }
table.appendChild(clone); table.appendChild(clone);
} }
function clickPin(table, pin, pdiv) { function clickPin(table, pin, pdiv) {
table.parentElement.style.display = "table"; table.parentElement.style.display = "table";
table.innerHTML = ""; table.innerHTML = "";
@ -40,6 +56,7 @@ function clickPin(table, pin, pdiv) {
pins[i].classList.remove("selected"); pins[i].classList.remove("selected");
} }
pdiv.classList.add("selected"); pdiv.classList.add("selected");
hideEmptyColumns(table.parentElement);
} }
window.addEventListener('load', function() { window.addEventListener('load', function() {
@ -109,6 +126,7 @@ window.addEventListener('load', function() {
cdiv.appendChild(pdiv); cdiv.appendChild(pdiv);
addRow(fullTable, connector.pins[i], pdiv); addRow(fullTable, connector.pins[i], pdiv);
} }
hideEmptyColumns(sdiv.querySelector('.pinout-table'));
}.bind(null, connector, sdiv, img)); }.bind(null, connector, sdiv, img));
img.src = connector.info.image.file; img.src = connector.info.image.file;
} }