diff --git a/src/week.rs b/src/week.rs index 8744ce2..5168b1c 100644 --- a/src/week.rs +++ b/src/week.rs @@ -53,7 +53,7 @@ pub async fn week(week_number: u8, mut db: Connection, cookies: &CookieJar<' } }; - Template::render("index", context! { + Template::render("weeks/index", context! { week_data: week_data, truths: truths, user: user, @@ -70,7 +70,7 @@ pub async fn week(week_number: u8, mut db: Connection, cookies: &CookieJar<' } }; - Template::render("index", context! { + Template::render("weeks/index", context! { week_data: week_data, truths: truths, user: user, diff --git a/static_files/style.css b/static_files/style.css index edc39a7..ddb3d5c 100644 --- a/static_files/style.css +++ b/static_files/style.css @@ -5,7 +5,7 @@ margin-right: 2em; } -.page_body { +.truth_page_body { display: flex; flex-direction: row; justify-content: space-between; diff --git a/templates/base_page.html.tera b/templates/base_page.html.tera new file mode 100644 index 0000000..42f0895 --- /dev/null +++ b/templates/base_page.html.tera @@ -0,0 +1,36 @@ + + +{% set title = "Vérités Fabula Ultima" %} + + + {{ title }} + + + {% block scripts %} + {% endblock %} + + + +{% block top_bar %} +
+

{{ title }}

+ {% if user.logged_in == true %} + + {% else %} + + {% endif %} +
+{% endblock %} + +{% block body %} +{% endblock %} + + + diff --git a/templates/index.html.tera b/templates/index.html.tera deleted file mode 100644 index 2e7a831..0000000 --- a/templates/index.html.tera +++ /dev/null @@ -1,142 +0,0 @@ - - -{% set title = "Vérités Fabula Ultima" %} - - - {{ title }} - - - {% if user.logged_in == true and not user.is_admin %} - - {% endif %} - - - - -{#{% import "week_change_arrows" as week_macro %}#} -{# For some reason the import does not work ? Figure it out at some point... #} -{%- macro display(display_character, to, enabled) -%} - {%- set class = "week_change" -%} - {%- if enabled == true %} - {% set target = ("href=/" ~ to) %} - {%- else -%} - {% set class = class ~ " week_change_hidden" -%} - {% set target = "" %} - {%- endif -%} - {%- if enabled == true -%}{{- display_character -}}{%- endif -%} -{%- endmacro display -%} - - -{% set back_arrow_enabled = week_data.number > 1 %} -{% set next_arrow_enabled = (week_data.is_last_week != true or user.is_admin == true) %} -{% set next_arrow_href = (week_data.number + 1) %} -{% if user.is_admin == true %} - {% set next_arrow_href = next_arrow_href ~ "/create" %} - {% set next_arrow_chara = '⥅' %} -{% else %} - {% set next_arrow_chara = '⟹' %} -{% endif %} - -{# Remove the form if all votes are locked, to reduce confusion. #} -{% set lock_truth_form = user.votes | length + 1 == truths | length and week_data.is_last_week != true %} - - -
-

{{ title }}

- {% if user.logged_in == true %} - - {% else %} - - {% endif %} -
- -

{{- self::display(display_character='⟸', to=(week_data.number - 1), enabled=back_arrow_enabled) }} - Semaine {{ week_data.number }} - {{- self::display(display_character=next_arrow_chara, to=next_arrow_href, enabled=next_arrow_enabled) -}}

-
-
- {% if user.is_admin == true and week_data.is_last_week != true %} -
- -
- {% endif %} -
- {{ week_data.rendered_text | safe }} - {%- if user.is_admin == true -%} -
-
- - -
- {% endif %} -
- {% if user.logged_in == true and user.is_admin == false and not lock_truth_form %} -
- {% endif %} - - {# Truths start at 1 but the array starts at 0 #} - {% set index_delta = 1 %} - {% for truth in truths %} - {# - The truths are in an ordered array, but one of them might be the user's. - In this case, we need to stop the array index from incrementing if the current - truth is the user's, as they cannot have voted for themselves, leading to one - less votes than there are truths. - #} - {%- if truth.author_id == user.id -%} - {%- set_global index_delta = 2 -%} - {% endif %} - {% set truth_index = truth.number - index_delta %} - - {% if user.is_admin == true %} - {% include "weeks/editable_truth" %} - {% else %} - {% include "weeks/truth" %} - {% endif %} - {% endfor %} - - {% if user.logged_in == true and user.is_admin == false and not lock_truth_form %} -
- -
- {% endif %} - - {# If admin, show an additional box for creating a new Truth. #} - {% if user.is_admin == true %} -
-

Nouvelle vérité

-
- {% include "weeks/truth_editor" %} -
-
- {% endif %} -
- -
-
- -
-
-
- - - diff --git a/templates/weeks/index.html.tera b/templates/weeks/index.html.tera new file mode 100644 index 0000000..ddf8c70 --- /dev/null +++ b/templates/weeks/index.html.tera @@ -0,0 +1,120 @@ +{% extends "base_page" %} + +{% block scripts %} + {% if user.logged_in == true and not user.is_admin %} + + {% endif %} + + +{% endblock %} + +{#{% import "week_change_arrows" as week_macro %}#} +{# For some reason the import does not work ? Figure it out at some point... #} +{%- macro display(display_character, to, enabled) -%} + {%- set class = "week_change" -%} + {%- if enabled == true %} + {% set target = ("href=/" ~ to) %} + {%- else -%} + {% set class = class ~ " week_change_hidden" -%} + {% set target = "" %} + {%- endif -%} + {%- if enabled == true -%}{{- display_character -}}{%- endif -%} +{%- endmacro display -%} + +{# Remove the form if all votes are locked, to reduce confusion. #} +{% set lock_truth_form = user.votes | length + 1 == truths | length and week_data.is_last_week != true %} + +{% block body %} + + {# Apparently needs to be inside the block ? #} + {% set back_arrow_enabled = week_data.number > 1 %} + {% set next_arrow_enabled = (week_data.is_last_week != true or user.is_admin == true) %} + {% set next_arrow_href = (week_data.number + 1) %} + {% if user.is_admin == true %} + {% set next_arrow_href = next_arrow_href ~ "/create" %} + {% set next_arrow_chara = '⥅' %} + {% else %} + {% set next_arrow_chara = '⟹' %} + {% endif %} + +

{{- self::display(display_character='⟸', to=(week_data.number - 1), enabled=back_arrow_enabled) }} + Semaine {{ week_data.number }} + {{- self::display(display_character=next_arrow_chara, to=next_arrow_href, enabled=next_arrow_enabled) -}}

+
+
+ {% if user.is_admin == true and week_data.is_last_week != true %} +
+ +
+ {% endif %} +
+ {{ week_data.rendered_text | safe }} + {%- if user.is_admin == true -%} +
+
+ + +
+ {% endif %} +
+ {% if user.logged_in == true and user.is_admin == false and not lock_truth_form %} +
+ {% endif %} + + {# Truths start at 1 but the array starts at 0 #} + {% set index_delta = 1 %} + {% for truth in truths %} + {# + The truths are in an ordered array, but one of them might be the user's. + In this case, we need to stop the array index from incrementing if the current + truth is the user's, as they cannot have voted for themselves, leading to one + less votes than there are truths. + #} + {%- if truth.author_id == user.id -%} + {%- set_global index_delta = 2 -%} + {% endif %} + {% set truth_index = truth.number - index_delta %} + + {% if user.is_admin == true %} + {% include "weeks/editable_truth" %} + {% else %} + {% include "weeks/truth" %} + {% endif %} + {% endfor %} + + {% if user.logged_in == true and user.is_admin == false and not lock_truth_form %} +
+ +
+ {% endif %} + + {# If admin, show an additional box for creating a new Truth. #} + {% if user.is_admin == true %} +
+

Nouvelle vérité

+
+ {% include "weeks/truth_editor" %} +
+
+ {% endif %} +
+ +
+
+ +
+
+
+{% endblock %}