From 6cbfd97031e86c21105fecbb5c37a376dc526d81 Mon Sep 17 00:00:00 2001 From: iziram Date: Wed, 13 Sep 2023 08:24:08 +0200 Subject: [PATCH 1/3] Assiduites : fix #686 --- app/scodoc/sco_saisie_notes.py | 40 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/app/scodoc/sco_saisie_notes.py b/app/scodoc/sco_saisie_notes.py index 058c53ef..489165bd 100644 --- a/app/scodoc/sco_saisie_notes.py +++ b/app/scodoc/sco_saisie_notes.py @@ -46,6 +46,7 @@ from app.models import ( Module, ModuleImpl, ScolarNews, + Assiduite, ) from app.models.etudiants import Identite @@ -75,6 +76,8 @@ import app.scodoc.sco_utils as scu from app.scodoc.sco_utils import json_error from app.scodoc.sco_utils import ModuleType +from flask_sqlalchemy.query import Query + def convert_note_from_string( note: str, @@ -1102,30 +1105,21 @@ def _get_sorted_etuds(evaluation: Evaluation, etudids: list, formsemestre_id: in # Groupes auxquels appartient cet étudiant: e["groups"] = sco_groups.get_etud_groups(etudid, formsemestre_id) - # Information sur absence (tenant compte de la demi-journée) - jour_iso = ( - evaluation.date_debut.date().isoformat() if evaluation.date_debut else "" - ) - warn_abs_lst = [] - # XXX TODO-ASSIDUITE (issue #686) - if evaluation.is_matin(): - nbabs = 0 # TODO-ASSIDUITE sco_abs.count_abs(etudid, jour_iso, jour_iso, matin=True) - nbabsjust = 0 # TODO-ASSIDUITE sco_abs.count_abs_just(etudid, jour_iso, jour_iso, matin=True) - if nbabs: - if nbabsjust: - warn_abs_lst.append("absent justifié le matin !") - else: - warn_abs_lst.append("absent le matin !") - if evaluation.is_apresmidi(): - nbabs = 0 # TODO-ASSIDUITE sco_abs.count_abs(etudid, jour_iso, jour_iso, matin=0) - nbabsjust = 0 # TODO-ASSIDUITE sco_abs.count_abs_just(etudid, jour_iso, jour_iso, matin=0) - if nbabs: - if nbabsjust: - warn_abs_lst.append("absent justifié l'après-midi !") - else: - warn_abs_lst.append("absent l'après-midi !") + # Information sur absence + warn_abs_lst: str = "" + if evaluation.date_debut is not None and evaluation.date_fin is not None: + assiduites_etud: Query = etud.assiduites.filter( + Assiduite.etat == scu.EtatAssiduite.ABSENT, + Assiduite.date_debut <= evaluation.date_fin, + Assiduite.date_fin >= evaluation.date_debut, + ) + premiere_assi: Assiduite = assiduites_etud.first() + if premiere_assi is not None: + warn_abs_lst: str = ( + f"absent {'justifié' if premiere_assi.est_just else ''}" + ) - e["absinfo"] = '' + " ".join(warn_abs_lst) + " " + e["absinfo"] = '' + warn_abs_lst + " " # Note actuelle de l'étudiant: if etudid in notes_db: From a7058fb86b37f68c30319b95f53b2371d32739cd Mon Sep 17 00:00:00 2001 From: iziram Date: Wed, 13 Sep 2023 08:59:54 +0200 Subject: [PATCH 2/3] Assiduites : fix #728 --- app/scodoc/sco_groups_view.py | 2 +- app/static/js/assiduites.js | 2 +- app/views/assiduites.py | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/scodoc/sco_groups_view.py b/app/scodoc/sco_groups_view.py index 728ccb36..0eefe058 100644 --- a/app/scodoc/sco_groups_view.py +++ b/app/scodoc/sco_groups_view.py @@ -900,7 +900,7 @@ def form_choix_jour_saisie_hebdo(groups_infos, moduleimpl_id=None): formsemestre_id=groups_infos.formsemestre_id, moduleimpl_id="" if moduleimpl_id is None else moduleimpl_id ) - }';">Saisie du jour + }';">Saisie du jour ({datetime.date.today().strftime('%d/%m/%Y')}) """ diff --git a/app/static/js/assiduites.js b/app/static/js/assiduites.js index 019cb894..dbfa3736 100644 --- a/app/static/js/assiduites.js +++ b/app/static/js/assiduites.js @@ -577,7 +577,7 @@ function updateDate() { return true; } else { const att = document.createTextNode( - "Le jour sélectionné n'est pas un jour travaillé." + `Le jour sélectionné (${formatDate(date)}) n'est pas un jour travaillé.` ); openAlertModal("Erreur", att, "", "crimson"); dateInput.value = dateInput.getAttribute("value"); diff --git a/app/views/assiduites.py b/app/views/assiduites.py index a2e5a3b1..db3cb900 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -565,10 +565,14 @@ def signal_assiduites_group(): real_date = scu.is_iso_formated(date, True).date() - if real_date < formsemestre.date_debut: - date = formsemestre.date_debut.isoformat() - elif real_date > formsemestre.date_fin: - date = formsemestre.date_fin.isoformat() + if real_date < formsemestre.date_debut or real_date > formsemestre.date_fin: + real_str = real_date.strftime("%d/%m/%Y") + form_deb = formsemestre.date_debut.strftime("%d/%m/%Y") + form_fin = formsemestre.date_fin.strftime("%d/%m/%Y") + raise ScoValueError( + f"Impossible de saisir les assiduités pour le {real_str}" + + f" : Jour en dehors du semestre ( {form_deb} → {form_fin}) " + ) # --- Restriction en fonction du moduleimpl_id --- if moduleimpl_id: From 18908594828fc060746b659eb0becb1e671b2f02 Mon Sep 17 00:00:00 2001 From: iziram Date: Wed, 13 Sep 2023 15:19:21 +0200 Subject: [PATCH 3/3] Assiduites : fix Justificatifs en attentes #724 --- app/api/justificatifs.py | 67 +++- app/scodoc/sco_formsemestre_status.py | 5 + app/scodoc/sco_utils.py | 4 +- app/templates/assiduites/pages/bilan_dept.j2 | 13 +- .../assiduites/pages/liste_assiduites.j2 | 4 +- .../assiduites/widgets/tableau_assi.j2 | 181 +++++++++ .../assiduites/widgets/tableau_base.j2 | 343 +----------------- .../assiduites/widgets/tableau_justi.j2 | 192 +++++++++- app/templates/sidebar.j2 | 5 +- app/views/assiduites.py | 18 +- 10 files changed, 470 insertions(+), 362 deletions(-) diff --git a/app/api/justificatifs.py b/app/api/justificatifs.py index e68b397a..f753fc0e 100644 --- a/app/api/justificatifs.py +++ b/app/api/justificatifs.py @@ -19,7 +19,13 @@ from app.api import api_bp as bp from app.api import api_web_bp from app.api import get_model_api_object, tools from app.decorators import permission_required, scodoc -from app.models import Identite, Justificatif, Departement, FormSemestre +from app.models import ( + Identite, + Justificatif, + Departement, + FormSemestre, + FormSemestreInscription, +) from app.models.assiduites import ( compute_assiduites_justified, ) @@ -27,6 +33,7 @@ from app.scodoc.sco_archives_justificatifs import JustificatifArchiver from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_permissions import Permission from app.scodoc.sco_utils import json_error +from app.scodoc.sco_groups import get_group_members # Partie Modèle @@ -145,14 +152,40 @@ def justificatifs_dept(dept_id: int = None, with_query: bool = False): if with_query: justificatifs_query = _filter_manager(request, justificatifs_query) + data_set: list[dict] = [] - for just in justificatifs_query.all(): - data = just.to_dict(format_api=True) - data_set.append(data) + for just in justificatifs_query: + data_set.append(_set_sems_and_groupe(just)) return data_set +def _set_sems_and_groupe(justi: Justificatif) -> dict: + from app.scodoc.sco_groups import get_etud_groups + + data = justi.to_dict(format_api=True) + + formsemestre: FormSemestre = ( + FormSemestre.query.join( + FormSemestreInscription, + FormSemestre.id == FormSemestreInscription.formsemestre_id, + ) + .filter( + justi.date_debut <= FormSemestre.date_fin, + justi.date_fin >= FormSemestre.date_debut, + FormSemestreInscription.etudid == justi.etudid, + ) + .first() + ) + if formsemestre: + data["formsemestre"] = { + "id": formsemestre.id, + "title": formsemestre.session_id(), + } + + return data + + @bp.route( "/justificatifs/formsemestre/", defaults={"with_query": False} ) @@ -732,13 +765,16 @@ def _filter_manager(requested, justificatifs_query): # cas 5 : formsemestre_id formsemestre_id = requested.args.get("formsemestre_id") - if formsemestre_id is not None: + if formsemestre_id not in [None, "", -1]: formsemestre: FormSemestre = None - formsemestre_id = int(formsemestre_id) - formsemestre = FormSemestre.query.filter_by(id=formsemestre_id).first() - justificatifs_query = scass.filter_by_formsemestre( - justificatifs_query, Justificatif, formsemestre - ) + try: + formsemestre_id = int(formsemestre_id) + formsemestre = FormSemestre.query.filter_by(id=formsemestre_id).first() + justificatifs_query = scass.filter_by_formsemestre( + justificatifs_query, Justificatif, formsemestre + ) + except ValueError: + formsemestre = None order = requested.args.get("order", None) if order is not None: @@ -755,4 +791,15 @@ def _filter_manager(requested, justificatifs_query): Justificatif.date_fin <= scu.date_fin_anne_scolaire(annee), ) + group_id = requested.args.get("group_id", None) + if group_id is not None: + try: + group_id = int(group_id) + etudids: list[int] = [etu["etudid"] for etu in get_group_members(group_id)] + justificatifs_query = justificatifs_query.filter( + Justificatif.etudid.in_(etudids) + ) + except ValueError: + group_id = None + return justificatifs_query diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 7e67e4af..c21e8774 100755 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -852,6 +852,11 @@ def _make_listes_sem(formsemestre: FormSemestre, with_absences=True): }?group_ids=%(group_id)s&formsemestre_id={ formsemestre.formsemestre_id }"> + """ else: diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 7cbc3e0d..f92ab38e 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -670,8 +670,8 @@ def AbsencesURL(): def AssiduitesURL(): """URL of Assiduités""" - return url_for("assiduites.index_html", scodoc_dept=g.scodoc_dept)[ - : -len("/index_html") + return url_for("assiduites.bilan_dept", scodoc_dept=g.scodoc_dept)[ + : -len("/BilanDept") ] diff --git a/app/templates/assiduites/pages/bilan_dept.j2 b/app/templates/assiduites/pages/bilan_dept.j2 index 2e8ca5be..3301c85f 100644 --- a/app/templates/assiduites/pages/bilan_dept.j2 +++ b/app/templates/assiduites/pages/bilan_dept.j2 @@ -6,6 +6,7 @@

