aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-05-04 23:48:37 +1000
committerTerry Truong <terry06890@gmail.com>2022-05-04 23:48:45 +1000
commit165f7ad0ba4b7f08bbc231a44073cdb998bcb4c2 (patch)
tree7401686d590fd70c8883ca203c3ca6e793ace21a
parent73a4aa2d9ad3a740c51d1fac62487efba3e5bff6 (diff)
Make search-enter use user input, instead of first match
-rwxr-xr-xbackend/server.py6
-rw-r--r--src/components/SearchModal.vue49
2 files changed, 22 insertions, 33 deletions
diff --git a/backend/server.py b/backend/server.py
index 580b4fb..3afcbd0 100755
--- a/backend/server.py
+++ b/backend/server.py
@@ -134,8 +134,10 @@ class DbServer(BaseHTTPRequestHandler):
# Get node
nodeObj = lookupNode(name)
if nodeObj == None:
- if ranOnce:
- print("ERROR: Parent-chain node {} not found".format(name), file=sys.stderr)
+ if not ranOnce:
+ self.respondJson(json.dumps(results))
+ return
+ print("ERROR: Parent-chain node {} not found".format(name), file=sys.stderr)
break
results[name] = nodeObj
# Conditionally add children
diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue
index 5f5320d..4ba0c1a 100644
--- a/src/components/SearchModal.vue
+++ b/src/components/SearchModal.vue
@@ -30,33 +30,11 @@ export default defineComponent({
}
},
onEnter(){
- // Check for a focused search-suggestion
- if (this.focusedSuggIdx != null){
+ if (this.focusedSuggIdx == null){
+ this.resolveSearch((this.$refs.searchInput as HTMLInputElement).value.toLowerCase())
+ } else {
this.resolveSearch(this.searchSuggs[this.focusedSuggIdx].name);
- return;
}
- // Get tol-node-name from server
- let input = this.$refs.searchInput as HTMLInputElement;
- let url = new URL(window.location.href);
- url.pathname = '/data/search';
- url.search = '?name=' + encodeURIComponent(input.value);
- fetch(url.toString())
- .then(response => response.json())
- .then(obj => {
- let results = obj[0];
- if (results.length == 0){
- input.value = '';
- // Trigger failure animation
- input.classList.remove('animate-red-then-fade');
- input.offsetWidth; // Triggers reflow
- input.classList.add('animate-red-then-fade');
- } else {
- this.resolveSearch(results[0].name)
- }
- })
- .catch(error => {
- console.log('ERROR getting search results from server', error);
- });
},
resolveSearch(tolNodeName: string){
// Asks server for nodes in parent-chain, updates tolMap, then emits search event
@@ -66,12 +44,21 @@ export default defineComponent({
fetch(url.toString())
.then(response => response.json())
.then(obj => {
- Object.getOwnPropertyNames(obj).forEach(key => {
- if (!this.tolMap.has(key)){
- this.tolMap.set(key, obj[key])
- }
- });
- this.$emit('search-node', tolNodeName);
+ let keys = Object.getOwnPropertyNames(obj);
+ if (keys.length > 0){
+ keys.forEach(key => {
+ if (!this.tolMap.has(key)){
+ this.tolMap.set(key, obj[key])
+ }
+ });
+ this.$emit('search-node', tolNodeName);
+ } else {
+ // Trigger failure animation
+ let input = this.$refs.searchInput as HTMLInputElement;
+ input.classList.remove('animate-red-then-fade');
+ input.offsetWidth; // Triggers reflow
+ input.classList.add('animate-red-then-fade');
+ }
})
.catch(error => {
console.log('ERROR loading tolnode chain', error);