From 52998fa280005044eb7f100eccfcec8a855a4dfa Mon Sep 17 00:00:00 2001 From: eneller Date: Sun, 16 Mar 2025 13:12:17 +0100 Subject: [PATCH] feat: basic table display --- src/epub2go_web/settings.py | 5 ++- src/epub2go_web/static/bookmark.svg | 1 + src/epub2go_web/static/download.svg | 1 + src/epub2go_web/static/github.svg | 1 + src/epub2go_web/static/open-link.svg | 1 + src/epub2go_web/static/script.js | 28 +++++++++++++ src/epub2go_web/static/styles.css | 11 +++++ src/epub2go_web/templates/index.html | 63 +++++++++++++--------------- src/epub2go_web/urls.py | 3 ++ 9 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 src/epub2go_web/static/bookmark.svg create mode 100644 src/epub2go_web/static/download.svg create mode 100644 src/epub2go_web/static/github.svg create mode 100644 src/epub2go_web/static/open-link.svg create mode 100644 src/epub2go_web/static/script.js create mode 100644 src/epub2go_web/static/styles.css diff --git a/src/epub2go_web/settings.py b/src/epub2go_web/settings.py index f19ffae..0892213 100644 --- a/src/epub2go_web/settings.py +++ b/src/epub2go_web/settings.py @@ -55,7 +55,7 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [ - 'epub2go_web/templates/' + "epub2go_web/templates/" ], "APP_DIRS": True, "OPTIONS": { @@ -118,6 +118,9 @@ USE_TZ = True # https://docs.djangoproject.com/en/5.1/howto/static-files/ STATIC_URL = "static/" +STATICFILES_DIRS = [ + BASE_DIR / "epub2go_web/static", +] # Default primary key field type # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field diff --git a/src/epub2go_web/static/bookmark.svg b/src/epub2go_web/static/bookmark.svg new file mode 100644 index 0000000..4ee0276 --- /dev/null +++ b/src/epub2go_web/static/bookmark.svg @@ -0,0 +1 @@ + diff --git a/src/epub2go_web/static/download.svg b/src/epub2go_web/static/download.svg new file mode 100644 index 0000000..b14e70a --- /dev/null +++ b/src/epub2go_web/static/download.svg @@ -0,0 +1 @@ + diff --git a/src/epub2go_web/static/github.svg b/src/epub2go_web/static/github.svg new file mode 100644 index 0000000..9236fb2 --- /dev/null +++ b/src/epub2go_web/static/github.svg @@ -0,0 +1 @@ + diff --git a/src/epub2go_web/static/open-link.svg b/src/epub2go_web/static/open-link.svg new file mode 100644 index 0000000..f8ec425 --- /dev/null +++ b/src/epub2go_web/static/open-link.svg @@ -0,0 +1 @@ + diff --git a/src/epub2go_web/static/script.js b/src/epub2go_web/static/script.js new file mode 100644 index 0000000..480505f --- /dev/null +++ b/src/epub2go_web/static/script.js @@ -0,0 +1,28 @@ +// needs to be included at bottom to get document references +const params = new URLSearchParams(window.location.search); +const searchInput = document.getElementById('searchInput'); +const table = document.getElementById('table'); +const table_r = Array.from(table.getElementsByTagName('tr')); + +// allow search from url parameter +let searchParam = params.get('s'); +if (searchParam){ + searchInput.value = searchParam; + search(searchParam); +} + +function submitSearch(event){ + event.preventDefault(); + search(); +} +function search(searchStr = searchInput.value){ + function showMatch(tr){ + // match search with list + let searchSuccess = Array.from(tr.getElementsByClassName('table-data')).map(e => e.textContent) + .join(' ') + .indexOf(searchStr) > -1; + if (searchSuccess) tr.style.display = ""; + else tr.style.display = "none"; + } + table_r.map(showMatch, table_r); +} diff --git a/src/epub2go_web/static/styles.css b/src/epub2go_web/static/styles.css new file mode 100644 index 0000000..d618033 --- /dev/null +++ b/src/epub2go_web/static/styles.css @@ -0,0 +1,11 @@ +tr:nth-child(even){ + background-color: #EEEEEE; +} +.table-icon{ + vertical-align: middle; + height: 1em; +} +.header-icon{ + vertical-align: middle; + height: 1em; +} \ No newline at end of file diff --git a/src/epub2go_web/templates/index.html b/src/epub2go_web/templates/index.html index 0015cad..a6be78d 100644 --- a/src/epub2go_web/templates/index.html +++ b/src/epub2go_web/templates/index.html @@ -1,11 +1,20 @@ +{% load static %} {{ title }} +
+

{{ title }}

+ + Bookmarklet + + + GitHub +
@@ -13,51 +22,35 @@
- {% for item in items %} + + + + + + + + {% for item in books %} + + - + {% endfor %} +
TitleAuthor
+ + Open Link + + {{ item.title }} Download + {{ item.author }} +
- + \ No newline at end of file diff --git a/src/epub2go_web/urls.py b/src/epub2go_web/urls.py index ec8b32d..1d639e4 100644 --- a/src/epub2go_web/urls.py +++ b/src/epub2go_web/urls.py @@ -19,10 +19,12 @@ from django.contrib import admin from django.urls import path from django.http import HttpRequest, HttpResponse from django.shortcuts import render, redirect +from epub2go.convert import get_all_books, GBConvert, Book def root(request:HttpRequest): title = 'epub2go' targetParam = request.GET.get('t', None) + books = get_all_books() if targetParam is not None: getEpub(targetParam) return render(request, 'index.html', locals()) @@ -33,6 +35,7 @@ urlpatterns = [ ] def getEpub(param): + print(param) # TODO validate / sanitize input # TODO check for existing file and age # TODO download