forked from mirrors/bookwyrm
Merge pull request #553 from mouse-reeve/pages-percents
Makes pages/percents toggle-able in sidebar for progress readthrough
This commit is contained in:
commit
7ed63bacc9
5 changed files with 106 additions and 93 deletions
36
bookwyrm/migrations/0040_auto_20210122_0057.py
Normal file
36
bookwyrm/migrations/0040_auto_20210122_0057.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# Generated by Django 3.0.7 on 2021-01-22 00:57
|
||||||
|
|
||||||
|
import bookwyrm.models.fields
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bookwyrm', '0039_merge_20210120_0753'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='progressupdate',
|
||||||
|
name='progress',
|
||||||
|
field=models.IntegerField(validators=[django.core.validators.MinValueValidator(0)]),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='progressupdate',
|
||||||
|
name='readthrough',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookwyrm.ReadThrough'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='progressupdate',
|
||||||
|
name='remote_id',
|
||||||
|
field=bookwyrm.models.fields.RemoteIdField(max_length=255, null=True, validators=[bookwyrm.models.fields.validate_remote_id]),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='readthrough',
|
||||||
|
name='progress',
|
||||||
|
field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)]),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,27 +1,27 @@
|
||||||
<form class="field is-grouped is-small" action="/edit-readthrough" method="POST">
|
<form class="field is-grouped is-small" action="/edit-readthrough" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="id" value="{{ readthrough.id }}"/>
|
<input type="hidden" name="id" value="{{ readthrough.id }}"/>
|
||||||
<label class="label is-align-self-center mb-0 pr-2" for="progress">Currently at</label>
|
<div class="field">
|
||||||
<div class="control">
|
<label class="label is-align-self-center mb-0 pr-2" for="progress">Progress:</label>
|
||||||
<div class="field has-addons">
|
<div class="field has-addons mb-0">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input
|
<input
|
||||||
aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}"
|
aria-label="{% if readthrough.progress_mode == 'PG' %}Current page{% else %}Percent read{% endif %}"
|
||||||
class="input is-small" type="number"
|
class="input is-small" type="number" min="0"
|
||||||
name="progress" size="3" value="{{ readthrough.progress|default:'' }}">
|
name="progress" size="3" value="{{ readthrough.progress|default:'' }}">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control select is-small">
|
||||||
|
<select name="progress_mode" aria-label="Progress mode">
|
||||||
|
<option value="PG" {% if readthrough.progress_mode == 'PG' %}selected{% endif %}>pages</option>
|
||||||
|
<option value="PCT" {% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>percent</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<a class="button is-small is-static">
|
<button class="button is-small px-2 is-primary" type="submit">Save</button>
|
||||||
{% if readthrough.progress_mode == 'PG' %}
|
|
||||||
pages
|
|
||||||
{% else %}
|
|
||||||
%
|
|
||||||
{% endif %}
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% if readthrough.progress_mode == 'PG' and book.pages %}
|
||||||
<div class="control">
|
<p class="help">of {{ book.pages }} pages</p>
|
||||||
<button class="button is-small px-2" type="submit">Save</button>
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,67 +1,52 @@
|
||||||
{% load humanize %}
|
{% load humanize %}
|
||||||
<div class="content block">
|
<div class="content block">
|
||||||
<div id="hide-edit-readthrough-{{ readthrough.id }}">
|
<div id="hide-edit-readthrough-{{ readthrough.id }}">
|
||||||
<dl class="mb-1">
|
<div class="columns">
|
||||||
{% if readthrough.start_date %}
|
<div class="column">
|
||||||
<div class="is-flex">
|
Progress Updates:
|
||||||
<dt>Started reading:</dt>
|
</dl>
|
||||||
<dd>{{ readthrough.start_date | naturalday }}</dd>
|
<ul>
|
||||||
|
{% if readthrough.progress %}
|
||||||
|
<li>{% if readthrough.finish_date %} {{ readthrough.finish_date | naturalday }}: finished {% else %}{% if readthrough.progress_mode == 'PG' %}on page {{ readthrough.progress }}{% if book.pages %} of {{ book.pages }}{% endif %}
|
||||||
|
{% else %}{{ readthrough.progress }}%{% endif %}{% endif %}
|
||||||
|
{% include 'snippets/toggle/toggle_button.html' with text="Show all updates" controls_text="updates" controls_uid=readthrough.id class="is-small" %}
|
||||||
|
<ul id="updates-{{ readthrough.id }}" class="hidden">
|
||||||
|
{% for progress_update in readthrough.progress_updates %}
|
||||||
|
<li>
|
||||||
|
<form name="delete-update" action="/delete-progressupdate" method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ progress_update.created_date | naturalday }}:
|
||||||
|
{% if progress_update.mode == 'PG' %}
|
||||||
|
page {{ progress_update.progress }} of {{ book.pages }}
|
||||||
|
{% else %}
|
||||||
|
{{ progress_update.progress }}%
|
||||||
|
{% endif %}
|
||||||
|
<input type="hidden" name="id" value="{{ progress_update.id }}"/>
|
||||||
|
<button type="submit" class="button is-small" for="delete-progressupdate-{{ progress_update.id }}" role="button" tabindex="0">
|
||||||
|
<span class="icon icon-x" title="Delete this progress update">
|
||||||
|
<span class="is-sr-only">Delete this progress update</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
<li>{{ readthrough.start_date | naturalday }}: started</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
<div class="column is-narrow">
|
||||||
{% if readthrough.finish_date %}
|
<div class="field has-addons">
|
||||||
<div class="is-flex">
|
<div class="control">
|
||||||
<dt>Finished reading:</dt>
|
{% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Edit read dates" icon="pencil" controls_text="edit-readthrough" controls_uid=readthrough.id focus="edit-readthrough" %}
|
||||||
<dd>{{ readthrough.finish_date | naturalday }}</dd>
|
</div>
|
||||||
</div>
|
<div class="control">
|
||||||
{% elif readthrough.progress %}
|
{% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Delete these read dates" icon="x" controls_text="delete-readthrough" controls_uid=readthrough.id focus="modal-title-delete-readthrough" %}
|
||||||
<div class="is-flex">
|
</div>
|
||||||
<dt>Progress:</dt>
|
</div>
|
||||||
{% if readthrough.progress_mode == 'PG' %}
|
|
||||||
<dd>on page {{ readthrough.progress }} of {{ book.pages }}</dd>
|
|
||||||
{% else %}
|
|
||||||
<dd>{{ readthrough.progress }}%</dd>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</dl>
|
|
||||||
<div class="field has-addons">
|
|
||||||
<div class="control">
|
|
||||||
{% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Edit read dates" icon="pencil" controls_text="edit-readthrough" controls_uid=readthrough.id focus="edit-readthrough" %}
|
|
||||||
</div>
|
|
||||||
<div class="control">
|
|
||||||
{% include 'snippets/toggle/toggle_button.html' with class="is-small" text="Delete these read dates" icon="x" controls_text="delete-readthrough" controls_uid=readthrough.id focus="modal-title-delete-readthrough" %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if show_progress %}
|
|
||||||
Progress Updates:
|
|
||||||
<ul>
|
|
||||||
{% if readthrough.finish_date %}
|
|
||||||
<li>{{ readthrough.start_date | naturalday }}: finished</li>
|
|
||||||
{% endif %}
|
|
||||||
{% for progress_update in readthrough.progress_updates %}
|
|
||||||
<li>
|
|
||||||
<form name="delete-update" action="/delete-progressupdate" method="POST">
|
|
||||||
{% csrf_token %}
|
|
||||||
{{ progress_update.created_date | naturalday }}:
|
|
||||||
{% if progress_update.mode == 'PG' %}
|
|
||||||
page {{ progress_update.progress }} of {{ book.pages }}
|
|
||||||
{% else %}
|
|
||||||
{{ progress_update.progress }}%
|
|
||||||
{% endif %}
|
|
||||||
<input type="hidden" name="id" value="{{ progress_update.id }}"/>
|
|
||||||
<button type="submit" class="button is-small" for="delete-progressupdate-{{ progress_update.id }}" role="button" tabindex="0">
|
|
||||||
<span class="icon icon-x">
|
|
||||||
<span class="is-sr-only">Delete this progress update</span>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
<li>{{ readthrough.start_date | naturalday }}: started</li>
|
|
||||||
</ul>
|
|
||||||
{% elif readthrough.progress_updates|length %}
|
|
||||||
<a href="?showprogress">Show {{ readthrough.progress_updates|length }} Progress Updates</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -9,26 +9,18 @@
|
||||||
</div>
|
</div>
|
||||||
{# Only show progress for editing existing readthroughs #}
|
{# Only show progress for editing existing readthroughs #}
|
||||||
{% if readthrough.id and not readthrough.finish_date %}
|
{% if readthrough.id and not readthrough.finish_date %}
|
||||||
<div class="columns">
|
<label class="label" for="id_progress-{{ readthrough.id }}">
|
||||||
<div class="column">
|
Progress
|
||||||
<div class="field">
|
</label>
|
||||||
<label class="label">
|
<div class="field has-addons">
|
||||||
Progress
|
<div class="control">
|
||||||
<input type="number" name="progress" class="input" id="id_progress-{{ readthrough.id }}" value="{{ readthrough.progress }}">
|
<input type="number" name="progress" class="input" id="id_progress-{{ readthrough.id }}" value="{{ readthrough.progress }}">
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="control select">
|
||||||
<div class="control mt-5">
|
<select name="progress_mode" aria-label="Progress mode">
|
||||||
<label class="radio">
|
<option value="PG" {% if readthrough.progress_mode == 'PG' %}selected{% endif %}>pages</option>
|
||||||
<input type="radio" name="progress_mode" id="id_progress_mode-{{ readthrough.id }}" value="PG" {% if readthrough.progress_mode == 'PG' %}checked{% endif %}>
|
<option value="PCT" {% if readthrough.progress_mode == 'PCT' %}selected{% endif %}>percent</option>
|
||||||
pages
|
</select>
|
||||||
</label>
|
|
||||||
<label class="radio">
|
|
||||||
<input type="radio" name="progress_mode" id="id_progress_mode-{{ readthrough.id }}" value="PCT" {% if readthrough.progress_mode == 'PCT' %}checked{% endif %}>
|
|
||||||
percent
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -74,7 +74,8 @@ class Book(View):
|
||||||
|
|
||||||
for readthrough in readthroughs:
|
for readthrough in readthroughs:
|
||||||
readthrough.progress_updates = \
|
readthrough.progress_updates = \
|
||||||
readthrough.progressupdate_set.all().order_by('-updated_date')
|
readthrough.progressupdate_set.all() \
|
||||||
|
.order_by('-updated_date')
|
||||||
|
|
||||||
user_shelves = models.ShelfBook.objects.filter(
|
user_shelves = models.ShelfBook.objects.filter(
|
||||||
added_by=request.user, book=book
|
added_by=request.user, book=book
|
||||||
|
@ -98,7 +99,6 @@ class Book(View):
|
||||||
'user_shelves': user_shelves,
|
'user_shelves': user_shelves,
|
||||||
'other_edition_shelves': other_edition_shelves,
|
'other_edition_shelves': other_edition_shelves,
|
||||||
'readthroughs': readthroughs,
|
'readthroughs': readthroughs,
|
||||||
'show_progress': ('showprogress' in request.GET),
|
|
||||||
'path': '/book/%s' % book_id,
|
'path': '/book/%s' % book_id,
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, 'book.html', data)
|
return TemplateResponse(request, 'book.html', data)
|
||||||
|
|
Loading…
Reference in a new issue