Репозитории /
Promptly /
public/index.html
index.html
| 1 | <!DOCTYPE html> |
| 2 | <html lang="ru"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | <title>Promptly — студия презентаций</title> |
| 7 | <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"> |
| 8 | <style> |
| 9 | :root { |
| 10 | --accent: #4cc2ff; |
| 11 | --accent-soft: rgba(76, 194, 255, .12); |
| 12 | --glass: rgba(30, 30, 30, .55); |
| 13 | --glass-deep: rgba(20, 20, 25, .68); |
| 14 | --border: rgba(255, 255, 255, .08); |
| 15 | --text: #e5e5e5; |
| 16 | --muted: #aaa; |
| 17 | --dim: #777; |
| 18 | --danger: #ff6b6b; |
| 19 | --ease: cubic-bezier(.4, 0, .2, 1); |
| 20 | --shadow: 0 4px 20px rgba(0, 0, 0, .25); |
| 21 | } |
| 22 | * { box-sizing: border-box; } |
| 23 | html, body { margin: 0; } |
| 24 | body { |
| 25 | min-height: 100vh; color: var(--text); |
| 26 | font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; |
| 27 | background: #0d0d10 url('/img/bipfr-bg.png') center / cover fixed no-repeat; |
| 28 | } |
| 29 | 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; } |
| 30 | button:hover:not(:disabled) { background: rgba(255,255,255,.12); color: #fff; transform: translateY(-1px); } |
| 31 | button:active:not(:disabled) { transform: scale(.94); background: rgba(255,255,255,.08); } |
| 32 | button:disabled { opacity: .35; cursor: default; } |
| 33 | input { font: inherit; } |
| 34 | code { color: var(--accent); } |
| 35 | |
| 36 | .shell { max-width: 1200px; margin: 0 auto; padding: 88px 20px 60px; } |
| 37 | header { |
| 38 | position: fixed; top: 7px; left: 7px; right: 7px; z-index: 100; |
| 39 | height: 48px; padding: 0 8px; |
| 40 | display: flex; align-items: center; justify-content: space-between; gap: 12px; |
| 41 | background: var(--glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); |
| 42 | border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); |
| 43 | } |
| 44 | .logo { font-size: 17px; font-weight: 700; letter-spacing: .3px; color: #fff; display: flex; align-items: center; gap: 9px; } |
| 45 | .logo-mark { width: 12px; height: 12px; border-radius: 4px; background: var(--accent); box-shadow: 0 0 10px rgba(76,194,255,.7); } |
| 46 | .logo span { color: var(--accent); } |
| 47 | .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; } |
| 48 | .status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); } |
| 49 | .dot { width: 8px; height: 8px; border-radius: 50%; background: #4cd137; box-shadow: 0 0 10px #4cd137; } |
| 50 | .dot.off { background: var(--danger); box-shadow: 0 0 10px var(--danger); } |
| 51 | |
| 52 | .hero { |
| 53 | text-align: center; padding: 46px 20px 40px; margin-bottom: 30px; |
| 54 | background: rgba(30, 30, 30, .4); border-radius: 24px; border: 1px solid rgba(255, 255, 255, .05); |
| 55 | backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); |
| 56 | } |
| 57 | .dash-title h1 { font-size: 2.5rem; margin: 0 0 10px; color: #fff; font-weight: 700; letter-spacing: -.5px; } |
| 58 | .dash-title h1 em { font-style: normal; color: var(--accent); } |
| 59 | .dash-title p { margin: 0 0 26px; color: var(--muted); font-size: 1.1rem; } |
| 60 | .dash-actions { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; } |
| 61 | .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; } |
| 62 | .dash-actions .link:hover { background: rgba(255,255,255,.12); color: #fff; transform: translateY(-1px); } |
| 63 | .create-btn { font-size: 14px; padding: 12px 28px; border-radius: 12px; font-weight: 600; background: var(--accent); color: #000; } |
| 64 | .create-btn:hover { background: var(--accent); transform: scale(1.05); box-shadow: 0 0 20px rgba(76, 194, 255, .4); color: #000; } |
| 65 | |
| 66 | .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px; margin: 34px 0 0; } |
| 67 | .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); } |
| 68 | .stat-card b { font-size: 2.5rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; } |
| 69 | .stat-card span { color: #888; font-size: .9rem; margin-top: 5px; } |
| 70 | |
| 71 | .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; } |
| 72 | .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; } |
| 73 | .tab:hover { background: rgba(255, 255, 255, .12); color: #fff; transform: translateY(-1px); } |
| 74 | .tab.active { background: rgba(255, 255, 255, .08); color: #fff; font-weight: 600; } |
| 75 | .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; } |
| 76 | @keyframes expandFromCenter { from { transform: scaleX(0); opacity: 0; } to { transform: scaleX(1); opacity: 1; } } |
| 77 | .badge { background: rgba(255, 255, 255, .14); border-radius: 999px; padding: 1px 8px; font-size: 11px; min-width: 21px; text-align: center; } |
| 78 | |
| 79 | .toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; } |
| 80 | .search-wrap { position: relative; flex: 1; max-width: 380px; min-width: 200px; } |
| 81 | .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; } |
| 82 | .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); } |
| 83 | .search::placeholder { color: #666; } |
| 84 | .search:focus { outline: 2px solid rgba(76, 194, 255, .55); border-color: transparent; } |
| 85 | .toolbar .muted { margin-left: auto; } |
| 86 | |
| 87 | .panel { display: none; } .panel.active { display: block; animation: fade .25s ease; } |
| 88 | @keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } } |
| 89 | |
| 90 | .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; } |
| 91 | .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; } |
| 92 | .card:hover { border-color: rgba(76, 194, 255, .45); transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0, 0, 0, .4); } |
| 93 | .thumb { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #101014; border-bottom: 1px solid rgba(255,255,255,.06); } |
| 94 | .thumb-canvas { position: absolute; inset: 0; } |
| 95 | .thumb-chips { position: absolute; top: 9px; left: 9px; right: 9px; display: flex; align-items: center; gap: 6px; pointer-events: none; } |
| 96 | .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); } |
| 97 | .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; } |
| 98 | .chip.live .dot { width: 6px; height: 6px; background: #000; box-shadow: none; animation: pulse 1.2s infinite; } |
| 99 | @keyframes pulse { 50% { opacity: .25; } } |
| 100 | |
| 101 | .card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 11px; flex: 1; } |
| 102 | .card-body h3 { margin: 0; font-size: 16.5px; line-height: 1.3; color: #fff; } |
| 103 | .muted { color: var(--muted); font-size: 12px; } |
| 104 | .actions { display: flex; gap: 7px; flex-wrap: wrap; } |
| 105 | .actions .grow { flex: 1; } |
| 106 | .primary { background: var(--accent); color: #000; font-weight: 600; } |
| 107 | .primary:hover:not(:disabled) { background: var(--accent); color: #000; box-shadow: 0 0 16px rgba(76, 194, 255, .35); } |
| 108 | .ghost { background: rgba(255,255,255,.07); } |
| 109 | .danger { background: rgba(255, 107, 107, .15); color: #ff8e8e; border: 1px solid rgba(255, 107, 107, .32); } |
| 110 | .danger:hover:not(:disabled) { background: rgba(255, 107, 107, .25); color: #ffb3b3; } |
| 111 | .icon-btn { padding: 9px 12px; } |
| 112 | |
| 113 | .live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--accent); } |
| 114 | .live .dot { width: 7px; height: 7px; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1.2s infinite; } |
| 115 | .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; } |
| 116 | .empty b { color: var(--accent); } |
| 117 | |
| 118 | .session-card { padding: 18px; display: flex; flex-direction: column; gap: 13px; } |
| 119 | .session-top { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; } |
| 120 | .session-top h3 { margin: 0 0 6px; font-size: 16.5px; color: #fff; } |
| 121 | .progress { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .08); overflow: hidden; } |
| 122 | .progress > div { height: 100%; border-radius: 999px; background: var(--accent); box-shadow: 0 0 8px rgba(76,194,255,.6); transition: width .3s; } |
| 123 | .session-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); align-items: center; } |
| 124 | .viewers { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; color: var(--accent); font-size: 13px; } |
| 125 | .session-actions { display: flex; gap: 7px; flex-wrap: wrap; } |
| 126 | .session-actions button { flex: 1; min-width: 110px; } |
| 127 | |
| 128 | .toast { |
| 129 | position: fixed; right: 30px; bottom: 30px; transform: translateY(-20px) scale(.9); |
| 130 | background: rgba(30, 30, 30, .85); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); |
| 131 | border: 1px solid var(--border); color: var(--text); padding: 16px 20px; border-radius: 12px; |
| 132 | font-size: 13.5px; z-index: 9999; opacity: 0; pointer-events: none; |
| 133 | transition: all .3s var(--ease); max-width: min(400px, 80vw); box-shadow: var(--shadow); |
| 134 | } |
| 135 | .toast.visible { opacity: 1; transform: translateY(0) scale(1); } |
| 136 | |
| 137 | .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; } |
| 138 | |
| 139 | ::-webkit-scrollbar { width: 10px; height: 10px; } |
| 140 | ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 999px; } |
| 141 | ::-webkit-scrollbar-track { background: transparent; } |
| 142 | |
| 143 | @media (max-width: 760px) { |
| 144 | .shell { padding: 108px 12px 40px; } |
| 145 | header { flex-wrap: wrap; height: auto; min-height: 48px; padding: 8px 12px; row-gap: 4px; } |
| 146 | .hero { padding: 30px 14px; border-radius: 18px; } |
| 147 | .dash-title h1 { font-size: 1.7rem; } |
| 148 | .dash-title p { font-size: .95rem; } |
| 149 | .create-btn { width: 100%; } |
| 150 | .dash-actions .link { flex: 1; text-align: center; } |
| 151 | .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; } |
| 152 | .stat-card b { font-size: 1.9rem; } |
| 153 | .tabs { width: 100%; } |
| 154 | .tab { flex: 1; justify-content: center; } |
| 155 | .grid { grid-template-columns: 1fr; } |
| 156 | .session-actions button { min-width: 90px; } |
| 157 | .toast { right: 12px; left: 12px; bottom: 12px; max-width: none; } |
| 158 | } |
| 159 | </style> |
| 160 | </head> |
| 161 | <body> |
| 162 | <div class="shell"> |
| 163 | <header> |
| 164 | <div class="logo"><span class="logo-mark"></span>Prompt<span>ly</span> <small>studio</small></div> |
| 165 | <div class="status"><span class="dot" id="conn-dot"></span><span id="conn-text">Подключение…</span></div> |
| 166 | </header> |
| 167 | |
| 168 | <section class="hero"> |
| 169 | <div class="dash-title"> |
| 170 | <h1>Студия <em>Promptly</em></h1> |
| 171 | <p>Презентации, прямые эфиры и материалы</p> |
| 172 | </div> |
| 173 | <div class="dash-actions"> |
| 174 | <a class="link" href="docs.html" target="_blank" rel="noopener">Документация</a> |
| 175 | <button class="link" id="import-btn" title="Загрузить презентацию из JSON-файла">Импорт</button> |
| 176 | <button class="create-btn" id="create-btn">+ Новая презентация</button> |
| 177 | </div> |
| 178 | <div class="stats-grid"> |
| 179 | <div class="stat-card"><b id="stat-presentations">0</b><span>презентаций</span></div> |
| 180 | <div class="stat-card"><b id="stat-sessions">0</b><span>в эфире</span></div> |
| 181 | </div> |
| 182 | </section> |
| 183 | |
| 184 | <div class="tabs"> |
| 185 | <button class="tab active" data-tab="presentations">Мои презентации <span class="badge" id="count-presentations">0</span></button> |
| 186 | <button class="tab" data-tab="sessions">Прямые эфиры <span class="badge" id="count-sessions">0</span></button> |
| 187 | </div> |
| 188 | |
| 189 | <div class="panel active" id="panel-presentations"> |
| 190 | <div class="toolbar"> |
| 191 | <div class="search-wrap"> |
| 192 | <input class="search" id="search" placeholder="Поиск по названию…"> |
| 193 | </div> |
| 194 | <span class="muted" id="result-count"></span> |
| 195 | </div> |
| 196 | <div class="grid" id="presentations"></div> |
| 197 | </div> |
| 198 | |
| 199 | <div class="panel" id="panel-sessions"> |
| 200 | <div class="grid" id="sessions"></div> |
| 201 | </div> |
| 202 | |
| 203 | <div class="foot"> |
| 204 | <span>Promptly Studio · презентации в реальном времени</span> |
| 205 | <span>Докладчик управляет слайдами, кнопками и звуком · зрители видят только слайд</span> |
| 206 | </div> |
| 207 | </div> |
| 208 | |
| 209 | <div class="toast" id="toast"></div> |
| 210 | <input type="file" id="import-file" accept=".json,application/json" hidden> |
| 211 | |
| 212 | <script src="js/slide-view.js"></script> |
| 213 | <script> |
| 214 | const state = { presentations: [], sessions: [], search: '' }; |
| 215 | let lastLiveIds = ''; |
| 216 | |
| 217 | const $ = (id) => document.getElementById(id); |
| 218 | const presentationsEl = $('presentations'); |
| 219 | const sessionsEl = $('sessions'); |
| 220 | const connDot = $('conn-dot'); |
| 221 | const connText = $('conn-text'); |
| 222 | |
| 223 | const esc = (s) => |
| 224 | String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); |
| 225 | |
| 226 | function timeAgo(ts) { |
| 227 | const diff = Math.max(0, Date.now() - ts); |
| 228 | const min = Math.floor(diff / 60000); |
| 229 | if (min < 1) return 'только что'; |
| 230 | if (min < 60) return `${min} мин назад`; |
| 231 | const hours = Math.floor(min / 60); |
| 232 | if (hours < 24) return `${hours} ч назад`; |
| 233 | return new Date(ts).toLocaleDateString('ru-RU'); |
| 234 | } |
| 235 | |
| 236 | function plural(n, one, few, many) { |
| 237 | const mod10 = n % 10; |
| 238 | const mod100 = n % 100; |
| 239 | if (mod10 === 1 && mod100 !== 11) return one; |
| 240 | if (mod10 >= 2 && mod10 <= 4 && (mod100 < 10 || mod100 >= 20)) return few; |
| 241 | return many; |
| 242 | } |
| 243 | |
| 244 | let toastTimer = null; |
| 245 | function toast(message) { |
| 246 | const el = $('toast'); |
| 247 | el.textContent = message; |
| 248 | el.classList.add('visible'); |
| 249 | clearTimeout(toastTimer); |
| 250 | toastTimer = setTimeout(() => el.classList.remove('visible'), 2600); |
| 251 | } |
| 252 | |
| 253 | function isLive(id) { |
| 254 | return state.sessions.some((session) => session.presentationId === id); |
| 255 | } |
| 256 | |
| 257 | function renderPresentations() { |
| 258 | const total = state.presentations.length; |
| 259 | $('count-presentations').textContent = total; |
| 260 | $('stat-presentations').textContent = total; |
| 261 | |
| 262 | const query = state.search.trim().toLowerCase(); |
| 263 | const base = [...state.presentations].sort((a, b) => (b.updatedAt || 0) - (a.updatedAt || 0)); |
| 264 | const list = query |
| 265 | ? base.filter((p) => p.title.toLowerCase().includes(query)) |
| 266 | : base; |
| 267 | $('result-count').textContent = query ? `Найдено: ${list.length}` : ''; |
| 268 | |
| 269 | if (!list.length) { |
| 270 | presentationsEl.innerHTML = `<div class="empty" style="grid-column:1/-1">${ |
| 271 | query ? 'Ничего не найдено по запросу.' : 'Пока нет презентаций — <b>создайте первую!</b>' |
| 272 | }</div>`; |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | presentationsEl.innerHTML = list.map((p) => { |
| 277 | const slides = (p.slides || []).length; |
| 278 | const live = isLive(p.id); |
| 279 | return ` |
| 280 | <div class="card"> |
| 281 | <div class="thumb"> |
| 282 | <div class="thumb-canvas" data-pres="${esc(p.id)}"></div> |
| 283 | <div class="thumb-chips"> |
| 284 | <span class="chip">${slides} ${plural(slides, 'слайд', 'слайда', 'слайдов')}</span> |
| 285 | ${live ? '<span class="chip live"><span class="dot"></span> LIVE</span>' : ''} |
| 286 | </div> |
| 287 | </div> |
| 288 | <div class="card-body"> |
| 289 | <h3>${esc(p.title)}</h3> |
| 290 | <div class="muted">Обновлено ${timeAgo(p.updatedAt)}</div> |
| 291 | <div class="actions"> |
| 292 | <button class="primary grow" onclick="startDemo('${esc(p.id)}')">Демонстрировать</button> |
| 293 | </div> |
| 294 | <div class="actions"> |
| 295 | <button class="ghost grow" onclick="editPresentation('${esc(p.id)}')">Изменить</button> |
| 296 | ${live ? `<button class="ghost" onclick="watchSession('${esc(p.id)}')" title="Смотреть как зритель">Смотреть</button>` : ''} |
| 297 | <button class="ghost icon-btn" onclick="duplicatePresentation('${esc(p.id)}')" title="Дублировать">Копия</button> |
| 298 | <button class="ghost icon-btn" onclick="exportPresentation('${esc(p.id)}')" title="Экспорт в JSON">Экспорт</button> |
| 299 | <button class="danger icon-btn" onclick="removePresentation('${esc(p.id)}')" title="Удалить">Удалить</button> |
| 300 | </div> |
| 301 | </div> |
| 302 | </div>`; |
| 303 | }).join(''); |
| 304 | |
| 305 | mountThumbs(); |
| 306 | } |
| 307 | |
| 308 | function mountThumbs() { |
| 309 | presentationsEl.querySelectorAll('.thumb-canvas').forEach((container) => { |
| 310 | const presentation = state.presentations.find((item) => item.id === container.dataset.pres); |
| 311 | if (!presentation) return; |
| 312 | const slide = (presentation.slides || [])[0] || { elements: [] }; |
| 313 | SlideView.render(container, slide, { variables: presentation.variables || {} }); |
| 314 | }); |
| 315 | } |
| 316 | |
| 317 | function renderSessions() { |
| 318 | const total = state.sessions.length; |
| 319 | $('count-sessions').textContent = total; |
| 320 | $('stat-sessions').textContent = total; |
| 321 | |
| 322 | if (!total) { |
| 323 | sessionsEl.innerHTML = '<div class="empty" style="grid-column:1/-1">Сейчас нет активных демонстраций.<br>Нажмите «Демонстрировать» на любой презентации.</div>'; |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | sessionsEl.innerHTML = state.sessions.map((session) => { |
| 328 | const progress = session.slidesCount ? Math.round(((session.currentSlide + 1) / session.slidesCount) * 100) : 0; |
| 329 | return ` |
| 330 | <div class="card session-card"> |
| 331 | <div class="session-top"> |
| 332 | <div> |
| 333 | <h3>${esc(session.title)}</h3> |
| 334 | <div class="live"><span class="dot"></span> идёт ${timeAgo(session.startedAt)}</div> |
| 335 | </div> |
| 336 | <span class="viewers">зрителей: ${session.viewers}</span> |
| 337 | </div> |
| 338 | <div class="progress"><div style="width:${progress}%"></div></div> |
| 339 | <div class="session-meta"> |
| 340 | <span>Слайд ${session.currentSlide + 1} из ${session.slidesCount}</span> |
| 341 | ${session.presenters ? '<span>докладчик на связи</span>' : '<span>докладчик не подключён</span>'} |
| 342 | </div> |
| 343 | <div class="session-actions"> |
| 344 | <button class="ghost" onclick="watchSession('${esc(session.presentationId)}')">Смотреть</button> |
| 345 | <button class="ghost" onclick="startDemo('${esc(session.presentationId)}')" title="Открыть панель докладчика">Докладчик</button> |
| 346 | <button class="danger" onclick="stopSession('${esc(session.presentationId)}')">Остановить</button> |
| 347 | </div> |
| 348 | </div>`; |
| 349 | }).join(''); |
| 350 | } |
| 351 | |
| 352 | function renderAll() { |
| 353 | renderPresentations(); |
| 354 | renderSessions(); |
| 355 | } |
| 356 | |
| 357 | $('search').addEventListener('input', (event) => { |
| 358 | state.search = event.target.value; |
| 359 | renderPresentations(); |
| 360 | }); |
| 361 | |
| 362 | $('create-btn').addEventListener('click', () => (location.href = 'editor.html')); |
| 363 | $('import-btn').addEventListener('click', () => $('import-file').click()); |
| 364 | |
| 365 | window.startDemo = (id) => window.open(`viewer.html?id=${encodeURIComponent(id)}&mode=speaker`, '_blank'); |
| 366 | window.watchSession = (id) => window.open(`viewer.html?id=${encodeURIComponent(id)}&mode=audience`, '_blank'); |
| 367 | window.editPresentation = (id) => (location.href = `editor.html?id=${encodeURIComponent(id)}`); |
| 368 | |
| 369 | window.duplicatePresentation = async (id) => { |
| 370 | const response = await fetch(`/api/presentations/${encodeURIComponent(id)}/duplicate`, { method: 'POST' }); |
| 371 | if (response.ok) toast('Копия создана'); |
| 372 | }; |
| 373 | |
| 374 | window.removePresentation = async (id) => { |
| 375 | if (!confirm('Удалить презентацию? Это действие необратимо.')) return; |
| 376 | await fetch(`/api/presentations/${encodeURIComponent(id)}`, { method: 'DELETE' }); |
| 377 | toast('Презентация удалена'); |
| 378 | }; |
| 379 | |
| 380 | window.stopSession = async (presentationId) => { |
| 381 | if (!confirm('Остановить демонстрацию для всех зрителей?')) return; |
| 382 | await fetch(`/api/sessions/${encodeURIComponent(presentationId)}`, { method: 'DELETE' }); |
| 383 | toast('Демонстрация остановлена'); |
| 384 | }; |
| 385 | |
| 386 | window.exportPresentation = async (id) => { |
| 387 | try { |
| 388 | const response = await fetch(`/api/presentations/${encodeURIComponent(id)}`); |
| 389 | if (!response.ok) throw new Error('not found'); |
| 390 | const data = await response.json(); |
| 391 | const payload = { |
| 392 | app: 'promptly', version: 2, exportedAt: new Date().toISOString(), |
| 393 | title: data.title, slides: data.slides, variables: data.variables, |
| 394 | music: data.music, lua: data.lua, commands: data.commands, graph: data.graph, |
| 395 | }; |
| 396 | const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' }); |
| 397 | const link = document.createElement('a'); |
| 398 | const safeTitle = String(data.title || 'presentation').replace(/[^\wа-яёА-ЯЁ -]+/gi, '').trim().slice(0, 48) || 'presentation'; |
| 399 | link.href = URL.createObjectURL(blob); |
| 400 | link.download = `${safeTitle}.promptly.json`; |
| 401 | link.click(); |
| 402 | setTimeout(() => URL.revokeObjectURL(link.href), 4000); |
| 403 | toast('Файл скачан'); |
| 404 | } catch (error) { |
| 405 | toast('Не удалось экспортировать'); |
| 406 | } |
| 407 | }; |
| 408 | |
| 409 | $('import-file').addEventListener('change', async (event) => { |
| 410 | const file = event.target.files && event.target.files[0]; |
| 411 | event.target.value = ''; |
| 412 | if (!file) return; |
| 413 | try { |
| 414 | const data = JSON.parse(await file.text()); |
| 415 | if (!data || !Array.isArray(data.slides)) throw new Error('bad format'); |
| 416 | const response = await fetch('/api/presentations', { |
| 417 | method: 'POST', |
| 418 | headers: { 'Content-Type': 'application/json' }, |
| 419 | body: JSON.stringify(data), |
| 420 | }); |
| 421 | if (!response.ok) throw new Error('http'); |
| 422 | toast('Презентация импортирована'); |
| 423 | } catch (error) { |
| 424 | toast('Не удалось импортировать: проверьте JSON-файл'); |
| 425 | } |
| 426 | }); |
| 427 | |
| 428 | document.querySelectorAll('.tab').forEach((tab) => { |
| 429 | tab.addEventListener('click', () => { |
| 430 | document.querySelectorAll('.tab').forEach((item) => item.classList.remove('active')); |
| 431 | document.querySelectorAll('.panel').forEach((panel) => panel.classList.remove('active')); |
| 432 | tab.classList.add('active'); |
| 433 | $('panel-' + tab.dataset.tab).classList.add('active'); |
| 434 | }); |
| 435 | }); |
| 436 | |
| 437 | let ws; |
| 438 | function connect() { |
| 439 | connText.textContent = 'Подключение…'; |
| 440 | const wsProto = location.protocol === 'https:' ? 'wss' : 'ws'; |
| 441 | ws = new WebSocket(`${wsProto}://${location.host}/`); |
| 442 | |
| 443 | ws.onopen = () => { |
| 444 | connDot.classList.remove('off'); |
| 445 | connText.textContent = 'Онлайн'; |
| 446 | }; |
| 447 | |
| 448 | ws.onmessage = (event) => { |
| 449 | let message; |
| 450 | try { message = JSON.parse(event.data); } catch (error) { return; } |
| 451 | if (message.type === 'presentations') { |
| 452 | state.presentations = message.presentations; |
| 453 | renderPresentations(); |
| 454 | } |
| 455 | if (message.type === 'sessions') { |
| 456 | state.sessions = message.sessions; |
| 457 | // Список сессий обновляем всегда, а карточки презентаций — только когда |
| 458 | // изменился набор эфиров (иначе LIVE-чипы мигают при каждой навигации). |
| 459 | renderSessions(); |
| 460 | const liveIds = state.sessions.map((item) => item.presentationId).join(','); |
| 461 | if (liveIds !== lastLiveIds) { |
| 462 | lastLiveIds = liveIds; |
| 463 | renderPresentations(); |
| 464 | } |
| 465 | } |
| 466 | }; |
| 467 | |
| 468 | ws.onclose = () => { |
| 469 | connDot.classList.add('off'); |
| 470 | connText.textContent = 'Нет соединения — переподключение…'; |
| 471 | setTimeout(connect, 1500); |
| 472 | }; |
| 473 | |
| 474 | ws.onerror = () => ws.close(); |
| 475 | } |
| 476 | |
| 477 | connect(); |
| 478 | </script> |
| 479 | </body> |
| 480 | </html> |