Justificatifs en attente (ou modifiés)

+ {% include "assiduites/widgets/tableau_justi.j2" %}
@@ -34,14 +35,17 @@ generate(defAnnee) } + let formsemestre_id = "{{formsemestre_id}}" + let group_id = "{{group_id}}" + function getDeptJustificatifsFromPeriod(action) { - const path = getUrl() + `/api/justificatifs/dept/${dept_id}/query?date_debut=${bornes.deb}&date_fin=${bornes.fin}&etat=attente,modifie` + const formsemestre = formsemestre_id ? `&formsemestre_id=${formsemestre_id}` : "" + const group = group_id ? `&group_id=${group_id}` : "" + const path = getUrl() + `/api/justificatifs/dept/${dept_id}/query?date_debut=${bornes.deb}&date_fin=${bornes.fin}&etat=attente,modifie${formsemestre}${group}` async_get( path, (data, status) => { - console.log(data); justificatifCallBack(data); - }, (data, status) => { console.error(data, status) @@ -88,6 +92,7 @@ filterJustificatifs = { "columns": [ + "formsemestre", "etudid", "entry_date", "date_debut", @@ -100,7 +105,7 @@ "etat": [ "attente", "modifie" - ] + ], } } const select = document.querySelector('#annee'); diff --git a/app/templates/assiduites/pages/liste_assiduites.j2 b/app/templates/assiduites/pages/liste_assiduites.j2 index eb1f9ade..aefc644b 100644 --- a/app/templates/assiduites/pages/liste_assiduites.j2 +++ b/app/templates/assiduites/pages/liste_assiduites.j2 @@ -4,10 +4,10 @@

Liste de l'assiduité et des justificatifs de {{sco.etud.nomprenom}}

{% include "assiduites/widgets/tableau_base.j2" %}

Assiduités :

- + {% include "assiduites/widgets/tableau_assi.j2" %}

Justificatifs :

- + {% include "assiduites/widgets/tableau_justi.j2" %}
  • Detail
  • diff --git a/app/templates/assiduites/widgets/tableau_assi.j2 b/app/templates/assiduites/widgets/tableau_assi.j2 index fd1ee7df..b6f5349b 100644 --- a/app/templates/assiduites/widgets/tableau_assi.j2 +++ b/app/templates/assiduites/widgets/tableau_assi.j2 @@ -261,4 +261,185 @@ } ); } + + function filterAssi() { + let html = ` +
    +

    Affichage des colonnes:

    +
    + + + + + + +
    +
    +

    Filtrage des colonnes:

    + + Date de saisie + + + + + Date de début + + + + + Date de fin + + + + + Etat + + + + + + Module + + + + Est Justifiée + + +
    + `; + const span = document.createElement('span'); + span.innerHTML = html + html = span.firstElementChild + + const filterHead = html.querySelector('.filter-head'); + filterHead.innerHTML = "" + let cols = ["entry_date", "date_debut", "date_fin", "etat", "moduleimpl_id", "est_just"]; + + cols.forEach((k) => { + const label = document.createElement('label') + label.classList.add('f-label') + const s = document.createElement('span'); + s.textContent = columnTranslator(k); + + + const input = document.createElement('input'); + input.classList.add('chk') + input.type = "checkbox" + input.name = k + input.id = k; + input.checked = filterAssiduites.columns.includes(k) + + label.appendChild(s) + label.appendChild(input) + filterHead.appendChild(label) + }) + + const sl = html.querySelector('.filter-line #moduleimpl_id'); + let opts = [] + Object.keys(moduleimpls).forEach((k) => { + const opt = document.createElement('option'); + opt.value = k == null ? "null" : k; + opt.textContent = moduleimpls[k]; + opts.push(opt); + }) + + opts = opts.sort((a, b) => { + return a.value < b.value + }) + + sl.append(...opts); + + // Mise à jour des filtres + + Object.keys(filterAssiduites.filters).forEach((key) => { + const l = html.querySelector(`.filter-title[for="${key}"]`).parentElement; + if (key.indexOf('date') != -1) { + l.querySelector(`#${key}_pref`).value = filterAssiduites.filters[key].pref; + l.querySelector(`#${key}_time`).value = filterAssiduites.filters[key].time.format("YYYY-MM-DDTHH:mm"); + + } else if (key.indexOf('etat') != -1) { + l.querySelectorAll('input').forEach((e) => { + e.checked = filterAssiduites.filters[key].includes(e.value) + }) + } else if (key.indexOf("module") != -1) { + l.querySelector('#moduleimpl_id').value = filterAssiduites.filters[key]; + } else if (key.indexOf("est_just") != -1) { + l.querySelector('#est_just').value = filterAssiduites.filters[key]; + } + }) + + openPromptModal("Filtrage des assiduités", html, () => { + + const columns = [...document.querySelectorAll('.chk')] + .map((el) => { if (el.checked) return el.id }) + .filter((el) => el) + + filterAssiduites.columns = columns + filterAssiduites.filters = {} + //reste des filtres + + const lines = [...document.querySelectorAll('.filter-line')]; + + lines.forEach((l) => { + const key = l.querySelector('.filter-title').getAttribute('for'); + + if (key.indexOf('date') != -1) { + const pref = l.querySelector(`#${key}_pref`).value; + const time = l.querySelector(`#${key}_time`).value; + if (l.querySelector(`#${key}_time`).value != "") { + filterAssiduites.filters[key] = { + pref: pref, + time: new moment.tz(time, TIMEZONE) + } + } + } else if (key.indexOf('etat') != -1) { + filterAssiduites.filters[key] = [...l.querySelectorAll("input:checked")].map((e) => e.value); + } else if (key.indexOf("module") != -1) { + filterAssiduites.filters[key] = l.querySelector('#moduleimpl_id').value; + } else if (key.indexOf("est_just") != -1) { + filterAssiduites.filters[key] = l.querySelector('#est_just').value; + } + }) + + + getAllAssiduitesFromEtud(etudid, assiduiteCallBack) + + }, () => { }, "#7059FF"); + } \ No newline at end of file diff --git a/app/templates/assiduites/widgets/tableau_base.j2 b/app/templates/assiduites/widgets/tableau_base.j2 index 2b468e6a..e337ebed 100644 --- a/app/templates/assiduites/widgets/tableau_base.j2 +++ b/app/templates/assiduites/widgets/tableau_base.j2 @@ -102,6 +102,10 @@ return f.obj_id.includes(obj_id) } + if (k == "formsemestre") { + return f.formsemestre === "" || (el.hasOwnProperty("formsemestre") && el.formsemestre.title.replaceAll('-', ' ').indexOf(f.formsemestre) != -1); + } + return true; }) @@ -286,343 +290,6 @@ } - function filter(assi = true) { - if (assi) { - let html = ` -
    -

    Affichage des colonnes:

    -
    - - - - - - -
    -
    -

    Filtrage des colonnes:

    - - Date de saisie - - - - - Date de début - - - - - Date de fin - - - - - Etat - - - - - - Module - - - - Est Justifiée - - -
    - `; - const span = document.createElement('span'); - span.innerHTML = html - html = span.firstElementChild - - const filterHead = html.querySelector('.filter-head'); - filterHead.innerHTML = "" - let cols = ["entry_date", "date_debut", "date_fin", "etat", "moduleimpl_id", "est_just"]; - - cols.forEach((k) => { - const label = document.createElement('label') - label.classList.add('f-label') - const s = document.createElement('span'); - s.textContent = columnTranslator(k); - - - const input = document.createElement('input'); - input.classList.add('chk') - input.type = "checkbox" - input.name = k - input.id = k; - input.checked = filterAssiduites.columns.includes(k) - - label.appendChild(s) - label.appendChild(input) - filterHead.appendChild(label) - }) - - const sl = html.querySelector('.filter-line #moduleimpl_id'); - let opts = [] - Object.keys(moduleimpls).forEach((k) => { - const opt = document.createElement('option'); - opt.value = k == null ? "null" : k; - opt.textContent = moduleimpls[k]; - opts.push(opt); - }) - - opts = opts.sort((a, b) => { - return a.value < b.value - }) - - sl.append(...opts); - - // Mise à jour des filtres - - Object.keys(filterAssiduites.filters).forEach((key) => { - const l = html.querySelector(`.filter-title[for="${key}"]`).parentElement; - if (key.indexOf('date') != -1) { - l.querySelector(`#${key}_pref`).value = filterAssiduites.filters[key].pref; - l.querySelector(`#${key}_time`).value = filterAssiduites.filters[key].time.format("YYYY-MM-DDTHH:mm"); - - } else if (key.indexOf('etat') != -1) { - l.querySelectorAll('input').forEach((e) => { - e.checked = filterAssiduites.filters[key].includes(e.value) - }) - } else if (key.indexOf("module") != -1) { - l.querySelector('#moduleimpl_id').value = filterAssiduites.filters[key]; - } else if (key.indexOf("est_just") != -1) { - l.querySelector('#est_just').value = filterAssiduites.filters[key]; - } - }) - - openPromptModal("Filtrage des assiduités", html, () => { - - const columns = [...document.querySelectorAll('.chk')] - .map((el) => { if (el.checked) return el.id }) - .filter((el) => el) - - filterAssiduites.columns = columns - filterAssiduites.filters = {} - //reste des filtres - - const lines = [...document.querySelectorAll('.filter-line')]; - - lines.forEach((l) => { - const key = l.querySelector('.filter-title').getAttribute('for'); - - if (key.indexOf('date') != -1) { - const pref = l.querySelector(`#${key}_pref`).value; - const time = l.querySelector(`#${key}_time`).value; - if (l.querySelector(`#${key}_time`).value != "") { - filterAssiduites.filters[key] = { - pref: pref, - time: new moment.tz(time, TIMEZONE) - } - } - } else if (key.indexOf('etat') != -1) { - filterAssiduites.filters[key] = [...l.querySelectorAll("input:checked")].map((e) => e.value); - } else if (key.indexOf("module") != -1) { - filterAssiduites.filters[key] = l.querySelector('#moduleimpl_id').value; - } else if (key.indexOf("est_just") != -1) { - filterAssiduites.filters[key] = l.querySelector('#est_just').value; - } - }) - - - getAllAssiduitesFromEtud(etudid, assiduiteCallBack) - - }, () => { }, "#7059FF"); - } else { - let html = ` -
    -

    Affichage des colonnes:

    -
    - - - - - - -
    -
    -

    Filtrage des colonnes:

    - - Date de saisie - - - - - Date de début - - - - - Date de fin - - - - - Etat - - - - - -
    - `; - const span = document.createElement('span'); - span.innerHTML = html - html = span.firstElementChild - - const filterHead = html.querySelector('.filter-head'); - filterHead.innerHTML = "" - let cols = ["entry_date", "date_debut", "date_fin", "etat", "raison", "fichier"]; - - cols.forEach((k) => { - const label = document.createElement('label') - label.classList.add('f-label') - const s = document.createElement('span'); - s.textContent = columnTranslator(k); - - - const input = document.createElement('input'); - input.classList.add('chk') - input.type = "checkbox" - input.name = k - input.id = k; - input.checked = filterJustificatifs.columns.includes(k) - - label.appendChild(s) - label.appendChild(input) - filterHead.appendChild(label) - }) - - // Mise à jour des filtres - - Object.keys(filterJustificatifs.filters).forEach((key) => { - const l = html.querySelector(`.filter-title[for="${key}"]`).parentElement; - if (key.indexOf('date') != -1) { - l.querySelector(`#${key}_pref`).value = filterJustificatifs.filters[key].pref; - l.querySelector(`#${key}_time`).value = filterJustificatifs.filters[key].time.format("YYYY-MM-DDTHH:mm"); - - } else if (key.indexOf('etat') != -1) { - l.querySelectorAll('input').forEach((e) => { - e.checked = filterJustificatifs.filters[key].includes(e.value) - }) - } - }) - - openPromptModal("Filtrage des Justificatifs", html, () => { - - const columns = [...document.querySelectorAll('.chk')] - .map((el) => { if (el.checked) return el.id }) - .filter((el) => el) - - filterJustificatifs.columns = columns - filterJustificatifs.filters = {} - //reste des filtres - - const lines = [...document.querySelectorAll('.filter-line')]; - - lines.forEach((l) => { - const key = l.querySelector('.filter-title').getAttribute('for'); - - if (key.indexOf('date') != -1) { - const pref = l.querySelector(`#${key}_pref`).value; - const time = l.querySelector(`#${key}_time`).value; - if (l.querySelector(`#${key}_time`).value != "") { - filterJustificatifs.filters[key] = { - pref: pref, - time: new moment.tz(time, TIMEZONE) - } - } - } else if (key.indexOf('etat') != -1) { - filterJustificatifs.filters[key] = [...l.querySelectorAll("input:checked")].map((e) => e.value); - } - }) - - - getAllJustificatifsFromEtud(etudid, justificatifCallBack) - - }, () => { }, "#7059FF"); - } - } function columnTranslator(colName) { switch (colName) { @@ -644,6 +311,8 @@ return "Fichier"; case "etudid": return "Etudiant"; + case "formsemestre": + return "Semestre"; } } diff --git a/app/templates/assiduites/widgets/tableau_justi.j2 b/app/templates/assiduites/widgets/tableau_justi.j2 index 4b3a5022..636f9ede 100644 --- a/app/templates/assiduites/widgets/tableau_justi.j2 +++ b/app/templates/assiduites/widgets/tableau_justi.j2 @@ -99,7 +99,13 @@ } else if (k.indexOf('etudid') != -1) { const e = getEtudiant(justificatif.etudid); - td.textContent = `${e.prenom.capitalize()} ${e.nom.toUpperCase()}`; + td.innerHTML = `${e.prenom.capitalize()} ${e.nom.toUpperCase()}`; + } else if (k == "formsemestre") { + if (justificatif.hasOwnProperty("formsemestre")) { + td.textContent = justificatif.formsemestre.title.replaceAll('-', ' '); + } else { + td.textContent = `Pas de Semestre`; + } } else { if (justificatif[k] != null) { @@ -458,7 +464,191 @@ }) } + function filterJusti(dept = false) { + let dept_html_head = ` + + + ` + + let dept_html_body = ` + + Recherche dans les semestre + + + ` + + let html = ` +
    +

    Affichage des colonnes:

    +
    + ${dept ? dept_html_head : ""} + + + + + + +
    +
    +

    Filtrage des colonnes:

    + + Date de saisie + + + + + Date de début + + + + + Date de fin + + + + + Etat + + + + + + ${dept ? dept_html_body : ""} +
    + `; + const span = document.createElement('span'); + span.innerHTML = html + html = span.firstElementChild + + const filterHead = html.querySelector('.filter-head'); + filterHead.innerHTML = "" + let cols = ["formsemestre", "etudid", "entry_date", "date_debut", "date_fin", "etat", "raison", "fichier"]; + + cols.forEach((k) => { + const label = document.createElement('label') + label.classList.add('f-label') + const s = document.createElement('span'); + s.textContent = columnTranslator(k); + + + const input = document.createElement('input'); + input.classList.add('chk') + input.type = "checkbox" + input.name = k + input.id = k; + input.checked = filterJustificatifs.columns.includes(k) + + label.appendChild(s) + label.appendChild(input) + filterHead.appendChild(label) + }) + + // Mise à jour des filtres + + Object.keys(filterJustificatifs.filters).forEach((key) => { + const l = html.querySelector(`.filter-title[for="${key}"]`).parentElement; + if (key.indexOf('date') != -1) { + l.querySelector(`#${key}_pref`).value = filterJustificatifs.filters[key].pref; + l.querySelector(`#${key}_time`).value = filterJustificatifs.filters[key].time.format("YYYY-MM-DDTHH:mm"); + + } else if (key.indexOf('etat') != -1) { + l.querySelectorAll('input').forEach((e) => { + e.checked = filterJustificatifs.filters[key].includes(e.value) + }) + } else if (key == "formsemestre") { + l.querySelector('#formsemestre').value = filterJustificatifs.filters["formsemestre"]; + } + }) + + openPromptModal("Filtrage des Justificatifs", html, () => { + + const columns = [...document.querySelectorAll('.chk')] + .map((el) => { if (el.checked) return el.id }) + .filter((el) => el) + + filterJustificatifs.columns = columns + filterJustificatifs.filters = {} + //reste des filtres + + const lines = [...document.querySelectorAll('.filter-line')]; + + lines.forEach((l) => { + const key = l.querySelector('.filter-title').getAttribute('for'); + + if (key.indexOf('date') != -1) { + const pref = l.querySelector(`#${key}_pref`).value; + const time = l.querySelector(`#${key}_time`).value; + if (l.querySelector(`#${key}_time`).value != "") { + filterJustificatifs.filters[key] = { + pref: pref, + time: new moment.tz(time, TIMEZONE) + } + } + } else if (key.indexOf('etat') != -1) { + filterJustificatifs.filters[key] = [...l.querySelectorAll("input:checked")].map((e) => e.value); + } else if (key == "formsemestre") { + filterJustificatifs.filters["formsemestre"] = l.querySelector('#formsemestre').value; + } + }) + + + if (dept) { + loadAll(); + } else { + getAllJustificatifsFromEtud(etudid, justificatifCallBack) + } + + }, () => { }, "#7059FF"); + }