Add Pro multiple notes and refresh guides

This commit is contained in:
livio committed 2026-10-05 08:31:32 +02:00
1 parent bb69b9fd0d
commit fc1ee8f21a
6 files changed
+200 -15

No files matched your search

+99 -9
View File
@@ -119,6 +119,8 @@ const lmeState = {
measurementSystem: "metric",
entitlements: {
advancedGeometry: false,
fiducialPoints: false,
multipleNotes: false,
maxDrawingObjects: 15,
drawingLimitMessage: "Hai raggiunto il limite di 15 oggetti del piano Base."
},
@@ -2476,6 +2478,89 @@ function managedGroupTotals(records) {
return values.join(" | ") || `${records.length} oggetti`;
}
function managedNotes(properties = {}) {
const stored = Array.isArray(properties._lmeNotesList) ? properties._lmeNotesList : [];
const notes = stored.map((item, index) => {
const value = typeof item === "string" ? { text: item } : (item || {});
const text = String(value.text || "").trim();
return text ? {
id: String(value.id || `note-${index}`),
text,
createdAt: value.createdAt || null,
updatedAt: value.updatedAt || null
} : null;
}).filter(Boolean);
const legacy = String(properties._lmeNotes || "").trim();
if (!notes.length && legacy) {
notes.push({ id: "legacy-note", text: legacy, createdAt: null, updatedAt: null });
}
return notes;
}
function writeManagedNotes(properties, notes) {
properties._lmeNotesList = notes.map(note => ({
id: String(note.id),
text: String(note.text || "").trim(),
createdAt: note.createdAt || null,
updatedAt: note.updatedAt || null
})).filter(note => note.text);
properties._lmeNotes = properties._lmeNotesList.map(note => note.text).join("\n\n");
}
function managedNoteId() {
return globalThis.crypto?.randomUUID?.() || `note-${Date.now()}-${Math.random().toString(16).slice(2)}`;
}
function managedNoteDate(note) {
const value = note.updatedAt || note.createdAt;
if (!value) return "Nota importata";
const date = new Date(value);
return Number.isNaN(date.getTime()) ? "Nota" : date.toLocaleString("it-IT");
}
function showManagedNotesDialog(record) {
const properties = record.layer?.feature?.properties || {};
const title = `Note - ${managedObjectEditableName(record) || "Oggetto"}`;
const notes = managedNotes(properties);
const canEdit = Boolean(lmeState.entitlements?.multipleNotes) && !lmeState.readOnly;
const list = notes.map((note, index) => `<article class="managed-note" data-note-id="${escapeHtml(note.id)}">
<header><strong>Nota ${index + 1}</strong><time>${escapeHtml(managedNoteDate(note))}</time></header>
<p>${escapeHtml(note.text).replaceAll("\n", "<br>")}</p>
${canEdit ? `<div class="managed-note-actions"><button type="button" data-edit-note="${escapeHtml(note.id)}">Modifica</button><button type="button" class="danger-command" data-delete-note="${escapeHtml(note.id)}">Elimina</button></div>` : ""}
</article>`).join("");
const editor = canEdit ? `<form class="managed-note-editor">
<label>Nuova nota<textarea name="note" rows="4" maxlength="1000" required placeholder="Scrivi una nuova nota tecnica"></textarea></label>
<button type="submit" class="primary-command">Aggiungi nota</button>
</form>` : `<p class="managed-note-pro-message">${lmeState.readOnly ? "Il progetto e' in sola lettura: le note possono essere consultate ma non modificate." : "La consultazione e' disponibile; per aggiungere, modificare o eliminare note serve LME Pro con abbonamento o licenza manuale."}</p>`;
const dialog = showAppDialog(title, `<div class="managed-notes-list">${list || "<p>Nessuna nota presente.</p>"}</div>${editor}`);
dialog.querySelector(".managed-note-editor")?.addEventListener("submit", event => {
event.preventDefault();
if (!requireProFeature("multipleNotes")) return;
const text = String(event.currentTarget.elements.note?.value || "").trim();
if (!text) return;
const now = new Date().toISOString();
updateManagedProperties([record], value => writeManagedNotes(value, [...managedNotes(value), { id: managedNoteId(), text, createdAt: now }]));
showManagedNotesDialog(record);
});
dialog.querySelectorAll("[data-edit-note]").forEach(button => button.addEventListener("click", async () => {
if (!requireProFeature("multipleNotes")) return;
const current = managedNotes(record.layer?.feature?.properties || {}).find(note => note.id === button.dataset.editNote);
if (!current) return;
const result = await showFormDialog("Modifica nota", [{ name: "note", label: "Testo", type: "textarea", rows: 6, maxLength: 1000, value: current.text }], "Salva nota");
if (!result) { showManagedNotesDialog(record); return; }
const text = String(result.note || "").trim();
if (!text) { showManagedNotesDialog(record); return; }
updateManagedProperties([record], value => writeManagedNotes(value, managedNotes(value).map(note => note.id === current.id ? { ...note, text, updatedAt: new Date().toISOString() } : note)));
showManagedNotesDialog(record);
}));
dialog.querySelectorAll("[data-delete-note]").forEach(button => button.addEventListener("click", () => {
if (!requireProFeature("multipleNotes")) return;
updateManagedProperties([record], value => writeManagedNotes(value, managedNotes(value).filter(note => note.id !== button.dataset.deleteNote)));
showManagedNotesDialog(record);
}));
return dialog;
}
function renderManagedObjectTools(record) {
const properties = record.layer.feature?.properties || (record.layer.feature = { type: "Feature", properties: {} }).properties;
const selected = lmeState.managerSelectedObjectIds.has(record.id);
@@ -2493,7 +2578,7 @@ function renderManagedObjectTools(record) {
<label>Opacita<input type="range" data-field="opacity" min="0.1" max="1" step="0.1" value="${Number(properties._lmeOpacity) || 1}"></label>
<label>Riempimento %<input type="range" data-field="fillOpacity" min="0" max="0.8" step="0.05" value="${Number.isFinite(Number(properties._lmeFillOpacity)) ? Number(properties._lmeFillOpacity) : 0.2}"></label>
<label>Tratto<select data-field="dash"><option value="">Continuo</option><option value="8 6" ${properties._lmeDash === "8 6" ? "selected" : ""}>Tratteggiato</option><option value="2 6" ${properties._lmeDash === "2 6" ? "selected" : ""}>Puntinato</option></select></label></div>
<label>Note<textarea data-field="notes" rows="2" maxlength="1000" placeholder="Note tecniche">${escapeHtml(properties._lmeNotes || "")}</textarea></label>
<div class="managed-notes-command"><button type="button" data-action="notes">Visualizza note (${managedNotes(properties).length})</button><small>Le note multiple sono modificabili con LME Pro.</small></div>
<label class="layer-photo-picker">Foto<input type="file" data-field="photo" accept="image/*"></label>
${properties._lmePhoto ? `<img class="layer-photo-preview" src="${properties._lmePhoto}" alt="Foto allegata"><button type="button" data-action="remove-photo">Rimuovi foto</button>` : ""}
<div class="layer-compact-actions"><button type="button" data-action="attributes">Attributi</button><button type="button" data-action="duplicate">Duplica</button><button type="button" data-action="numeric">Coordinate</button><button type="button" data-action="inspect">WGS84 / UTM</button><button type="button" data-action="move">Sposta geometria</button><button type="button" data-action="buffer">Buffer</button></div>`;
@@ -2514,7 +2599,7 @@ function renderManagedObjectTools(record) {
});
bindManagedColorEditors(tools, applyCurrentStyle);
tools.querySelectorAll(".layer-style-controls input[type='range'],.layer-style-controls select").forEach(input => input.addEventListener("change", applyCurrentStyle));
tools.querySelector("[data-field='notes']").addEventListener("change", event => updateManagedProperties([record], value => { value._lmeNotes = event.target.value.trim(); }));
tools.querySelector("[data-action='notes']").addEventListener("click", () => showManagedNotesDialog(record));
tools.querySelector("[data-field='photo']").addEventListener("change", async event => {
const file = event.target.files?.[0]; if (!file) return;
if (file.size > 2_500_000) { setInfo("Foto troppo grande: usa un file inferiore a 2,5 MB."); return; }
@@ -2831,9 +2916,9 @@ function showObjectTable() {
const details = managedObjectDetails(record.layer);
const selected = lmeState.managerSelectedObjectIds.has(record.id);
const locked = Boolean(properties._lmeLocked);
return `<tr data-object-id="${escapeHtml(record.id)}"><td><input type="checkbox" data-select="${escapeHtml(record.id)}" ${selected ? "checked" : ""} aria-label="Seleziona ${escapeHtml(managedObjectLabel(record, index))}"></td><td><input type="checkbox" data-lock="${escapeHtml(record.id)}" ${locked ? "checked" : ""} ${lmeState.readOnly ? "disabled" : ""} aria-label="Blocca ${escapeHtml(managedObjectLabel(record, index))}"></td><td><button type="button" data-locate="${escapeHtml(record.id)}" title="Mostra sulla mappa" aria-label="Mostra sulla mappa">⌖</button></td><td><button type="button" data-attributes="${escapeHtml(record.id)}" title="Modifica metadati" aria-label="Modifica metadati di ${escapeHtml(managedObjectLabel(record, index))}" ${lmeState.readOnly ? "disabled" : ""}>✎</button></td><td>${escapeHtml(managedObjectLabel(record, index))}</td><td>${escapeHtml(managedCategoryName(layerManagerCategories().find(item => item.key === record.categoryKey) || { key: record.categoryKey, label: record.categoryKey }, [record]))}</td><td>${escapeHtml(properties.foglio || properties.FOGLIO || "")}</td><td>${escapeHtml(properties.particella || properties.PARTICELLA || properties.LABEL || "")}</td><td>${escapeHtml(details.slice(0, 2).join(" | "))}</td></tr>`;
return `<tr data-object-id="${escapeHtml(record.id)}"><td><input type="checkbox" data-select="${escapeHtml(record.id)}" ${selected ? "checked" : ""} aria-label="Seleziona ${escapeHtml(managedObjectLabel(record, index))}"></td><td><input type="checkbox" data-lock="${escapeHtml(record.id)}" ${locked ? "checked" : ""} ${lmeState.readOnly ? "disabled" : ""} aria-label="Blocca ${escapeHtml(managedObjectLabel(record, index))}"></td><td><button type="button" data-locate="${escapeHtml(record.id)}" title="Mostra sulla mappa" aria-label="Mostra sulla mappa">⌖</button></td><td><button type="button" data-attributes="${escapeHtml(record.id)}" title="Modifica metadati" aria-label="Modifica metadati di ${escapeHtml(managedObjectLabel(record, index))}" ${lmeState.readOnly ? "disabled" : ""}>✎</button></td><td><button type="button" class="object-notes-button" data-notes="${escapeHtml(record.id)}" title="Visualizza note">Note (${managedNotes(properties).length})</button></td><td>${escapeHtml(managedObjectLabel(record, index))}</td><td>${escapeHtml(managedCategoryName(layerManagerCategories().find(item => item.key === record.categoryKey) || { key: record.categoryKey, label: record.categoryKey }, [record]))}</td><td>${escapeHtml(properties.foglio || properties.FOGLIO || "")}</td><td>${escapeHtml(properties.particella || properties.PARTICELLA || properties.LABEL || "")}</td><td>${escapeHtml(details.slice(0, 2).join(" | "))}</td></tr>`;
}).join("");
const dialog = showAppDialog("Elenco oggetti e particelle", `<label class="object-table-search">Filtra<input type="search" placeholder="Nome, foglio, particella o gruppo"></label><div class="object-table-legend"><span>Seleziona più oggetti con i flag nella colonna Selez.</span><span>Il lucchetto impedisce modifiche e rimozioni; la matita modifica i metadati.</span></div><div class="object-table-wrap"><table><thead><tr><th>Selez.</th><th>Blocca</th><th>Mappa</th><th>Metadati</th><th>Nome</th><th>Gruppo</th><th>Foglio</th><th>Particella</th><th>Misure</th></tr></thead><tbody>${body || "<tr><td colspan='9'>Nessun oggetto</td></tr>"}</tbody></table></div>`);
const dialog = showAppDialog("Elenco oggetti e particelle", `<label class="object-table-search">Filtra<input type="search" placeholder="Nome, foglio, particella o gruppo"></label><div class="object-table-legend"><span>Seleziona più oggetti con i flag nella colonna Selez.</span><span>Il lucchetto impedisce modifiche e rimozioni; la matita modifica i metadati.</span><span>Note apre l'elenco completo; le modifiche richiedono LME Pro.</span></div><div class="object-table-wrap"><table><thead><tr><th>Selez.</th><th>Blocca</th><th>Mappa</th><th>Metadati</th><th>Note</th><th>Nome</th><th>Gruppo</th><th>Foglio</th><th>Particella</th><th>Misure</th></tr></thead><tbody>${body || "<tr><td colspan='10'>Nessun oggetto</td></tr>"}</tbody></table></div>`);
const byId = new Map(records.map(record => [record.id, record]));
dialog.querySelector("input[type='search']").addEventListener("input", event => {
const query = event.target.value.toLocaleLowerCase("it");
@@ -2865,6 +2950,10 @@ function showObjectTable() {
const record = byId.get(button.dataset.attributes); if (!record) return;
dialog.remove(); editManagedAttributes(record);
}));
dialog.querySelectorAll("[data-notes]").forEach(button => button.addEventListener("click", () => {
const record = byId.get(button.dataset.notes); if (!record) return;
showManagedNotesDialog(record);
}));
return records.length;
}
@@ -3180,8 +3269,8 @@ function showLeafletToolbarHelp() {
<div><dt>✓</dt><dd><strong>Controlla e ripara</strong>Verifica gli oggetti selezionati e prova a correggere coordinate duplicate o poligoni non validi. Esempio: usalo quando un contorno importato non si esporta o si riempie male; al termine compare un riepilogo.</dd></div>
<div><dt>◉</dt><dd><strong>Crea foro</strong>Seleziona esattamente due poligoni: prima l'area esterna, poi quella interna. Esempio: sottrai il cortile dal perimetro di un fabbricato o un'isola esclusa da un'area di lavoro.</dd></div>
<div><dt>⇄</dt><dd><strong>Confronta due confini</strong>Seleziona esattamente due poligoni. L'app crea il solo primo in rosso, il solo secondo in blu e la sovrapposizione in verde, mostrando le rispettive aree.</dd></div>
<div><dt>PF</dt><dd><strong>Scarica Punti Fiduciali</strong>Seleziona una particella o un foglio catastale; in alternativa usa la particella rilevata dal GPS. I PF vengono aggiunti come sottogruppo del relativo foglio.</dd></div>
<div><dt>?</dt><dd><strong>Guida</strong>Riapre questa descrizione. I risultati di riparazione e confronto vengono mostrati anche in una finestra, così l'operazione non resta senza riscontro.</dd></div>
<div><dt>PF</dt><dd><strong>Scarica Punti Fiduciali</strong>Seleziona una particella o un foglio catastale; in alternativa usa la particella rilevata dal GPS. I PF vengono aggiunti come sottogruppo del relativo foglio e richiedono LME Pro.</dd></div>
<div><dt>?</dt><dd><strong>Guida</strong>Riapre questa descrizione. I risultati di riparazione e confronto vengono mostrati anche in una finestra; per uscire dal confronto usa Annulla oppure avvia un nuovo confronto.</dd></div>
</dl>
</div>`);
}
@@ -5453,11 +5542,12 @@ function bindStoredFeaturePopup(feature, layer) {
function updateStoredFeaturePopup(layer, sourceProperties) {
const properties = sourceProperties || layer?.feature?.properties || {};
const label = properties.name || properties.Name || properties.label || properties.LABEL;
const notes = String(properties._lmeNotes || "").trim();
const notes = managedNotes(properties);
const photo = String(properties._lmePhoto || "");
if (label || notes || photo) {
if (label || notes.length || photo) {
const image = photo.startsWith("data:image/") ? `<img class="lme-popup-photo" src="${photo}" alt="Foto allegata">` : "";
layer.bindPopup(`${label ? `<strong>${escapeHtml(label)}</strong>` : ""}${notes ? `<p>${escapeHtml(notes)}</p>` : ""}${image}`);
const noteList = notes.length ? `<div class="lme-popup-notes"><strong>Note</strong>${notes.map(note => `<p>${escapeHtml(note.text).replaceAll("\n", "<br>")}</p>`).join("")}</div>` : "";
layer.bindPopup(`${label ? `<strong>${escapeHtml(label)}</strong>` : ""}${noteList}${image}`);
return;
}
if (typeof layer?.unbindPopup === "function") {