diff --git a/scripts/walletsBalance.sh b/scripts/walletsBalance.sh index c227bb2..91c1cc1 100755 --- a/scripts/walletsBalance.sh +++ b/scripts/walletsBalance.sh @@ -23,9 +23,11 @@ work() { if [[ $1 == "members" ]]; then username=$(curl -m 20 -s $DUNITER/wot/members | jq -r --arg pubkey "$i" '.results[] | select(.pubkey==$pubkey) | .uid') formatedBalance=$(printf "%-10s | %-45s | %-1s" $balance $i $username) + htmlBloc="$htmlBloc"$'\n'"$balance$i$username" unset username else formatedBalance=$(printf "%-10s | %-45s" $balance $i) + htmlBloc="$htmlBloc"$'\n'"$balance$i " fi unset balance @@ -49,3 +51,12 @@ work && unset wallets totalBalance=$(sort -nr <<<$totalBalance) [[ ! -d $GPATH/db ]] && mkdir $GPATH/db grep . <<<"$totalBalance" > $GPATH/db/wallets_balance.txt && rm /tmp/balance-g1.txt + +# Construct HTML +cp $GPATH/tpl/css/wallets_balance.css $WEBPATH/css/ +cp $GPATH/tpl/js/wallets_balance.js $WEBPATH/js/ +cp $GPATH/tpl/wallets_balance.html $WEBPATH/data/wallets_balance.html + +echo "$htmlBloc" > /tmp/solde_g1_html.txt +printf '%s\n' '/_LINE/r /tmp/solde_g1_html.txt' 1 '/_LINE/d' w | ed $WEBPATH/data/wallets_balance.html > /dev/null +rm /tmp/solde_g1_html.txt \ No newline at end of file diff --git a/tpl/css/wallets_balance.css b/tpl/css/wallets_balance.css new file mode 100644 index 0000000..4b1da9c --- /dev/null +++ b/tpl/css/wallets_balance.css @@ -0,0 +1,39 @@ +#pseudo, #key { + background-position: 10px 12px; /* Position the search icon */ + background-repeat: no-repeat; /* Do not repeat the icon image */ + width: 300px; /* Full-width */ + font-size: 16px; /* Increase font-size */ + padding: 12px 20px 12px 20px; /* Add some padding */ + border: 1px solid #ddd; /* Add a grey border */ + margin-bottom: 12px; /* Add some space below the input */ +} + +#soldes { + border-collapse: collapse; /* Collapse borders */ + width: 50%; /* Full-width */ + border: 1px solid #ddd; /* Add a grey border */ + font-size: 16px; /* Increase font-size */ +} + +#soldes th, #soldes td { + text-align: left; /* Left-align text */ + padding: 8px; /* Add padding */ +} + +#soldes tr { + /* Add a bottom border to all table rows */ + border-bottom: 1px solid #ddd; +} + +#soldes tr:hover { + /* Add a grey background color to the table header and on hover */ + background-color: #f1f1f1; +} + +#soldes th { + /* Add a grey background color to the table header and on hover */ + background-color: #ddd; + cursor: pointer; + position: sticky; + top: 0px; +} diff --git a/tpl/js/wallets_balance.js b/tpl/js/wallets_balance.js new file mode 100644 index 0000000..db3724e --- /dev/null +++ b/tpl/js/wallets_balance.js @@ -0,0 +1,41 @@ + +const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent; + +const comparer = (idx, asc) => (a, b) => ((v1, v2) => + v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2) + )(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx)); + +// Sort work +document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => { + const table = th.closest('table'); + Array.from(table.querySelectorAll('tr:nth-child(n+2)')) + .sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc)) + .forEach(tr => table.appendChild(tr) ); +}))); + +// Search +function recherche(select) { + // Declare variables + var input, filter, table, tr, td, i, txtValue; + input = document.getElementById(select); + filter = input.value.toUpperCase(); + table = document.getElementById("soldes"); + tr = table.getElementsByTagName("tr"); + th = table.getElementsByTagName("th"); + + // Loop through all table rows, and hide those who don't match the search query + for (i = 0; i < tr.length; i++) { + if (select == "pseudo") { td = tr[i].getElementsByTagName("td")[2]; } + else if (select == "key") { td = tr[i].getElementsByTagName("td")[1]; } + + if (td) { + txtValue = td.textContent || td.innerText; + if (txtValue.toUpperCase().indexOf(filter) > -1) { + tr[i].style.display = ""; + } else { + tr[i].style.display = "none"; + } + } + } + +} diff --git a/tpl/wallets_balance.html b/tpl/wallets_balance.html new file mode 100644 index 0000000..cd3fe7e --- /dev/null +++ b/tpl/wallets_balance.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + _LINE +
SoldeClé publiquePseudo
+ + + + +