From b45e4925a6e8fbd6e2a9c2fe782103f86fc27017 Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Sun, 6 Sep 2026 18:39:08 +0300 Subject: [PATCH] feat: clarify VK template and schedule flow --- web/admin.html | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/web/admin.html b/web/admin.html index 6764975..6437121 100644 --- a/web/admin.html +++ b/web/admin.html @@ -29,6 +29,15 @@ .control-group input, .control-group select { align-self: start; } .schedule-time-control { align-content: start; } .schedule-time-control .muted { font-size: .78rem; font-weight: 400; letter-spacing: 0; line-height: 1.35; text-transform: none; } + .vk-step { margin: 24px 0; padding: 22px; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); } + .vk-step h3 { margin: 0 0 4px; font: 500 1.45rem/1.2 Georgia, "Times New Roman", serif; } + .vk-step > p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; } + .vk-template-grid { display: grid; grid-template-columns: minmax(210px, .45fr) minmax(320px, 1fr); gap: 14px; align-items: start; } + .vk-template-grid textarea { min-height: 132px; width: 100%; resize: vertical; } + .vk-template-preview { min-height: 132px; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #f8f5f0; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.5; } + .vk-template-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-top: 12px; } + .vk-template-actions .control-group { min-width: 210px; } + .vk-template-actions .muted { font-size: .8rem; font-weight: 400; letter-spacing: 0; text-transform: none; } .weekday-field { min-width: 260px; } .weekday-field legend { padding: 0; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .055em; text-transform: uppercase; } .weekday-options { display: grid; grid-template-columns: repeat(7, minmax(30px, 1fr)); gap: 5px; } @@ -132,8 +141,8 @@ @@ -169,7 +178,9 @@ let items = [], galleryPhotos = [], galleryIndex = 0, activeCategory = 'all'; let applications = [], activeApplicationStatus = 'pending', selectedApplicationId = null, activeAdminView = 'reports', updatesSocket = null, updatesRetry = null; async function loadVk() { const errorNode=document.querySelector('#vkError'); errorNode.textContent=''; try { const [convResponse, templateResponse, scheduleResponse]=await Promise.all([fetch('/api/admin/vk/conversations'),fetch('/api/admin/vk/templates'),fetch('/api/admin/vk/schedules')]); const convData=await convResponse.json(), templateData=await templateResponse.json(), scheduleData=await scheduleResponse.json(); if(!convResponse.ok||!templateResponse.ok||!scheduleResponse.ok) throw new Error('Не удалось загрузить настройки VK'); const conversations=convData.items||[], templates=templateData.items||[], schedules=scheduleData.items||[]; const conversationSelect=document.querySelector('#vkConversation'), templateSelect=document.querySelector('#vkTemplate'); conversationSelect.replaceChildren(); conversations.forEach(item=>conversationSelect.add(new Option(`${item.title||'Без названия'} · ${item.chat_id}`, item.peer_id))); templateSelect.replaceChildren(); templates.forEach(item=>templateSelect.add(new Option(`${item.name} · ${item.text.slice(0,50)}`, item.id))); const rowsNode=document.querySelector('#vkRows'); rowsNode.replaceChildren(); document.querySelector('#vkCount').textContent=`${conversations.length} бесед · ${schedules.length} расписаний`; conversations.forEach(item=>{const row=document.createElement('tr'); const name=document.createElement('td'); name.textContent=`${item.title||'Без названия'} · ${item.peer_id} / chat ${item.chat_id}`; const status=document.createElement('td'); status.textContent=item.status||'—'; const mailing=document.createElement('td'); mailing.textContent=item.mailing_enabled?'Есть активная рассылка':'Управляется расписаниями'; const added=document.createElement('td'); added.textContent=displayDate(item.added_at); const success=document.createElement('td'); success.textContent=displayDate(item.last_success_at); const lastError=document.createElement('td'); lastError.textContent=item.last_error||item.removal_reason||'—'; row.append(name,status,mailing,added,success,lastError); rowsNode.append(row); }); const scheduleRows=document.querySelector('#vkScheduleRows'); scheduleRows.replaceChildren(); schedules.forEach(item=>{const row=document.createElement('tr'); row.innerHTML=`${item.id}${templates.find(x=>x.id===item.template_id)?.name||item.template_id}${item.peer_id}${item.weekdays.join(', ')} · ${item.times.join(', ')}`; const toggle=document.createElement('button'); toggle.type='button'; toggle.textContent=item.active?'Выключить':'Включить'; toggle.onclick=async()=>{toggle.disabled=true; await fetch(`/api/admin/vk/schedules/${item.id}`,{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({active:!item.active})}); loadVk();}; row.children[4].append(toggle); const remove=document.createElement('button'); remove.type='button'; remove.className='delete'; remove.textContent='Удалить'; remove.onclick=async()=>{if(!window.confirm(`Удалить расписание №${item.id}?`))return; remove.disabled=true; const response=await fetch(`/api/admin/vk/schedules/${item.id}`,{method:'DELETE'}); if(!response.ok){const data=await response.json();errorNode.textContent=data.error||'Не удалось удалить расписание';remove.disabled=false;return;} loadVk();}; row.children[5].append(remove); scheduleRows.append(row); }); } catch(err) { errorNode.textContent=err.message; } } - async function createVkTemplate() { const textValue=document.querySelector('#vkTemplateText').value.trim(); if(!textValue)return; const response=await fetch('/api/admin/vk/templates',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name:'Шаблон VK',text:textValue,active:true})}); if(!response.ok){const data=await response.json();document.querySelector('#vkError').textContent=data.error||'Не удалось создать шаблон';return;} document.querySelector('#vkTemplateText').value=''; } + async function updateVkTemplatePreview() { const selected=document.querySelector('#vkTemplate').selectedOptions[0]; if(!selected){document.querySelector('#vkTemplatePreview').textContent='Выберите сохранённый шаблон или напишите новый текст.';return;} try { const response=await fetch('/api/admin/vk/templates'), data=await response.json(), item=(data.items||[]).find(template=>String(template.id)===selected.value); document.querySelector('#vkTemplatePreview').textContent=item ? item.text : selected.textContent; } catch (_) { document.querySelector('#vkTemplatePreview').textContent=selected.textContent; } } + async function createVkTemplate() { const textValue=document.querySelector('#vkTemplateText').value.trim(), nameValue=document.querySelector('#vkTemplateName').value.trim() || 'Шаблон VK'; if(!textValue){document.querySelector('#vkError').textContent='Введите текст шаблона';return;} const response=await fetch('/api/admin/vk/templates',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name:nameValue,text:textValue,active:true})}), data=await response.json(); if(!response.ok){document.querySelector('#vkError').textContent=data.error||'Не удалось создать шаблон';return;} document.querySelector('#vkTemplateText').value=''; document.querySelector('#vkTemplateName').value=''; updateVkTemplateCount(); await loadVk(); document.querySelector('#vkTemplate').value=String(data.id); updateVkTemplatePreview(); document.querySelector('#vkError').textContent='Шаблон сохранён и выбран для расписания.'; } + function updateVkTemplateCount() { document.querySelector('#vkTemplateCount').textContent=`${document.querySelector('#vkTemplateText').value.length} / 4096`; } async function createVkSchedule() { const times=document.querySelector('#vkTimes').value.split(',').map(value=>value.trim()).filter(Boolean), weekdays=[...document.querySelectorAll('.weekday-options input:checked')].map(input=>Number(input.value)); const payload={peer_id:Number(document.querySelector('#vkConversation').value),template_id:Number(document.querySelector('#vkTemplate').value),times,weekdays,starts_on:document.querySelector('#vkStartsOn').value||null,ends_on:document.querySelector('#vkEndsOn').value||null,active:false}; const response=await fetch('/api/admin/vk/schedules',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(payload)}); if(!response.ok){const data=await response.json();document.querySelector('#vkError').textContent=data.error||'Не удалось создать расписание';return;} document.querySelector('#vkTimes').value=''; loadVk(); } // Extracts the primary person identity from a stored report payload. @@ -235,6 +246,7 @@ document.querySelectorAll('.admin-tab').forEach(tab => tab.addEventListener('click', () => selectAdminView(tab.dataset.adminView))); document.querySelector('#loadVk').addEventListener('click', loadVk); document.querySelector('#saveVkTemplate').addEventListener('click', createVkTemplate); document.querySelector('#saveVkSchedule').addEventListener('click', createVkSchedule); + document.querySelector('#vkTemplate').addEventListener('change', updateVkTemplatePreview); document.querySelector('#vkTemplateText').addEventListener('input', updateVkTemplateCount); restoreAdminSession();