Skip to content

Commit

Permalink
Make slide advance buttons and API work on directly-displayed decks
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepman4267 committed Jul 12, 2024
1 parent 77f2c72 commit 8f78e0a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
20 changes: 20 additions & 0 deletions OpenShow/slides/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ class Display(models.Model): # A set of characteristics used to modify slide ap
) # TODO: What the heck is this for?

def advance_slide(self, direction):
if self.current_deck:
self._advance_slide_in_deck(direction)
elif self.current_show:
self._advance_slide_in_show(direction)

def _advance_slide_in_deck(self, direction):
if self.previous_slide and self.current_slide.auto_advance:
if timezone.now() - \
self.slide_changed_at < \
timedelta(seconds=self.previous_slide.auto_advance_duration):
# Abort and continue silently if we're getting a "next slide" directive and
# the previous slide's auto_advance_duration has not passed
# Manually selecting a different slide will override this.
return 1
slide = self.current_slide.next(direction)
if not slide:
slide = self.current_slide
slide.send_to_display([self, ])

def _advance_slide_in_show(self, direction):
if self.previous_slide and self.current_slide.auto_advance:
if timezone.now() - \
self.slide_changed_at < \
Expand Down
36 changes: 22 additions & 14 deletions OpenShow/slides/templates/slides/deck.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,28 @@ <h1>{{ deck.name }}</h1>
</div>
</div>
<div id="show-controls" class="mobile-hidden">
{# <div id="forward-reverse">#}
{# <form action="{% url 'show-slide' %}" method="POST">#}
{# {% csrf_token %}#}
{# <input type="hidden" name="show_pk" value="{{ show.pk }}">#}
{# <input type="hidden" name="direction" value="reverse">#}
{# <button class="icon-button" hx-post="{% url 'show-slide' %}" hx-swap="innerHTML" hx-target="#show-container" hx-select="#show">{% icon 'chevron-left' %}</button>#}
{# </form>#}
{# <form action="{% url 'show-slide' %}" method="POST">#}
{# {% csrf_token %}#}
{# <input type="hidden" name="show_pk" value="{{ show.pk }}">#}
{# <input type="hidden" name="direction" value="forward">#}
{# <button class="icon-button" hx-post="{% url 'show-slide' %}" hx-swap="innerHTML" hx-target="#show-container" hx-select="#show">{% icon 'chevron-right' %}</button>#}
{# </form>#}
{# </div>#}
<div id="forward-reverse">
<button class="icon-button" _="
on click
for display_checkbox in <input.display-checkbox:checked/>
set display_pk to display_checkbox's @data-display-pk
then log display_pk
set req_body to `{\&quot;display_pk&quot;: $display_pk, &quot;direction&quot;: &quot;reverse&quot;}`
log req_body
then fetch {% url "api-1.0.0:next_slide" %} with method:'POST', body: req_body
then halt
">{% icon 'chevron-left' %}</button>
<button class="icon-button" _="
on click
for display_checkbox in <input.display-checkbox:checked/>
set display_pk to display_checkbox's @data-display-pk
then log display_pk
set req_body to `{\&quot;display_pk&quot;: $display_pk, &quot;direction&quot;: &quot;forward&quot;}`
log req_body
then fetch {% url "api-1.0.0:next_slide" %} with method:'POST', body: req_body
then halt
">{% icon 'chevron-right' %}</button>
</div>
<button class="iconbutton" id="settings-toggle" _="on click toggle .expand on next <.settings/>">{% icon 'settings' %}</button>
<div class="settings box expand">
{# <form action="{% url 'advance-mode' show.pk %}">#}
Expand Down

0 comments on commit 8f78e0a

Please sign in to comment.