Skip to content

Commit cb09c0b

Browse files
committed
Prototype: use partials
1 parent 2832e76 commit cb09c0b

10 files changed

Lines changed: 96 additions & 205 deletions

File tree

core/static/bundled/base-bundle-index.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
// Must be loaded before Apline
10-
import htmx from "htmx.org";
10+
import htmx, { HtmxResponse } from "htmx.org";
1111
import "htmx.org/dist/ext/hx-alpine-compat.js";
1212
import "htmx.org/dist/ext/hx-prompt.js";
1313
import "htmx.org/dist/ext/hx-download.js";
@@ -18,7 +18,6 @@ import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill";
1818
import { limitedChoices } from "#core:alpine/limited-choices";
1919
import { expireOldStorage } from "#core:core/localstorage";
2020
import { default as navbar } from "#core:core/navbar";
21-
import { getErrorCallbacksExt } from "#core:htmx/error-callback";
2221
import {
2322
type NotificationPlugin,
2423
notificationsPlugin as notifications,
@@ -49,22 +48,13 @@ polyfillCountryFlagEmojis();
4948
/**
5049
* HTMX
5150
*/
52-
document.body.addEventListener(
53-
"htmx:before:request" as keyof HTMLElementEventMap,
54-
(event) => {
55-
(event as CustomEvent).detail.ctx.target.ariaBusy = true;
56-
},
57-
);
58-
59-
document.body.addEventListener(
60-
"htmx:before:swap" as keyof HTMLElementEventMap,
61-
(event) => {
62-
(event as CustomEvent).detail.ctx.target.ariaBusy = null;
63-
},
64-
);
51+
document.body.addEventListener("htmx:before:request", (event) => {
52+
event.target.ariaBusy = true;
53+
});
6554

66-
const errorCallbackExt = getErrorCallbacksExt();
67-
htmx.registerExtension(errorCallbackExt.name, errorCallbackExt.extension);
55+
document.body.addEventListener("htmx:before:swap", (event) => {
56+
event.target.ariaBusy = null;
57+
});
6858

6959
Object.assign(window, { htmx });
7060

core/static/bundled/htmx/error-callback.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

pedagogy/templates/pedagogy/fragments/ue_comments.jinja

Lines changed: 0 additions & 17 deletions
This file was deleted.

pedagogy/templates/pedagogy/fragments/ue_detail.jinja

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% if comments %}
2+
<h2>{% trans %}Comments{% endtrans %}</h2>
3+
<br>
4+
{% endif %}
5+
6+
<section>
7+
{% for comment in comments %}
8+
{% include "pedagogy/fragments/ue_comment.jinja" %}
9+
{% endfor %}
10+
</section>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% if object.has_user_already_commented(user) %}
2+
<div class="leave-comment-not-allowed">
3+
<p>{% trans %}You already posted a comment on this UE. If you want to comment again, please modify or delete your previous comment.{% endtrans %}</p>
4+
</div>
5+
<br>
6+
{% endif %}
7+
8+
{% if not object.has_user_already_commented(user) and user.has_perm("pedagogy.add_uecomment") %}
9+
{{ add_comment_form }}
10+
{% endif %}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div class="ue-details-container">
2+
<div class="grade">
3+
<p>{% trans %}Global grade{% endtrans %}</p>
4+
<p>{% trans %}Utility{% endtrans %}</p>
5+
<p>{% trans %}Interest{% endtrans %}</p>
6+
<p>{% trans %}Teaching{% endtrans %}</p>
7+
<p>{% trans %}Work load{% endtrans %}</p>
8+
</div>
9+
<div class="grade-stars">
10+
<p>{{ display_star(object.grade_global_average) }}</p>
11+
<p>{{ display_star(object.grade_utility_average) }}</p>
12+
<p>{{ display_star(object.grade_interest_average) }}</p>
13+
<p>{{ display_star(object.grade_teaching_average) }}</p>
14+
<p>{{ display_star(object.grade_work_load_average) }}</p>
15+
</div>
16+
<div class="ue-infos">
17+
<p><b>{% trans %}Objectives{% endtrans %}</b></p>
18+
<p>{{ object.objectives|markdown }}</p>
19+
<p><b>{% trans %}Program{% endtrans %}</b></p>
20+
<p>{{ object.program|markdown }}</p>
21+
<p><b>{% trans %}Earned skills{% endtrans %}</b></p>
22+
<p>{{ object.skills|markdown }}</p>
23+
<p><b>{% trans %}Key concepts{% endtrans %}</b></p>
24+
<p>{{ object.key_concepts|markdown }}</p>
25+
<p><b>{% trans %}UE manager: {% endtrans %}</b>{{ object.manager }}</p>
26+
</div>
27+
</div>

pedagogy/templates/pedagogy/ue_detail.jinja

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
{% from "pedagogy/macros.jinja" import display_star %}
22

33
{% if is_fragment %}
4-
{% include "pedagogy/fragments/ue_detail.jinja" %}
4+
5+
<hx-partial id="ue-grade">
6+
{% include "pedagogy/fragments/ue_details/grade.jinja" %}
7+
</hx-partial>
8+
9+
<hx-partial id="comment-form">
10+
{% include "pedagogy/fragments/ue_details/form.jinja" %}
11+
</hx-partial>
12+
13+
<hx-partial id="comments" hx-swap="innerMorph">
14+
{% include "pedagogy/fragments/ue_details/comments.jinja" %}
15+
</hx-partial>
16+
517
{% else %}
618
{% extends "core/base.jinja" %}
719

@@ -59,12 +71,23 @@
5971

6072
<br>
6173

62-
{% include "pedagogy/fragments/ue_detail.jinja" %}
74+
<div id="ue-grade">
75+
{% include "pedagogy/fragments/ue_details/grade.jinja" %}
76+
</div>
6377

64-
{{ comments }}
78+
<br>
79+
80+
<div id="comment-form">
81+
{% include "pedagogy/fragments/ue_details/form.jinja" %}
82+
</div>
83+
84+
<div id="comments">
85+
{% for comment in comments %}
86+
{% include "pedagogy/fragments/ue_comment.jinja" %}
87+
{% endfor %}
88+
</div>
6589

6690
</div>
6791
</div>
68-
6992
{% endblock %}
7093
{% endif %}

pedagogy/urls.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
UECommentUpdateView,
3232
UECreateView,
3333
UEDeleteView,
34-
UEDetailCommentsView,
3534
UEDetailView,
3635
UEGuideView,
3736
UEModerationFormView,
@@ -42,11 +41,6 @@
4241
# Urls displaying the actual application for visitors
4342
path("", UEGuideView.as_view(), name="guide"),
4443
path("ue/<int:ue_id>/", UEDetailView.as_view(), name="ue_detail"),
45-
path(
46-
"ue/<int:ue_id>/comments",
47-
UEDetailCommentsView.as_view(),
48-
name="ue_comments",
49-
),
5044
path(
5145
"ue/<int:ue_id>/comment",
5246
UECommentCreateView.as_view(),

0 commit comments

Comments
 (0)