481 lines
26 KiB
HTML
481 lines
26 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Promptly — студия презентаций</title>
|
||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect width='100' height='100' rx='24' fill='%234cc2ff'/%3E%3Crect x='26' y='34' width='48' height='10' rx='5' fill='%23000'/%3E%3Crect x='26' y='54' width='32' height='10' rx='5' fill='%23000'/%3E%3C/svg%3E">
|
||
<style>
|
||
:root {
|
||
--accent: #4cc2ff;
|
||
--accent-soft: rgba(76, 194, 255, .12);
|
||
--glass: rgba(30, 30, 30, .55);
|
||
--glass-deep: rgba(20, 20, 25, .68);
|
||
--border: rgba(255, 255, 255, .08);
|
||
--text: #e5e5e5;
|
||
--muted: #aaa;
|
||
--dim: #777;
|
||
--danger: #ff6b6b;
|
||
--ease: cubic-bezier(.4, 0, .2, 1);
|
||
--shadow: 0 4px 20px rgba(0, 0, 0, .25);
|
||
}
|
||
* { box-sizing: border-box; }
|
||
html, body { margin: 0; }
|
||
body {
|
||
min-height: 100vh; color: var(--text);
|
||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||
background: #0d0d10 url('/img/bipfr-bg.png') center / cover fixed no-repeat;
|
||
}
|
||
button { border: none; border-radius: 8px; padding: 9px 16px; font: inherit; font-size: 13px; cursor: pointer; transition: all .2s var(--ease); background: rgba(255,255,255,.08); color: #c5c5c5; }
|
||
button:hover:not(:disabled) { background: rgba(255,255,255,.12); color: #fff; transform: translateY(-1px); }
|
||
button:active:not(:disabled) { transform: scale(.94); background: rgba(255,255,255,.08); }
|
||
button:disabled { opacity: .35; cursor: default; }
|
||
input { font: inherit; }
|
||
code { color: var(--accent); }
|
||
|
||
.shell { max-width: 1200px; margin: 0 auto; padding: 88px 20px 60px; }
|
||
header {
|
||
position: fixed; top: 7px; left: 7px; right: 7px; z-index: 100;
|
||
height: 48px; padding: 0 8px;
|
||
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
||
background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
|
||
border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
|
||
}
|
||
.logo { font-size: 17px; font-weight: 700; letter-spacing: .3px; color: #fff; display: flex; align-items: center; gap: 9px; }
|
||
.logo-mark { width: 12px; height: 12px; border-radius: 4px; background: var(--accent); box-shadow: 0 0 10px rgba(76,194,255,.7); }
|
||
.logo span { color: var(--accent); }
|
||
.logo small { font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted); font-weight: 700; background: rgba(255,255,255,.06); border: 1px solid var(--border); padding: 3px 7px; border-radius: 999px; }
|
||
.status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
|
||
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4cd137; box-shadow: 0 0 10px #4cd137; }
|
||
.dot.off { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
|
||
|
||
.hero {
|
||
text-align: center; padding: 46px 20px 40px; margin-bottom: 30px;
|
||
background: rgba(30, 30, 30, .4); border-radius: 24px; border: 1px solid rgba(255, 255, 255, .05);
|
||
backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
|
||
}
|
||
.dash-title h1 { font-size: 2.5rem; margin: 0 0 10px; color: #fff; font-weight: 700; letter-spacing: -.5px; }
|
||
.dash-title h1 em { font-style: normal; color: var(--accent); }
|
||
.dash-title p { margin: 0 0 26px; color: var(--muted); font-size: 1.1rem; }
|
||
.dash-actions { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
|
||
.dash-actions .link { font-size: 13px; color: #c5c5c5; text-decoration: none; padding: 10px 18px; border-radius: 8px; background: rgba(255,255,255,.06); border: 1px solid var(--border); transition: all .2s var(--ease); cursor: pointer; }
|
||
.dash-actions .link:hover { background: rgba(255,255,255,.12); color: #fff; transform: translateY(-1px); }
|
||
.create-btn { font-size: 14px; padding: 12px 28px; border-radius: 12px; font-weight: 600; background: var(--accent); color: #000; }
|
||
.create-btn:hover { background: var(--accent); transform: scale(1.05); box-shadow: 0 0 20px rgba(76, 194, 255, .4); color: #000; }
|
||
|
||
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px; margin: 34px 0 0; }
|
||
.stat-card { background: rgba(0, 0, 0, .2); padding: 20px; border-radius: 16px; display: flex; flex-direction: column; align-items: center; border: 1px solid rgba(255, 255, 255, .05); }
|
||
.stat-card b { font-size: 2.5rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
|
||
.stat-card span { color: #888; font-size: .9rem; margin-top: 5px; }
|
||
|
||
.tabs { display: flex; gap: 6px; margin: 0 0 18px; flex-wrap: wrap; align-items: center; background: var(--glass); border: 1px solid var(--border); border-radius: 12px; padding: 6px; backdrop-filter: blur(16px); width: fit-content; }
|
||
.tab { padding: 9px 16px; border-radius: 8px; border: none; background: transparent; color: #c5c5c5; cursor: pointer; font: inherit; font-size: 13.5px; transition: all .2s var(--ease); display: flex; align-items: center; gap: 8px; position: relative; white-space: nowrap; }
|
||
.tab:hover { background: rgba(255, 255, 255, .12); color: #fff; transform: translateY(-1px); }
|
||
.tab.active { background: rgba(255, 255, 255, .08); color: #fff; font-weight: 600; }
|
||
.tab.active::after { content: ''; position: absolute; bottom: 3px; left: 16px; right: 16px; height: 3px; background: var(--accent); border-radius: 2px; box-shadow: 0 0 6px rgba(76, 194, 255, .5); animation: expandFromCenter .4s cubic-bezier(.25, .8, .25, 1) forwards; }
|
||
@keyframes expandFromCenter { from { transform: scaleX(0); opacity: 0; } to { transform: scaleX(1); opacity: 1; } }
|
||
.badge { background: rgba(255, 255, 255, .14); border-radius: 999px; padding: 1px 8px; font-size: 11px; min-width: 21px; text-align: center; }
|
||
|
||
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
|
||
.search-wrap { position: relative; flex: 1; max-width: 380px; min-width: 200px; }
|
||
.search-wrap::before { content: ''; position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; border: 2px solid #666; border-radius: 50%; box-shadow: 6px 6px 0 -4px #666; }
|
||
.search { width: 100%; padding: 11px 14px 11px 38px; border-radius: 8px; font-size: 13.5px; background: rgba(0, 0, 0, .3); border: 1px solid var(--border); color: var(--text); }
|
||
.search::placeholder { color: #666; }
|
||
.search:focus { outline: 2px solid rgba(76, 194, 255, .55); border-color: transparent; }
|
||
.toolbar .muted { margin-left: auto; }
|
||
|
||
.panel { display: none; } .panel.active { display: block; animation: fade .25s ease; }
|
||
@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
|
||
|
||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
|
||
.card { background: var(--glass-deep); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: transform .3s ease, box-shadow .3s ease, border-color .3s ease; }
|
||
.card:hover { border-color: rgba(76, 194, 255, .45); transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0, 0, 0, .4); }
|
||
.thumb { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #101014; border-bottom: 1px solid rgba(255,255,255,.06); }
|
||
.thumb-canvas { position: absolute; inset: 0; }
|
||
.thumb-chips { position: absolute; top: 9px; left: 9px; right: 9px; display: flex; align-items: center; gap: 6px; pointer-events: none; }
|
||
.chip { font-size: 10.5px; color: #e2e2e2; background: rgba(10, 10, 15, .72); border: 1px solid rgba(255,255,255,.14); padding: 3px 8px; border-radius: 6px; backdrop-filter: blur(8px); }
|
||
.chip.live { margin-left: auto; color: #000; background: var(--accent); border-color: var(--accent); font-weight: 700; display: inline-flex; align-items: center; gap: 5px; }
|
||
.chip.live .dot { width: 6px; height: 6px; background: #000; box-shadow: none; animation: pulse 1.2s infinite; }
|
||
@keyframes pulse { 50% { opacity: .25; } }
|
||
|
||
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 11px; flex: 1; }
|
||
.card-body h3 { margin: 0; font-size: 16.5px; line-height: 1.3; color: #fff; }
|
||
.muted { color: var(--muted); font-size: 12px; }
|
||
.actions { display: flex; gap: 7px; flex-wrap: wrap; }
|
||
.actions .grow { flex: 1; }
|
||
.primary { background: var(--accent); color: #000; font-weight: 600; }
|
||
.primary:hover:not(:disabled) { background: var(--accent); color: #000; box-shadow: 0 0 16px rgba(76, 194, 255, .35); }
|
||
.ghost { background: rgba(255,255,255,.07); }
|
||
.danger { background: rgba(255, 107, 107, .15); color: #ff8e8e; border: 1px solid rgba(255, 107, 107, .32); }
|
||
.danger:hover:not(:disabled) { background: rgba(255, 107, 107, .25); color: #ffb3b3; }
|
||
.icon-btn { padding: 9px 12px; }
|
||
|
||
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--accent); }
|
||
.live .dot { width: 7px; height: 7px; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1.2s infinite; }
|
||
.empty { color: var(--dim); padding: 52px 20px; text-align: center; border: 1px dashed rgba(255, 255, 255, .12); border-radius: 16px; font-size: 13.5px; line-height: 1.6; }
|
||
.empty b { color: var(--accent); }
|
||
|
||
.session-card { padding: 18px; display: flex; flex-direction: column; gap: 13px; }
|
||
.session-top { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
|
||
.session-top h3 { margin: 0 0 6px; font-size: 16.5px; color: #fff; }
|
||
.progress { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .08); overflow: hidden; }
|
||
.progress > div { height: 100%; border-radius: 999px; background: var(--accent); box-shadow: 0 0 8px rgba(76,194,255,.6); transition: width .3s; }
|
||
.session-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); align-items: center; }
|
||
.viewers { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; color: var(--accent); font-size: 13px; }
|
||
.session-actions { display: flex; gap: 7px; flex-wrap: wrap; }
|
||
.session-actions button { flex: 1; min-width: 110px; }
|
||
|
||
.toast {
|
||
position: fixed; right: 30px; bottom: 30px; transform: translateY(-20px) scale(.9);
|
||
background: rgba(30, 30, 30, .85); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
|
||
border: 1px solid var(--border); color: var(--text); padding: 16px 20px; border-radius: 12px;
|
||
font-size: 13.5px; z-index: 9999; opacity: 0; pointer-events: none;
|
||
transition: all .3s var(--ease); max-width: min(400px, 80vw); box-shadow: var(--shadow);
|
||
}
|
||
.toast.visible { opacity: 1; transform: translateY(0) scale(1); }
|
||
|
||
.foot { margin-top: 44px; color: #666; font-size: 11.5px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; border-top: 1px solid rgba(255,255,255,.06); padding-top: 16px; }
|
||
|
||
::-webkit-scrollbar { width: 10px; height: 10px; }
|
||
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 999px; }
|
||
::-webkit-scrollbar-track { background: transparent; }
|
||
|
||
@media (max-width: 760px) {
|
||
.shell { padding: 108px 12px 40px; }
|
||
header { flex-wrap: wrap; height: auto; min-height: 48px; padding: 8px 12px; row-gap: 4px; }
|
||
.hero { padding: 30px 14px; border-radius: 18px; }
|
||
.dash-title h1 { font-size: 1.7rem; }
|
||
.dash-title p { font-size: .95rem; }
|
||
.create-btn { width: 100%; }
|
||
.dash-actions .link { flex: 1; text-align: center; }
|
||
.stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
|
||
.stat-card b { font-size: 1.9rem; }
|
||
.tabs { width: 100%; }
|
||
.tab { flex: 1; justify-content: center; }
|
||
.grid { grid-template-columns: 1fr; }
|
||
.session-actions button { min-width: 90px; }
|
||
.toast { right: 12px; left: 12px; bottom: 12px; max-width: none; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="shell">
|
||
<header>
|
||
<div class="logo"><span class="logo-mark"></span>Prompt<span>ly</span> <small>studio</small></div>
|
||
<div class="status"><span class="dot" id="conn-dot"></span><span id="conn-text">Подключение…</span></div>
|
||
</header>
|
||
|
||
<section class="hero">
|
||
<div class="dash-title">
|
||
<h1>Студия <em>Promptly</em></h1>
|
||
<p>Презентации, прямые эфиры и материалы</p>
|
||
</div>
|
||
<div class="dash-actions">
|
||
<a class="link" href="docs.html" target="_blank" rel="noopener">Документация</a>
|
||
<button class="link" id="import-btn" title="Загрузить презентацию из JSON-файла">Импорт</button>
|
||
<button class="create-btn" id="create-btn">+ Новая презентация</button>
|
||
</div>
|
||
<div class="stats-grid">
|
||
<div class="stat-card"><b id="stat-presentations">0</b><span>презентаций</span></div>
|
||
<div class="stat-card"><b id="stat-sessions">0</b><span>в эфире</span></div>
|
||
</div>
|
||
</section>
|
||
|
||
<div class="tabs">
|
||
<button class="tab active" data-tab="presentations">Мои презентации <span class="badge" id="count-presentations">0</span></button>
|
||
<button class="tab" data-tab="sessions">Прямые эфиры <span class="badge" id="count-sessions">0</span></button>
|
||
</div>
|
||
|
||
<div class="panel active" id="panel-presentations">
|
||
<div class="toolbar">
|
||
<div class="search-wrap">
|
||
<input class="search" id="search" placeholder="Поиск по названию…">
|
||
</div>
|
||
<span class="muted" id="result-count"></span>
|
||
</div>
|
||
<div class="grid" id="presentations"></div>
|
||
</div>
|
||
|
||
<div class="panel" id="panel-sessions">
|
||
<div class="grid" id="sessions"></div>
|
||
</div>
|
||
|
||
<div class="foot">
|
||
<span>Promptly Studio · презентации в реальном времени</span>
|
||
<span>Докладчик управляет слайдами, кнопками и звуком · зрители видят только слайд</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="toast" id="toast"></div>
|
||
<input type="file" id="import-file" accept=".json,application/json" hidden>
|
||
|
||
<script src="js/slide-view.js"></script>
|
||
<script>
|
||
const state = { presentations: [], sessions: [], search: '' };
|
||
let lastLiveIds = '';
|
||
|
||
const $ = (id) => document.getElementById(id);
|
||
const presentationsEl = $('presentations');
|
||
const sessionsEl = $('sessions');
|
||
const connDot = $('conn-dot');
|
||
const connText = $('conn-text');
|
||
|
||
const esc = (s) =>
|
||
String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
||
|
||
function timeAgo(ts) {
|
||
const diff = Math.max(0, Date.now() - ts);
|
||
const min = Math.floor(diff / 60000);
|
||
if (min < 1) return 'только что';
|
||
if (min < 60) return `${min} мин назад`;
|
||
const hours = Math.floor(min / 60);
|
||
if (hours < 24) return `${hours} ч назад`;
|
||
return new Date(ts).toLocaleDateString('ru-RU');
|
||
}
|
||
|
||
function plural(n, one, few, many) {
|
||
const mod10 = n % 10;
|
||
const mod100 = n % 100;
|
||
if (mod10 === 1 && mod100 !== 11) return one;
|
||
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 10 || mod100 >= 20)) return few;
|
||
return many;
|
||
}
|
||
|
||
let toastTimer = null;
|
||
function toast(message) {
|
||
const el = $('toast');
|
||
el.textContent = message;
|
||
el.classList.add('visible');
|
||
clearTimeout(toastTimer);
|
||
toastTimer = setTimeout(() => el.classList.remove('visible'), 2600);
|
||
}
|
||
|
||
function isLive(id) {
|
||
return state.sessions.some((session) => session.presentationId === id);
|
||
}
|
||
|
||
function renderPresentations() {
|
||
const total = state.presentations.length;
|
||
$('count-presentations').textContent = total;
|
||
$('stat-presentations').textContent = total;
|
||
|
||
const query = state.search.trim().toLowerCase();
|
||
const base = [...state.presentations].sort((a, b) => (b.updatedAt || 0) - (a.updatedAt || 0));
|
||
const list = query
|
||
? base.filter((p) => p.title.toLowerCase().includes(query))
|
||
: base;
|
||
$('result-count').textContent = query ? `Найдено: ${list.length}` : '';
|
||
|
||
if (!list.length) {
|
||
presentationsEl.innerHTML = `<div class="empty" style="grid-column:1/-1">${
|
||
query ? 'Ничего не найдено по запросу.' : 'Пока нет презентаций — <b>создайте первую!</b>'
|
||
}</div>`;
|
||
return;
|
||
}
|
||
|
||
presentationsEl.innerHTML = list.map((p) => {
|
||
const slides = (p.slides || []).length;
|
||
const live = isLive(p.id);
|
||
return `
|
||
<div class="card">
|
||
<div class="thumb">
|
||
<div class="thumb-canvas" data-pres="${esc(p.id)}"></div>
|
||
<div class="thumb-chips">
|
||
<span class="chip">${slides} ${plural(slides, 'слайд', 'слайда', 'слайдов')}</span>
|
||
${live ? '<span class="chip live"><span class="dot"></span> LIVE</span>' : ''}
|
||
</div>
|
||
</div>
|
||
<div class="card-body">
|
||
<h3>${esc(p.title)}</h3>
|
||
<div class="muted">Обновлено ${timeAgo(p.updatedAt)}</div>
|
||
<div class="actions">
|
||
<button class="primary grow" onclick="startDemo('${esc(p.id)}')">Демонстрировать</button>
|
||
</div>
|
||
<div class="actions">
|
||
<button class="ghost grow" onclick="editPresentation('${esc(p.id)}')">Изменить</button>
|
||
${live ? `<button class="ghost" onclick="watchSession('${esc(p.id)}')" title="Смотреть как зритель">Смотреть</button>` : ''}
|
||
<button class="ghost icon-btn" onclick="duplicatePresentation('${esc(p.id)}')" title="Дублировать">Копия</button>
|
||
<button class="ghost icon-btn" onclick="exportPresentation('${esc(p.id)}')" title="Экспорт в JSON">Экспорт</button>
|
||
<button class="danger icon-btn" onclick="removePresentation('${esc(p.id)}')" title="Удалить">Удалить</button>
|
||
</div>
|
||
</div>
|
||
</div>`;
|
||
}).join('');
|
||
|
||
mountThumbs();
|
||
}
|
||
|
||
function mountThumbs() {
|
||
presentationsEl.querySelectorAll('.thumb-canvas').forEach((container) => {
|
||
const presentation = state.presentations.find((item) => item.id === container.dataset.pres);
|
||
if (!presentation) return;
|
||
const slide = (presentation.slides || [])[0] || { elements: [] };
|
||
SlideView.render(container, slide, { variables: presentation.variables || {} });
|
||
});
|
||
}
|
||
|
||
function renderSessions() {
|
||
const total = state.sessions.length;
|
||
$('count-sessions').textContent = total;
|
||
$('stat-sessions').textContent = total;
|
||
|
||
if (!total) {
|
||
sessionsEl.innerHTML = '<div class="empty" style="grid-column:1/-1">Сейчас нет активных демонстраций.<br>Нажмите «Демонстрировать» на любой презентации.</div>';
|
||
return;
|
||
}
|
||
|
||
sessionsEl.innerHTML = state.sessions.map((session) => {
|
||
const progress = session.slidesCount ? Math.round(((session.currentSlide + 1) / session.slidesCount) * 100) : 0;
|
||
return `
|
||
<div class="card session-card">
|
||
<div class="session-top">
|
||
<div>
|
||
<h3>${esc(session.title)}</h3>
|
||
<div class="live"><span class="dot"></span> идёт ${timeAgo(session.startedAt)}</div>
|
||
</div>
|
||
<span class="viewers">зрителей: ${session.viewers}</span>
|
||
</div>
|
||
<div class="progress"><div style="width:${progress}%"></div></div>
|
||
<div class="session-meta">
|
||
<span>Слайд ${session.currentSlide + 1} из ${session.slidesCount}</span>
|
||
${session.presenters ? '<span>докладчик на связи</span>' : '<span>докладчик не подключён</span>'}
|
||
</div>
|
||
<div class="session-actions">
|
||
<button class="ghost" onclick="watchSession('${esc(session.presentationId)}')">Смотреть</button>
|
||
<button class="ghost" onclick="startDemo('${esc(session.presentationId)}')" title="Открыть панель докладчика">Докладчик</button>
|
||
<button class="danger" onclick="stopSession('${esc(session.presentationId)}')">Остановить</button>
|
||
</div>
|
||
</div>`;
|
||
}).join('');
|
||
}
|
||
|
||
function renderAll() {
|
||
renderPresentations();
|
||
renderSessions();
|
||
}
|
||
|
||
$('search').addEventListener('input', (event) => {
|
||
state.search = event.target.value;
|
||
renderPresentations();
|
||
});
|
||
|
||
$('create-btn').addEventListener('click', () => (location.href = 'editor.html'));
|
||
$('import-btn').addEventListener('click', () => $('import-file').click());
|
||
|
||
window.startDemo = (id) => window.open(`viewer.html?id=${encodeURIComponent(id)}&mode=speaker`, '_blank');
|
||
window.watchSession = (id) => window.open(`viewer.html?id=${encodeURIComponent(id)}&mode=audience`, '_blank');
|
||
window.editPresentation = (id) => (location.href = `editor.html?id=${encodeURIComponent(id)}`);
|
||
|
||
window.duplicatePresentation = async (id) => {
|
||
const response = await fetch(`/api/presentations/${encodeURIComponent(id)}/duplicate`, { method: 'POST' });
|
||
if (response.ok) toast('Копия создана');
|
||
};
|
||
|
||
window.removePresentation = async (id) => {
|
||
if (!confirm('Удалить презентацию? Это действие необратимо.')) return;
|
||
await fetch(`/api/presentations/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||
toast('Презентация удалена');
|
||
};
|
||
|
||
window.stopSession = async (presentationId) => {
|
||
if (!confirm('Остановить демонстрацию для всех зрителей?')) return;
|
||
await fetch(`/api/sessions/${encodeURIComponent(presentationId)}`, { method: 'DELETE' });
|
||
toast('Демонстрация остановлена');
|
||
};
|
||
|
||
window.exportPresentation = async (id) => {
|
||
try {
|
||
const response = await fetch(`/api/presentations/${encodeURIComponent(id)}`);
|
||
if (!response.ok) throw new Error('not found');
|
||
const data = await response.json();
|
||
const payload = {
|
||
app: 'promptly', version: 2, exportedAt: new Date().toISOString(),
|
||
title: data.title, slides: data.slides, variables: data.variables,
|
||
music: data.music, lua: data.lua, commands: data.commands, graph: data.graph,
|
||
};
|
||
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
|
||
const link = document.createElement('a');
|
||
const safeTitle = String(data.title || 'presentation').replace(/[^\wа-яёА-ЯЁ -]+/gi, '').trim().slice(0, 48) || 'presentation';
|
||
link.href = URL.createObjectURL(blob);
|
||
link.download = `${safeTitle}.promptly.json`;
|
||
link.click();
|
||
setTimeout(() => URL.revokeObjectURL(link.href), 4000);
|
||
toast('Файл скачан');
|
||
} catch (error) {
|
||
toast('Не удалось экспортировать');
|
||
}
|
||
};
|
||
|
||
$('import-file').addEventListener('change', async (event) => {
|
||
const file = event.target.files && event.target.files[0];
|
||
event.target.value = '';
|
||
if (!file) return;
|
||
try {
|
||
const data = JSON.parse(await file.text());
|
||
if (!data || !Array.isArray(data.slides)) throw new Error('bad format');
|
||
const response = await fetch('/api/presentations', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(data),
|
||
});
|
||
if (!response.ok) throw new Error('http');
|
||
toast('Презентация импортирована');
|
||
} catch (error) {
|
||
toast('Не удалось импортировать: проверьте JSON-файл');
|
||
}
|
||
});
|
||
|
||
document.querySelectorAll('.tab').forEach((tab) => {
|
||
tab.addEventListener('click', () => {
|
||
document.querySelectorAll('.tab').forEach((item) => item.classList.remove('active'));
|
||
document.querySelectorAll('.panel').forEach((panel) => panel.classList.remove('active'));
|
||
tab.classList.add('active');
|
||
$('panel-' + tab.dataset.tab).classList.add('active');
|
||
});
|
||
});
|
||
|
||
let ws;
|
||
function connect() {
|
||
connText.textContent = 'Подключение…';
|
||
const wsProto = location.protocol === 'https:' ? 'wss' : 'ws';
|
||
ws = new WebSocket(`${wsProto}://${location.host}/`);
|
||
|
||
ws.onopen = () => {
|
||
connDot.classList.remove('off');
|
||
connText.textContent = 'Онлайн';
|
||
};
|
||
|
||
ws.onmessage = (event) => {
|
||
let message;
|
||
try { message = JSON.parse(event.data); } catch (error) { return; }
|
||
if (message.type === 'presentations') {
|
||
state.presentations = message.presentations;
|
||
renderPresentations();
|
||
}
|
||
if (message.type === 'sessions') {
|
||
state.sessions = message.sessions;
|
||
// Список сессий обновляем всегда, а карточки презентаций — только когда
|
||
// изменился набор эфиров (иначе LIVE-чипы мигают при каждой навигации).
|
||
renderSessions();
|
||
const liveIds = state.sessions.map((item) => item.presentationId).join(',');
|
||
if (liveIds !== lastLiveIds) {
|
||
lastLiveIds = liveIds;
|
||
renderPresentations();
|
||
}
|
||
}
|
||
};
|
||
|
||
ws.onclose = () => {
|
||
connDot.classList.add('off');
|
||
connText.textContent = 'Нет соединения — переподключение…';
|
||
setTimeout(connect, 1500);
|
||
};
|
||
|
||
ws.onerror = () => ws.close();
|
||
}
|
||
|
||
connect();
|
||
</script>
|
||
</body>
|
||
</html>
|