From a9195861bbdc6867d8c806ae427006b99323cbe9 Mon Sep 17 00:00:00 2001 From: geoffroy-noel-ddh Date: Mon, 9 Dec 2024 19:08:26 +0000 Subject: [PATCH 1/4] feat(search): unselect all tags after saving changes. --- app/assets/search.mjs | 6 ++++++ app/utils.mjs | 1 + 2 files changed, 7 insertions(+) diff --git a/app/assets/search.mjs b/app/assets/search.mjs index e88ba1171..a9e48e66b 100644 --- a/app/assets/search.mjs +++ b/app/assets/search.mjs @@ -337,9 +337,15 @@ createApp({ } if (ret) { this.selection.items.clear() + this.unselectAllTags() } return ret }, + unselectAllTags() { + Object.keys(this.definitions.tags).forEach(k => { + this.definitions.tags[k] = null + }) + }, resetSearch() { this.selection.searchPhrase = '' this.selection.facets = {} diff --git a/app/utils.mjs b/app/utils.mjs index a21ad2fe5..5067791d7 100644 --- a/app/utils.mjs +++ b/app/utils.mjs @@ -4,6 +4,7 @@ export const IS_BROWSER = (typeof window !== "undefined") export const IS_BROWSER_LOCAL = IS_BROWSER && (window.location.hostname == 'localhost') export const DEBUG_DONT_SAVE = false; +// export const DEBUG_DONT_SAVE = true; // export const DEBUG_DONT_SAVE = IS_BROWSER; async function mod(exports) { From 30048791d7de3cc831a29c6013ac4c41149990ab Mon Sep 17 00:00:00 2001 From: geoffroy-noel-ddh Date: Mon, 9 Dec 2024 19:18:32 +0000 Subject: [PATCH 2/4] feat(search): clear button now clears all the selected tags, selected annotations and resets the date range to its initial value. --- app/assets/search.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/search.mjs b/app/assets/search.mjs index a9e48e66b..a5581f923 100644 --- a/app/assets/search.mjs +++ b/app/assets/search.mjs @@ -349,6 +349,10 @@ createApp({ resetSearch() { this.selection.searchPhrase = '' this.selection.facets = {} + this.selection.items.clear() + this.selection.dateFrom = DATE_MIN + this.selection.dateTo = DATE_MAX + this.unselectAllTags() this.search() }, resetItemsjsconfig() { From 1ace139e379fff6d2605b3943a365480cdd493a3 Mon Sep 17 00:00:00 2001 From: geoffroy-noel-ddh Date: Mon, 9 Dec 2024 20:43:40 +0000 Subject: [PATCH 3/4] fix(search): moved the C&F facet above the C facet.. --- app/assets/search.mjs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/search.mjs b/app/assets/search.mjs index a5581f923..379fd6e14 100644 --- a/app/assets/search.mjs +++ b/app/assets/search.mjs @@ -417,17 +417,17 @@ createApp({ tag: { title: 'Tags', }, + cxf: { + title: 'Component x Features', + // gh-56 + sort: 'key' + }, com: { title: 'Components', }, fea: { title: 'Features', }, - cxf: { - title: 'Component x Features', - // gh-56 - sort: 'key' - }, mat: { title: 'Material', }, From 76a03f5840fca057e2097063f3966968ddba0230 Mon Sep 17 00:00:00 2001 From: geoffroy-noel-ddh Date: Mon, 9 Dec 2024 22:27:59 +0000 Subject: [PATCH 4/4] feat(search): clear will now remove the inscription reference from the query string and it won't come back. Also fixed issues with numeric parameters in the query string. --- app/assets/search.mjs | 44 ++++++++++++++++++++++++++++++++----------- app/utils.mjs | 8 +++++--- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/assets/search.mjs b/app/assets/search.mjs index 379fd6e14..f9e04ca54 100644 --- a/app/assets/search.mjs +++ b/app/assets/search.mjs @@ -33,7 +33,9 @@ createApp({ annotationId: '', object: null, // ? image: null, // ? - searchPhrase: '', + // if null, &img in query string will be the phrase. + // if '' the phrase will be empty. + searchPhrase: null, dateFrom: DATE_MIN, dateTo: DATE_MAX, facets: {}, @@ -98,7 +100,7 @@ createApp({ } this.setSelectionFromAddressBar() - this.search(true) + this.search() }, watch: { 'selection.searchPhrase'() { @@ -459,7 +461,7 @@ createApp({ per_page: this.selection.perPage, page: this.selection.page, sort: 'or1', - query: this.selection.searchPhrase, + query: (this.selection.searchPhrase || '').trim(), filters: this.selection.facets } if (this.selection.dateFrom > DATE_MIN || this.selection.dateTo < DATE_MAX) { @@ -696,7 +698,18 @@ createApp({ for (let facet of Object.keys(this.selection.facets)) { searchParams[`f.${facet}`] = this.selection.facets[facet].join('|') } - utils.setQueryString(searchParams) + + let defaults = { + // make sure q is always in the query string, even if '' + q: 'DEFAULT', + pag: 1, + ppg: ITEMS_PER_PAGE, + daf: DATE_MIN, + dat: DATE_MAX, + sup: 0, + } + + utils.setQueryString(searchParams, defaults) }, setSelectionFromAddressBar() { let searchParams = new URLSearchParams(window.location.search); @@ -705,16 +718,19 @@ createApp({ this.selection.image = searchParams.get('img') || '' this.selection.showSuppliedText = searchParams.get('sup') === '1' this.selection.annotationId = searchParams.get('ann') || '' - this.selection.dateFrom = searchParams.get('daf') || DATE_MIN - this.selection.dateTo = searchParams.get('dat') || DATE_MAX - // this.description.script = searchParams.get('scr') || '' + this.selection.dateFrom = this._getNumberFromString(searchParams.get('daf'), DATE_MIN) + this.selection.dateTo = this._getNumberFromString(searchParams.get('dat'), DATE_MAX) + // this.description.script = searchParams.get('scr') || '' - this.selection.searchPhrase = searchParams.get('q') || '' - if (!this.selection.searchPhrase && this.selection.image) { + this.selection.searchPhrase = searchParams.get('q') + if (this.selection.searchPhrase === null && this.selection.image) { this.selection.searchPhrase = this.selection.image.replace(/\.[^.]+$/, '') + } else { + this.selection.searchPhrase = (this.selection.searchPhrase || '').trim() } - this.selection.page = parseInt(searchParams.get('pag') || '1') - this.selection.perPage = parseInt(searchParams.get('ppg') || ITEMS_PER_PAGE) + + this.selection.page = this._getNumberFromString(searchParams.get('pag'), 1) + this.selection.perPage = this._getNumberFromString(searchParams.get('ppg'), ITEMS_PER_PAGE) for (let facet of Object.keys(this.getFacetDefinitions())) { let options = searchParams.get(`f.${facet}`) @@ -723,5 +739,11 @@ createApp({ } } }, + _getNumberFromString(stringValue, defaultValue=0) { + let res = parseInt(stringValue) + let ret = isNaN(res) ? defaultValue : res + console.log(stringValue, res, defaultValue, ret) + return ret + } } }).mount('#search'); diff --git a/app/utils.mjs b/app/utils.mjs index 5067791d7..3c1957e73 100644 --- a/app/utils.mjs +++ b/app/utils.mjs @@ -18,15 +18,17 @@ async function mod(exports) { return str.replace(/\W+/g, '-').toLowerCase() } - exports.setQueryString = function(parameters) { + exports.setQueryString = function(parameters, defaults={}) { let newRelativePathQuery = window.location.pathname let qsKeys = Object.keys(parameters) let qs = '' if (qsKeys.length) { for (let k of qsKeys) { - if (parameters[k]) { + let defaultValue = defaults[k] ?? '' + let valueStr = `${parameters[k]}`.trim() + if (valueStr != defaultValue) { if (qs) qs += '&'; - qs += `${k}=${parameters[k]}` + qs += `${k}=${encodeURIComponent(valueStr)}` } } if (qs) {