@@ -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