From f942979e21222b4538608efb680656f84477cf86 Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 26 Nov 2019 23:08:08 +0100 Subject: [PATCH] Improved search performance --- maloja/__init__.py | 4 + maloja/controller.py | 5 +- maloja/info.py | 2 +- maloja/website/common/footer.html | 12 ++- maloja/website/css/style.css | 5 +- maloja/website/javascript/search.js | 116 ++++++++++++++++------------ maloja/website/less/grisons.less | 7 ++ setup.py | 3 +- 8 files changed, 100 insertions(+), 54 deletions(-) diff --git a/maloja/__init__.py b/maloja/__init__.py index 505f5ba..b255fe9 100644 --- a/maloja/__init__.py +++ b/maloja/__init__.py @@ -17,3 +17,7 @@ resources = [ "data_files/*/*", "data_files/.doreah" ] + +commands = { + "maloja":"controller:main" +} diff --git a/maloja/controller.py b/maloja/controller.py index ad4bcc2..f4ad4cf 100755 --- a/maloja/controller.py +++ b/maloja/controller.py @@ -9,6 +9,7 @@ from distutils import dir_util import stat import pathlib import pkg_resources +from doreah.control import mainfunction from .info import DATA_DIR @@ -153,7 +154,7 @@ def loadlastfm(filename): def direct(): from . import server -from doreah.control import mainfunction + @mainfunction({},shield=True) def main(action,*args,**kwargs): @@ -166,7 +167,7 @@ def main(action,*args,**kwargs): } if action in actions: actions[action](*args,**kwargs) else: print("Valid commands: " + " ".join(a for a in actions)) - + return True #if __name__ == "__main__": diff --git a/maloja/info.py b/maloja/info.py index 6fc7dac..b204cec 100644 --- a/maloja/info.py +++ b/maloja/info.py @@ -5,7 +5,7 @@ author = { "email":"maloja@krateng.dev", "github": "krateng" } -version = 2,0,1 +version = 2,0,2 versionstr = ".".join(str(n) for n in version) diff --git a/maloja/website/common/footer.html b/maloja/website/common/footer.html index 733f222..7de3865 100644 --- a/maloja/website/common/footer.html +++ b/maloja/website/common/footer.html @@ -9,7 +9,17 @@ - + +
+ Artists + +
+

+ Tracks + +
+
+
diff --git a/maloja/website/css/style.css b/maloja/website/css/style.css index 576b7a1..54eca3e 100644 --- a/maloja/website/css/style.css +++ b/maloja/website/css/style.css @@ -668,4 +668,7 @@ a.hidelink:hover { } a:hover { text-decoration: underline; -} \ No newline at end of file +} +.hide { + display:none; +} diff --git a/maloja/website/javascript/search.js b/maloja/website/javascript/search.js index e068313..9dd14e2 100644 --- a/maloja/website/javascript/search.js +++ b/maloja/website/javascript/search.js @@ -10,66 +10,86 @@ function search(searchfield) { xhttp.send(); } } + + +function html_to_fragment(html) { + var template = document.createElement("template"); + template.innerHTML = resulthtml; + return template.content; +} + + +const results_artists = document.getElementById("searchresults_artists"); +const results_tracks = document.getElementById("searchresults_tracks"); +const searchresultwrap = document.getElementById("resultwrap"); + +var resulthtml = ` + + + +
+ + + +` +const oneresult = html_to_fragment(resulthtml).firstElementChild; + + + + function searchresult() { if (this.readyState == 4 && this.status == 200 && document.getElementById("searchinput").value != "") { // checking if field is empty in case we get an old result coming in that would overwrite our cleared result window - result = JSON.parse(this.responseText); - artists = result["artists"].slice(0,5) - tracks = result["tracks"].slice(0,5) - html = `
- Artists - ` + var result = JSON.parse(this.responseText); + var artists = result["artists"].slice(0,5) + var tracks = result["tracks"].slice(0,5) - for (var i=0;i - - - ` - } + for (var i=0;i -

- Tracks -
- ` + name + `
-
` + var node = oneresult.cloneNode(true); + node.setAttribute("onclick","goto(" + link + ")"); + node.children[0].style.backgroundImage = "url('" + image + "')"; + node.children[1].children[0].innerHTML = name; - for (var i=0;i - - - ` + var node = oneresult.cloneNode(true); + node.setAttribute("onclick","goto(" + link + ")"); + node.children[0].style.backgroundImage = "url('" + image + "')"; + node.children[1].children[0].innerHTML = artists; + node.children[1].children[2].innerHTML = title; - } + results_tracks.appendChild(node); + } + searchresultwrap.classList.remove("hide") - html += `
- ` + artists + `
- ` + title + ` -
-
` - - - document.getElementById("resultwrap").innerHTML = html; } } - function clearresults() { - window.setTimeout(reallyclear,500) - } - function reallyclear() { - document.getElementById("resultwrap").innerHTML = ""; - } - - function goto(link) { - window.location = link +function clearresults() { + window.setTimeout(reallyclear,500) +} +function reallyclear() { + searchresultwrap.classList.add("hide") +} + +function goto(link) { + window.location = link } diff --git a/maloja/website/less/grisons.less b/maloja/website/less/grisons.less index fd2efc9..fd8e39a 100644 --- a/maloja/website/less/grisons.less +++ b/maloja/website/less/grisons.less @@ -132,3 +132,10 @@ div.grisons_bar:hover>div { a:hover { text-decoration:underline; } + + + + +.hide { + display:none; +} diff --git a/setup.py b/setup.py index 2dcde39..2272aa3 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,8 @@ setuptools.setup( include_package_data=True, entry_points = { "console_scripts":[ - "maloja = maloja.controller:main" + cmd + " = " + module.name + "." + module.commands[cmd] + for cmd in module.commands ] } )