mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Improved search performance
This commit is contained in:
parent
8f53839db8
commit
f942979e21
@ -17,3 +17,7 @@ resources = [
|
||||
"data_files/*/*",
|
||||
"data_files/.doreah"
|
||||
]
|
||||
|
||||
commands = {
|
||||
"maloja":"controller:main"
|
||||
}
|
||||
|
@ -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__":
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -9,7 +9,17 @@
|
||||
<span><input id="searchinput" placeholder="Search for an artist or track..." oninput="search(this)" onblur="clearresults()" /></span>
|
||||
</div>
|
||||
|
||||
<span id="resultwrap"></span>
|
||||
<span id="resultwrap" class="hide">
|
||||
<div class="searchresults">
|
||||
<span>Artists</span>
|
||||
<table class="searchresults_artists" id="searchresults_artists">
|
||||
</table>
|
||||
<br/><br/>
|
||||
<span>Tracks</span>
|
||||
<table class="searchresults_tracks" id="searchresults_tracks">
|
||||
</table>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<a href="/admin"><div title="Server Administration" id="settingsicon">
|
||||
|
@ -668,4 +668,7 @@ a.hidelink:hover {
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
.hide {
|
||||
display:none;
|
||||
}
|
||||
|
@ -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 = `
|
||||
<tr>
|
||||
<td class="image"></td>
|
||||
<td>
|
||||
<span></span><br/>
|
||||
<span></span>
|
||||
</td>
|
||||
</tr>
|
||||
`
|
||||
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 = `<div class="searchresults">
|
||||
<span>Artists</span>
|
||||
<table class="searchresults_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<artists.length;i++) {
|
||||
name = artists[i]["name"];
|
||||
link = artists[i]["link"];
|
||||
image = artists[i]["image"];
|
||||
while (results_artists.firstChild) {
|
||||
results_artists.removeChild(results_artists.firstChild);
|
||||
}
|
||||
while (results_tracks.firstChild) {
|
||||
results_tracks.removeChild(results_tracks.firstChild);
|
||||
}
|
||||
|
||||
html += `<tr onclick="goto('` + link + `')">
|
||||
<td class="image" style="background-image:url('` + image + `');"></td>
|
||||
<td>
|
||||
<span>` + name + `</span><br/>
|
||||
</td>
|
||||
</tr>`
|
||||
}
|
||||
for (var i=0;i<artists.length;i++) {
|
||||
name = artists[i]["name"];
|
||||
link = artists[i]["link"];
|
||||
image = artists[i]["image"];
|
||||
|
||||
html += `</table>
|
||||
<br/><br/>
|
||||
<span>Tracks</span>
|
||||
<table class="searchresults_tracks">`
|
||||
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<tracks.length;i++) {
|
||||
results_artists.appendChild(node);
|
||||
}
|
||||
for (var i=0;i<tracks.length;i++) {
|
||||
|
||||
artists = tracks[i]["artists"].join(", ");
|
||||
title = tracks[i]["title"];
|
||||
link = tracks[i]["link"];
|
||||
image = tracks[i]["image"];
|
||||
artists = tracks[i]["artists"].join(", ");
|
||||
title = tracks[i]["title"];
|
||||
link = tracks[i]["link"];
|
||||
image = tracks[i]["image"];
|
||||
|
||||
html += `<tr onclick="goto('` + link + `')">
|
||||
<td class="image" style="background-image:url('` + image + `');"></td>
|
||||
<td>
|
||||
<span>` + artists + `</span><br/>
|
||||
<span>` + title + `</span>
|
||||
</td>
|
||||
</tr>`
|
||||
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 += `</table>
|
||||
</div>`
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -132,3 +132,10 @@ div.grisons_bar:hover>div {
|
||||
a:hover {
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.hide {
|
||||
display:none;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user