- android/ — Capacitor project (build/, local.properties ignored) - app/js/native.js — bridge สำหรับ APK: savePhoto/saveZip/shareItems ผ่าน Filesystem+Share - app/js/csv.js — นำเข้าโฟลเดอร์หลายรายการจาก CSV (site,letter,datetime,name) - app/js/orient.js — จัดการ orientation ของ preview/กล้อง - app/manual.html + APK.md — คู่มือใช้งานและวิธี build APK - app/templates/folders-template.csv — เทมเพลต CSV - package.json / package-lock.json / capacitor.config.json / scripts/build-apk.sh - ปรับ ui, camera, exif, archive, db, naming, main, sw + css/README ตามงานข้างบน
415 lines
24 KiB
JavaScript
415 lines
24 KiB
JavaScript
// ── UI: markup + toast + bottom sheet ────────────────────────
|
||
import { humanDateTime } from "./naming.js";
|
||
import { formatExposure } from "./exif.js";
|
||
|
||
export const esc = (s) =>
|
||
String(s ?? "")
|
||
.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")
|
||
.replace(/"/g, """).replace(/'/g, "'");
|
||
|
||
export function fmtBytes(n) {
|
||
if (!Number.isFinite(n) || n <= 0) return "0 B";
|
||
if (n < 1024) return n + " B";
|
||
if (n < 1024 ** 2) return (n / 1024).toFixed(1) + " KB";
|
||
if (n < 1024 ** 3) return (n / 1024 ** 2).toFixed(1) + " MB";
|
||
return (n / 1024 ** 3).toFixed(2) + " GB";
|
||
}
|
||
|
||
const ICON = {
|
||
torch: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 2h6l-1 7h4l-7 13 1-8H8z"/></svg>`,
|
||
flip: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 4v6h-6M1 20v-6h6"/><path d="M3.5 9a9 9 0 0 1 14.9-3.4L23 10M1 14l4.6 4.4A9 9 0 0 0 20.5 15"/></svg>`,
|
||
grid: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18M15 3v18M3 9h18M3 15h18"/></svg>`,
|
||
pencil: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/></svg>`,
|
||
trash: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6"/><path d="M10 11v6M14 11v6"/></svg>`,
|
||
zip: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7"/><path d="M12 2v4M10 6h4M10 10h4M10 14h4"/></svg>`,
|
||
share: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V3"/><path d="M8 7l4-4 4 4"/><path d="M4 14v5a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5"/></svg>`,
|
||
camera: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>`,
|
||
lock: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="10" width="16" height="11" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>`,
|
||
block: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M5.6 5.6l12.8 12.8"/></svg>`,
|
||
folder: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>`,
|
||
image: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>`,
|
||
};
|
||
|
||
// ── Toast ──
|
||
let toastTimer = null;
|
||
export function toast(msg, ms = 2600) {
|
||
const el = document.getElementById("toast");
|
||
el.textContent = msg;
|
||
el.classList.add("show");
|
||
clearTimeout(toastTimer);
|
||
toastTimer = setTimeout(() => el.classList.remove("show"), ms);
|
||
}
|
||
|
||
// ── Bottom sheet ──
|
||
export function openSheet(html) {
|
||
const overlay = document.getElementById("sheet-overlay");
|
||
document.getElementById("sheet-content").innerHTML = html;
|
||
overlay.hidden = false;
|
||
overlay.setAttribute("aria-hidden", "false");
|
||
}
|
||
|
||
export function closeSheet() {
|
||
const overlay = document.getElementById("sheet-overlay");
|
||
overlay.hidden = true;
|
||
overlay.setAttribute("aria-hidden", "true");
|
||
document.getElementById("sheet-content").innerHTML = "";
|
||
}
|
||
|
||
export function isSheetOpen() {
|
||
return !document.getElementById("sheet-overlay").hidden;
|
||
}
|
||
|
||
// ── Camera ──
|
||
export function cameraShell() {
|
||
return `
|
||
<div id="camera-view">
|
||
<div class="stage">
|
||
<div class="frame ratio-43" id="cam-frame">
|
||
<video id="video" autoplay playsinline muted></video>
|
||
<div class="grid-lines" id="grid-lines"></div>
|
||
</div>
|
||
<div class="cam-top">
|
||
<button class="cam-chip ratio-chip" type="button" id="chip-ratio" data-action="toggle-ratio" aria-label="สลับอัตราส่วนภาพ 4:3 / 3:4">4:3</button>
|
||
<button class="cam-chip" type="button" data-action="toggle-grid" aria-label="เส้นแบ่ง 3 ส่วน">${ICON.grid}</button>
|
||
<button class="cam-chip" type="button" id="chip-torch" data-action="toggle-torch" aria-pressed="false" aria-label="ไฟแฟลช" hidden>${ICON.torch}</button>
|
||
<button class="cam-chip" type="button" data-action="switch-camera" aria-label="สลับกล้องหน้า/หลัง">${ICON.flip}</button>
|
||
</div>
|
||
</div>
|
||
<div class="cam-bottom">
|
||
<div class="zoom-pills" id="zoom-pills" hidden></div>
|
||
<div class="shutter-row">
|
||
<div class="shutter-side"><button class="thumb-btn" id="last-thumb" type="button" data-action="open-last" aria-label="รูปล่าสุด"></button></div>
|
||
<button id="shutter" type="button" data-action="shoot" aria-label="ถ่ายรูป"></button>
|
||
<div class="shutter-side"><span id="shot-count"></span></div>
|
||
</div>
|
||
</div>
|
||
<div id="cam-overlay"></div>
|
||
</div>`;
|
||
}
|
||
|
||
export function overlay(html) {
|
||
const el = document.getElementById("cam-overlay");
|
||
if (el) el.innerHTML = html;
|
||
}
|
||
|
||
export function hero(kind, { title, text = "", steps = [], action = null, note = "" }) {
|
||
const stepsHtml = steps.length
|
||
? `<ol>${steps.map((s) => `<li>${s}</li>`).join("")}</ol>`
|
||
: "";
|
||
const actionHtml = action
|
||
? `<button class="btn btn-primary" type="button" data-action="${action.act}">${action.label}</button>`
|
||
: "";
|
||
return `<div class="hero cover">
|
||
<div class="ico">${kind === "denied" ? ICON.block : kind === "insecure" ? ICON.lock : ICON.camera}</div>
|
||
<h2>${esc(title)}</h2>
|
||
${text ? `<p>${esc(text)}</p>` : ""}
|
||
${stepsHtml ? `<div class="notice" style="text-align:left">${stepsHtml}</div>` : ""}
|
||
${actionHtml}
|
||
${note ? `<p style="font-size:11px">${note}</p>` : ""}
|
||
</div>`;
|
||
}
|
||
|
||
export function syncCameraControls({ torchAvailable, torchOn, zoomRange, zoomValue, gridOn, count, thumbUrl, ready, ratio }) {
|
||
const chip = document.getElementById("chip-torch");
|
||
if (chip) {
|
||
chip.hidden = !torchAvailable;
|
||
chip.setAttribute("aria-pressed", torchOn ? "true" : "false");
|
||
}
|
||
|
||
const pills = document.getElementById("zoom-pills");
|
||
if (pills) {
|
||
const min = zoomRange ? Number(zoomRange.min) : 1;
|
||
const max = zoomRange ? Number(zoomRange.max) : 1;
|
||
if (zoomRange && max > min) {
|
||
const levels = [1, 2, 3].filter((z) => z >= min - 0.05 && z <= max + 0.05);
|
||
if (!levels.length) levels.push(min);
|
||
const current = zoomValue ?? min;
|
||
pills.hidden = false;
|
||
pills.innerHTML = levels
|
||
.map(
|
||
(z) =>
|
||
`<button class="zoom-pill ${Math.abs(current - z) < 0.25 ? "on" : ""}" type="button" data-action="zoom-set" data-zoom="${z}" aria-label="ซูม ${z} เท่า" aria-pressed="${Math.abs(current - z) < 0.25}">${z}×</button>`
|
||
)
|
||
.join("");
|
||
} else {
|
||
pills.hidden = true;
|
||
pills.innerHTML = "";
|
||
}
|
||
}
|
||
|
||
const frame = document.getElementById("cam-frame");
|
||
const ratioChip = document.getElementById("chip-ratio");
|
||
if (frame) {
|
||
const portrait = ratio === "3:4";
|
||
frame.classList.toggle("ratio-43", !portrait);
|
||
frame.classList.toggle("ratio-34", portrait);
|
||
}
|
||
if (ratioChip) ratioChip.textContent = ratio || "4:3";
|
||
|
||
const grid = document.getElementById("grid-lines");
|
||
if (grid) grid.classList.toggle("on", !!gridOn);
|
||
const cnt = document.getElementById("shot-count");
|
||
if (cnt) cnt.textContent = count ? count + " รูป" : "";
|
||
const thumb = document.getElementById("last-thumb");
|
||
if (thumb && thumbUrl) thumb.innerHTML = `<img src="${thumbUrl}" alt="รูปล่าสุด">`;
|
||
const sh = document.getElementById("shutter");
|
||
if (sh) sh.disabled = !ready;
|
||
}
|
||
|
||
// ── Folders ──
|
||
export function renderFolders({ folders, counts, activeId, storage }) {
|
||
const total = counts.reduce((a, b) => a + b, 0);
|
||
let html = `<div class="folder-view"><div class="section-head">
|
||
<div><h2>โฟลเดอร์</h2><div class="sub">${folders.length} โฟลเดอร์ · ${total} รูป</div></div>
|
||
<div class="head-btns">
|
||
<button class="btn btn-ghost" type="button" data-action="csv-sheet">CSV</button>
|
||
<button class="btn btn-primary" type="button" data-action="new-folder">+ โฟลเดอร์ใหม่</button>
|
||
</div>
|
||
</div>`;
|
||
|
||
if (!folders.length) {
|
||
html += `<div class="empty"><span class="ico">${ICON.folder}</span>ยังไม่มีโฟลเดอร์</div>`;
|
||
} else {
|
||
html += `<div class="folder-list">`;
|
||
folders.forEach((f, i) => {
|
||
const active = f.id === activeId;
|
||
html += `<div class="folder-item ${active ? "active" : ""}" data-action="select-folder" data-id="${esc(f.id)}" role="button" tabindex="0" aria-label="โฟลเดอร์ ${esc(f.name)} · ${counts[i]} รูป">
|
||
<span class="f-ico" aria-hidden="true">${ICON.folder}</span>
|
||
<div class="f-main">
|
||
<div class="f-name">${esc(f.name)}</div>
|
||
<div class="f-meta">${counts[i]} รูป${active ? " · ใช้งานอยู่" : ""}</div>
|
||
</div>
|
||
<div class="f-actions">
|
||
<button class="icon-btn" type="button" data-action="rename-folder" data-id="${esc(f.id)}" aria-label="เปลี่ยนชื่อโฟลเดอร์">${ICON.pencil}</button>
|
||
<button class="icon-btn danger" type="button" data-action="delete-folder" data-id="${esc(f.id)}" aria-label="ลบโฟลเดอร์">${ICON.trash}</button>
|
||
</div>
|
||
</div>`;
|
||
});
|
||
html += `</div>`;
|
||
}
|
||
|
||
html += `<div class="folder-bulk">
|
||
<button class="btn btn-ghost btn-block" type="button" data-action="zip-all">${ICON.zip} ZIP ทุกโฟลเดอร์ (${total} รูป)</button>
|
||
</div>`;
|
||
|
||
html += `<div class="storage-line">
|
||
พื้นที่เก็บในเครื่อง${storage ? ` · ใช้ ${fmtBytes(storage.usage)} จาก ${fmtBytes(storage.quota)}` : ""}
|
||
<br><button class="btn btn-ghost" type="button" style="min-height:34px;height:34px;font-size:11px;margin-top:8px" data-action="diagnostics">ข้อมูลอุปกรณ์และกล้อง</button>
|
||
<button class="btn btn-ghost" type="button" style="min-height:34px;height:34px;font-size:11px;margin-top:8px;margin-left:6px" data-action="show-qr">QR ลิงก์ทดสอบ</button>
|
||
</div>`;
|
||
|
||
html += `</div>`;
|
||
return html;
|
||
}
|
||
|
||
// ── Gallery ──
|
||
export function renderGallery({ folder, images, thumbUrl }) {
|
||
const bytes = images.reduce((a, i) => a + (i.size || i.blob?.size || 0), 0);
|
||
let html = `<div class="gallery-view"><div class="section-head">
|
||
<div><h2>${esc(folder ? folder.name : "ยังไม่เลือกโฟลเดอร์")}</h2>
|
||
<div class="sub">${images.length} รูป · ${fmtBytes(bytes)}</div></div>
|
||
</div>`;
|
||
|
||
if (!folder) {
|
||
return html + `<div class="empty"><span class="ico">${ICON.folder}</span>เลือกโฟลเดอร์ก่อน</div></div>`;
|
||
}
|
||
if (!images.length) {
|
||
return html + `<div class="empty"><span class="ico">${ICON.image}</span>ยังไม่มีรูปในโฟลเดอร์นี้</div></div>`;
|
||
}
|
||
|
||
html += `<div class="gallery-grid">`;
|
||
images.forEach((img) => {
|
||
html += `<button class="gallery-item" type="button" data-action="open-photo" data-id="${esc(img.id)}">
|
||
<img src="${thumbUrl(img)}" alt="${esc(img.name || "")}" loading="lazy" decoding="async">
|
||
</button>`;
|
||
});
|
||
html += `</div>`;
|
||
|
||
html += `<div class="action-bar">
|
||
<button class="btn btn-primary btn-block" type="button" data-action="zip-download">${ICON.zip} ZIP โฟลเดอร์นี้ (${images.length} รูป)</button>
|
||
</div></div>`;
|
||
return html;
|
||
}
|
||
|
||
// ── Photo sheet ──
|
||
export function photoSheet({ record, url, folderName }) {
|
||
const m = record.meta || {};
|
||
const rows = [
|
||
["ไฟล์", record.name || "-"],
|
||
["ขนาด", fmtBytes(record.size || record.blob?.size || 0)],
|
||
["ความละเอียด", m.width && m.height ? `${m.width} × ${m.height} (${(m.width * m.height / 1e6).toFixed(1)} MP)` : "—"],
|
||
["ถ่ายเมื่อ", humanDateTime(record.createdAt)],
|
||
["โฟลเดอร์", folderName || "-"],
|
||
["อุปกรณ์", m.device || "—"],
|
||
["กล้อง", m.facingLabel || "—"],
|
||
["ที่มาไฟล์", m.sourceLabel || "—"],
|
||
];
|
||
if (m.gps) rows.push(["พิกัด GPS", `${m.gps.lat.toFixed(6)}, ${m.gps.lng.toFixed(6)}${m.gps.accuracy ? ` (±${Math.round(m.gps.accuracy)} ม.)` : ""}`]);
|
||
if (m.exif && (m.exif.fNumber || m.exif.iso || m.exif.exposureTime)) rows.push(["ค่าแสง EXIF", formatExposure(m.exif)]);
|
||
if (m.exif?.model) {
|
||
const make = (m.exif.make || "").trim();
|
||
const model = m.exif.model.trim();
|
||
const label = make && !model.toLowerCase().startsWith(make.toLowerCase()) ? `${make} ${model}` : model;
|
||
rows.push(["รุ่นใน EXIF", label]);
|
||
}
|
||
if (m.exif?.orientation) rows.push(["Orientation", String(m.exif.orientation)]);
|
||
if (m.exif?.dateTimeOriginal) rows.push(["EXIF DateTimeOriginal", m.exif.dateTimeOriginal]);
|
||
if (m.exif?.software) rows.push(["Software", m.exif.software]);
|
||
if (m.exif?.gps?.dateStamp) {
|
||
const t = Array.isArray(m.exif.gps.timeStamp) ? m.exif.gps.timeStamp.map((x) => String(Math.round(x)).padStart(2, "0")).join(":") : "";
|
||
rows.push(["GPS date/time", `${m.exif.gps.dateStamp}${t ? " " + t : ""}`]);
|
||
}
|
||
if (m.exif?.uniqueId) rows.push(["ImageUniqueID", m.exif.uniqueId.slice(0, 16) + "…"]);
|
||
|
||
const rowsHtml = rows
|
||
.map(([k, v]) => `<div class="row"><span class="k">${esc(k)}</span><span class="v">${esc(v)}</span></div>`)
|
||
.join("");
|
||
|
||
return `
|
||
<h3>${esc(record.name || "รูปภาพ")}</h3>
|
||
<div class="hint">${esc(humanDateTime(record.createdAt))}</div>
|
||
<img class="preview" src="${url}" alt="">
|
||
<div class="meta-table">${rowsHtml}</div>
|
||
<div class="hint" style="margin-top:10px;margin-bottom:0">ข้อมูลทั้งหมดฝังอยู่ในไฟล์ JPEG (EXIF) แล้ว — ติดไปกับรูปตอนแชร์/ดาวน์โหลด ไม่มีไฟล์แยก</div>
|
||
<div class="sheet-actions" style="margin-top:14px">
|
||
<button class="btn btn-ghost" type="button" data-action="rotate-photo" data-id="${esc(record.id)}" data-dir="-90" aria-label="หมุนซ้าย 90 องศา">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12a10 10 0 1 0 3-7"/><path d="M2 3v6h6"/></svg>
|
||
ซ้าย
|
||
</button>
|
||
<button class="btn btn-ghost" type="button" data-action="rotate-photo" data-id="${esc(record.id)}" data-dir="90" aria-label="หมุนขวา 90 องศา">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 12a10 10 0 1 1-3-7"/><path d="M22 3v6h-6"/></svg>
|
||
ขวา
|
||
</button>
|
||
</div>
|
||
<div class="sheet-actions" style="margin-top:8px">
|
||
<button class="btn btn-ghost" type="button" data-action="close-sheet">ปิด</button>
|
||
<button class="btn btn-primary" type="button" data-action="share-photo" data-id="${esc(record.id)}">${ICON.share} แชร์รูปนี้</button>
|
||
</div>
|
||
<div class="sheet-actions" style="margin-top:8px">
|
||
<button class="btn btn-danger btn-block" type="button" data-action="delete-photo" data-id="${esc(record.id)}">${ICON.trash} ลบรูปนี้</button>
|
||
</div>`;
|
||
}
|
||
|
||
// ── Folder sheet ──
|
||
export function folderSheet(mode, { id = "", name = "", suggested = "", count = 0 }) {
|
||
if (mode === "delete") {
|
||
return `<h3>ลบโฟลเดอร์นี้?</h3>
|
||
<div class="hint">"${esc(name)}" · ${count} รูป จะถูกลบทั้งหมดและกู้คืนไม่ได้</div>
|
||
<div class="sheet-actions">
|
||
<button class="btn btn-ghost" type="button" data-action="close-sheet">ยกเลิก</button>
|
||
<button class="btn btn-danger" type="button" data-action="confirm-delete-folder" data-id="${esc(id)}">ลบ</button>
|
||
</div>`;
|
||
}
|
||
const isNew = mode === "new";
|
||
return `<h3>${isNew ? "โฟลเดอร์ใหม่" : "เปลี่ยนชื่อโฟลเดอร์"}</h3>
|
||
<div class="hint">ชื่อเริ่มต้น = Site + ตัวอักษรถัดไป + ปี.เดือน.วัน.ชั่วโมง.นาที (แก้ได้)</div>
|
||
<input id="folder-name-input" type="text" inputmode="text" autocomplete="off"
|
||
value="${esc(isNew ? suggested : name)}" placeholder="Site a 2569.10.25.21.45">
|
||
${isNew ? `<div class="hint" style="margin-top:-6px">ถ้าชื่อซ้ำ ระบบจะเติม (2) ให้อัตโนมัติ</div>` : ""}
|
||
<div class="sheet-actions">
|
||
<button class="btn btn-ghost" type="button" data-action="close-sheet">ยกเลิก</button>
|
||
<button class="btn btn-primary" type="button" data-action="${isNew ? "confirm-new-folder" : "confirm-rename-folder"}" data-id="${esc(id)}">
|
||
${isNew ? "สร้าง" : "บันทึก"}
|
||
</button>
|
||
</div>`;
|
||
}
|
||
|
||
// ── QR ลิงก์ทดสอบบนมือถือ ────────────────────────────
|
||
export function qrSheet(url) {
|
||
return `<h3>ทดสอบบนมือถือ</h3>
|
||
<div class="hint">สแกนด้วยกล้อง Samsung S23 แล้วเปิดใน Chrome</div>
|
||
<div class="qr-box"><div id="qr-holder"></div></div>
|
||
<div class="qr-url">${esc(url)}</div>
|
||
<div class="hint">กล้องใช้ได้เฉพาะหน้า HTTPS — ถ้าลิงก์ขึ้นต้น http:// กล้องจะถูกบล็อก</div>
|
||
<div class="sheet-actions">
|
||
<button class="btn btn-ghost" type="button" data-action="copy-url">คัดลอกลิงก์</button>
|
||
<button class="btn btn-primary" type="button" data-action="zip-share">${ICON.share} แชร์ ZIP</button>
|
||
</div></div>`;
|
||
}
|
||
|
||
// ── CSV import ──────────────────────────────────────────────
|
||
export function csvSheet() {
|
||
return `<h3>นำเข้าโฟลเดอร์จาก CSV</h3>
|
||
<div class="hint">สร้างทีละหลายโฟลเดอร์ในครั้งเดียว — ชื่อที่ได้จะใช้กฎ Site + ตัวอักษร + ปี.เดือน.วัน.ชั่วโมง.นาที</div>
|
||
<div class="meta-table">
|
||
<div class="row"><span class="k">site</span><span class="v">คำนำหน้า เช่น Site (เว้นว่าง = Site)</span></div>
|
||
<div class="row"><span class="k">letter</span><span class="v">a…z, aa… (เว้นว่าง = ไล่ต่ออัตโนมัติ)</span></div>
|
||
<div class="row"><span class="k">datetime</span><span class="v">2569.10.25.21.45</span></div>
|
||
<div class="row"><span class="k">name</span><span class="v">ชื่อเต็ม (ถ้าใส่ จะทับชื่อที่ประกอบ)</span></div>
|
||
</div>
|
||
<div class="hint" style="margin-top:12px">ตัวอย่างแถว<br><code>Site,a,2569.10.25.21.45,</code><br><code>Site,b,2569.10.25.22.10,</code></div>
|
||
<div class="sheet-actions" style="margin-top:12px">
|
||
<a class="btn btn-ghost" href="templates/folders-template.csv" download="folders-template.csv">ไฟล์เปล่า</a>
|
||
<button class="btn btn-primary" type="button" data-action="pick-csv">เลือกไฟล์ CSV</button>
|
||
</div>
|
||
<div class="sheet-actions" style="margin-top:8px">
|
||
<button class="btn btn-ghost btn-block" type="button" data-action="close-sheet">ปิด</button>
|
||
</div>`;
|
||
}
|
||
|
||
export function importResultSheet({ created, skipped, errors = [], total }) {
|
||
const list = errors.length
|
||
? `<div class="notice" style="margin:12px 0 0">
|
||
<b>ข้าม ${skipped} แถว</b>
|
||
<ol>${errors.slice(0, 12).map((e) => `<li>แถว ${e.row}: ${esc(e.reason)}</li>`).join("")}</ol>
|
||
${errors.length > 12 ? `<div style="margin-top:6px">…อีก ${errors.length - 12} แถว</div>` : ""}
|
||
</div>`
|
||
: "";
|
||
return `<h3>สร้างโฟลเดอร์แล้ว ${created} รายการ</h3>
|
||
<div class="hint">อ่าน ${total} แถว · สำเร็จ ${created} · ข้าม ${skipped}</div>
|
||
${list}
|
||
<div class="sheet-actions" style="margin-top:14px">
|
||
<button class="btn btn-primary btn-block" type="button" data-action="close-sheet">เรียบร้อย</button>
|
||
</div>`;
|
||
}
|
||
|
||
// ── พร้อมแชร์ (หลังสร้าง ZIP) ────────────────────────────────
|
||
export function shareReadySheet({ name, size, canShare, reason }) {
|
||
const status = canShare ? "พร้อมส่งเข้าแอปอื่น" : "เบราว์เซอร์นี้ไม่รองรับการแชร์ไฟล์";
|
||
const note = canShare
|
||
? "แตะปุ่มด้านล่างเพื่อเปิด share sheet ของ Samsung"
|
||
: "บันทึกไฟล์แล้วแชร์ผ่าน Files/My Files หรือเปิดด้วย Chrome";
|
||
return `<h3>ZIP พร้อมแล้ว</h3>
|
||
<div class="meta-table">
|
||
<div class="row"><span class="k">ไฟล์</span><span class="v">${esc(name)}</span></div>
|
||
<div class="row"><span class="k">ขนาด</span><span class="v">${esc(fmtBytes(size))}</span></div>
|
||
<div class="row"><span class="k">การแชร์</span><span class="v">${esc(status)}</span></div>
|
||
</div>
|
||
<div class="hint" style="margin-top:12px">${esc(note)}${reason ? " · " + esc(reason) : ""}</div>
|
||
<div class="sheet-actions">
|
||
<button class="btn btn-ghost" type="button" data-action="save-zip">บันทึกไฟล์</button>
|
||
<button class="btn btn-primary" type="button" data-action="share-zip-now" ${canShare ? "" : "disabled"}>แชร์ไปแอปอื่น</button>
|
||
</div>
|
||
<div class="sheet-actions" style="margin-top:8px">
|
||
<button class="btn btn-ghost btn-block" type="button" data-action="close-sheet">ปิด</button>
|
||
</div>`;
|
||
}
|
||
|
||
// ── Diagnostics ──
|
||
export function diagnosticsSheet(rows) {
|
||
const body = rows
|
||
.map(([k, v]) => `<div class="row"><span class="k">${esc(k)}</span><span class="v">${esc(v)}</span></div>`)
|
||
.join("");
|
||
return `<h3>ข้อมูลอุปกรณ์และกล้อง</h3>
|
||
<div class="hint">ใช้ตรวจว่ารันบน S23 จริงและกล้องได้ความละเอียดเท่าไร</div>
|
||
<div class="meta-table">${body}</div>
|
||
<div class="sheet-actions" style="margin-top:14px">
|
||
<button class="btn btn-ghost btn-block" type="button" data-action="close-sheet">ปิด</button>
|
||
</div>`;
|
||
}
|
||
|
||
// ── Progress ──
|
||
export function progressSheet(label) {
|
||
openSheet(`<div class="progress-card" id="progress-card">
|
||
<div class="spinner"></div>
|
||
<div class="label" id="progress-label">${esc(label)}</div>
|
||
</div>`);
|
||
}
|
||
|
||
export function progressUpdate(pct, label) {
|
||
const card = document.getElementById("progress-card");
|
||
if (!card) return;
|
||
const p = Math.max(0, Math.min(100, Math.round(pct)));
|
||
card.innerHTML = `<div class="spinner"></div><div class="label">${esc(label || "")} ${p}%</div>`;
|
||
}
|