feat(files): photo-style cards with main-design buttons and links
This commit is contained in:
+18
-5
@@ -6,10 +6,23 @@
|
|||||||
<title>Файлы — Админ-панель</title>
|
<title>Файлы — Админ-панель</title>
|
||||||
<link rel="stylesheet" href="admin.css">
|
<link rel="stylesheet" href="admin.css">
|
||||||
<style>
|
<style>
|
||||||
.file-icon{width:80px;height:80px;border-radius:8px;background:var(--bg);border:1px solid var(--border);display:flex;align-items:center;justify-content:center;font-size:1.6rem;flex-shrink:0;color:var(--muted)}
|
.ph-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:14px}
|
||||||
.file-name{font-weight:600;font-size:.95rem}
|
.ph-card{background:var(--card);border:1px solid var(--border);border-radius:12px;overflow:hidden;display:flex;flex-direction:column;min-width:0;transition:box-shadow .15s ease}
|
||||||
.file-name a{color:var(--text);text-decoration:none}
|
.ph-card:hover{box-shadow:0 4px 12px rgba(0,0,0,.06)}
|
||||||
.file-name a:hover{color:var(--accent)}
|
.ph-card img{width:100%;aspect-ratio:4/3;object-fit:cover;display:block;cursor:zoom-in;background:var(--bg);transition:opacity .15s}
|
||||||
|
.ph-card:hover img{opacity:.9}
|
||||||
|
.ph-card .ph-body{padding:10px 12px;display:flex;flex-direction:column;gap:4px;min-width:0}
|
||||||
|
.ph-badge{align-self:flex-start;background:var(--bg);border:1px solid var(--border);color:var(--muted);border-radius:999px;padding:2px 8px;font-size:.68rem;font-weight:700}
|
||||||
|
.ph-title{font-size:.82rem;font-weight:600;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;word-break:break-word}
|
||||||
|
.ph-meta{font-size:.72rem;color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.ph-time{font-size:.7rem;color:var(--muted)}
|
||||||
|
.ph-card .ph-link{color:var(--accent);font-size:.78rem;font-weight:500;text-decoration:none;transition:color .15s ease}
|
||||||
|
.ph-card .ph-link:hover{color:#1d4ed8;text-decoration:underline}
|
||||||
|
.ph-card .ph-action{background:var(--bg);border:1px solid var(--border);color:var(--accent);border-radius:8px;padding:6px 10px;font-size:.8rem;font-weight:600;cursor:pointer;white-space:nowrap;transition:border-color .15s ease,color .15s ease,background .15s ease}
|
||||||
|
.ph-card .ph-action:hover{background:rgba(37,99,235,.06);border-color:var(--accent);color:var(--accent)}
|
||||||
|
.ph-card .ph-action--danger{color:#ef4444}
|
||||||
|
.ph-card .ph-action--danger:hover{background:rgba(239,68,68,.07);border-color:#ef4444;color:#ef4444}
|
||||||
|
.ph-card__placeholder{width:100%;aspect-ratio:4/3;background:var(--bg);border:1px solid var(--border);border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:2rem;color:var(--muted)}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body data-page="files">
|
<body data-page="files">
|
||||||
@@ -30,7 +43,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid" id="grid"><div class="empty">Загрузка...</div></div>
|
<div class="ph-grid" id="grid"><div class="empty" style="grid-column:1/-1">Загрузка...</div></div>
|
||||||
<div class="pager" id="pager"></div>
|
<div class="pager" id="pager"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+19
-18
@@ -34,26 +34,25 @@ function humanSize(b) {
|
|||||||
function fileCardHTML(f) {
|
function fileCardHTML(f) {
|
||||||
const url = `${API}/api/files/${f.token}`;
|
const url = `${API}/api/files/${f.token}`;
|
||||||
const thumb = isImageFile(f.name)
|
const thumb = isImageFile(f.name)
|
||||||
? `<img src="${thumbSrc(url)}" data-img="${esc(url)}" loading="lazy" decoding="async" alt="">`
|
? `<img src="${esc(thumbSrc(url))}" data-img="${esc(url)}" loading="lazy" decoding="async" alt="">`
|
||||||
: `<div class="file-icon">📄</div>`;
|
: `<div class="ph-card__placeholder">📄</div>`;
|
||||||
const target = isImageFile(f.name)
|
|
||||||
? `href="#" data-img="${esc(url)}"`
|
|
||||||
: `href="${url}" download`;
|
|
||||||
const meta = mode === 'detached'
|
const meta = mode === 'detached'
|
||||||
? `<div class="group" style="color:#f59e0b">Откреплён от записи, не привязан</div>`
|
? '<div class="ph-meta">Откреплён от записи, не привязан</div>'
|
||||||
: `<div class="group">${esc(f.student_name)} · ${esc(f.group_name)}</div>`;
|
: `<div class="ph-meta">${esc(f.student_name || '')} · ${esc(f.group_name || '')}</div>`;
|
||||||
|
const time = `<div class="ph-time">${fmtFull(f.created_at)}${f.size ? ' · ' + humanSize(f.size) : ''}</div>`;
|
||||||
const action = mode === 'detached'
|
const action = mode === 'detached'
|
||||||
? `<button class="f-action f-del" data-delete="${f.id}" title="Удалить файл навсегда">Удалить</button>`
|
? `<button class="ph-action ph-action--danger" data-delete="${f.id}" title="Удалить файл навсегда">Удалить</button>`
|
||||||
: `<button class="f-action" data-detach="${f.id}" title="Открепить файл от записи">Открепить</button>`;
|
: `<button class="ph-action" data-detach="${f.id}" title="Открепить от записи">Открепить</button>`;
|
||||||
return `
|
return `
|
||||||
<div class="card">
|
<div class="ph-card">
|
||||||
${thumb}
|
${thumb}
|
||||||
<div class="info">
|
<div class="ph-body">
|
||||||
<div class="file-name"><a ${target}>${esc(f.name)}</a></div>
|
<span class="ph-badge">📎 Файл</span>
|
||||||
|
<div class="ph-title">${isImageFile(f.name) ? esc(f.name) : `<a href="${url}" download class="ph-link">${esc(f.name)}</a>`}</div>
|
||||||
${meta}
|
${meta}
|
||||||
<div class="time">${fmtFull(f.created_at)}${f.size ? ' · ' + humanSize(f.size) : ''}</div>
|
${time}
|
||||||
|
${action}
|
||||||
</div>
|
</div>
|
||||||
<div class="f-actions">${action}</div>
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -61,16 +60,18 @@ function fileCardHTML(f) {
|
|||||||
function renderGrid() {
|
function renderGrid() {
|
||||||
const grid = document.getElementById('grid');
|
const grid = document.getElementById('grid');
|
||||||
if (!currentFiles.length) {
|
if (!currentFiles.length) {
|
||||||
grid.className = 'grid';
|
grid.className = 'ph-grid';
|
||||||
grid.innerHTML = mode === 'detached'
|
grid.innerHTML = mode === 'detached'
|
||||||
? '<div class="empty">Откреплённых файлов нет</div>'
|
? '<div class="empty" style="grid-column:1/-1">Откреплённых файлов нет</div>'
|
||||||
: '<div class="empty">Файлов не найдено</div>';
|
: '<div class="empty" style="grid-column:1/-1">Файлов не найдено</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
grid.className = 'grid';
|
grid.className = 'ph-grid';
|
||||||
grid.innerHTML = currentFiles.map(fileCardHTML).join('');
|
grid.innerHTML = currentFiles.map(fileCardHTML).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function detachFile(id) {
|
async function detachFile(id) {
|
||||||
if (!confirm('Открепить файл от записи? Он переместится во вкладку «Откреплённые».')) return;
|
if (!confirm('Открепить файл от записи? Он переместится во вкладку «Откреплённые».')) return;
|
||||||
const res = await fetch(`${API}/api/files/${id}/detach`, { method: 'POST', headers: hdr() });
|
const res = await fetch(`${API}/api/files/${id}/detach`, { method: 'POST', headers: hdr() });
|
||||||
|
|||||||
Reference in New Issue
Block a user