Skip to content

Commit

Permalink
Fix broken pagination, start adding buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
rix0rrr committed Jan 5, 2025
1 parent ec33809 commit 6edac63
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 62 deletions.
2 changes: 0 additions & 2 deletions templates/public-adventures2/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ <h1>{{_('public_adventures')}}</h1>
<input type="submit" value="{{_('search')}}" class="green-btn">
</div>
</div>
<!-- Holds the current page token -->
<input type="hidden" name="page" id="page_input" value="{{page}}">
</form>
</div>

Expand Down
73 changes: 38 additions & 35 deletions templates/public-adventures2/htmx-preview-adventure.html
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
{# Tabs #}
<div class="flex flex-row w-min gap-2 mb-4">
<div
class="cust-adv-tab cust-adv-tab-text active flex items-center justify-center whitespace-nowrap px-2"
tabindex="0"
data-tab="adventure-preview" data-activeclass="active">
{{ _('Adventure') }}
</div>
{% if adventure.solution_example %}
<div
class="cust-adv-tab cust-adv-tab-text flex items-center justify-center whitespace-nowrap px-2"
tabindex="0"
data-tab="adventure-answer" data-activeclass="active">
{{ _('solution_example') }}
{# Set the level and keyword language for all adventure content #}
<div data-level="{{adventure.level}}" data-kwlang="{{ g.keyword_lang }}">
{# Tabs #}
<div class="flex flex-row w-min gap-2 mb-4">
<div
class="cust-adv-tab cust-adv-tab-text active flex items-center justify-center whitespace-nowrap px-2"
tabindex="0"
data-tab="adventure-preview" data-activeclass="active">
{{ _('adventure') }}
</div>
{% if adventure.solution_example %}
<div
class="cust-adv-tab cust-adv-tab-text flex items-center justify-center whitespace-nowrap px-2"
tabindex="0"
data-tab="adventure-answer" data-activeclass="active">
{{ _('solution_example') }}
</div>
{% endif %}
</div>
{% endif %}
</div>

{# Panes #}
<div class="shadow-md bg-white p-4">
<div data-tabtarget="adventure-preview">
<h1>{{ adventure.name }}</h1>
{# Panes #}
<div class="shadow-md bg-white p-4">
<div data-tabtarget="adventure-preview">
<h1>{{ adventure.name }}</h1>

{% set adventure_content_topright_include = 'public-adventures2/incl-about.html' %}
{% include "incl/adventure-content.html" %}
{% set adventure_content_topright_include = 'public-adventures2/incl-about.html' %}
{% include "incl/adventure-content.html" %}

<div class="clear-both"></div>
<div class="clear-both"></div>

{% set public_adventures_page = True %}
{% include "incl/editor-and-output.html" %}
</div>
{% if adventure.solution_example %}
<div data-tabtarget="adventure-answer" class="hidden turn-pre-into-ace" data-level="{{adventure.level}}">
{% if adventure.is_teacher_adventure %}
{{ adventure.solution_example|safe }}
{% else %}
{{ adventure.solution_example|commonmark }}
{% endif %}
{% set public_adventures_page = True %}
{% include "incl/editor-and-output.html" %}
</div>
{% endif %}
</div>
{% if adventure.solution_example %}
<div data-tabtarget="adventure-answer" class="hidden turn-pre-into-ace">
{% if adventure.is_teacher_adventure %}
{{ adventure.solution_example|safe }}
{% else %}
{{ adventure.solution_example|commonmark }}
{% endif %}
</div>
{% endif %}
</div>
</div>
52 changes: 43 additions & 9 deletions templates/public-adventures2/incl-about.html
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
<div class="w-96 max-w-full border border-gray-600 mb-4">
<div class="bg-gray-600 text-white px-4 py-1">{{ _('about_this_adventure') }}</div>

{# Info #}
<div class="px-4 py-2">
{% set creator = _('owner') if adventure["author"] != adventure["creator"] else _('creator') %}

{% set labelstyles = "inline-block text-gray-600 mt-1 font-bold min-w-16" %}
{% set labelclass = "inline-block text-gray-600 mt-1 font-bold" %}
{% set labelstyle = "min-width: 5rem;" %}

{% if adventure["creator_public_profile"] or adventure["public_user"] %}
<div>
<span class="{{ labelstyles }}">{{ creator }}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{ creator }}:</span>
<a href="/user/{{adventure.creator or adventure.username}}" target="_blank">{{ adventure.creator or adventure.username }}</a>
</div>
{% else %}
<div>
<span class="{{ labelstyles }}">{{ creator }}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{ creator }}:</span>
{{ adventure.creator or adventure.username }}
</div>
{% endif %}
{% if adventure["author"] != adventure["creator"] %}
<div>
<span class="{{ labelstyles }}">{{ _('creator') }}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{ _('creator') }}:</span>
{{ adventure.author or adventure.username }}
</div>
{% endif %}

{% if adventure.get("language") %}
<div>
<span class="{{ labelstyles }}">{{ _('language') }}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{ _('language') }}:</span>
{{ lang_to_sym(adventure.language) }}
</div>
{% endif %}

<div>
<!-- adventure.level will gradually be removed until we have all adventures using only levels. -->
{% if adventure.levels and adventure.levels|length > 1 %}
<span class="{{ labelstyles }}">{{ _('levels') }}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{ _('levels') }}:</span>
{% for level in adventure.levels %}
{{level}}{% if loop.index != adventure.levels|length %}, {% endif %}
{% endfor %}
{% else %}
<span class="{{ labelstyles }}">{{ _('level') }}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{ _('level') }}:</span>
{{ adventure.level }}
{% endif %}
</div>

