Compare commits
2 Commits
21ee170302
...
bf51819cbc
| Author | SHA1 | Date | |
|---|---|---|---|
| bf51819cbc | |||
| a69ed2677a |
|
|
@ -1,6 +1,7 @@
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.videoAPI),
|
path('search/', views.searchAPI),
|
||||||
|
path('', include('sage_stream.api.urls')),
|
||||||
]
|
]
|
||||||
|
|
@ -5,7 +5,7 @@ from core.models import Video
|
||||||
from core.serializers import VideoSerializer
|
from core.serializers import VideoSerializer
|
||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
def videoAPI(request):
|
def searchAPI(request):
|
||||||
q = request.GET.get('q', '')
|
q = request.GET.get('q', '')
|
||||||
l = request.GET.get('limit', '6')
|
l = request.GET.get('limit', '6')
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="float-right" style="width:100%">
|
<div class="float-right" style="width:100%">
|
||||||
|
|
||||||
<form class="form-inline ml-0 ml-md-3 float-right">
|
<form class="form-inline ml-0 ml-md-3 float-right">
|
||||||
<div class="input-group input-group-sm">
|
<div class="input-group input-group-sm">
|
||||||
<input class="form-control form-control-navbar"
|
<input class="form-control form-control-navbar"
|
||||||
|
|
@ -58,6 +59,9 @@
|
||||||
placeholder="Search"
|
placeholder="Search"
|
||||||
aria-label="Search"
|
aria-label="Search"
|
||||||
id="searchinput">
|
id="searchinput">
|
||||||
|
<!--
|
||||||
|
<div id="searchsuggestions"></div>
|
||||||
|
-->
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<button class="btn btn-navbar" type="submit">
|
<button class="btn btn-navbar" type="submit">
|
||||||
<i class="fas fa-search"></i>
|
<i class="fas fa-search"></i>
|
||||||
|
|
@ -65,6 +69,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
#'sage_stream',
|
'sage_stream',
|
||||||
'core'
|
'core'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ urlpatterns = [
|
||||||
path('auth/', include('django.contrib.auth.urls')),
|
path('auth/', include('django.contrib.auth.urls')),
|
||||||
path('', include('core.urls')),
|
path('', include('core.urls')),
|
||||||
path('api/', include('api.urls')),
|
path('api/', include('api.urls')),
|
||||||
|
#path('api/', include('sage_stream.api.urls')),
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|
|
||||||
18
static/dist/js/searchsuggestions.js
vendored
18
static/dist/js/searchsuggestions.js
vendored
|
|
@ -1,13 +1,27 @@
|
||||||
|
/*
|
||||||
const searchinput = document.querySelector("#searchinput");
|
const searchinput = document.querySelector("#searchinput");
|
||||||
|
const searchsuggestions = document.querySelector("#searchsuggestions");
|
||||||
searchinput.addEventListener("input", (e) => {
|
searchinput.addEventListener("input", (e) => {
|
||||||
q(e.target.value);
|
q(e.target.value);
|
||||||
});
|
});
|
||||||
async function q(s) {
|
async function q(s) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:8000/api/?q=" + s);
|
const response = await fetch("/api/?q=" + s);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
console.log("Success: " + JSON.stringify(result));
|
console.log("Success: " + JSON.stringify(result));
|
||||||
|
setSuggestions(searchsuggestions, result);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log("Error: " + error);
|
console.log("Error: " + error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
o.replaceChildren(...newSuggestions);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user