Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [20.x]

steps:
- name: Checkout code
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
matrix:
node-version:
- 12.x
- 14.x
- 20.x
- 20.x
os:
- ubuntu-latest
- windows-latest
Expand Down
53 changes: 48 additions & 5 deletions views/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
<section class="section">
<div class="container">
<h2 class="title is-2">Templates</h2>
<table class="table box versions">

<!-- Search Bar -->
<div class="field">
<div class="control">
<input type="text" id="searchInput" class="input" placeholder="SEARCH FOR TEMPLATE" onkeyup="filterTable()">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teja-pola if I am not wrong this is for searching templates, possible to make the id more related to that.
ex: id=searchTemplateInput

</div>
</div>

<table class="table box versions" id="templateTable">
<thead>
<tr>
<th>Name</th>
Expand All @@ -26,8 +34,8 @@
<th>Type</th>
</tr>
</thead>
<tbody>
{% for name, val in templateIndex |dictsort%}
<tbody id="tableBody">
{% for name, val in templateIndex | dictsort %}
<tr>
<th>
<a href="{{name}}.html">
Expand All @@ -36,12 +44,19 @@
{% else %}
{{name}}
{% endif %}
<a>
</a>
</th>
<td>{{val.description}}</td>
<td>{{val.ciceroVersion}}</td>
<td>{% if val.type === 0 %}Contract{% else %}Clause{% endif %}</td>
</tr>
{% endfor %}

<!-- No Results Row (Hidden by Default) -->
<tr id="noResultsRow" style="display: none;">
<td colspan="4" class="has-text-centered">No results found</td>
</tr>

</tbody>
<tfoot>
<tr>
Expand All @@ -58,4 +73,32 @@
</div>
</section>

{% endblock %}
<!-- JavaScript for Search Functionality -->
<script>
function filterTable() {
let input = document.getElementById("searchInput");
let filter = input.value.toLowerCase();
let table = document.getElementById("templateTable");
let rows = table.getElementsByTagName("tr");
let noResultsRow = document.getElementById("noResultsRow");
let matchFound = false;

for (let i = 1; i < rows.length - 1; i++) { // Exclude the last row (noResultsRow)
let td = rows[i].getElementsByTagName("th")[0];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getElementsByTagName is not the most concise way to access the first element, possible to use
let td = rows[i].querySelector("th");
querySelector to target the first and avoid the need for the index 0.

What do you say?

if (td) {
let textValue = td.textContent || td.innerText;
if (textValue.toLowerCase().indexOf(filter) > -1) {
rows[i].style.display = "";
matchFound = true;
} else {
rows[i].style.display = "none";
}
}
}

// Show "No results found" row if no matches are found
noResultsRow.style.display = matchFound ? "none" : "";
}
</script>

{% endblock %}