{% if adventure["cloned_times"] %}
<div>
<span class="{{ labelstyles }}">{{_('cloned_times')}}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{_('cloned_times')}}:</span>
{{adventure["cloned_times"]}}
</div>
{%endif%}
<div>
<span class="{{ labelstyles }}">{{_('last_update')}}:</span>
<span class="{{ labelclass }}" style="{{ labelstyle }}">{{_('last_update')}}:</span>
{{ adventure.date|format_date }}
</div>

Expand All @@ -62,4 +65,35 @@
</div>
{% endif %}
</div>

{# Actions #}
<div class="flex items-center px-6 py-4 bg-gray-200 shadow-lg">
{% if user["username"] != adventure["creator"] %}
{# Not your adventure, clone #}
<button class="green-btn"
hx-post="/public-adventures2/clone/{{adventure.id}}"
hx-swap="outerHTML"
data-cy="clone_{{adventure.name}}"
data-id="{{adventure.id}}">{{_('clone')}}</button>
{% else %}
{# Already your adventure, show an edit link #}
<a href="/for-teachers/customize-adventure/{{adventure.id}}"
data-cy="edit_{{adventure.name}}"
class="green-btn" id="edit_adventure_button">
{{_('edit_adventure')}}</a>
{% endif %}
<a hx-confirm="{{_('flag_adventure_prompt')}}"
hx-post="/public-adventures2/flag/{{adventure.id}}/{{adventure.flagged}}"
hx-swap="outerHTML">
<span class="fa fa-flag bg-{% if adventure.flagged %}red{%else%}blue{%endif%}-300 hover:bg-blue-600 p-2 mx-4 rounded-full text-white"></span>
</a>
{% if is_super_teacher %}
<a hx-confirm="{{_('delete_adventure_prompt')}}"
hx-delete="/for-teachers/customize-adventure/{{adventure.id}}/{{adventure.creator}}"
hx-swap="none"
_="on htmx:afterRequest if detail.xhr.status == 200 then window.location.reload()">
<span class="fa fa-trash p-2 bg-red-500 mr-4 rounded-full cursor-pointer" id="{{adventure.id}}"></span>
</a>
{% endif %}
</div>
</div>
32 changes: 22 additions & 10 deletions templates/public-adventures2/incl-adventure-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,32 @@
<div class="flex gap-2 w-full items-stretch mt-4">
<div class="flex-1">
{% if prev_page_token %}
<button
id="prev_button"
class="green-btn px-2 w-full h-full"
_="on click set (#page_input).value to '{{prev_page_token}}' then call (#filterform).requestSubmit()">
{{_('previous_page')}}<br>«</button>
<form hx-get="/public-adventures2/" hx-target="#public_adventures_page_div">
<input type="hidden" name="selected_lang" value="{{selected_lang}}">
<input type="hidden" name="selected_level" value="{{selected_level}}">
<input type="hidden" name="q" value="{{q}}">
<input type="hidden" name="selected_tag" value="{{selected_tag}}">
<input type="hidden" name="page" value="{{prev_page_token}}">
<button type="submit"
id="prev_button"
class="green-btn px-2 w-full h-full">
{{_('previous_page')}}<br>«</button>
</form>
{% endif %}
</div>
<div class="flex-1">
{% if next_page_token %}
<button
id="next_button"
class="green-btn px-2 w-full h-full"
_="on click set (#page_input).value to '{{next_page_token}}' then call (#filterform).requestSubmit()">
{{_('next_page')}}<br>»</button>
<form hx-get="/public-adventures2/" hx-target="#public_adventures_page_div">
<input type="hidden" name="selected_lang" value="{{selected_lang}}">
<input type="hidden" name="selected_level" value="{{selected_level}}">
<input type="hidden" name="q" value="{{q}}">
<input type="hidden" name="selected_tag" value="{{selected_tag}}">
<input type="hidden" name="page" value="{{next_page_token}}">
<button
id="next_button"
class="green-btn px-2 w-full h-full">
{{_('next_page')}}<br>»</button>
</form>
{% endif %}
</div>
</div>
Expand Down
7 changes: 1 addition & 6 deletions website/public_adventures2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import bs4

import hedy
import hedy_content
import utils
from website.auth import requires_teacher
Expand Down Expand Up @@ -80,10 +79,6 @@ def search(self, user):
page_title=gettext("title_public-adventures"),
)

response = make_response(temp, 200)
# response.headers["HX-Trigger"] = json.dumps({"updateTSCode": js})
return response

def enhance_adventure_for_list(self, adventure):
"""For each adventure in the list, add some extra information."""
if 'levels' not in adventure:
Expand All @@ -98,7 +93,7 @@ def enhance_adventure_for_list(self, adventure):
if bs4.BeautifulSoup(adventure['solution_example'], 'html.parser').text.strip() == '':
adventure['solution_example'] = ''
else:
adventure['solution_example'] = hedy_content.try_render_keywords(adventure['solution_example'], adventure['language'])
adventure['solution_example'] = hedy_content.try_render_keywords(adventure['solution_example'], g.keyword_lang)

return adventure

Expand Down

0 comments on commit 6edac63

Please sign in to comment.