diff --git a/src/core/views.py b/src/core/views.py index feca43a..b23cd19 100644 --- a/src/core/views.py +++ b/src/core/views.py @@ -15,15 +15,10 @@ books = sorted(get_all_books(), key= lambda b: b.title)# TODO get from pickle gbnetloc = urlparse(allbooks_url).netloc def index(request: HttpRequest): - context = { - 'title': 'epub2go', - 'http_host': f'http://{ request.META['HTTP_HOST'] }', - 'books': books, - 'book_count': len(books), - 'allbooks_url': allbooks_url, - } + localbooks = books targetParam = request.GET.get('t', None) + searchParam = request.GET.get('s', None) if targetParam: if validateUrl(targetParam): # download file @@ -36,9 +31,18 @@ def index(request: HttpRequest): response['Content-Disposition'] = f'attachment; filename="{fname}"' return response else: return HttpResponseBadRequest('Input URL invalid.') - else: - # return base view - return render(request, 'home.html', context) + elif searchParam: + localbooks = [book for book in books if searchParam in book.title] + + # return base view + context = { + 'title': 'epub2go', + 'http_host': f'http://{ request.META['HTTP_HOST'] }', + 'books': localbooks, + 'book_count': len(books), + 'allbooks_url': allbooks_url, + } + return render(request, 'home.html', context) def validateUrl(param)->bool : diff --git a/src/epub2go_web/static/script.js b/src/epub2go_web/static/script.js index a022f88..9c84b3f 100644 --- a/src/epub2go_web/static/script.js +++ b/src/epub2go_web/static/script.js @@ -15,7 +15,6 @@ document.addEventListener('keydown', (event)=>{ let searchParam = params.get('s'); if (searchParam){ searchInput.value = searchParam; - search(searchParam); } function submitSearch(event){ @@ -23,15 +22,3 @@ function submitSearch(event){ let path = window.location.pathname + "./?s="+encodeURIComponent(searchInput.value); window.location.href= path; } -function search(searchStr = searchInput.value){ - searchStr= searchStr.toLowerCase(); - function showMatch(tr){ - // match search with list - let searchSuccess = Array.from(tr.getElementsByClassName('table-data')).map(e => e.textContent.toLowerCase()) - .join(' ') - .indexOf(searchStr) > -1; - if (searchSuccess) tr.style.display = ""; - else tr.style.display = "none"; - } - table_r.map(showMatch, table_r); -}