From 4bb7beb4175b9dafe3727a6097da4ce0f0a79276 Mon Sep 17 00:00:00 2001 From: "Daniel W. Hieber" Date: Tue, 16 Jul 2024 19:55:48 -0500 Subject: [PATCH] NEW: Sort Priority (#130) closes #130 --- pages/Search/Search.css | 29 ++++++++++++++++++++++---- pages/Search/Search.hbs | 38 +++++++++++++++++++++-------------- pages/Search/Search.js | 2 +- pages/Search/scripts/Table.js | 10 +++++++-- scripts/SortDirectives.js | 14 ++++++------- 5 files changed, 64 insertions(+), 29 deletions(-) diff --git a/pages/Search/Search.css b/pages/Search/Search.css index 0cfc38d1..00ceaf20 100644 --- a/pages/Search/Search.css +++ b/pages/Search/Search.css @@ -59,6 +59,26 @@ body { } +.priority { + align-items: center; + background-color: var(--pink-swan); + block-size: 1em; + border-radius: 50%; + color: black; + content: attr(data-priority); + display: flex; + font-size: small; + inline-size: 1em; + inset-block-start: 0; + inset-inline-start: 0; + justify-content: center; + padding: 0.75em; + position: absolute; + text-align: center; + transform: translate(50%, -50%); + vertical-align: middle; +} + /* NB: The .sticky class is applied conditionally in the footer Handlebars template. */ .footer { @@ -75,6 +95,10 @@ h2 { text-align: center; } +.hint { + display: none; +} + .issue-link { inset-inline-end: 0; position: sticky; @@ -121,6 +145,7 @@ h2 { & th { font-weight: bold; + position: relative; } & thead { @@ -207,10 +232,6 @@ search { word-break: keep-all; } -#sort-hint { - display: none; -} - .sort-icon { --icon-size: 0.75em; block-size: var(--icon-size); diff --git a/pages/Search/Search.hbs b/pages/Search/Search.hbs index 6a26d64c..0dcd694b 100644 --- a/pages/Search/Search.hbs +++ b/pages/Search/Search.hbs @@ -47,7 +47,8 @@
- Click on a header column to sort. + Priority + Click on a header column to sort. @@ -66,47 +67,54 @@ {{!-- Component Fields --}} {{#with sort }} - - - - - - - {{/with}} diff --git a/pages/Search/Search.js b/pages/Search/Search.js index e2038232..a94cdda4 100644 --- a/pages/Search/Search.js +++ b/pages/Search/Search.js @@ -52,7 +52,7 @@ export function Search(req, res) { allResults.sort((a, b) => { const comparisons = Array.from(sort.entries()) - .map(([field, direction]) => { + .map(([field, { direction }]) => { const comparison = (a[field] || ``).localeCompare(b[field] || ``) return direction === `ascending` ? comparison : comparison * -1 }) diff --git a/pages/Search/scripts/Table.js b/pages/Search/scripts/Table.js index fe0e17b3..91772d61 100644 --- a/pages/Search/scripts/Table.js +++ b/pages/Search/scripts/Table.js @@ -27,8 +27,14 @@ export default class Table { const directive = directivesOrder[directivesOrder.indexOf(direction) + 1] directives.add(field, directive) - sort = directives.serialize() - url.searchParams.set(`sort`, sort) + + if (directives.size) { + sort = directives.serialize() + url.searchParams.set(`sort`, sort) + } else { + url.searchParams.delete(`sort`) + } + window.location = url.href } diff --git a/scripts/SortDirectives.js b/scripts/SortDirectives.js index 2597a05a..eca4f379 100644 --- a/scripts/SortDirectives.js +++ b/scripts/SortDirectives.js @@ -8,12 +8,12 @@ export default class SortDirectives extends Map { directives.split(`,`) .filter(Boolean) - .forEach(directive => { + .forEach((directive, i) => { const field = directive.replace(/^-/v, ``) const direction = directive.startsWith(`-`) ? `descending` : `ascending` - this.set(field, direction) + this.set(field, { direction, priority: i + 1 }) }) @@ -31,20 +31,20 @@ export default class SortDirectives extends Map { const entries = Array.from(this.entries()) if (direction) { - entries.unshift([field, direction]) + entries.unshift([field, { direction, priority: 1 }]) } this.clear() - for (const [f, d] of entries) { - this.set(f, d) - } + entries.forEach(([field, { direction }], i) => { + this.set(field, { direction, priority: i + 1 }) + }) } serialize() { return Array.from(this.entries()) - .map(([field, direction]) => `${ direction === `descending` ? `-` : `` }${ field }`) + .map(([field, { direction }]) => `${ direction === `descending` ? `-` : `` }${ field }`) .join(`,`) }

Search Results

+ + {{#if displayLanguage }}{{ displayLanguage.priority }}{{/if}} + + {{#if form }}{{ form.priority }}{{/if}} + + {{#if UR }}{{ UR.priority }}{{/if}} + + {{#if PA }}{{ PA.priority }}{{/if}} + + {{#if definition }}{{ definition.priority }}{{/if}} + + {{#if type }}{{ type.priority }}{{/if}} + + {{#if subcategory }}{{ subcategory.priority }}{{/if}}