-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from Marvell-Consulting/fix-paging-bug
Fix paging bug
- Loading branch information
Showing
9 changed files
with
221 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import path from 'node:path'; | ||
|
||
export function fileMimeTypeHandler(mimetype: string, originalFileName: string): string { | ||
let ext = 'unknown'; | ||
if (mimetype === 'application/octet-stream') { | ||
ext = path.extname(originalFileName); | ||
switch (ext) { | ||
case '.parquet': | ||
return 'application/vnd.apache.parquet'; | ||
case '.json': | ||
return 'application/json'; | ||
case '.xls': | ||
case '.xlsx': | ||
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; | ||
case '.csv': | ||
return 'text/csv'; | ||
default: | ||
throw new Error(`unsupported format ${ext}`); | ||
} | ||
} else if (mimetype === 'application/x-gzip') { | ||
ext = originalFileName.split('.').reverse()[1]; | ||
switch (ext) { | ||
case 'json': | ||
case 'csv': | ||
return 'application/x-gzip'; | ||
default: | ||
throw new Error(`unsupported format ${ext}`); | ||
} | ||
} | ||
return mimetype; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
// Special thanks ChatGPT... The GovUK pagination algorithm | ||
export function generateSequenceForNumber(highlight: number, end: number): (string | number)[] { | ||
const sequence: (string | number)[] = []; | ||
|
||
// Validate input | ||
if (highlight < 1 || highlight > end) { | ||
throw new Error(`Highlighted number must be between 1 and ${end}.`); | ||
} | ||
|
||
if (end - 1 < 3) { | ||
sequence.push( | ||
...Array.from({ length: end - 1 + 1 }, (_, index) => 1 + index).map((num) => | ||
num === highlight ? num : num | ||
) | ||
); | ||
return sequence; | ||
} | ||
|
||
// Case 1: Highlight is within the first 3 pages | ||
if (highlight <= 3) { | ||
sequence.push(...Array.from({ length: 3 }, (_, index) => 1 + index)); | ||
sequence[highlight - 1] = highlight; // Highlight the specific number | ||
if (end > 4) { | ||
sequence.push('...'); | ||
sequence.push(end); | ||
} | ||
return sequence; | ||
} | ||
|
||
// Case 2: Highlight is near or at the last 3 pages | ||
if (highlight >= end - 2) { | ||
if (end - 3 > 1) { | ||
sequence.push(1, '...'); | ||
} | ||
for (let i = end - 3; i <= end; i++) { | ||
if (i === highlight) { | ||
sequence.push(i); | ||
} else { | ||
sequence.push(i); | ||
} | ||
} | ||
return sequence; | ||
} | ||
|
||
// Case 3: General case | ||
if (highlight - 2 > 1) { | ||
sequence.push(1, '...'); | ||
sequence.push(highlight - 1); | ||
} else { | ||
sequence.push(...Array.from({ length: highlight - 1 }, (_, index) => index + 1)); | ||
} | ||
|
||
sequence.push(highlight); // Highlight the number | ||
|
||
if (highlight + 1 < end) { | ||
sequence.push(highlight + 1, '...', end); | ||
} else { | ||
sequence.push(...Array.from({ length: end - highlight }, (_, index) => highlight + 1 + index)); | ||
} | ||
|
||
return sequence; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<nav class="govuk-pagination" role="navigation" aria-label="Pagination"> | ||
<% if (locals.total_pages === 1) { %> | ||
<ul class="govuk-pagination__list"> | ||
<li class="govuk-pagination__item govuk-pagination__item--current"> | ||
<a href="#" aria-current="page" class="govuk-link govuk-pagination__link"> | ||
<%= locals.current_page %> | ||
</a> | ||
</li> | ||
</ul> | ||
<% } else { %> | ||
<% if (locals.current_page > 1) { %> | ||
<div class="govuk-pagination__prev"> | ||
<a class="govuk-link govuk-pagination__link" | ||
href="<%= buildUrl(url, i18n.language, { page_number: locals.current_page - 1, page_size: locals.page_size }) %>" | ||
rel="prev"> | ||
<svg class="govuk-pagination__icon govuk-pagination__icon--prev" xmlns="http://www.w3.org/2000/svg" | ||
height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13"> | ||
<path | ||
d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"> | ||
</path> | ||
</svg> | ||
<span class="govuk-pagination__link-title"> | ||
<%= t('pagination.previous') %> | ||
</span> | ||
</a> | ||
</div> | ||
<% } %> | ||
<ul class="govuk-pagination__list"> | ||
<% locals.pagination.forEach((item) => { %> | ||
<% if (item === '...') { %> | ||
<li class="govuk-pagination__item govuk-pagination__item--ellipses"> | ||
⋯ | ||
</li> | ||
<% } else if(item === locals.current_page) { %> | ||
<li class="govuk-pagination__item govuk-pagination__item--current"> | ||
<a href="#" aria-current="page" class="govuk-link govuk-pagination__link"> | ||
<%= item %> | ||
</a> | ||
</li> | ||
<% } else { %> | ||
<li class="govuk-pagination__item"> | ||
<a class="govuk-link govuk-pagination__link" | ||
href="<%= buildUrl(url, i18n.language, { page_number: item, page_size: locals.page_size }) %>" | ||
aria-label="Page <%= item %>"> | ||
<%= item %> | ||
</a> | ||
</li> | ||
<% }%> | ||
<% }); %> | ||
</ul> | ||
<% if (locals.current_page < locals.total_pages) { %> | ||
<div class="govuk-pagination__next"> | ||
<a class="govuk-link govuk-pagination__link" | ||
href="<%= buildUrl(url, i18n.language, { page_number: locals.current_page + 1, page_size: locals.page_size }) %>" | ||
rel="next"> | ||
<span class="govuk-pagination__link-title"> | ||
<%= t('pagination.next') %> | ||
</span> | ||
<svg class="govuk-pagination__icon govuk-pagination__icon--next" | ||
xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" | ||
focusable="false" viewBox="0 0 15 13"> | ||
<path | ||
d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"> | ||
</path> | ||
</svg> | ||
</a> | ||
</div> | ||
<% } %> | ||
<% } %> | ||
</nav> | ||
</div> | ||
|
||
<div class="govuk-grid-column-one-third"> | ||
<p class="govuk-body" style="text-align: right; padding-top: 10px"> | ||
<%= t('publish.preview.showing_rows', {start: locals.page_info.start_record, end: locals.page_info.end_record, total: locals.page_info.total_records}) %> | ||
</p> | ||
</div> | ||
</div> |
Oops, something went wrong.