diff --git a/src/frontend/urls.py b/src/frontend/urls.py index 1b2c0d0..9a6cb42 100755 --- a/src/frontend/urls.py +++ b/src/frontend/urls.py @@ -21,20 +21,17 @@ from interface import views urlpatterns = [ path("admin/", admin.site.urls), path("", views.index, name="index"), + path("sort/<_order>", views.index, name="index"), path("download/", views.download, name="download"), path("favorite/", views.favorite, name="favorite"), path("share/", views.share, name="share"), path("share/", views.info, name="info"), path("prev_page/", views.prev_page, name="prev_page"), path("next_page/", views.next_page, name="next_page"), - path("search/", views.search, name="search"), - path("search/", views.search, name="search"), - path("search//<_set>", views.search, name="search"), - path( - "show_collection/<_collection>/<_colset>", - views.show_collection, - name="show_collection", - ), + path("search/", views.index, name="search"), + path("search/", views.index, name="search"), + path("search//<_set>", views.index, name="search"), + path("show_collection/<_collection>/<_colset>", views.show_collection, name="show_collection",), ] if settings.DEBUG: import debug_toolbar diff --git a/src/interface/static/css/main.css b/src/interface/static/css/main.css index 4dbeb28..a7cd5df 100644 --- a/src/interface/static/css/main.css +++ b/src/interface/static/css/main.css @@ -376,7 +376,7 @@ body { display: flex; align-items: center; justify-content: flex-start; - padding: 0px 0px 0px 5px; + padding: 0px 5px 0px 5px; font-size: medium; border-bottom: 1px solid; background-color: #fefefeb3; diff --git a/src/interface/static/css/main.scss b/src/interface/static/css/main.scss index bab9f69..ebc9b94 100755 --- a/src/interface/static/css/main.scss +++ b/src/interface/static/css/main.scss @@ -388,7 +388,7 @@ body { display: flex; align-items: center; justify-content: flex-start; - padding: 0px 0px 0px 5px; + padding: 0px 5px 0px 5px; font-size: medium; border-bottom: 1px solid; background-color: $ui-color-1; diff --git a/src/interface/static/js/pyshelf_ux.js b/src/interface/static/js/pyshelf_ux.js index 0c7ee46..79c58cb 100755 --- a/src/interface/static/js/pyshelf_ux.js +++ b/src/interface/static/js/pyshelf_ux.js @@ -74,4 +74,10 @@ $(document).ready(function(){ $('#btn_login').on('click', function(){ $('#hdr_nav_login').toggle(); }); + $('#sortlist').change(function () { + var optionSelected = $(this).find("option:selected"); + var valueSelected = optionSelected.val(); + var textSelected = optionSelected.text(); + window.location.href=valueSelected + }); }); diff --git a/src/interface/templates/index.html b/src/interface/templates/index.html index bdd6480..d05bd0a 100755 --- a/src/interface/templates/index.html +++ b/src/interface/templates/index.html @@ -23,6 +23,8 @@ + +
@@ -37,7 +39,7 @@

pyShelf {{Version}}

    - + @@ -45,14 +47,14 @@
-
+
diff --git a/src/interface/views.py b/src/interface/views.py index df757f4..1b9ce16 100755 --- a/src/interface/views.py +++ b/src/interface/views.py @@ -15,26 +15,17 @@ from .models import Books, Collections, Navigation config = Config(Path("../")) collections = Collections.objects.all() -def index(request): + + +def index(request, query=None, _set=1, _limit=None, _order='title'): """ Return template index - TODO: revise the way sets are handled so that they can be used uniformly in js - for ui page displays """ - _set = 1 + _payload = payload(query, _set, _limit, _order) return render( request, "index.html", - { - "Books": book_set(20, _set), - "Set": str(_set), - "Version": config.VERSION, - "LeftNavCollections": menu("collections"), - "LeftNavMenu0": menu("nav_l_0"), - "BookStats": Books.objects.all().count, - "CollectionStats": Collections.objects.all().count, - "CollectionObject": collections_list() - }, + _payload ) def show_collection(request, _collection, _colset): @@ -69,7 +60,8 @@ def next_page(request, bookset): _set = 1 return render( request, - "index.html", + """ + index.html", { "Books": book_set(None, _set), "Set": str(_set), @@ -84,6 +76,7 @@ def next_page(request, bookset): "LeftNavCollections": menu("collections"), "LeftNav": menu("collections"), }, + """ ) def prev_page(request, bookset): @@ -123,7 +116,20 @@ def search(request, query=None, _set=1, _limit=None): """ _set = int(_set) if query is None: - return render(request, "index.html", {"Books": None, "Version": config.VERSION}) + return render( + request, + "index.html", + { + "Books": book_set(20, _set), + "Set": str(_set), + "Version": config.VERSION, + "LeftNavCollections": menu("collections"), + "LeftNavMenu0": menu("nav_l_0"), + "BookStats": Books.objects.all().count, + "CollectionStats": Collections.objects.all().count, + "CollectionObject": collections_list() + } + ) if _limit is None: _limit = 20 ## TODO set to user defaults if _set < 1: @@ -147,7 +153,7 @@ def search(request, query=None, _set=1, _limit=None): }, ) -def book_set(_limit=None, _set=1): +def book_set(_order, _limit=None, _set=1): """ Get books results by set # """ @@ -155,7 +161,7 @@ def book_set(_limit=None, _set=1): _limit = 20 # TODO default from user choice _set_max = int(_set) * _limit _set_min = _set_max - _limit - books = Books.objects.all()[_set_min:_set_max] + books = Books.objects.all().order_by(_order)[_set_min:_set_max] return books def collection(_collection, _set, _limit=None): @@ -297,3 +303,44 @@ def collections_list(): if i.collection not in collection_key: collection_key.append(i.collection) return json.dumps(list(set(collection_key))) + +def payload(query, _set, _limit, _order): + """ + Return formatted data to template + # TODO hook into payload and provide handling of next,prev, & search combos + """ + _set = int(_set) + if _set < 1: _set = 1 + if _limit is None: _limit = 20 + _set_max = int(_set) * _limit + _set_min = _set_max - _limit + _now_showing = "%s of %s"%(_set_min, _set_max) + + if query: + _results = Books().generic_search(query) + _r_len = _results.count() + _r, _search = _results[_set_min:_set_max], query + else: _r, _r_len, _search = book_set(_order, _limit, _set), None, None + + _bookstats, _collectionstats, _collectionobject = \ + Books.objects.all().count, Collections.objects.all().count, \ + collections_list() + + if (_r_len): _btotal = _r_len + else: _btotal = _bookstats + + return { + "Books": _r, + "Set": str(_set), + "Version": config.VERSION, + "LeftNavCollections": menu("collections"), + "LeftNavMenu0": menu("nav_l_0"), + "BookStats": _btotal, + "CollectionStats": _collectionstats, + "CollectionObject": _collectionobject, + "NowShowing": _now_showing, + "PostedSearch": _search, + "SearchLen": _r_len, + "Order": _order + } +