Compare commits

..

2 Commits

Author SHA1 Message Date
2defe8a4bd Search works 2023-05-20 02:57:30 +02:00
4d60016ef4 god save me 2023-05-20 02:11:33 +02:00
3 changed files with 33 additions and 23 deletions

View File

@ -12,8 +12,7 @@
<link rel="stylesheet" href="{% static 'dist/css/adminlte.css' %}">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
<link rel="stylesheet"
href="{% static 'plugins/fontawesome-free/css/all.min.css' %}">
<link rel="stylesheet" href="{% static 'plugins/select2/css/select2.min.css' %}">
</head>
<body class="layout-top-nav" style="height: auto;">
<div class="wrapper">
@ -54,14 +53,15 @@
<form class="form-inline ml-0 ml-md-3 float-right">
<div class="input-group input-group-sm">
<input class="form-control form-control-navbar"
<input class="form-control form-control-navbar" data-toggle="dropdown"
type="search"
placeholder="Search"
aria-label="Search"
id="searchinput">
<!--
<div id="searchsuggestions"></div>
-->
autocomplete="off"
id="search">
<ul class="dropdown-menu" id="searchdropdown">
<li><span class="dropdown-item-text">Nothing</span></li>
</ul>
<div class="input-group-append">
<button class="btn btn-navbar" type="submit">
<i class="fas fa-search"></i>

View File

@ -23,7 +23,6 @@ urlpatterns = [
path('auth/', include('django.contrib.auth.urls')),
path('', include('core.urls')),
path('api/', include('api.urls')),
#path('api/', include('sage_stream.api.urls')),
]
if settings.DEBUG:

View File

@ -1,27 +1,38 @@
/*
const searchinput = document.querySelector("#searchinput");
const searchsuggestions = document.querySelector("#searchsuggestions");
const searchinput = document.querySelector("#search");
const searchsuggestions = document.querySelector("#searchdropdown");
searchinput.addEventListener("input", (e) => {
q(e.target.value);
});
async function q(s) {
if (s.length < 1) {clearSuggestions(searchsuggestions)}
else {
try {
const response = await fetch("/api/?q=" + s);
const response = await fetch("/api/search/?q=" + s);
const result = await response.json();
console.log("Success: " + JSON.stringify(result));
setSuggestions(searchsuggestions, result);
} catch(error) {
console.log("Error: " + error);
}
}
}
function clearSuggestions(o) {
const span = document.createElement("span");
span.setAttribute("class", "dropdown-item-text");
span.insertAdjacentText("afterbegin", "Nothing");
const li = document.createElement("li");
li.appendChild(span);
o.replaceChildren(li);
}
function setSuggestions(o, s) {
const newSuggestions = [];
for (const vid of s) {
const newSugg = document.createElement("a");
newSugg.setAttribute("href", "/view/" + vid.id);
newSugg.insertAdjacentText("afterbegin", vid.name + " " + vid.id);
newSuggestions.push(newSugg);
const a = document.createElement("a");
a.setAttribute("class", "dropdown-item")
a.setAttribute("href", "/view/" + vid.id);
a.insertAdjacentText("afterbegin", vid.name + " " + vid.id);
const li = document.createElement("li");
li.appendChild(a);
newSuggestions.push(li);
}
o.replaceChildren(...newSuggestions);
}
*/