From 942c4a666449180c084934a1404364bb96570f06 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 20 Mar 2021 17:18:18 -0700 Subject: [PATCH 1/6] Move progress updates into modal --- bookwyrm/models/readthrough.py | 3 ++ bookwyrm/static/css/format.css | 3 -- bookwyrm/templates/feed/feed_layout.html | 14 +++---- .../snippets/create_status_form.html | 39 ++++++++++++++++- .../templates/snippets/progress_update.html | 28 ------------- .../shelve_button/progress_update_modal.html | 42 +++++++++++++++++++ .../snippets/shelve_button/shelve_button.html | 4 +- .../shelve_button/shelve_button_options.html | 8 ++++ bookwyrm/urls.py | 2 +- 9 files changed, 101 insertions(+), 42 deletions(-) delete mode 100644 bookwyrm/templates/snippets/progress_update.html create mode 100644 bookwyrm/templates/snippets/shelve_button/progress_update_modal.html diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 3445573c4..b76b90221 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -7,6 +7,7 @@ from .base_model import BookWyrmModel class ProgressMode(models.TextChoices): + """ types of prgress available """ PAGE = "PG", "page" PERCENT = "PCT", "percent" @@ -32,10 +33,12 @@ class ReadThrough(BookWyrmModel): super().save(*args, **kwargs) def create_update(self): + """ add update to the readthrough """ if self.progress: return self.progressupdate_set.create( user=self.user, progress=self.progress, mode=self.progress_mode ) + return None class ProgressUpdate(BookWyrmModel): diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index 435d8eb9e..05451e160 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -14,9 +14,6 @@ html { .card { overflow: visible; } -.card-header-title { - overflow: hidden; -} /* --- SHELVING --- */ .shelf-option:disabled > *::after { diff --git a/bookwyrm/templates/feed/feed_layout.html b/bookwyrm/templates/feed/feed_layout.html index 24294e5d0..6ed696a12 100644 --- a/bookwyrm/templates/feed/feed_layout.html +++ b/bookwyrm/templates/feed/feed_layout.html @@ -47,20 +47,18 @@ {% for book in shelf.books %}
-

- {% include 'snippets/book_titleby.html' with book=book %} -

+
+
+

{% include 'snippets/book_titleby.html' with book=book %}

+ {% include 'snippets/shelve_button/shelve_button.html' with book=book %} +
+
{% trans "Close" as button_text %} {% include 'snippets/toggle/toggle_button.html' with label=button_text controls_text="book" controls_uid=book.id class="delete" nonbutton=True pressed=True %}
- {% include 'snippets/shelve_button/shelve_button.html' with book=book %} - {% active_shelf book as active_shelf %} - {% if active_shelf.shelf.identifier == 'reading' and book.latest_readthrough %} - {% include 'snippets/progress_update.html' with readthrough=book.latest_readthrough %} - {% endif %} {% include 'snippets/create_status.html' with book=book %}
diff --git a/bookwyrm/templates/snippets/create_status_form.html b/bookwyrm/templates/snippets/create_status_form.html index 187eae605..d0b763bfd 100644 --- a/bookwyrm/templates/snippets/create_status_form.html +++ b/bookwyrm/templates/snippets/create_status_form.html @@ -13,7 +13,15 @@ {% endif %}
{% if type != 'reply' and type != 'direct' %} - + {% endif %} {% if type == 'review' %} @@ -45,6 +53,35 @@ {% include 'snippets/content_warning_field.html' with parent_status=status %}
+ {% elif type == 'comment' %} +
+ {% active_shelf book as active_shelf %} + {% if active_shelf.shelf.identifier == 'reading' and book.latest_readthrough %} + + {% with readthrough=book.latest_readthrough %} +
+ +
+
+ +
+
+ +
+
+ {% if readthrough.progress_mode == 'PG' and book.pages %} +

{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}

+ {% endif %} +
+ {% endwith %} + {% endif %} +
{% endif %} {# bottom bar #} diff --git a/bookwyrm/templates/snippets/progress_update.html b/bookwyrm/templates/snippets/progress_update.html deleted file mode 100644 index cb7096258..000000000 --- a/bookwyrm/templates/snippets/progress_update.html +++ /dev/null @@ -1,28 +0,0 @@ -{% load i18n %} -
- {% csrf_token %} - -
- -
-
- -
-
- -
-
- -
-
- {% if readthrough.progress_mode == 'PG' and book.pages %} -

{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}

- {% endif %} -
-
diff --git a/bookwyrm/templates/snippets/shelve_button/progress_update_modal.html b/bookwyrm/templates/snippets/shelve_button/progress_update_modal.html new file mode 100644 index 000000000..5879264b5 --- /dev/null +++ b/bookwyrm/templates/snippets/shelve_button/progress_update_modal.html @@ -0,0 +1,42 @@ +{% extends 'components/modal.html' %} +{% load i18n %} + +{% block modal-title %} +{% trans "Update progress" %} +{% endblock %} + +{% block modal-form-open %} +
+{% endblock %} + +{% block modal-body %} +{% csrf_token %} + +
+ +
+
+ +
+
+ +
+
+ {% if readthrough.progress_mode == 'PG' and book.pages %} +

{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}

+ {% endif %} +
+{% endblock %} + +{% block modal-footer %} + +{% trans "Cancel" as button_text %} +{% include 'snippets/toggle/toggle_button.html' with text=button_text %} +{% endblock %} +{% block modal-form-close %}
{% endblock %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button.html b/bookwyrm/templates/snippets/shelve_button/shelve_button.html index 5f6ed8d20..586d7d9d1 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button.html @@ -3,7 +3,7 @@ {% with book.id|uuid as uuid %} {% active_shelf book as active_shelf %} -
+
{% if switch_mode and active_shelf.book != book %}
{% include 'snippets/switch_edition_button.html' with edition=book size='is-small' %} @@ -23,5 +23,7 @@ {% latest_read_through book request.user as readthrough %} {% include 'snippets/shelve_button/finish_reading_modal.html' with book=active_shelf.book controls_text="finish-reading" controls_uid=uuid readthrough=readthrough %} +{% include 'snippets/shelve_button/progress_update_modal.html' with book=shelf_book.book controls_text="progress-update" controls_uid=uuid readthrough=readthrough %} + {% endwith %} {% endif %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html index d6fdb13bc..56783b2cc 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_options.html @@ -27,3 +27,11 @@
{% if dropdown %}{% endif %} {% endfor %} +{% if dropdown %} +
  • + +
  • +{% endif %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 44492668b..c24b83f70 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -183,7 +183,7 @@ urlpatterns = [ re_path(r"^shelve/?$", views.shelve), re_path(r"^unshelve/?$", views.unshelve), # reading progress - re_path(r"^edit-readthrough/?$", views.edit_readthrough), + re_path(r"^edit-readthrough/?$", views.edit_readthrough, name="edit-readthrough"), re_path(r"^delete-readthrough/?$", views.delete_readthrough), re_path(r"^create-readthrough/?$", views.create_readthrough), re_path(r"^delete-progressupdate/?$", views.delete_progressupdate), From daa0268eb31512a3e3aa59ed29a8b979d51d3a5f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 20 Mar 2021 17:34:58 -0700 Subject: [PATCH 2/6] Update progress with comments --- bookwyrm/forms.py | 2 +- .../migrations/0055_auto_20210321_0025.py | 24 +++++++++++++++++++ bookwyrm/models/status.py | 8 +++++++ .../snippets/create_status_form.html | 5 ++-- bookwyrm/views/status.py | 5 ++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 bookwyrm/migrations/0055_auto_20210321_0025.py diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index edf1d9e45..6cc81c049 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -76,7 +76,7 @@ class ReviewForm(CustomForm): class CommentForm(CustomForm): class Meta: model = models.Comment - fields = ["user", "book", "content", "content_warning", "sensitive", "privacy"] + fields = ["user", "book", "content", "content_warning", "sensitive", "privacy", "progress", "mode"] class QuotationForm(CustomForm): diff --git a/bookwyrm/migrations/0055_auto_20210321_0025.py b/bookwyrm/migrations/0055_auto_20210321_0025.py new file mode 100644 index 000000000..446181f95 --- /dev/null +++ b/bookwyrm/migrations/0055_auto_20210321_0025.py @@ -0,0 +1,24 @@ +# Generated by Django 3.1.6 on 2021-03-21 00:25 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0054_auto_20210319_1942'), + ] + + operations = [ + migrations.AddField( + model_name='comment', + name='mode', + field=models.CharField(blank=True, choices=[('PG', 'page'), ('PCT', 'percent')], default='PG', max_length=3, null=True), + ), + migrations.AddField( + model_name='comment', + name='progress', + field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 09a7c4ec1..60c00f5a6 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -14,6 +14,7 @@ from .activitypub_mixin import ActivitypubMixin, ActivityMixin from .activitypub_mixin import OrderedCollectionPageMixin from .base_model import BookWyrmModel from .fields import image_serializer +from .readthrough import ProgressMode from . import fields @@ -229,6 +230,13 @@ class Comment(Status): "Edition", on_delete=models.PROTECT, activitypub_field="inReplyToBook" ) + # this is it's own field instead of a foreign key to the progress update + # so that the update can be deleted without impacting the status + progress = models.IntegerField(validators=[MinValueValidator(0)], null=True, blank=True) + mode = models.CharField( + max_length=3, choices=ProgressMode.choices, default=ProgressMode.PAGE, null=True, blank=True + ) + @property def pure_content(self): """ indicate the book in question for mastodon (or w/e) users """ diff --git a/bookwyrm/templates/snippets/create_status_form.html b/bookwyrm/templates/snippets/create_status_form.html index d0b763bfd..75f5d28b0 100644 --- a/bookwyrm/templates/snippets/create_status_form.html +++ b/bookwyrm/templates/snippets/create_status_form.html @@ -60,13 +60,14 @@ {% with readthrough=book.latest_readthrough %}
    - + +
    + name="progress" size="3" value="{{ readthrough.progress|default:'' }}" id="progress-{{ uuid }}">
    +
    + aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}" + class="input" + type="number" + min="0" + name="progress" + size="3" + value="{{ readthrough.progress|default:'' }}">