forked from mirrors/bookwyrm
Merge pull request #1476 from bookwyrm-social/progress-modal
Progress modal
This commit is contained in:
commit
e308ca2511
14 changed files with 70 additions and 56 deletions
|
@ -13,7 +13,7 @@ VERSION = "0.0.1"
|
||||||
PAGE_LENGTH = env("PAGE_LENGTH", 15)
|
PAGE_LENGTH = env("PAGE_LENGTH", 15)
|
||||||
DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
|
DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
|
||||||
|
|
||||||
JS_CACHE = "7f2343cf"
|
JS_CACHE = "e2bc0653"
|
||||||
|
|
||||||
# email
|
# email
|
||||||
EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")
|
EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend")
|
||||||
|
|
|
@ -141,8 +141,10 @@ let StatusCache = new class {
|
||||||
modal.getElementsByClassName("modal-close")[0].click();
|
modal.getElementsByClassName("modal-close")[0].click();
|
||||||
|
|
||||||
// Update shelve buttons
|
// Update shelve buttons
|
||||||
|
if (form.reading_status) {
|
||||||
document.querySelectorAll("[data-shelve-button-book='" + form.book.value +"']")
|
document.querySelectorAll("[data-shelve-button-book='" + form.book.value +"']")
|
||||||
.forEach(button => this.cycleShelveButtons(button, form.reading_status.value));
|
.forEach(button => this.cycleShelveButtons(button, form.reading_status.value));
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
27
bookwyrm/templates/snippets/progress_field.html
Normal file
27
bookwyrm/templates/snippets/progress_field.html
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{% load i18n %}
|
||||||
|
<div class="field has-addons">
|
||||||
|
<div class="control">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="progress"
|
||||||
|
class="input"
|
||||||
|
id="id_progress_{{ readthrough.id }}"
|
||||||
|
value="{{ readthrough.progress }}"
|
||||||
|
{% if progress_required %}required{% endif %}
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div class="control select">
|
||||||
|
<select name="progress_mode" aria-label="Progress mode">
|
||||||
|
<option
|
||||||
|
value="PG"
|
||||||
|
{% if readthrough.progress_mode == 'PG' %}selected{% endif %}>
|
||||||
|
{% trans "pages" %}
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="PCT"
|
||||||
|
{% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>
|
||||||
|
{% trans "percent" %}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -11,6 +11,7 @@ Finish "<em>{{ book_title }}</em>"
|
||||||
{% block modal-form-open %}
|
{% block modal-form-open %}
|
||||||
<form name="finish-reading" action="{% url 'reading-status' 'finish' book.id %}" method="post" class="submit-status">
|
<form name="finish-reading" action="{% url 'reading-status' 'finish' book.id %}" method="post" class="submit-status">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||||
<input type="hidden" name="reading_status" value="read">
|
<input type="hidden" name="reading_status" value="read">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@
|
||||||
|
|
||||||
{% block content_label %}
|
{% block content_label %}
|
||||||
{% trans "Comment:" %}
|
{% trans "Comment:" %}
|
||||||
|
{% if optional %}
|
||||||
<span class="help mt-0 has-text-weight-normal">{% trans "(Optional)" %}</span>
|
<span class="help mt-0 has-text-weight-normal">{% trans "(Optional)" %}</span>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block initial_fields %}
|
{% block initial_fields %}
|
||||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||||
<input type="hidden" name="mention_books" value="{{ book.id }}">
|
<input type="hidden" name="mention_books" value="{{ book.id }}">
|
||||||
<input type="hidden" name="book" value="{{ book.id }}">
|
<input type="hidden" name="book" value="{{ book.id }}">
|
||||||
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -13,14 +13,18 @@
|
||||||
{% trans "Post to feed" %}
|
{% trans "Post to feed" %}
|
||||||
</label>
|
</label>
|
||||||
<div class="is-hidden" id="hide_reading_content_{{ local_uuid }}_{{ uuid }}">
|
<div class="is-hidden" id="hide_reading_content_{{ local_uuid }}_{{ uuid }}">
|
||||||
<button class="button is-link" type="submit">{% trans "Save" %}</button>
|
<button class="button is-link" type="submit">
|
||||||
|
<span class="icon icon-spinner" aria-hidden="true"></span>
|
||||||
|
<span>{% trans "Save" %}</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="reading_content_{{ local_uuid }}_{{ uuid }}">
|
<div id="reading_content_{{ local_uuid }}_{{ uuid }}">
|
||||||
<hr aria-hidden="true">
|
<hr aria-hidden="true">
|
||||||
<fieldset id="reading_content_fieldset_{{ local_uuid }}_{{ uuid }}">
|
<fieldset id="reading_content_fieldset_{{ local_uuid }}_{{ uuid }}">
|
||||||
{% include "snippets/reading_modals/form.html" with optional=True %}
|
{% comparison_bool controls_text "progress_update" True as optional %}
|
||||||
|
{% include "snippets/reading_modals/form.html" with optional=optional %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends 'components/modal.html' %}
|
{% extends 'snippets/reading_modals/layout.html' %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block modal-title %}
|
{% block modal-title %}
|
||||||
|
@ -6,42 +6,12 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block modal-form-open %}
|
{% block modal-form-open %}
|
||||||
<form action="{% url 'edit-readthrough' %}" method="POST" class="submit-status">
|
<form name="reading-progress" action="{% url 'reading-status-update' book.id %}" method="POST" class="submit-status">
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block modal-body %}
|
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="id" value="{{ readthrough.id }}"/>
|
<input type="hidden" name="id" value="{{ readthrough.id }}">
|
||||||
<div class="field">
|
|
||||||
<label class="label is-align-self-center mb-0 pr-2" for="progress">{% trans "Progress:" %}</label>
|
|
||||||
<div class="field has-addons mb-0">
|
|
||||||
<div class="control">
|
|
||||||
<input
|
|
||||||
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:'' }}"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<div class="control select">
|
|
||||||
<select name="progress_mode" aria-label="Progress mode">
|
|
||||||
<option value="PG" {% if readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
|
|
||||||
<option value="PCT" {% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% if readthrough.progress_mode == 'PG' and book.pages %}
|
|
||||||
<p class="help">{% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block modal-footer %}
|
{% block reading-dates %}
|
||||||
<button class="button is-success" type="submit">{% trans "Save" %}</button>
|
<label for="id_progress_{{ readthrough.id }}" class="label">{% trans "Progress:" %}</label>
|
||||||
{% trans "Cancel" as button_text %}
|
{% include "snippets/progress_field.html" with progress_required=True %}
|
||||||
{% include 'snippets/toggle/toggle_button.html' with text=button_text %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block modal-form-close %}</form>{% endblock %}
|
|
||||||
|
|
|
@ -13,17 +13,7 @@
|
||||||
<label class="label" for="id_progress_{{ readthrough.id }}">
|
<label class="label" for="id_progress_{{ readthrough.id }}">
|
||||||
{% trans "Progress" %}
|
{% trans "Progress" %}
|
||||||
</label>
|
</label>
|
||||||
<div class="field has-addons">
|
{% include "snippets/progress_field.html" %}
|
||||||
<div class="control">
|
|
||||||
<input type="number" name="progress" class="input" id="id_progress_{{ readthrough.id }}" value="{{ readthrough.progress }}">
|
|
||||||
</div>
|
|
||||||
<div class="control select">
|
|
||||||
<select name="progress_mode" aria-label="Progress mode">
|
|
||||||
<option value="PG" {% if readthrough.progress_mode == 'PG' %}selected{% endif %}>{% trans "pages" %}</option>
|
|
||||||
<option value="PCT" {% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>{% trans "percent" %}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="id_finish_date_{{ readthrough.id }}">
|
<label class="label" for="id_finish_date_{{ readthrough.id }}">
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid readthrough=readthrough %}
|
{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid readthrough=readthrough %}
|
||||||
|
|
||||||
{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf_book.book controls_text="progress_update" controls_uid=uuid readthrough=readthrough %}
|
{% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book controls_text="progress_update" controls_uid=uuid readthrough=readthrough %}
|
||||||
|
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -36,8 +36,10 @@ def get_title(book, too_short=5):
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=False)
|
@register.simple_tag(takes_context=False)
|
||||||
def comparison_bool(str1, str2):
|
def comparison_bool(str1, str2, reverse=False):
|
||||||
"""idk why I need to write a tag for this, it returns a bool"""
|
"""idk why I need to write a tag for this, it returns a bool"""
|
||||||
|
if reverse:
|
||||||
|
return str1 != str2
|
||||||
return str1 == str2
|
return str1 == str2
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -370,6 +370,11 @@ urlpatterns = [
|
||||||
re_path(r"^create-readthrough/?$", views.create_readthrough),
|
re_path(r"^create-readthrough/?$", views.create_readthrough),
|
||||||
re_path(r"^delete-progressupdate/?$", views.delete_progressupdate),
|
re_path(r"^delete-progressupdate/?$", views.delete_progressupdate),
|
||||||
# shelve actions
|
# shelve actions
|
||||||
|
re_path(
|
||||||
|
r"^reading-status/update/(?P<book_id>\d+)/?$",
|
||||||
|
views.update_progress,
|
||||||
|
name="reading-status-update",
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
r"^reading-status/(?P<status>want|start|finish)/(?P<book_id>\d+)/?$",
|
r"^reading-status/(?P<status>want|start|finish)/(?P<book_id>\d+)/?$",
|
||||||
views.ReadingStatus.as_view(),
|
views.ReadingStatus.as_view(),
|
||||||
|
|
|
@ -59,7 +59,7 @@ from .search import Search
|
||||||
from .shelf import Shelf
|
from .shelf import Shelf
|
||||||
from .shelf import create_shelf, delete_shelf
|
from .shelf import create_shelf, delete_shelf
|
||||||
from .shelf import shelve, unshelve
|
from .shelf import shelve, unshelve
|
||||||
from .status import CreateStatus, DeleteStatus, DeleteAndRedraft
|
from .status import CreateStatus, DeleteStatus, DeleteAndRedraft, update_progress
|
||||||
from .updates import get_notification_count, get_unread_status_count
|
from .updates import get_notification_count, get_unread_status_count
|
||||||
from .user import User, Followers, Following, hide_suggestions
|
from .user import User, Followers, Following, hide_suggestions
|
||||||
from .wellknown import *
|
from .wellknown import *
|
||||||
|
|
|
@ -167,6 +167,8 @@ def edit_readthrough(request):
|
||||||
# use default now for date field
|
# use default now for date field
|
||||||
readthrough.create_update()
|
readthrough.create_update()
|
||||||
|
|
||||||
|
if is_api_request(request):
|
||||||
|
return HttpResponse()
|
||||||
return redirect(request.headers.get("Referer", "/"))
|
return redirect(request.headers.get("Referer", "/"))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
from bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
|
@ -135,6 +136,15 @@ class DeleteAndRedraft(View):
|
||||||
return TemplateResponse(request, "compose.html", data)
|
return TemplateResponse(request, "compose.html", data)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@require_POST
|
||||||
|
def update_progress(request, book_id): # pylint: disable=unused-argument
|
||||||
|
"""Either it's just a progress update, or it's a comment with a progress update"""
|
||||||
|
if request.POST.get("post-status"):
|
||||||
|
return CreateStatus.as_view()(request, "comment")
|
||||||
|
return edit_readthrough(request)
|
||||||
|
|
||||||
|
|
||||||
def find_mentions(content):
|
def find_mentions(content):
|
||||||
"""detect @mentions in raw status content"""
|
"""detect @mentions in raw status content"""
|
||||||
if not content:
|
if not content:
|
||||||
|
|
Loading…
Reference in a new issue