Skip to content

Commit

Permalink
Merge branch 'issue_530_add_peek_page' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Jan 3, 2025
2 parents 35286b3 + fd8c3b0 commit 49c1980
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
17 changes: 16 additions & 1 deletion lute/read/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
bp = Blueprint("read", __name__, url_prefix="/read")


def _render_book_page(book, pagenum):
def _render_book_page(book, pagenum, track_page_open=True):
"""
Render a particular book page.
"""
Expand All @@ -36,6 +36,7 @@ def _render_book_page(book, pagenum):
page_count=book.page_count,
show_highlights=show_highlights,
lang_id=lang.id,
track_page_open=track_page_open,
term_dicts=term_dicts,
)

Expand Down Expand Up @@ -81,6 +82,20 @@ def read_page(bookid, pagenum):
return _render_book_page(book, pagenum)


@bp.route("/<int:bookid>/peek/<int:pagenum>", methods=["GET"])
def peek_page(bookid, pagenum):
"""
Peek at a page; i.e. render it, but don't set the current text or start date.
"""
book = _find_book(bookid)
if book is None:
flash(f"No book matching id {bookid}")
return redirect("/", 302)

pagenum = book.page_in_range(pagenum)
return _render_book_page(book, pagenum, track_page_open=False)


@bp.route("/page_done", methods=["post"])
def page_done():
"Handle POST when page is done."
Expand Down
11 changes: 6 additions & 5 deletions lute/read/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,17 @@ def _save_new_status_0_terms(self, paragraphs):
self.session.add(ti.term)
self.session.commit()

def _get_reading_data(self, dbbook, pagenum, set_text_start_date=False):
def _get_reading_data(self, dbbook, pagenum, track_page_open=False):
"Get paragraphs, set text.start_date if needed."
text = dbbook.text_at_page(pagenum)
if set_text_start_date:
text.start_date = datetime.now()
text.load_sentences()

svc = StatsService(self.session)
svc.mark_stale(dbbook)
dbbook.current_tx_id = text.id

if track_page_open:
text.start_date = datetime.now()
dbbook.current_tx_id = text.id

self.session.add(dbbook)
self.session.add(text)
self.session.commit()
Expand Down
8 changes: 7 additions & 1 deletion lute/templates/read/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
page_num: <input id="page_num" value="{{ page_num }}">
page_count: <input id="page_count" value="{{ page_count }}">
highlights: <span id="show_highlights">{{ show_highlights|lower }}</span>
track_page_open: <input id="track_page_open" value="{{ track_page_open|lower }}">
</pre>
</div>

Expand Down Expand Up @@ -458,7 +459,12 @@ <h2>&#127881;</h2>

updateReadSlider(actualPage);

const url = `/read/start_reading/${bookid}/${actualPage}`;
let read_action = 'start_reading';
if ($("#track_page_open").val() == "false")
read_action = 'refresh_page';
const url = `/read/${read_action}/${bookid}/${actualPage}`;
// console.log(`go to page ${url}`);

$.get(
url,
function(data, status) {
Expand Down
2 changes: 1 addition & 1 deletion lute/templates/term/sentences.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<li style="margin-top: 4px;">
{{ dto.sentence | safe }}
<br/>
<a href="/read/{{ dto.book_id }}/page/{{ dto.page_number }}"
<a href="/read/{{ dto.book_id }}/peek/{{ dto.page_number }}"
target="_blank"
style="cursor: pointer; font-size: 0.9em; font-style: italic;">
{{ dto.title }}
Expand Down
8 changes: 8 additions & 0 deletions tests/acceptance/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ def when_go_to_page(luteclient, position):
# b.reload()


@given(parsers.parse("I peek at page {pagenum}"))
def given_peek_at_page(luteclient, pagenum):
"Peek at a page of the current book."
currurl = luteclient.browser.url
peekurl = re.sub(r"/page/.*", f"/peek/{pagenum}", currurl)
luteclient.browser.visit(peekurl)


@when(parsers.parse("I delete the current page"))
def when_delete_current_page(luteclient):
"Delete the current page."
Expand Down
23 changes: 23 additions & 0 deletions tests/acceptance/reading.feature
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,26 @@ Feature: User can actually read and stuff.
three/.
And book pages with start dates are:
Hola; 3


# Issue 530: "peeking" at page doesn't set page data.
Scenario: Peeking at page does not set current page or start date.
Given a Spanish book "Hola" with content:
Uno.
---
Dos.
Then the reading pane shows:
Uno/.
And book pages with start dates are:
Hola; 1

Given I peek at page 2
Then the reading pane shows:
Dos/.
And book pages with start dates are:
Hola; 1

Given I visit "/"
When I set the book table filter to "Hola"
Then the book table contains:
Hola; Spanish; ; 2;

0 comments on commit 49c1980

Please sign in to comment.