diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1842570..becf192 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,3 @@ repos: rev: v0.4.0 hooks: - id: autoflake8 -- repo: https://github.com/ambv/black - rev: 22.10.0 - hooks: - - id: black diff --git a/src/frontend/lib/FastAPIServer.py b/src/frontend/lib/FastAPIServer.py index 924db2e..bbc9a1e 100644 --- a/src/frontend/lib/FastAPIServer.py +++ b/src/frontend/lib/FastAPIServer.py @@ -101,22 +101,30 @@ def book_tojson(book) -> dumps: "publisher": book[0].publisher, }) +def tojson(obj) -> dumps: + return dumps(obj) def collections_tojson(collection) -> dumps: """Convert a collections object to json.""" _collections = [] + _collection_id_set = set() for _collection in collection: - _collections.append({ - "collection_id": _collection[0].collection_id, - "book_id": _collection[0].book_id, - "collection": _collection[0].collection, - }) + if _collection[0].id in _collection_id_set: + pass + else: + _collection_id_set.add(_collection[0].id) + _collections.append({ + "collection_id": _collection[0].id, + "collection": _collection[0].collection, + }) return dumps(_collections) templates.env.filters["b64decode"] = base64decode templates.env.filters["summarize"] = summarize templates.env.filters["books_tojson"] = books_tojson +templates.env.filters["collections_tojson"] = collections_tojson +templates.env.filters["tojson"] = tojson class FastAPIServer(): @@ -143,13 +151,6 @@ class FastAPIServer(): with open('src/frontend/static/styles/pyShelf.css', 'w') as _pyShelf: _pyShelf.write(_pyShelf_src[0]) - #_bulma_src = sass.compile( - # filename='src/frontend/static/styles/bulma.sass', - # source_map_filename='src/frontend/static/styles/bulma.sass', - # output_style='compressed') - #with open('src/frontend/static/styles/bulma.css', 'w') as _bulma: - # _bulma.write(_bulma_src[0]) - self.JSInterface.install() return True @@ -163,11 +164,12 @@ class FastAPIServer(): async def index(request: Request, skip: int = 0, limit: int = 10): storage = Storage(Config(os.path.abspath(os.getcwd()))) books = storage.get_books(collection=None, skip=skip, limit=limit) + collections = storage.get_collections() """Home page responder.""" - context = {"request": request, "books": books} + context = {"request": request, "books": books, "collections": collections} return templates.TemplateResponse("index.html", context) - @app.get("/books", response_class=JSONResponse) + @app.get("/api/books", response_class=JSONResponse) async def books(request: Request, skip: int = 0, limit: int = 10, collection=None): storage = Storage(Config(os.path.abspath(os.getcwd()))) books = storage.get_books(collection, skip=skip, limit=limit) @@ -176,14 +178,14 @@ class FastAPIServer(): return JSONResponse(content=books_tojson(books)) # return JSONResponse(content=books) - @app.get("/book/{book_id}", response_class=JSONResponse) + @app.get("/api/book/{book_id}", response_class=JSONResponse) async def book(request: Request, book_id: int): storage = Storage(Config(os.path.abspath(os.getcwd()))) book = storage.get_book(book_id) """Home page responder.""" return JSONResponse(content=book_tojson(book)) - @app.get("/collections", response_class=JSONResponse) + @app.get("/api/collections", response_class=JSONResponse) async def collections(request: Request): storage = Storage(Config(os.path.abspath(os.getcwd()))) collections = storage.get_collections() diff --git a/src/frontend/static/script/pyshelf.ts b/src/frontend/static/script/pyshelf.ts index 441834e..b5fc42c 100644 --- a/src/frontend/static/script/pyshelf.ts +++ b/src/frontend/static/script/pyshelf.ts @@ -12,15 +12,38 @@ function sizeMaster() { var master = $('#master').height(size.height - navbar - footer); } -$(document).ready(function() { - // Get the current URL +function getParams() { var url = window.location.href; - console.log(url); - // Get the last part of the URL + var params = url.split('?')[1]; + if (params) { + var paramstr = params.split('&'); + var paramsObj = {}; + for (var i = 0; i < paramstr.length; i++) { + var param = paramstr[i].split('='); + paramsObj[param[0]] = param[1]; + } + return paramsObj; + } + return null; +} + +function localStorePutTest(data) { + console.log('localStorePutTest'); + localStorage.setItem('test', JSON.stringify(data)); +} + +function localStoreGetTest() { + console.log('localStoreGetTest'); + console.log(localStorage.getItem('test')); +} + +$(document).ready(function() { + console.log(getParams()); $(".navbar-burger").click(function(){ $(".navbar-burger").toggleClass("is-active"); $(".navbar-menu").toggleClass("is-active"); }); + sizeMaster(); $(window).on('resize', function() { sizeMaster(); diff --git a/src/frontend/static/styles/pyShelf.sass b/src/frontend/static/styles/pyShelf.sass index e16f7c4..eded395 100644 --- a/src/frontend/static/styles/pyShelf.sass +++ b/src/frontend/static/styles/pyShelf.sass @@ -101,3 +101,25 @@ $footer-padding: 0.5rem 0.5rem background-repeat: no-repeat; background-attachment: fixed; background-size: cover; + +#master-container + min-height: 100vh; + display: flex; + flex-direction: column; + justify-content: space-between; + +#book-shelf + display: grid; + justify-content: space-evenly; + align-items: center; + align-content: center; + padding: 1rem; + margin: 1rem; + // background-color: $ps-color-background; +.collection + display: flex; + flex-direction: column; + justify-content: space-evenly; + align-items: center; + align-content: center; + background-color: $ps-color-background; diff --git a/src/frontend/templates/index.html b/src/frontend/templates/index.html index c5b4abe..c02fac0 100644 --- a/src/frontend/templates/index.html +++ b/src/frontend/templates/index.html @@ -2,7 +2,7 @@ {% block javascript %} @@ -43,6 +46,13 @@ + + + {% for collection in collections %} + {{collection[0].collection}} + {% endfor %} + +