server_photo_s85js/public/js/gallery.js
2026-08-11 08:45:04 +02:00

83 lines
2.2 KiB
JavaScript

// public/js/gallery.js
// Coordinatore della galleria.
(() => {
"use strict";
const ACTIVITY_EXTENSIONS = ["fit", "tcx", "gpx"];
function filterByMode(items) {
if (window.state?.mode === "photos") {
return items.filter(item =>
item.mime_type?.startsWith("image/") ||
item.mime_type?.startsWith("video/")
);
}
return items.filter(item => {
const format = String(
item.format || item.file_extension || item.mime_type || ""
).toLowerCase();
const name = String(
item.name || item.file_name || item.path || ""
).toLowerCase();
return ACTIVITY_EXTENSIONS.some(extension =>
format === extension ||
format.includes(extension) ||
name.endsWith(`.${extension}`)
);
});
}
function refreshGallery() {
const startedAt = performance.now();
let items = window.getLocalItems?.() || [];
console.log(`[refreshGallery] mode=${window.state?.mode} items=${items.length}`);
items = filterByMode(items);
const showDeleted = document.getElementById("showDeleted")?.checked;
if (!showDeleted) items = items.filter(item => !item.deleted_at);
const filtered = window.GalleryUtils.applyFilters(items);
const sorted = window.GalleryUtils.sortByDate(
filtered,
window.currentSort || "desc"
);
const sections = window.GalleryUtils.groupByDate(
sorted,
window.currentGroup || "auto"
);
window.GalleryRenderer.renderGallery(sections);
console.log(
`[refreshGallery] render completato in ${Math.round(performance.now() - startedAt)} ms`
);
}
function initializeGallery() {
const checkbox = document.getElementById("showDeleted");
if (checkbox) {
checkbox.checked = localStorage.getItem("showDeleted") === "1";
checkbox.addEventListener("change", () => {
localStorage.setItem("showDeleted", checkbox.checked ? "1" : "0");
refreshGallery();
});
}
window.loadLocalState?.();
refreshGallery();
}
window.refreshGallery = refreshGallery;
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initializeGallery, { once: true });
} else {
initializeGallery();
}
})();