From 18b40ed485dc7ab1f06531fbbdec5c2031ec02ed Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Sun, 15 Jun 2025 22:07:02 +0200 Subject: [PATCH] Tables, template reflowing, docstrings, better index page --- src/digimarks/main.py | 55 ++++- src/digimarks/static/css/digimarks.css | 12 +- src/digimarks/static/css/digui.css | 33 ++- src/digimarks/templates/404.html | 6 +- src/digimarks/templates/base.html | 2 +- src/digimarks/templates/bookmarks.html | 200 ++++++++++--------- src/digimarks/templates/bookmarks.js | 11 - src/digimarks/templates/index.html | 37 ++-- src/digimarks/templates/publicbookmarks.html | 33 +-- src/digimarks/templates/tags.html | 119 +++++------ src/digimarks/templates/user_index.html | 65 +++++- 11 files changed, 357 insertions(+), 216 deletions(-) delete mode 100644 src/digimarks/templates/bookmarks.js diff --git a/src/digimarks/main.py b/src/digimarks/main.py index ab0d939..414156d 100644 --- a/src/digimarks/main.py +++ b/src/digimarks/main.py @@ -135,6 +135,14 @@ def clean_tags(tags_list: list) -> list: return tags_res +def list_tags_for_bookmarks(bookmarks: list) -> list: + """Generate a unique list of the tags from the list of bookmarks.""" + tags = [] + for bookmark in bookmarks: + tags += bookmark.tags_list + return clean_tags(tags) + + def file_type(filename: str) -> str: """Try to determine the file type for the file in `filename`. @@ -392,7 +400,7 @@ def list_bookmarks( offset: int = 0, limit: Annotated[int, Query(le=10000)] = 100, ) -> list[Bookmark]: - """List all bookmarks in the database. By default gives back 100 items.""" + """List all bookmarks in the database. By default 100 items are returned.""" bookmarks = session.exec( select(Bookmark) .where(Bookmark.userkey == user_key, Bookmark.status != Visibility.DELETED) @@ -567,10 +575,7 @@ def list_tags_for_user( ) -> list[str]: """List all tags in use by the user.""" bookmarks = session.exec(select(Bookmark).where(Bookmark.userkey == user_key)).all() - tags = [] - for bookmark in bookmarks: - tags += bookmark.tags_list - return clean_tags(tags) + return list_tags_for_bookmarks(bookmarks) @app.get('/{user_key}', response_class=HTMLResponse) @@ -579,6 +584,7 @@ def page_user_landing( request: Request, user_key: str, ): + """HTML page with the main view for the user.""" user = session.exec(select(User).where(User.key == user_key)).first() if not user: raise HTTPException(status_code=404, detail='User not found') @@ -588,3 +594,42 @@ def page_user_landing( name='user_index.html', context={'language': language, 'version': DIGIMARKS_VERSION, 'user_key': user_key}, ) + + +# def tags_page(userkey): +# """Overview of all tags used by user""" +# tags = get_cached_tags(userkey) +# alltags = [] +# for tag in tags: +# try: +# publictag = PublicTag.get(PublicTag.userkey == userkey, PublicTag.tag == tag) +# except PublicTag.DoesNotExist: +# publictag = None +# +# total = ( +# Bookmark.select() +# .where(Bookmark.userkey == userkey, Bookmark.tags.contains(tag), Bookmark.status == Bookmark.VISIBLE) +# .count() +# ) +# alltags.append({'tag': tag, 'publictag': publictag, 'total': total}) +# totaltags = len(alltags) +# totalbookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).count() +# totalpublic = PublicTag.select().where(PublicTag.userkey == userkey).count() +# totalstarred = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.starred).count() +# totaldeleted = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.DELETED).count() +# totalnotes = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.note != '').count() +# totalhttperrorstatus = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.http_status != 200).count() +# theme = get_theme(userkey) +# return render_template( +# 'tags.html', +# tags=alltags, +# totaltags=totaltags, +# totalpublic=totalpublic, +# totalbookmarks=totalbookmarks, +# totaldeleted=totaldeleted, +# totalstarred=totalstarred, +# totalhttperrorstatus=totalhttperrorstatus, +# totalnotes=totalnotes, +# userkey=userkey, +# theme=theme, +# ) diff --git a/src/digimarks/static/css/digimarks.css b/src/digimarks/static/css/digimarks.css index f79a63e..c37ef00 100644 --- a/src/digimarks/static/css/digimarks.css +++ b/src/digimarks/static/css/digimarks.css @@ -1,7 +1,7 @@ /** * digimarks styling * - * Overrides on the digui styling + * Overrides on and additions to the digui styling */ /* Star, error, note etc */ @@ -12,4 +12,14 @@ .star { color: #ffeb3b; +} + +.thumbnail { + /*width: 80px;*/ + width: 66; +} + +.thumbnail img { + /*width: 72px;*/ + width: 60px; } \ No newline at end of file diff --git a/src/digimarks/static/css/digui.css b/src/digimarks/static/css/digui.css index 6246333..e896185 100644 --- a/src/digimarks/static/css/digui.css +++ b/src/digimarks/static/css/digui.css @@ -200,7 +200,7 @@ h1 { font-size: 2em; } -a, a:hover, a:visited, a:active { +a, a:hover, a:visited, a:active, a.button, a.button:hover, a.button:active, a.button:visited { text-decoration: none; } @@ -230,9 +230,7 @@ ol li::marker, ul li::marker { /* Buttons */ -button, input, select, textarea { - border: var(--border-width) solid var(--border-color); - border-radius: var(--border-radius); +button, .button, input, select, textarea { box-sizing: border-box; color: var(--text-color-secondary); background-color: var(--button-color); @@ -241,7 +239,6 @@ button, input, select, textarea { font-size: 13px; /*line-height: 29px;*/ /*padding: 0 10px 0 11px;*/ - padding: .5rem .5rem; position: relative; text-align: left; text-decoration: none; @@ -251,14 +248,20 @@ button, input, select, textarea { vertical-align: middle; } -button:hover { +button, .button, input, select, textarea, table { + border: var(--border-width) solid var(--border-color); + border-radius: var(--border-radius); + padding: .5rem .5rem; +} + +button:hover, .button:hover { /*background-color: #f7fafa;*/ /*background-color: #d57803;*/ background-color: var(--color-highlight); filter: brightness(80%); } -button:focus { +button:focus, .button:focus { /*border-color: #008296;*/ /*box-shadow: rgba(213, 217, 217, .5) 0 2px 5px 0;*/ outline: 0; @@ -292,6 +295,16 @@ button:focus { filter: brightness(80%); } +/* Table */ + +th { + text-align: left; +} + +th, td { + padding: 0 0.3rem; +} + /* Cards */ .cards { @@ -311,14 +324,18 @@ button:focus { [data-theme='nebula'] .card, [data-theme='nebula'] button, +[data-theme='nebula'] .button, [data-theme='nebula'] input, [data-theme='nebula'] select, [data-theme='nebula'] textarea, +[data-theme='nebula'] table, [data-theme='nebula-dark'] .card, [data-theme='nebula-dark'] button, +[data-theme='nebula-dark'] .button, [data-theme='nebula-dark'] input, [data-theme='nebula-dark'] select, -[data-theme='nebula-dark'] textarea { +[data-theme='nebula-dark'] textarea, +[data-theme='nebula-dark'] table { box-shadow: var(--shadow-color) 0 2px 5px 0; } diff --git a/src/digimarks/templates/404.html b/src/digimarks/templates/404.html index 8f21320..056a970 100644 --- a/src/digimarks/templates/404.html +++ b/src/digimarks/templates/404.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% block title %}404: Page not found{% endblock %} -{% block pageheader %}404: Page not found{% endblock %} -{% block pagecontent %} -The page you requested was not found. +{% block page_header %}404: Page not found{% endblock %} +{% block page_content %} + The page you requested was not found. {% endblock %} diff --git a/src/digimarks/templates/base.html b/src/digimarks/templates/base.html index 6f67350..496e151 100644 --- a/src/digimarks/templates/base.html +++ b/src/digimarks/templates/base.html @@ -18,7 +18,7 @@ -{% block pagecontent %} +{% block page_content %}
diff --git a/src/digimarks/templates/bookmarks.html b/src/digimarks/templates/bookmarks.html index 403d6e8..9dc41a7 100644 --- a/src/digimarks/templates/bookmarks.html +++ b/src/digimarks/templates/bookmarks.html @@ -1,113 +1,127 @@ {% extends "base.html" %} {% if not action %} -{% set action = 'Bookmarks' %} + {% set action = 'Bookmarks' %} {% endif %} {% block title %}{{ action }}{% endblock %} -{% block pageheader %}{{ action }}{% endblock %} -{% block pagecontent %} +{% block page_header %}{{ action }}{% endblock %} +{% block page_content %} -{% if tag and not publictag %} - -{% endif %} + {% if tag and not publictag %} + + {% endif %} -{% if tag and publictag %} - -{% endif %} + {% if tag and publictag %} +
+ +
+ {% endif %} -{% if message %} -
-
-
+ {% if message %} +
+
+
{{ message|safe }} +
+
+ {% endif %} + +
+
+
+ +
+ +
+

+ + {% if show_as and show_as == 'list' %} + apps + {% else %} + reorder + {% endif %} +

+
+
-
-{% endif %} -
-
-
- + {% if tags %} +
+
+ +
+ {% endif %} -
-

- {% if show_as and show_as == 'list' %} - apps - {% else %} - reorder - {% endif %} -

-
- -
+ {% if show_as and show_as == 'list' %} + {% include 'list.html' %} + {% else %} + {% include 'cards.html' %} + {% endif %} -{% if tags %} -
-
- + -
-{% endif %} - -{% if show_as and show_as == 'list' %} - {% include 'list.html' %} -{% else %} - {% include 'cards.html' %} -{% endif %} - - {% endblock %} {% block extrajs %} - - + + {% endblock %} diff --git a/src/digimarks/templates/bookmarks.js b/src/digimarks/templates/bookmarks.js deleted file mode 100644 index dd92d5e..0000000 --- a/src/digimarks/templates/bookmarks.js +++ /dev/null @@ -1,11 +0,0 @@ -var elem = document.querySelector('.autocomplete'); -var instance = M.Autocomplete.getInstance(elem); -instance.updateData({ - {% for bookmark in bookmarks %} - {% if bookmark.favicon %} - "{{ bookmark.title | replace('"', '\\"') | replace('\n', '') | replace('\r', '') }}": "{{ url_for('static', filename='favicons/' + bookmark.favicon) }}", - {% else %} - "{{ bookmark.title | replace('"', '\\"') | replace('\n', '') | replace('\r', '') }}": null, - {% endif %} - {% endfor %} -}); diff --git a/src/digimarks/templates/index.html b/src/digimarks/templates/index.html index 1e05790..ffc0839 100644 --- a/src/digimarks/templates/index.html +++ b/src/digimarks/templates/index.html @@ -1,17 +1,30 @@ {% extends "base.html" %} {% block title %}digimarks{% endblock %} -{% block pageheader %}digimarks{% endblock %} -{% block pagecontent %} -

Please visit your personal url, or see the digimarks project page.

+{% block page_header %}digimarks{% endblock %} +{% block page_content %} +
-
-
-
- - If you forgot/lost your personal url, contact your digimarks administrator.{# On startup, the personal codes are printed to the standard output (so should be findable in a log). Of course, bookmarks.db contains the user information too.#} - -
-
-
+
+ +
+
+

Welcome to digimarks, your online bookmarking and notes tool

+ +

Please visit your personal url, or see the digimarks + project page.

+ +

If you forgot/lost your personal url, contact your digimarks + administrator.{# On startup, the personal codes are printed to the standard output (so should be findable in a log). Of course, bookmarks.db contains the user information too.#} +

+
+ +
{% endblock %} diff --git a/src/digimarks/templates/publicbookmarks.html b/src/digimarks/templates/publicbookmarks.html index 8bcb0e2..af7888e 100644 --- a/src/digimarks/templates/publicbookmarks.html +++ b/src/digimarks/templates/publicbookmarks.html @@ -1,29 +1,30 @@ {% extends "base.html" %} {% if not action %} -{% set action = 'Bookmarks' %} + {% set action = 'Bookmarks' %} {% endif %} {% block title %}{{ action }}{% endblock %} -{% block pageheader %}{{ action }}{% endblock %} -{% block pagecontent %} +{% block page_header %}{{ action }}{% endblock %} +{% block page_content %} -{% if message %} -
-
-
+ {% if message %} +
+
+
{{ message }} +
+
+
+ {% endif %} + + -
-{% endif %} -
- -
- -{% include 'cards.html' %} + {% include 'cards.html' %} {% endblock %} diff --git a/src/digimarks/templates/tags.html b/src/digimarks/templates/tags.html index 4342570..bbf13fa 100644 --- a/src/digimarks/templates/tags.html +++ b/src/digimarks/templates/tags.html @@ -1,65 +1,68 @@ {% extends "base.html" %} {% block title %}Tags{% endblock %} -{% block pageheader %}Tags{% endblock %} -{% block pagecontent %} -
+{% block page_header %}Tags{% endblock %} +{% block page_content %} +
-
- - - - - - - - - - - - - - - - - - - - - - - -
labelpresent_to_allturned_incommentstarwarningdelete
{{ totaltags }}{{ totalpublic }}{{ totalbookmarks }}{{ totalnotes }}{{ totalstarred }}{{ totalhttperrorstatus }}{{ totaldeleted }}
+
+ + + + + + + + + + + + + + + + + + + + + + + +
labelpresent_to_allturned_incommentstarwarningdelete
{{ totaltags }}{{ totalpublic }}{{ totalbookmarks }}{{ totalnotes }}{{ totalstarred }}{{ totalhttperrorstatus }}{{ totaldeleted }}
-

+

- - - - - - - - - - {% for tag in tags %} - - - - - - {% endfor %} - -
TagPublic linkNumber of bookmarks
- {{ tag['tag'] }} - - {% if tag['publictag'] %} - Public link (Delete warning) - {% else %} - Create - {% endif %} - - {{ tag['total'] }} -
+ + + + + + + + + + {% for tag in tags %} + + + + + + {% endfor %} + +
TagPublic linkNumber of bookmarks
+ {{ tag['tag'] }} + + {% if tag['publictag'] %} + Public + link ( + Delete + warning) + {% else %} + Create + {% endif %} + + {{ tag['total'] }} +
+
-
{% endblock %} diff --git a/src/digimarks/templates/user_index.html b/src/digimarks/templates/user_index.html index 0bc145b..2707c4d 100644 --- a/src/digimarks/templates/user_index.html +++ b/src/digimarks/templates/user_index.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block title %}Bookmarks{% endblock %} -{% block pageheader %}Bookmarks{% endblock %} -{% block pagecontent %} +{% block page_header %}Bookmarks{% endblock %} +{% block page_content %}
@@ -16,7 +16,7 @@
  • - +
  • @@ -50,12 +50,48 @@

    + + + + + + + + + + + + +
     TitleNoteTags
    + {#
    - +#}