Refactoring et uniformisation tables jury/recap.

This commit is contained in:
Emmanuel Viennet 2023-02-12 01:13:43 +01:00 committed by iziram
parent 0e5b4f9cb7
commit 8d7958c80d
2 changed files with 132 additions and 149 deletions

View File

@ -277,9 +277,7 @@ def _formsemestre_recapcomplet_to_file(
include_evaluations=include_evaluations,
filename=filename,
)
return scu.send_file(
data, filename=filename, mime=scu.get_mime_suffix(tabformat)
)
return scu.send_file(data, filename=filename, mime=scu.get_mime_suffix(format))
elif tabformat == "xml":
data = gen_formsemestre_recapcomplet_xml(
formsemestre.id,
@ -464,9 +462,11 @@ def _gen_formsemestre_recapcomplet_table(
mode_jury=False,
filename: str = "",
selected_etudid=None,
) -> str:
"""Génère le html"""
table = res.get_table_recap(
) -> TableRecap:
"""Construit la table récap."""
table_class = TableJury if mode_jury else TableRecap
table = table_class(
res,
convert_values=True,
include_evaluations=include_evaluations,
mode_jury=mode_jury,
@ -474,20 +474,7 @@ def _gen_formsemestre_recapcomplet_table(
)
table.data["filename"] = filename
table.select_row(selected_etudid)
return f"""
<div class="table_recap">
{
'<div class="message">aucun étudiant !</div>'
if table.is_empty()
else table.html(
extra_classes=[
'table_recap',
'apc' if formsemestre.formation.is_apc() else 'classic',
'jury' if mode_jury else ''
])
}
</div>
"""
return table
def gen_formsemestre_recapcomplet_excel(

View File

@ -24,23 +24,49 @@ $(function () {
}
// Etat (tri des colonnes) de la table:
const url = new URL(document.URL);
const formsemestre_id = url.searchParams.get("formsemestre_id");
const order_info_key = JSON.stringify([url.pathname, formsemestre_id]);
const etudids_key = JSON.stringify([
"etudids",
url.origin,
formsemestre_id,
]);
const noms_key = JSON.stringify(["noms", url.origin, formsemestre_id]);
let order_info;
if (formsemestre_id) {
const x = localStorage.getItem(order_info_key);
if (x) {
try {
order_info = JSON.parse(x);
} catch (error) {
console.error(error);
let hidden_colums = [
"etud_codes", "identite_detail",
"partition_aux", "partition_rangs", "admission",
"col_empty"
];
// Etat (tri des colonnes) de la table:
const url = new URL(document.URL);
const formsemestre_id = url.searchParams.get("formsemestre_id");
const order_info_key = JSON.stringify([url.pathname, formsemestre_id]);
const etudids_key = JSON.stringify(["etudids", url.origin, formsemestre_id]);
const noms_key = JSON.stringify(["noms", url.origin, formsemestre_id]);
let order_info;
if (formsemestre_id) {
const x = localStorage.getItem(order_info_key);
if (x) {
try {
order_info = JSON.parse(x);
} catch (error) {
console.error(error);
}
}
}
// Les colonnes visibles sont mémorisées, il faut initialiser l'état des boutons
function update_buttons_labels(dt) {
// chaque bouton controle une classe stockée dans le data-group du span
document.querySelectorAll("button.dt-button").forEach(but => {
let g_span = but.querySelector("span > span");
if (g_span) {
let group = g_span.dataset["group"];
if (group) {
// si le group (= la 1ere col.) est visible, but_on
if (dt.columns("." + group).visible()[0]) {
but.classList.add("but_on");
but.classList.remove("but_off");
} else {
but.classList.add("but_off");
but.classList.remove("but_on");
}
}
}
});
}
}
}
@ -63,89 +89,79 @@ $(function () {
}
}
}
});
}
// Definition des boutons au dessus de la table:
let buttons = [
{
extend: 'copyHtml5',
text: 'Copier',
exportOptions: { orthogonal: 'export' }
},
{
extend: 'excelHtml5',
// footer: true, // ne fonctionne pas ?
exportOptions: { orthogonal: 'export' },
title: document.querySelector('table.table_recap').dataset.filename
},
{
// force affichage de toutes les colonnes
text: '<a title="Afficher toutes les colonnes">&#10036;</a>',
action: function (e, dt, node, config) {
dt.columns().visible(true);
update_buttons_labels(dt);
}
},
{
text: '<a title="Rétablir l\'affichage par défaut" class="clearreload">&#128260;</a>',
action: function (e, dt, node, config) {
localStorage.clear();
console.log("cleared localStorage");
location.reload();
}
},
{
text: '<span data-group="identite_detail">Civilité</span>',
action: toggle_col_ident_visibility,
},
{
text: '<span data-group="partition_aux">Groupes</span>',
action: toggle_col_but_visibility,
},
{
text: '<span data-group="partition_rangs">Rg</span>',
action: toggle_col_but_visibility,
},
]; // fin des boutons communs à toutes les tables recap
// Changement visibilité groupes colonnes (boutons)
function toggle_col_but_visibility(e, dt, node, config) {
let group = node.children()[0].firstChild.dataset.group;
toggle_col_group_visibility(dt, group, node.hasClass("but_on"));
}
function toggle_col_ident_visibility(e, dt, node, config) {
let onoff = node.hasClass("but_on");
toggle_col_group_visibility(dt, "identite_detail", onoff);
toggle_col_group_visibility(dt, "identite_court", !onoff);
}
function toggle_col_ressources_visibility(e, dt, node, config) {
let onoff = node.hasClass("but_on");
toggle_col_group_visibility(dt, "col_res", onoff);
toggle_col_group_visibility(dt, "col_ue_bonus", onoff);
toggle_col_group_visibility(dt, "col_malus", onoff);
}
function toggle_col_group_visibility(dt, group, onoff) {
if (onoff) {
dt.columns("." + group).visible(false);
} else {
dt.columns("." + group).visible(true);
}
update_buttons_labels(dt);
}
// Definition des boutons au dessus de la table:
let buttons = [
{
extend: "copyHtml5",
text: "Copier",
exportOptions: { orthogonal: "export" },
},
{
extend: "excelHtml5",
// footer: true, // ne fonctionne pas ?
exportOptions: { orthogonal: "export" },
title: document.querySelector("table.table_recap").dataset.filename,
},
{
// force affichage de toutes les colonnes
text: '<a title="Afficher toutes les colonnes">&#10036;</a>',
action: function (e, dt, node, config) {
dt.columns().visible(true);
update_buttons_labels(dt);
},
},
{
text: '<a title="Rétablir l\'affichage par défaut" class="clearreload">&#128260;</a>',
action: function (e, dt, node, config) {
localStorage.clear();
console.log("cleared localStorage");
location.reload();
},
},
{
text: '<span data-group="identite_detail">Civilité</span>',
action: toggle_col_ident_visibility,
},
{
text: '<span data-group="partition_aux"><a title="Affichage des groupes secondaires (la première partition est toujours affichée)">Groupes</a></span>',
action: toggle_col_but_visibility,
},
{
text: '<span data-group="partition_rangs"><a title="Rangs dans les groupes (si activés dans les partitions concernées)">Rg</a></span>',
action: toggle_col_but_visibility,
},
]; // fin des boutons communs à toutes les tables recap
if ($("table.table_recap").hasClass("jury")) {
// table jury: avec ou sans codes enregistrés
buttons.push({
text: '<span data-group="recorded_code">Codes jury</span>',
action: toggle_col_but_visibility,
});
} else {
// BOUTONS SPECIFIQUES A LA TABLE RECAP NON JURY
buttons.push(
$("table.table_recap").hasClass("apc")
? {
text: '<span data-group="col_res">Ressources</span>',
action: toggle_col_ressources_visibility,
if ($('table.table_recap').hasClass("jury")) {
// table jury: avec ou sans codes enregistrés
buttons.push(
{
text: '<span data-group="recorded_code">Codes jury</span>',
action: toggle_col_but_visibility,
});
} else {
// BOUTONS SPECIFIQUES A LA TABLE RECAP NON JURY
buttons.push(
$('table.table_recap').hasClass("apc") ?
{
text: '<span data-group="col_res">Ressources</span>',
action: toggle_col_ressources_visibility,
} : {
name: "toggle_mod",
text: "Cacher les modules",
action: function (e, dt, node, config) {
let onoff = node.hasClass("but_on");
toggle_col_group_visibility(dt, "col_mod:not(.col_empty)", onoff);
toggle_col_group_visibility(dt, "col_ue_bonus", onoff);
toggle_col_group_visibility(dt, "col_malus", onoff);
}
}
);
if ($('table.table_recap').hasClass("apc")) {
buttons.push({
text: '<span data-group="col_sae">SAÉs</span>',
action: toggle_col_but_visibility,
});
}
: {
name: "toggle_mod",
@ -161,36 +177,16 @@ $(function () {
toggle_col_group_visibility(dt, "col_malus", onoff);
},
}
);
if ($("table.table_recap").hasClass("apc")) {
buttons.push({
text: '<span data-group="col_sae">SAÉs</span>',
action: toggle_col_but_visibility,
});
}
// S'il y a des colonnes vides:
if ($("table.table_recap td.col_empty").length > 0) {
buttons.push({
// modules vides
text: '<span data-group="col_empty">Vides</span>',
action: toggle_col_but_visibility,
});
}
// Boutons admission (pas en jury)
if (!$("table.table_recap").hasClass("jury")) {
buttons.push({
text: '<span data-group="admission">Admission</span>',
action: toggle_col_but_visibility,
});
}
}
// Boutons évaluations (si présentes)
if ($("table.table_recap").hasClass("with_evaluations")) {
buttons.push({
text: '<span data-group="eval">Évaluations</span>',
action: toggle_col_but_visibility,
});
}
}
// Boutons évaluations (si présentes)
if ($('table.table_recap').hasClass("with_evaluations")) {
buttons.push(
{
text: '<span data-group="eval">Évaluations</span>',
action: toggle_col_but_visibility,
}
);
}
// ------------- LA TABLE ---------
try {