Skip to content

Commit 4abd8d4

Browse files
committed
feat: add pagination to the history log table
1 parent 33748b0 commit 4abd8d4

File tree

4 files changed

+62
-17
lines changed

4 files changed

+62
-17
lines changed

assets/css/03_layout.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ input[type="radio"].nav {
121121
flex-wrap: wrap;
122122
gap: 6px;
123123
align-items: center;
124-
margin: 0 1rem 0 1rem;
124+
margin: 0 0.4rem 0 0.4rem;
125125
padding: 0.3rem 0.4rem 0.4rem 0.4rem;
126126
}
127127

128128
.view-content {
129129
max-width: 100vw;
130+
padding: 0.6rem;
130131
}
131132
}

assets/css/07_forms.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#parse-view textarea {
99
width: 40dvw;
10+
min-width: 350px;
1011
max-width: 650px;
1112
height: 400px;
1213
}
@@ -91,8 +92,7 @@ form .examples {
9192
}
9293

9394
fieldset {
94-
border: 1px solid rgba(0, 0, 0, 0.1);
95-
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
95+
border: none;
9696

9797
& legend {
9898
font-weight: 600;
@@ -103,8 +103,7 @@ fieldset {
103103
fieldset fieldset {
104104
font-size: 85%;
105105
margin: 0 0.4rem;
106-
border: 1px solid rgba(0, 0, 0, 0.05);
107-
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
106+
border: 1px solid var(--border);
108107

109108
& legend {
110109
color: var(--warm);

assets/css/10_history.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
& table {
1010
margin-top: 10px;
11+
min-width: 850px;
12+
max-width: var(--view-width);
1113
}
1214

1315
& th,
@@ -74,4 +76,28 @@
7476
font-size: var(--fsize-xxxs);
7577
font-style: italic;
7678
}
79+
80+
& {
81+
.pagination {
82+
display: flex;
83+
justify-content: left;
84+
align-items: left;
85+
gap: 0.5rem;
86+
}
87+
88+
.pagination a {
89+
color: var(--accent);
90+
text-decoration: underline;
91+
cursor: pointer;
92+
}
93+
94+
.pagination a.disabled {
95+
opacity: 0.5;
96+
cursor: not-allowed;
97+
}
98+
99+
.pagination span {
100+
color: var(--fg-1);
101+
}
102+
}
77103
}

assets/static/history.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ async function renameEntry(hash, newName) {
186186
}
187187

188188
// Render history table
189-
async function renderHistory() {
189+
let currentPage = 1;
190+
const entriesPerPage = 10;
191+
async function renderHistory(page = 1) {
190192
try {
191193
const entries = await getAllEntries();
192194
const container = document.getElementById("historyContainer");
@@ -197,24 +199,41 @@ async function renderHistory() {
197199
return;
198200
}
199201

202+
// calculate pagination
203+
const totalPages = Math.ceil(entries.length / entriesPerPage);
204+
currentPage = Math.max(1, Math.min(page, totalPages));
205+
const startIndex = (currentPage - 1) * entriesPerPage;
206+
const endIndex = startIndex + entriesPerPage;
207+
const paginatedEntries = entries.slice(startIndex, endIndex);
208+
200209
let html =
201210
"<table><thead><tr><th>Name</th><th>Hash</th><th>Created At</th><th>Actions</th></tr></thead><tbody>";
202211

203-
entries.forEach((entry) => {
212+
paginatedEntries.forEach((entry) => {
204213
html += `
205-
<tr>
206-
<td class="name-cell" onclick="editName('${entry.hash}')" id="name-${entry.hash}">${entry.name}</td>
207-
<td class="hash-cell"><abbr title="sha-256 digest generated from the logs input: ${entry.hash}">${entry.hash.slice(0, 10)}...</abbr></td>
208-
<td>${entry.created}</td>
209-
<td>
210-
<a class="btn-small btn-load" onclick="loadEntry('${entry.hash}')">Load</a>
211-
<a class="btn-small btn-delete" onclick="deleteEntry('${entry.hash}')">Delete</a>
212-
</td>
213-
</tr>
214-
`;
214+
<tr>
215+
<td class="name-cell" onclick="editName('${entry.hash}')" id="name-${entry.hash}">${entry.name}</td>
216+
<td class="hash-cell"><abbr title="sha-256 digest generated from the logs input: ${entry.hash}">${entry.hash.slice(0, 10)}...</abbr></td>
217+
<td>${entry.created}</td>
218+
<td>
219+
<a class="btn-small btn-load" onclick="loadEntry('${entry.hash}')">Load</a>
220+
<a class="btn-small btn-delete" onclick="deleteEntry('${entry.hash}')">Delete</a>
221+
</td>
222+
</tr>
223+
`;
215224
});
216225

217226
html += "</tbody></table>";
227+
228+
// pagination controls
229+
if (totalPages > 1) {
230+
html += '<div class="pagination">';
231+
html += `<a onclick="renderHistory(${currentPage - 1})" ${currentPage === 1 ? `class="disabled"` : ""}>Previous</a>`;
232+
html += `<span>Page ${currentPage} of ${totalPages}</span>`;
233+
html += `<a onclick="renderHistory(${currentPage + 1})" ${currentPage === totalPages ? `class="disabled"` : ""}>Next</a>`;
234+
html += "</div>";
235+
}
236+
218237
container.innerHTML = html;
219238
} catch (error) {
220239
container.innerHTML = "Error rendering history";

0 commit comments

Comments
 (0)