added fiel tecnici tags additional 2 and fixed menu

This commit is contained in:
2026-10-19 10:19:15 +02:00
parent ac23738037
commit f649bc0bd5
9 changed files with 510 additions and 82 deletions
@@ -130,7 +130,40 @@
});
};
let wsDisegniList = [];
// ================================================================
// Tab allegati della matrice: disegni tecnici, strumenti, cicli
// ================================================================
const WS_ATT_KINDS = {
disegni: {
flag: "is_disegno",
label: "Disegni tecnici",
icon: "📐",
itemLabel: "Disegno",
empty:
"Nessun disegno tecnico per questo profilo. " +
"Si possono segnare dalla gestione matrici (graffetta → pulsante compasso).",
},
strumenti: {
flag: "is_strumento",
label: "Strumenti di lavoro",
icon: "🔧",
itemLabel: "Strumento",
empty:
"Nessuno strumento di lavoro per questo profilo. " +
"Si possono segnare dalla gestione matrici (graffetta → pulsante chiave inglese).",
},
cicli: {
flag: "is_ciclo",
label: "Cicli di lavoro",
icon: "🔁",
itemLabel: "Ciclo",
empty:
"Nessun ciclo di lavoro per questo profilo. " +
"Si possono segnare dalla gestione matrici (graffetta → pulsante frecce).",
},
};
let wsAttLists = { disegni: [], strumenti: [], cicli: [] };
function wsFileExt(name) {
const p = String(name || "").split(".");
@@ -141,12 +174,15 @@
return ["jpg", "jpeg", "png", "gif", "bmp", "webp"].includes(ext);
}
function showWorksheetDisegno(index) {
const f = wsDisegniList[index];
function showWorksheetAttachment(kind, index) {
const list = wsAttLists[kind] || [];
const f = list[index];
if (!f) return;
$(".ws-disegno-item").removeClass("active");
$(`.ws-disegno-item[data-index="${index}"]`).addClass("active");
$(`.ws-disegno-item[data-kind="${kind}"]`).removeClass("active");
$(
`.ws-disegno-item[data-kind="${kind}"][data-index="${index}"]`,
).addClass("active");
const name = f.file_name || "";
const path = f.file_url || f.file_path || "";
@@ -161,7 +197,7 @@
viewer = `<div class="h-100 d-flex justify-content-center align-items-center text-muted">Anteprima non disponibile per questo formato: usa "Apri in nuova scheda"</div>`;
}
$("#wsDisegnoToolbar").html(`
$(`#wsToolbar_${kind}`).html(`
<div>
<div class="fw-bold">${escapeHtml(name)}</div>
${f.description ? `<div class="small text-muted">${escapeHtml(f.description)}</div>` : ""}
@@ -170,18 +206,59 @@
<i class="fa-solid fa-arrow-up-right-from-square"></i> Apri in nuova scheda
</a>
`);
$("#wsDisegnoViewer").html(viewer);
$(`#wsViewer_${kind}`).html(viewer);
}
function loadWorksheetDisegni(idmatrice) {
wsDisegniList = [];
const $c = $("#wsDisegniContainer");
function renderWorksheetAttachmentKind(kind) {
const cfg = WS_ATT_KINDS[kind];
const list = wsAttLists[kind];
const $c = $(`#wsContainer_${kind}`);
$(`#wsCount_${kind}`).text(list.length);
if (!list.length) {
$c.html(
`<div class="text-muted p-3">${escapeHtml(cfg.empty)}</div>`,
);
return;
}
let listHtml = "";
if (list.length > 1) {
listHtml =
'<div class="ws-disegni-list">' +
list
.map(
(f, i) =>
`<button type="button" class="ws-disegno-item" data-kind="${kind}" data-index="${i}">${cfg.icon} ${escapeHtml(f.file_name || cfg.itemLabel + " " + (i + 1))}</button>`,
)
.join("") +
"</div>";
}
$c.html(`
${listHtml}
<div class="ws-disegno-toolbar" id="wsToolbar_${kind}"></div>
<div class="ws-disegno-viewer" id="wsViewer_${kind}"></div>
`);
// Se l'utente ha già aperto il tab mentre caricava, mostro subito il primo
if ($(`.ws-tab[data-tab="${kind}"]`).hasClass("active")) {
showWorksheetAttachment(kind, 0);
}
}
function loadWorksheetAttachments(idmatrice) {
wsAttLists = { disegni: [], strumenti: [], cicli: [] };
const kinds = Object.keys(WS_ATT_KINDS);
if (!idmatrice) {
$("#wsDisegniCount").text("0");
$c.html(
'<div class="text-muted">Nessun profilo collegato a questo foglio.</div>',
);
kinds.forEach((k) => {
$(`#wsCount_${k}`).text("0");
$(`#wsContainer_${k}`).html(
'<div class="text-muted">Nessun profilo collegato a questo foglio.</div>',
);
});
return;
}
@@ -193,50 +270,25 @@
data.message || "Errore caricamento allegati",
);
wsDisegniList = (data.attachments || []).filter(
(a) => parseInt(a.is_disegno, 10) === 1,
);
$("#wsDisegniCount").text(wsDisegniList.length);
const all = data.attachments || [];
if (!wsDisegniList.length) {
$c.html(
'<div class="text-muted p-3">Nessun disegno tecnico per questo profilo. ' +
"Si possono segnare dalla gestione matrici (graffetta → pulsante compasso).</div>",
kinds.forEach((k) => {
const flag = WS_ATT_KINDS[k].flag;
wsAttLists[k] = all.filter(
(a) => parseInt(a[flag], 10) === 1,
);
return;
}
let listHtml = "";
if (wsDisegniList.length > 1) {
listHtml =
'<div class="ws-disegni-list">' +
wsDisegniList
.map(
(f, i) =>
`<button type="button" class="ws-disegno-item" data-index="${i}">📐 ${escapeHtml(f.file_name || "Disegno " + (i + 1))}</button>`,
)
.join("") +
"</div>";
}
$c.html(`
${listHtml}
<div class="ws-disegno-toolbar" id="wsDisegnoToolbar"></div>
<div class="ws-disegno-viewer" id="wsDisegnoViewer"></div>
`);
// Se l'utente ha già aperto il tab mentre caricava, mostro subito il primo
if ($('.ws-tab[data-tab="disegni"]').hasClass("active")) {
showWorksheetDisegno(0);
}
renderWorksheetAttachmentKind(k);
});
})
.catch((err) => {
$("#wsDisegniCount").text("!");
$c.html(
'<div class="text-danger">Errore nel caricamento dei disegni: ' +
escapeHtml(err.message || "") +
"</div>",
);
kinds.forEach((k) => {
$(`#wsCount_${k}`).text("!");
$(`#wsContainer_${k}`).html(
'<div class="text-danger">Errore nel caricamento degli allegati: ' +
escapeHtml(err.message || "") +
"</div>",
);
});
});
}
@@ -437,6 +489,28 @@
</div>
`;
const attTabsHtml = Object.keys(WS_ATT_KINDS)
.map((k) => {
const c = WS_ATT_KINDS[k];
return `
<button type="button" class="ws-tab" data-tab="${k}">
${c.icon} ${escapeHtml(c.label)} <span class="ws-tab-count" id="wsCount_${k}">…</span>
</button>`;
})
.join("");
const attPanesHtml = Object.keys(WS_ATT_KINDS)
.map((k) => {
const c = WS_ATT_KINDS[k];
return `
<div class="ws-tab-pane" data-pane="${k}">
<div id="wsContainer_${k}">
<div class="text-muted">Caricamento ${escapeHtml(c.label.toLowerCase())}...</div>
</div>
</div>`;
})
.join("");
const fullHtml = `
${headerHtml}
@@ -444,24 +518,18 @@
<button type="button" class="ws-tab active" data-tab="dati">
<i class="fa-solid fa-file-lines me-1"></i> Dati foglio
</button>
<button type="button" class="ws-tab" data-tab="disegni">
📐 Disegni tecnici <span class="ws-tab-count" id="wsDisegniCount">…</span>
</button>
${attTabsHtml}
</div>
<div class="ws-tab-pane active" data-pane="dati">
${html}
</div>
<div class="ws-tab-pane" data-pane="disegni">
<div id="wsDisegniContainer">
<div class="text-muted">Caricamento disegni tecnici...</div>
</div>
</div>
${attPanesHtml}
`;
$("#worksheetDetailContainer").html(fullHtml);
loadWorksheetDisegni(ws.idmatrice);
loadWorksheetAttachments(ws.idmatrice);
})
.catch((err) => {
console.error("Catch loadMatriceWorksheets:", err);
@@ -495,18 +563,21 @@
$(".ws-tab-pane").removeClass("active");
$(`.ws-tab-pane[data-pane="${tab}"]`).addClass("active");
// Carico il PDF solo la prima volta che si apre il tab
// Carico il file solo la prima volta che si apre il tab
if (
tab === "disegni" &&
wsDisegniList.length &&
$("#wsDisegnoViewer").is(":empty")
WS_ATT_KINDS[tab] &&
(wsAttLists[tab] || []).length &&
$(`#wsViewer_${tab}`).is(":empty")
) {
showWorksheetDisegno(0);
showWorksheetAttachment(tab, 0);
}
});
$(document).on("click", ".ws-disegno-item", function () {
showWorksheetDisegno(parseInt($(this).data("index"), 10));
showWorksheetAttachment(
$(this).data("kind"),
parseInt($(this).data("index"), 10),
);
});
$(document).on("click", ".open-worksheet-detail", function () {