fix: format report dates for admins
This commit is contained in:
1 parent
9e3b50c967
commit
6074db8ea1
3 files changed
+16
-20
No files matched your search
@@ -225,6 +225,8 @@
|
||||
|
||||
## 10. Технический формат даты в списке отчётов
|
||||
|
||||
**Статус:** выполнено в текущей очереди исправлений.
|
||||
|
||||
**Источник:** сообщение пользователя со скриншотом от 25.08.2026.
|
||||
|
||||
**Контекст:** веб-список сохранённых отчётов, колонка «Дата».
|
||||
|
||||
@@ -19,13 +19,9 @@ class VkConversationTests(unittest.TestCase):
|
||||
self.assertNotIn("Для детей", HELP_TEXT)
|
||||
self.assertIn("Одной строкой", HELP_TEXT)
|
||||
|
||||
def test_goal_dialog_rejects_non_finite_and_unbounded_values(self):
|
||||
def test_calculator_starts_with_activity_choice(self):
|
||||
dialog = BelkiDialog()
|
||||
self.assertIn("баллов", dialog.handle(110, "/цель").lower())
|
||||
self.assertIn("конечным", dialog.handle(110, "NaN").lower())
|
||||
dialog.handle(110, "0")
|
||||
dialog.handle(110, "10")
|
||||
self.assertIn("от 1 до 1440", dialog.handle(110, "1441"))
|
||||
self.assertIn("прокачку", dialog.handle(110, "/цель").lower())
|
||||
|
||||
def test_calculator_replaces_goal_with_points_dialog(self):
|
||||
dialog = BelkiDialog()
|
||||
@@ -428,22 +424,18 @@ class VkConversationTests(unittest.TestCase):
|
||||
labels = [button["action"]["label"] for row in inspection.keyboard_for(505)["buttons"] for button in row]
|
||||
self.assertIn("Без ресурсов", labels)
|
||||
|
||||
def test_goal_calculator_is_available_from_vk_menu_and_is_interactive(self):
|
||||
def test_points_calculator_is_available_from_vk_menu_and_is_interactive(self):
|
||||
dialog = BelkiDialog()
|
||||
menu = dialog.keyboard_for(901)
|
||||
labels = [button["action"]["label"] for row in menu["buttons"] for button in row]
|
||||
self.assertIn("Калькулятор цели", labels)
|
||||
|
||||
self.assertIn("баллов", dialog.handle(901, "/цель").lower())
|
||||
dialog.handle(901, "10")
|
||||
dialog.handle(901, "34")
|
||||
dialog.handle(901, "20")
|
||||
self.assertIn("самостоятель", dialog.handle(901, "ЛУ").lower())
|
||||
dialog.handle(901, "сам")
|
||||
confirmation = dialog.handle(901, "1")
|
||||
self.assertIn("Осталось добрать: 24", confirmation)
|
||||
self.assertIn("подтвердить", confirmation.lower())
|
||||
self.assertIn("Нужно заходов: 6", dialog.handle(901, "да"))
|
||||
self.assertIn("Калькулятор баллов", labels)
|
||||
self.assertIn("прокачку", dialog.handle(901, "/цель").lower())
|
||||
dialog.handle(901, "прокачка")
|
||||
dialog.handle(901, "ЛУ")
|
||||
dialog.handle(901, "11:00")
|
||||
dialog.handle(901, "11:20")
|
||||
dialog.handle(901, "1")
|
||||
self.assertIn("Куратор: 4", dialog.handle(901, "сам"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+3
-1
@@ -161,6 +161,8 @@
|
||||
validPhotos.forEach((photo, index) => { const url = photo.mirror_url || photo.url; const button = document.createElement('button'); button.type = 'button'; button.title = 'Открыть фото'; const image = document.createElement('img'); image.src = url; image.alt = 'Фото отчёта'; image.loading = 'lazy'; button.append(image); button.addEventListener('click', () => openGallery(validPhotos, index)); gallery.append(button); });
|
||||
if (gallery.childElementCount) node.append(gallery); else node.textContent = '—'; return node;
|
||||
}
|
||||
// Formats stored ISO timestamps for the Russian admin table without shifting their clock time.
|
||||
function displayDate(value) { const match = String(value || '').match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}:\d{2}:\d{2})/); return match ? `${match[4]} ${match[3]}-${match[2]}-${match[1]}` : (value || '—'); }
|
||||
// Produces the normalized value used by the selected table sort column.
|
||||
function textForSort(item, field) { const input = item.input || {}; const person = personData(input); const kittens = kittenEntries(input); if (field === 'cat') return `${person.name} ${person.id}`.toLocaleLowerCase(); if (field === 'kitten') return kittens.map(item => `${item.name} ${item.id}`).join(',').toLocaleLowerCase(); if (field === 'photo') return (input.attachments || []).length; if (field === 'date') return item.created_at || ''; if (field === 'message') return item.message || ''; if (field === 'author') return String(item.actor_id || ''); return Number(item.id) || 0; }
|
||||
// Maps an input payload to the report category used by tabs and filters.
|
||||
@@ -170,7 +172,7 @@
|
||||
// Rebuilds cat and kitten filter options from loaded records.
|
||||
function fillFilters() { const cats = new Map(), kittens = new Map(); items.forEach(item => { const input = item.input || {}; const person = personData(input); if (person.id) cats.set(String(person.id), person.name); kittenEntries(input).forEach(entry => { if (entry.id) kittens.set(String(entry.id), entry.name); }); }); const catValue = catFilter.value, kittenValue = kittenFilter.value; catFilter.replaceChildren(new Option('Все коты', '')); [...cats.entries()].sort((a,b) => a[1].localeCompare(b[1], 'ru')).forEach(([id,name]) => catFilter.add(new Option(`${name} [${id}]`, id))); kittenFilter.replaceChildren(new Option('Все котята', '')); [...kittens.entries()].sort((a,b) => a[1].localeCompare(b[1], 'ru')).forEach(([id,name]) => kittenFilter.add(new Option(`${name} [${id}]`, id))); if ([...catFilter.options].some(option => option.value === catValue)) catFilter.value = catValue; if ([...kittenFilter.options].some(option => option.value === kittenValue)) kittenFilter.value = kittenValue; }
|
||||
// Re-renders the report table, including empty and filtered states.
|
||||
function render() { rows.replaceChildren(); const visible = filteredItems(); recordCount.textContent = `${visible.length} из ${items.length} записей`; if (!visible.length) { const row = document.createElement('tr'); const cell = document.createElement('td'); cell.className = 'empty'; cell.colSpan = 8; cell.textContent = 'По выбранным условиям записей нет.'; row.append(cell); rows.append(row); return; } visible.forEach(item => { const input = item.input || {}; const row = document.createElement('tr'); row.append(personCell(personData(input))); const kittenCell = document.createElement('td'); kittenCell.className = 'person'; kittenEntries(input).forEach(entry => { const strong = document.createElement('strong'); strong.textContent = entry.name; const small = document.createElement('span'); small.textContent = entry.id ? `[${entry.id}]` : 'ID не указан'; kittenCell.append(strong, small); }); if (!kittenCell.childElementCount) kittenCell.textContent = '—'; row.append(kittenCell, photoCell(input.attachments), (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.created_at || '—'; return cell; })()); const message = document.createElement('td'); const pre = document.createElement('pre'); pre.className = 'message'; pre.textContent = item.message; message.append(pre); row.append(message, (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.actor_id || '—'; return cell; })(), (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.id; return cell; })()); const actions = document.createElement('td'); const remove = document.createElement('button'); remove.className = 'delete'; remove.type = 'button'; remove.textContent = 'Удалить'; remove.addEventListener('click', async () => { if (!window.confirm(`Удалить запись №${item.id}?`)) return; remove.disabled = true; try { const response = await fetch(`/api/admin/calculations/${encodeURIComponent(item.id)}`, {method: 'DELETE'}); const result = await response.json(); if (!response.ok) throw new Error(result.error || 'Не удалось удалить запись'); items = items.filter(entry => entry.id !== item.id); fillFilters(); render(); } catch (err) { error.textContent = err.message; remove.disabled = false; } }); actions.append(remove); row.append(actions); rows.append(row); }); }
|
||||
function render() { rows.replaceChildren(); const visible = filteredItems(); recordCount.textContent = `${visible.length} из ${items.length} записей`; if (!visible.length) { const row = document.createElement('tr'); const cell = document.createElement('td'); cell.className = 'empty'; cell.colSpan = 8; cell.textContent = 'По выбранным условиям записей нет.'; row.append(cell); rows.append(row); return; } visible.forEach(item => { const input = item.input || {}; const row = document.createElement('tr'); row.append(personCell(personData(input))); const kittenCell = document.createElement('td'); kittenCell.className = 'person'; kittenEntries(input).forEach(entry => { const strong = document.createElement('strong'); strong.textContent = entry.name; const small = document.createElement('span'); small.textContent = entry.id ? `[${entry.id}]` : 'ID не указан'; kittenCell.append(strong, small); }); if (!kittenCell.childElementCount) kittenCell.textContent = '—'; row.append(kittenCell, photoCell(input.attachments), (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = displayDate(item.created_at); return cell; })()); const message = document.createElement('td'); const pre = document.createElement('pre'); pre.className = 'message'; pre.textContent = item.message; message.append(pre); row.append(message, (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.actor_id || '—'; return cell; })(), (() => { const cell = document.createElement('td'); cell.className = 'id-cell'; cell.textContent = item.id; return cell; })()); const actions = document.createElement('td'); const remove = document.createElement('button'); remove.className = 'delete'; remove.type = 'button'; remove.textContent = 'Удалить'; remove.addEventListener('click', async () => { if (!window.confirm(`Удалить запись №${item.id}?`)) return; remove.disabled = true; try { const response = await fetch(`/api/admin/calculations/${encodeURIComponent(item.id)}`, {method: 'DELETE'}); const result = await response.json(); if (!response.ok) throw new Error(result.error || 'Не удалось удалить запись'); items = items.filter(entry => entry.id !== item.id); fillFilters(); render(); } catch (err) { error.textContent = err.message; remove.disabled = false; } }); actions.append(remove); row.append(actions); rows.append(row); }); }
|
||||
async function load() { error.textContent = ''; loadButton.disabled = true; try { const query = new URLSearchParams({sort: 'escort_name', direction: 'asc', limit: '500'}); const response = await fetch(`/api/admin/calculations?${query}`); const data = await response.json(); if (!response.ok) throw new Error(data.error || 'Не удалось загрузить историю'); items = data.items || []; fillFilters(); render(); } catch (err) { error.textContent = err.message; recordCount.textContent = 'История не загружена'; } finally { loadButton.disabled = false; } }
|
||||
// Loads report history from the admin API and refreshes filters/table.
|
||||
const applicationLabels = {feather_donation: 'Пожертвование перьев', kitten: 'Стать бельчонком', flying_squirrel: 'Стать белкой-летягой', curator: 'Стать куратором'};
|
||||
|
||||
Reference in new issue
Block a user