Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement autocomplete for search #1589

Merged
merged 94 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
65a840d
Mockup version for prototyping
joelit Jan 30, 2024
e7f0f60
Mockup version of autocomplete dropdown list
joelit Jan 31, 2024
e1e189e
Dropdown functionality for the autocomplete list
joelit Jan 31, 2024
7db9310
Fixed JS styling
joelit Jan 31, 2024
93eb5eb
Search functionality for the autocomplete list
joelit Jan 31, 2024
43e2603
Minor fixes
joelit Jan 31, 2024
88a7a06
Merge branch 'main' into issue1514-search-bar-autocomplete
joelit Jan 31, 2024
bcbb281
Mockup version for prototyping
joelit Jan 30, 2024
9372684
Mockup version of autocomplete dropdown list
joelit Jan 31, 2024
0a39115
Dropdown functionality for the autocomplete list
joelit Jan 31, 2024
ab93fbf
Fixed JS styling
joelit Jan 31, 2024
7b36a8c
Search functionality for the autocomplete list
joelit Jan 31, 2024
fe95e0c
Minor fixes
joelit Jan 31, 2024
287bb27
Scrollbar for autocomplete
joelit Feb 1, 2024
fb1f882
Basic structure for cache, translations from SKOSMOS object, tweaked …
joelit Feb 1, 2024
0537559
Added UI messages for Vue to scripts.inc
joelit Feb 1, 2024
6221b8b
Merge commit
joelit Feb 1, 2024
c914321
Added no results message and formatted wildcards for the search term
joelit Feb 1, 2024
a4e5eff
Fixed code styling
joelit Feb 1, 2024
36c5c23
English as default language for language strings, autocomplete result…
joelit Feb 1, 2024
e0c291b
Removed the mockup cache implementation, changed result links
joelit Feb 1, 2024
e8963da
Added cypress tests
joelit Feb 1, 2024
e5d02de
Tweaked cypress tests
joelit Feb 1, 2024
58ace93
Removed whitespace
joelit Feb 1, 2024
b5b6064
Merge branch 'main' into issue1514-search-bar-autocomplete
joelit Feb 1, 2024
1d8d81d
Adjusted autocomplete styling
joelit Feb 1, 2024
423daab
Removed styling, removed double attribute and replaced it with a cust…
joelit Feb 1, 2024
e41a6b0
Merge branch 'issue1514-search-bar-autocomplete' of github.com:NatLib…
joelit Feb 1, 2024
5fd43f0
Added cypress tests
joelit Feb 1, 2024
c9b3ba7
Render only the result related to the lastest search term
joelit Mar 5, 2024
5fbd180
Fix typo
joelit Mar 5, 2024
e945131
Search results are rendered according to preferredLabel, altLabel and…
joelit Mar 6, 2024
950d72c
CSS, labels, result types, and JS styling
joelit Mar 6, 2024
b8a2e97
Closing the dropdown on click outside the element. Making the bold pa…
joelit Mar 6, 2024
392345c
Style tweaks
joelit Mar 6, 2024
97242f1
Removed unnecessary binary expression
joelit Mar 6, 2024
9c576d2
Switched to rarr-arrow
joelit Mar 6, 2024
33f129b
Mockup version for prototyping
joelit Jan 30, 2024
4b87a98
Mockup version of autocomplete dropdown list
joelit Jan 31, 2024
ca32567
Dropdown functionality for the autocomplete list
joelit Jan 31, 2024
026a490
Fixed JS styling
joelit Jan 31, 2024
7b70bad
Search functionality for the autocomplete list
joelit Jan 31, 2024
89c75c2
Minor fixes
joelit Jan 31, 2024
10234d3
Scrollbar for autocomplete
joelit Feb 1, 2024
4758300
Basic structure for cache, translations from SKOSMOS object, tweaked …
joelit Feb 1, 2024
25d718a
Added UI messages for Vue to scripts.inc
joelit Feb 1, 2024
0bdd9ea
Mockup version for prototyping
joelit Jan 30, 2024
700cab7
Added no results message and formatted wildcards for the search term
joelit Feb 1, 2024
b4737ec
Fixed code styling
joelit Feb 1, 2024
019ea5a
English as default language for language strings, autocomplete result…
joelit Feb 1, 2024
677917e
Removed the mockup cache implementation, changed result links
joelit Feb 1, 2024
f15bd2a
Added cypress tests
joelit Feb 1, 2024
c6f7c1a
Tweaked cypress tests
joelit Feb 1, 2024
aa872c1
Removed whitespace
joelit Feb 1, 2024
f3cfd25
Adjusted autocomplete styling
joelit Feb 1, 2024
3ca1a14
Removed styling, removed double attribute and replaced it with a cust…
joelit Feb 1, 2024
7a58872
Added cypress tests
joelit Feb 1, 2024
42155e5
Render only the result related to the lastest search term
joelit Mar 5, 2024
e8e8992
Fix typo
joelit Mar 5, 2024
4627bcb
Search results are rendered according to preferredLabel, altLabel and…
joelit Mar 6, 2024
cace282
CSS, labels, result types, and JS styling
joelit Mar 6, 2024
7885e32
Closing the dropdown on click outside the element. Making the bold pa…
joelit Mar 6, 2024
77f9dce
Style tweaks
joelit Mar 6, 2024
bfa9423
Removed unnecessary binary expression
joelit Mar 6, 2024
0854758
Switched to rarr-arrow
joelit Mar 6, 2024
39ed662
Updated tests. Some of them broke down on their own. Probably the fra…
joelit Mar 7, 2024
d202ee1
Merge commit
joelit Mar 7, 2024
99f254c
Added a test that could not be tested locally due to cypress hickups
joelit Mar 7, 2024
f3d2f85
More cypress tests
joelit Mar 7, 2024
7e8ed8c
Adjusted comments, use result.pageUrl instead of re-using result.uri
joelit Mar 7, 2024
a11e65c
Addded TODO, removed logging
joelit Mar 7, 2024
322f73b
Removed definitions that came accidentally from rebase
joelit Mar 7, 2024
b14ae27
Removed an unnecessary verison number
joelit Mar 7, 2024
8ce7567
Encoded URI components for both enter search and autocomplete (and fi…
joelit Mar 7, 2024
e68ecaa
Fixed URL encoding, objectify URL parameters
joelit Mar 13, 2024
5535518
Implement all url parameters as URLSearchParams objects
joelit Mar 13, 2024
718e6b9
Make the whole autocomplete search result row a clickable link
joelit Mar 13, 2024
7651bbd
Changed test for URL parameters. Added a test for special characters
joelit Mar 13, 2024
70d64bf
Merge branch 'main' into issue1514-search-bar-autocomplete
joelit Mar 13, 2024
e35ca62
SKOSMOS -> window.SKOSMOS
joelit Mar 13, 2024
f2d2021
Merge branch 'issue1514-search-bar-autocomplete' of github.com:NatLib…
joelit Mar 13, 2024
59b4133
Togge the visibility of the autocomplete results list by clicking out…
joelit Mar 13, 2024
285f1b1
Adjusted CSS selector for search bar, new focus border for search ele…
joelit Mar 13, 2024
7813536
Render the HTML tags of a search result in the template
joelit Mar 13, 2024
d0a825f
Fix JS style
joelit Mar 13, 2024
db07ba2
Fix search result text wrap for altLabel hits
joelit Mar 13, 2024
f74d745
Mockup translation of hierarchical concepts in the search result list
joelit Mar 13, 2024
1b656e5
Removed trailing commas from json
joelit Mar 14, 2024
7f9043b
Search bar focus tweak
joelit Mar 14, 2024
b871bb9
Apply suggestions from code review
joelit Mar 14, 2024
0818e81
Use an object property for displaying the autocomplete result list
joelit Mar 14, 2024
1dcddd6
Move event listener to custom vue directive
joelit Mar 14, 2024
f7a8ad5
Added forceUpdate to toggling the result list visibility
joelit Mar 14, 2024
ddf2603
Fix JS styling
joelit Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"axe-core": "^4.7.1",
"cypress": "^12.17.4",
"cypress-axe": "^1.4.0",
"standard": "^17.0.0"
"standard": "^17.1.0"
}
}
30 changes: 30 additions & 0 deletions resource/css/skosmos.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,36 @@ body {
#headerbar input {
background-color: var(--search-bg);
border: 1px solid var(--search-border);

}
#headerbar span.dropdown {
width: 25rem;
}

