2019-06-15 21:31:31 +00:00
|
|
|
|
|
|
|
{% extends "core/base.jinja" %}
|
|
|
|
|
|
|
|
{% block title %}
|
|
|
|
{% trans %}UV Guide{% endtrans %}
|
|
|
|
{% endblock %}
|
|
|
|
|
2024-07-18 18:23:30 +00:00
|
|
|
{% block additional_js %}
|
|
|
|
<script src="{{ static('core/js/alpinejs.min.js') }}" defer></script>
|
|
|
|
{% endblock %}
|
|
|
|
|
2019-07-25 17:01:53 +00:00
|
|
|
{% block head %}
|
|
|
|
{{ super() }}
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=0.6, maximum-scale=2">
|
|
|
|
{% endblock head %}
|
|
|
|
|
2019-06-15 21:31:31 +00:00
|
|
|
{% block content %}
|
2024-07-18 18:23:30 +00:00
|
|
|
{% if can_create_uv %}
|
|
|
|
<div class="action-bar">
|
|
|
|
<p>
|
|
|
|
<a href="{{ url('pedagogy:uv_create') }}">{% trans %}Create UV{% endtrans %}</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a href="{{ url('pedagogy:moderation') }}">{% trans %}Moderate comments{% endtrans %}</a>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<br/>
|
|
|
|
{% endif %}
|
|
|
|
<div class="pedagogy" x-data="uv_search" x-cloak>
|
|
|
|
<form id="search_form">
|
2019-07-25 17:01:53 +00:00
|
|
|
<div class="search-form-container">
|
|
|
|
<div class="search-bar">
|
2024-07-18 18:23:30 +00:00
|
|
|
<input
|
|
|
|
id="search_input"
|
|
|
|
class="search-bar-input"
|
|
|
|
type="text"
|
|
|
|
name="search"
|
|
|
|
x-model.debounce.500ms="search"
|
|
|
|
/>
|
2019-07-25 17:01:53 +00:00
|
|
|
</div>
|
|
|
|
<div class="radio-department">
|
|
|
|
<div class="radio-guide">
|
2024-07-18 18:23:30 +00:00
|
|
|
{% for (display_name, real_name) in [
|
|
|
|
("EDIM", "EDIM"), ("ENERGIE", "EE"), ("IMSI", "IMSI"),
|
|
|
|
("INFO", "GI"), ("GMC", "MC"), ("HUMA", "HUMA"), ("TC", "TC")
|
|
|
|
] %}
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="department"
|
|
|
|
id="radio{{ real_name }}"
|
|
|
|
value="{{ real_name }}"
|
|
|
|
x-model="department"
|
|
|
|
/>
|
|
|
|
<label for="radio{{ real_name }}">{% trans %}{{ display_name }}{% endtrans %}</label>
|
2019-07-25 17:01:53 +00:00
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="radio-credit-type">
|
|
|
|
<div class="radio-guide">
|
|
|
|
{% for credit_type in ["CS", "TM", "EC", "QC", "OM"] %}
|
2024-07-18 18:23:30 +00:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="credit_type"
|
|
|
|
id="radio{{ credit_type }}"
|
|
|
|
value="{{ credit_type }}"
|
|
|
|
x-model="credit_type"
|
|
|
|
/>
|
|
|
|
<label for="radio{{ credit_type }}">{% trans %}{{ credit_type }}{% endtrans %}</label>
|
2019-07-25 17:01:53 +00:00
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="radio-semester">
|
|
|
|
<div class="radio-guide">
|
2024-07-18 18:23:30 +00:00
|
|
|
<input type="checkbox" name="semester" id="radioAUTUMN" value="AUTUMN" x-model="semester"/>
|
2024-07-22 16:40:32 +00:00
|
|
|
<label for="radioAUTUMN"><i class="fa fa-leaf"></i></label>
|
2024-07-18 18:23:30 +00:00
|
|
|
<input type="checkbox" name="semester" id="radioSPRING" value="SPRING" x-model="semester"/>
|
2024-07-22 16:40:32 +00:00
|
|
|
<label for="radioSPRING"><i class="fa fa-sun-o"></i></label>
|
2019-07-25 17:01:53 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-08 13:25:28 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<table id="dynamic_view">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<td>{% trans %}UV{% endtrans %}</td>
|
|
|
|
<td>{% trans %}Title{% endtrans %}</td>
|
|
|
|
<td>{% trans %}Department{% endtrans %}</td>
|
|
|
|
<td>{% trans %}Credit type{% endtrans %}</td>
|
|
|
|
<td><i class="fa fa-leaf"></i></td>
|
|
|
|
<td><i class="fa fa-sun-o"></i></td>
|
2024-07-18 18:23:30 +00:00
|
|
|
{% if can_create_uv %}
|
|
|
|
<td>{% trans %}Edit{% endtrans %}</td>
|
|
|
|
<td>{% trans %}Delete{% endtrans %}</td>
|
2019-07-06 00:57:20 +00:00
|
|
|
{% endif %}
|
2019-07-08 13:25:28 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody id="dynamic_view_content">
|
2024-07-22 16:40:32 +00:00
|
|
|
<template x-for="uv in uvs.results" :key="uv.id">
|
2024-07-18 18:23:30 +00:00
|
|
|
<tr @click="window.location.href = `/pedagogy/uv/${uv.id}`">
|
|
|
|
<td><a :href="`/pedagogy/uv/${uv.id}`" x-text="uv.code"></a></td>
|
|
|
|
<td x-text="uv.title"></td>
|
|
|
|
<td x-text="uv.department"></td>
|
|
|
|
<td x-text="uv.credit_type"></td>
|
2024-07-22 16:40:32 +00:00
|
|
|
<td><i :class="uv.semester.includes('AUTUMN') && 'fa fa-leaf'"></i></td>
|
|
|
|
<td><i :class="uv.semester.includes('SPRING') && 'fa fa-sun-o'"></i></td>
|
2024-07-18 18:23:30 +00:00
|
|
|
{% if can_create_uv -%}
|
2024-07-22 16:40:32 +00:00
|
|
|
<td><a :href="`/pedagogy/uv/${uv.id}/edit`">{% trans %}Edit{% endtrans %}</a></td>
|
2024-07-18 18:23:30 +00:00
|
|
|
<td><a :href="`/pedagogy/uv/${uv.id}/delete`">{% trans %}Delete{% endtrans %}</a></td>
|
|
|
|
{%- endif -%}
|
|
|
|
</tr>
|
|
|
|
</template>
|
2019-07-08 13:25:28 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
2024-07-22 16:40:32 +00:00
|
|
|
<nav id="pagination" class="hidden" :style="max_page() == 0 && 'display: none;'">
|
|
|
|
<button @click="page--" :disabled="page == 1">{% trans %}Previous{% endtrans %}</button>
|
|
|
|
<template x-for="i in max_page()">
|
|
|
|
<button x-text="i" @click="page = i" :class="i == page && 'active'"></button>
|
|
|
|
</template>
|
|
|
|
<button @click="page++" :disabled="page == max_page()">{% trans %}Next{% endtrans %}</button>
|
|
|
|
</nav>
|
2019-07-08 13:25:28 +00:00
|
|
|
</div>
|
2019-07-05 13:39:11 +00:00
|
|
|
<script>
|
2024-07-18 18:23:30 +00:00
|
|
|
const initialUrlParams = new URLSearchParams(window.location.search);
|
|
|
|
|
|
|
|
function update_query_string(key, value) {
|
|
|
|
const url = new URL(window.location.href);
|
|
|
|
if (!value) {
|
|
|
|
url.searchParams.delete(key)
|
|
|
|
} else if (Array.isArray(value)) {
|
|
|
|
url.searchParams.delete(key)
|
|
|
|
value.forEach((v) => url.searchParams.append(key, v))
|
|
|
|
} else {
|
|
|
|
url.searchParams.set(key, value);
|
|
|
|
}
|
|
|
|
history.pushState(null, document.title, url.toString());
|
2019-07-05 13:56:50 +00:00
|
|
|
}
|
|
|
|
|
2024-07-18 18:23:30 +00:00
|
|
|
{#
|
|
|
|
How does this work :
|
|
|
|
|
|
|
|
The page contains two main elements : the form and the results.
|
|
|
|
The form contains multiple inputs, allowing the user to apply the filter of its choice.
|
|
|
|
Each modification of those filters will modify the GET parameters of the URL,
|
|
|
|
then fetch the corresponding data from the API.
|
|
|
|
This data will then be displayed on the result part of the page.
|
|
|
|
#}
|
2024-07-22 16:40:32 +00:00
|
|
|
const page_default = 1;
|
|
|
|
const page_size_default = 100;
|
2024-07-18 18:23:30 +00:00
|
|
|
document.addEventListener("alpine:init", () => {
|
|
|
|
Alpine.data("uv_search", () => ({
|
|
|
|
uvs: [],
|
2024-07-22 16:40:32 +00:00
|
|
|
page: initialUrlParams.get("page") || page_default,
|
|
|
|
page_size: initialUrlParams.get("page_size") || page_size_default,
|
2024-07-18 18:23:30 +00:00
|
|
|
search: initialUrlParams.get("search") || "",
|
|
|
|
department: initialUrlParams.getAll("department"),
|
|
|
|
credit_type: initialUrlParams.getAll("credit_type"),
|
|
|
|
{# The semester is easier to use on the backend as an enum (spring/autumn/both/none)
|
|
|
|
and easier to use on the frontend as an array ([spring, autumn]).
|
|
|
|
Thus there is some conversion involved when both communicate together #}
|
|
|
|
semester: initialUrlParams.has("semester") ?
|
|
|
|
initialUrlParams.get("semester").split("_AND_") : [],
|
|
|
|
|
|
|
|
async init() {
|
2024-07-22 16:40:32 +00:00
|
|
|
let search_params = ["search", "department", "credit_type", "semester"];
|
|
|
|
let pagination_params = ["semester", "page"];
|
|
|
|
search_params.forEach((param) => {
|
|
|
|
this.$watch(param, async () => {
|
|
|
|
{# Reset pagination on search #}
|
|
|
|
this.page = page_default;
|
|
|
|
this.page_size = page_size_default;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
search_params.concat(pagination_params).forEach((param) => {
|
2024-07-18 18:23:30 +00:00
|
|
|
this.$watch(param, async (value) => {
|
|
|
|
update_query_string(param, value);
|
|
|
|
await this.fetch_data(); {# reload data on form change #}
|
|
|
|
});
|
2024-07-22 16:40:32 +00:00
|
|
|
});
|
2024-07-18 18:23:30 +00:00
|
|
|
await this.fetch_data(); {# load initial data #}
|
|
|
|
},
|
|
|
|
|
|
|
|
async fetch_data() {
|
|
|
|
const url = "{{ url("api:fetch_uvs") }}" + window.location.search;
|
|
|
|
this.uvs = await (await fetch(url)).json();
|
2024-07-22 16:40:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
max_page() {
|
|
|
|
return Math.round(this.uvs.count / this.page_size);
|
2024-07-18 18:23:30 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
})
|
2019-07-05 13:39:11 +00:00
|
|
|
</script>
|
2019-06-15 21:31:31 +00:00
|
|
|
{% endblock content %}
|