#headerbar .autocomplete {
position: relative;
}

#headerbar .autocomplete-results {
padding: 0;
margin: 0;
border: 1px solid #eeeeee;
height: 120px;
min-height: 1em;
max-height: 6em;
overflow: auto;
}

#headerbar .autocomplete-result {
list-style: none;
text-align: left;
padding: 4px 2px;
cursor: pointer;
}

#headerbar .autocomplete-result:hover {
background-color: #4AAE9B;
color: white;
}

/* Remove built-in x button from Internet Explorer */
Expand Down
72 changes: 63 additions & 9 deletions resource/js/vocab-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,47 @@ const vocabSearch = Vue.createApp({
this.languages = SKOSMOS.languageOrder
this.selectedLanguage = SKOSMOS.content_lang
this.languageStrings = SKOSMOS.language_strings[SKOSMOS.lang]
this.autoCompeteResults = []
},
methods: {
autoComplete () {
/* Take the input string
* - Once user has stopped typing aftes X ms, submit the search
* - Append an asterix after the search term
* - Display a waiting spinner? : NO
* - Process the search results into autoCompeteResults
* - If the user writes more text in addition to previously given input (startswith), don't perform search
* - But wait for X ms and filter the existing result list
* - When the result list is calculated, display the dropdown
* - If there are no results, display a dropdown with no results -message
* - Hide the dropdown list, if the user
* - Clears the text box from the clear-button
* - Deletes the contentents of the input field
* - Clicks on somewhere outside of the search result dropdown
*
* - Input element should be rectangular
*/
const delayMs = 500
// cancel pending API calls
clearTimeout(this._timerId)
// delay new call 500ms
this._timerId = setTimeout(() => { this.search() }, delayMs)
},
search () {
fetch('rest/v1/' + SKOSMOS.vocab + '/search?query=' + this.searchTerm + '*' + '&lang=' + SKOSMOS.lang)
.then(data => data.json())
.then(data => { this.autoCompeteResults = data.results })

this.renderResults()
},
renderResults () {
const element = document.getElementById('search-autocomplete-results')
element.classList.add('show')
},
hideDropdown () {
const element = document.getElementById('search-autocomplete-results')
element.classList.remove('show')
this.autoCompeteResults = []
},
gotoSearchPage () {
if (!this.searchTerm) return
Expand All @@ -32,24 +69,41 @@ const vocabSearch = Vue.createApp({
},
changeLang () {
SKOSMOS.content_lang = this.selectedLanguage
// TODO: Impelemnt partial page load to change content according to the new content language
// TODO: Impelement partial page load to change content according to the new content language
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still didn't fix all the typos in the word "Implement" ;)

}
},
template: `
<div class="d-flex mb-2 my-auto ms-auto">
<div class="input-group" id="search-wrapper">
<div class="d-flex my-auto ms-auto">
<div class="d-flex justify-content-end input-group ms-auto" id="search-wrapper">
<select class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown-item" aria-expanded="false"
v-model="selectedLanguage"
@change="changeLang()"
>
<option class="dropdown-item" v-for="(value, key) in languageStrings" :value="key">{{ value }}</option>
</select>
<input type="search" class="form-control" aria-label="Text input with dropdown button" placeholder="Search..."
v-model="searchTerm"
@input="autoComplete()"
@keyup.enter="gotoSearchPage()"
>
<button id="clear-button" class="btn btn-danger" type="clear" v-if="searchTerm" @click="searchTerm = ''">
<span class="dropdown">
<input type="search"
class="form-control"
id="search-field"
aria-expanded="false"
autocomplete="off"
data-bs-toggle=""
aria-label="Text input with dropdown button"
placeholder="Search..."
v-model="searchTerm"
@input="autoComplete()"
@keyup.enter="gotoSearchPage()"
@click="">
Copy link
Contributor Author

@joelit joelit Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit heavy handed to I disable the bootstap-determined onClick listener from the text box like so.

<ul id="search-autocomplete-results" class="dropdown-menu w-100"
aria-labelledby="search-field">
<li v-for="result in autoCompeteResults"
:key="result.prefLabel"
class="cursor-pointer hover:bg-gray-100 p-1" >
{{ result.prefLabel }}
</li>
</ul>
</span>
<button id="clear-button" class="btn btn-danger" type="clear" v-if="searchTerm" @click="searchTerm = ''" @click="hideDropdown()">
<i class="fa-solid fa-xmark"></i>
</button>
<button id="search-button" class="btn btn-outline-secondary" @click="gotoSearchPage()">
Expand Down
Loading