- Done button snaps block to full duration, marks complete, logs "Marked Done by User"; Reset after Done fully un-completes the block - Session action buttons stretch full-width and double height for tablet tapping - Super admin: reset password, disable/enable accounts, delete user (with cascade), last active date per user's timezone - Disabled account login returns specific error message instead of generic invalid credentials - Users can change own password from Admin → Settings - Strikes reset automatically at midnight in user's configured timezone (lazy reset on page load) - Break timer state fully restored when navigating away and back to dashboard - Timer no longer auto-starts on navigation if it wasn't running before - Implicit pause guard: no duplicate pause events when switching already-paused blocks or starting a break - Block selection events removed from activity log; all event types have human-readable labels - House emoji favicon via inline SVG data URI - README updated to reflect all changes Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
463 lines
15 KiB
Vue
463 lines
15 KiB
Vue
<template>
|
|
<div class="page">
|
|
<NavBar />
|
|
<main class="container">
|
|
<div class="page-header">
|
|
<h1>Activity Log</h1>
|
|
<button class="btn-sm" @click="showForm = !showForm">+ Add Note</button>
|
|
</div>
|
|
|
|
<ChildSelector style="margin-bottom: 1.5rem" />
|
|
|
|
<!-- Manual note form -->
|
|
<div class="card" v-if="showForm">
|
|
<h3>Add a Note</h3>
|
|
<form @submit.prevent="createLog">
|
|
<div class="field-row">
|
|
<div class="field">
|
|
<label>Child</label>
|
|
<select v-model="newLog.child_id" required>
|
|
<option v-for="c in childrenStore.children" :key="c.id" :value="c.id">{{ c.name }}</option>
|
|
</select>
|
|
</div>
|
|
<div class="field">
|
|
<label>Date</label>
|
|
<input v-model="newLog.log_date" type="date" required />
|
|
</div>
|
|
</div>
|
|
<div class="field">
|
|
<label>Notes</label>
|
|
<textarea v-model="newLog.notes" placeholder="Add a note..." rows="3"></textarea>
|
|
</div>
|
|
<div class="form-actions">
|
|
<button type="button" class="btn-sm" @click="showForm = false">Cancel</button>
|
|
<button type="submit" class="btn-primary">Save</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Filter bar -->
|
|
<div class="filter-bar">
|
|
<input v-model="filterDate" type="date" />
|
|
<button v-if="filterDate" class="btn-sm" @click="filterDate = ''">Clear</button>
|
|
</div>
|
|
|
|
<!-- Timeline -->
|
|
<div class="timeline" v-if="combinedEntries.length">
|
|
<template v-for="(group, date) in groupedByDate" :key="date">
|
|
<div class="date-heading">{{ formatDate(date) }}</div>
|
|
<div class="event-list">
|
|
<template v-for="entry in group" :key="entry._key">
|
|
|
|
<!-- Edit form -->
|
|
<div v-if="editingEntry?._key === entry._key" class="event-row editing">
|
|
<template v-if="entry._type === 'event'">
|
|
<div class="edit-field">
|
|
<label>Type</label>
|
|
<select v-model="editDraft.event_type">
|
|
<option value="start">▶ Started</option>
|
|
<option value="pause">⏸ Paused</option>
|
|
<option value="resume">↺ Resumed</option>
|
|
<option value="complete">✓ Completed</option>
|
|
<option value="skip">⟶ Skipped</option>
|
|
<option value="reset">↩ Reset</option>
|
|
<option value="break_start">☕ Break started</option>
|
|
<option value="break_pause">⏸ Break paused</option>
|
|
<option value="break_resume">↺ Break resumed</option>
|
|
<option value="break_reset">↩ Break reset</option>
|
|
</select>
|
|
</div>
|
|
<div class="edit-field">
|
|
<label>Time</label>
|
|
<input type="time" v-model="editDraft.time" />
|
|
</div>
|
|
</template>
|
|
<template v-else>
|
|
<div class="edit-field edit-field-full">
|
|
<label>Notes</label>
|
|
<textarea v-model="editDraft.notes" rows="2"></textarea>
|
|
</div>
|
|
</template>
|
|
<div class="edit-actions">
|
|
<button class="btn-sm btn-primary" @click="saveEdit(entry)">Save</button>
|
|
<button class="btn-sm" @click="editingEntry = null">Cancel</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Display row -->
|
|
<div v-else class="event-row" :class="entry._type">
|
|
<div class="event-time">{{ fmtTime(entry.occurred_at) }}</div>
|
|
<div
|
|
class="event-dot"
|
|
:style="entry.subject_color ? { background: entry.subject_color } : {}"
|
|
:class="{ 'dot-note': entry._type === 'note', 'dot-strike': entry._type === 'strike' }"
|
|
></div>
|
|
<div class="event-body">
|
|
<div class="event-label">
|
|
<span class="event-icon">{{ eventIcon(entry) }}</span>
|
|
{{ eventLabel(entry) }}
|
|
</div>
|
|
<div class="event-subject" v-if="entry.subject_name">
|
|
{{ entry.subject_icon }} {{ entry.subject_name }}
|
|
</div>
|
|
<div class="event-notes" v-if="entry.notes">{{ entry.notes }}</div>
|
|
<div class="event-child" v-if="childrenStore.children.length > 1">
|
|
{{ entry.child_name }}
|
|
</div>
|
|
</div>
|
|
<div class="row-actions">
|
|
<button class="btn-sm" v-if="entry._type === 'event' && entry.event_type !== 'session_start'" @click="startEdit(entry)">Edit</button>
|
|
<button class="btn-sm" v-if="entry._type === 'note'" @click="startEdit(entry)">Edit</button>
|
|
<button class="btn-sm btn-danger" @click="deleteEntry(entry)">✕</button>
|
|
</div>
|
|
</div>
|
|
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
|
|
<div v-else class="empty-state">No activity recorded yet.</div>
|
|
</main>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, computed, onMounted, watch } from 'vue'
|
|
import { useChildrenStore } from '@/stores/children'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
import api from '@/composables/useApi'
|
|
import NavBar from '@/components/NavBar.vue'
|
|
import ChildSelector from '@/components/ChildSelector.vue'
|
|
import { formatTime, getHHMM, getDateInTZ, tzDateTimeToUTC } from '@/utils/time'
|
|
|
|
const childrenStore = useChildrenStore()
|
|
const authStore = useAuthStore()
|
|
const timeline = ref([])
|
|
const manualLogs = ref([])
|
|
const strikeEvents = ref([])
|
|
const showForm = ref(false)
|
|
const filterDate = ref(new Date().toISOString().split('T')[0])
|
|
|
|
const today = new Date().toISOString().split('T')[0]
|
|
const newLog = ref({ child_id: null, log_date: today, notes: '' })
|
|
|
|
const activeChildId = computed(() => childrenStore.activeChild?.id || null)
|
|
|
|
const editingEntry = ref(null)
|
|
const editDraft = ref({})
|
|
|
|
// Merge and sort timeline events + manual notes + strike events
|
|
const combinedEntries = computed(() => {
|
|
const events = timeline.value.map(e => ({
|
|
...e,
|
|
_type: 'event',
|
|
_key: `event-${e.id}`,
|
|
occurred_at: e.occurred_at,
|
|
child_name: e.child_name,
|
|
}))
|
|
const notes = manualLogs.value.map(l => ({
|
|
...l,
|
|
_type: 'note',
|
|
_key: `note-${l.id}`,
|
|
occurred_at: l.log_date + 'T00:00:00',
|
|
child_name: childrenStore.children.find(c => c.id === l.child_id)?.name || '',
|
|
subject_name: null,
|
|
subject_icon: null,
|
|
subject_color: null,
|
|
}))
|
|
const strikes = strikeEvents.value.map(s => ({
|
|
...s,
|
|
_type: 'strike',
|
|
_key: `strike-${s.id}`,
|
|
subject_name: null,
|
|
subject_icon: null,
|
|
subject_color: null,
|
|
}))
|
|
return [...events, ...notes, ...strikes].sort((a, b) => b.occurred_at.localeCompare(a.occurred_at))
|
|
})
|
|
|
|
// Group by session_date (events) or log_date (notes/strikes)
|
|
const groupedByDate = computed(() => {
|
|
const groups = {}
|
|
for (const entry of combinedEntries.value) {
|
|
const d = entry._type === 'event' ? entry.session_date : entry.log_date
|
|
if (!groups[d]) groups[d] = []
|
|
groups[d].push(entry)
|
|
}
|
|
return groups
|
|
})
|
|
|
|
function formatDate(dateStr) {
|
|
const d = new Date(dateStr + 'T12:00:00')
|
|
return d.toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' })
|
|
}
|
|
|
|
function fmtTime(isoStr) {
|
|
return formatTime(isoStr, authStore.timezone)
|
|
}
|
|
|
|
const EVENT_META = {
|
|
session_start: { icon: '🏫', label: 'Day started' },
|
|
start: { icon: '▶', label: 'Started' },
|
|
pause: { icon: '⏸', label: 'Paused' },
|
|
resume: { icon: '↺', label: 'Resumed' },
|
|
complete: { icon: '✓', label: 'Completed' },
|
|
skip: { icon: '⟶', label: 'Skipped' },
|
|
reset: { icon: '↩', label: 'Reset' },
|
|
break_start: { icon: '☕', label: 'Break started' },
|
|
break_pause: { icon: '⏸', label: 'Break paused' },
|
|
break_resume: { icon: '↺', label: 'Break resumed' },
|
|
break_reset: { icon: '↩', label: 'Break reset' },
|
|
}
|
|
|
|
function eventIcon(entry) {
|
|
if (entry._type === 'note') return '📝'
|
|
if (entry._type === 'strike') return entry.new_strikes > entry.prev_strikes ? '✕' : '↩'
|
|
if (entry.event_type === 'complete' && !entry.block_label) return '🏁'
|
|
return EVENT_META[entry.event_type]?.icon || '•'
|
|
}
|
|
|
|
function eventLabel(entry) {
|
|
if (entry._type === 'note') return 'Note'
|
|
if (entry._type === 'strike') {
|
|
const added = entry.new_strikes > entry.prev_strikes
|
|
return added
|
|
? `Strike added (${entry.new_strikes}/3)`
|
|
: `Strike removed (${entry.new_strikes}/3)`
|
|
}
|
|
if (entry.event_type === 'complete' && !entry.block_label) return 'Day ended'
|
|
if (entry.event_type === 'complete' && entry.block_label) return `Marked Done by User — ${entry.block_label}`
|
|
const action = EVENT_META[entry.event_type]?.label || entry.event_type
|
|
return entry.block_label ? `${action} — ${entry.block_label}` : action
|
|
}
|
|
|
|
function startEdit(entry) {
|
|
editingEntry.value = entry
|
|
if (entry._type === 'event') {
|
|
editDraft.value = {
|
|
event_type: entry.event_type,
|
|
time: getHHMM(entry.occurred_at, authStore.timezone),
|
|
}
|
|
} else {
|
|
editDraft.value = { notes: entry.notes || '' }
|
|
}
|
|
}
|
|
|
|
async function saveEdit(entry) {
|
|
if (entry._type === 'event') {
|
|
const dateInTZ = getDateInTZ(entry.occurred_at, authStore.timezone)
|
|
const utcDate = tzDateTimeToUTC(dateInTZ, editDraft.value.time, authStore.timezone)
|
|
await api.patch(`/api/logs/timeline/${entry.id}`, {
|
|
event_type: editDraft.value.event_type,
|
|
occurred_at: utcDate.toISOString(),
|
|
})
|
|
} else {
|
|
await api.patch(`/api/logs/${entry.id}`, { notes: editDraft.value.notes })
|
|
}
|
|
editingEntry.value = null
|
|
await loadData()
|
|
}
|
|
|
|
async function deleteEntry(entry) {
|
|
if (!confirm('Delete this entry?')) return
|
|
if (entry._type === 'event') {
|
|
await api.delete(`/api/logs/timeline/${entry.id}`)
|
|
timeline.value = timeline.value.filter(e => e.id !== entry.id)
|
|
} else if (entry._type === 'strike') {
|
|
await api.delete(`/api/logs/strikes/${entry.id}`)
|
|
strikeEvents.value = strikeEvents.value.filter(s => s.id !== entry.id)
|
|
} else {
|
|
await api.delete(`/api/logs/${entry.id}`)
|
|
manualLogs.value = manualLogs.value.filter(l => l.id !== entry.id)
|
|
}
|
|
}
|
|
|
|
async function loadData() {
|
|
const params = {}
|
|
if (activeChildId.value) params.child_id = activeChildId.value
|
|
if (filterDate.value) params.log_date = filterDate.value
|
|
|
|
const [tRes, lRes, sRes] = await Promise.all([
|
|
api.get('/api/logs/timeline', { params }),
|
|
api.get('/api/logs', { params }),
|
|
api.get('/api/logs/strikes', { params }),
|
|
])
|
|
timeline.value = tRes.data
|
|
manualLogs.value = lRes.data
|
|
strikeEvents.value = sRes.data
|
|
}
|
|
|
|
async function createLog() {
|
|
await api.post('/api/logs', { ...newLog.value, session_id: null, subject_id: null, duration_minutes: null })
|
|
newLog.value = { child_id: newLog.value.child_id, log_date: today, notes: '' }
|
|
showForm.value = false
|
|
await loadData()
|
|
}
|
|
|
|
|
|
onMounted(async () => {
|
|
await childrenStore.fetchChildren()
|
|
if (childrenStore.activeChild) newLog.value.child_id = childrenStore.activeChild.id
|
|
await loadData()
|
|
})
|
|
|
|
watch([activeChildId, filterDate], loadData)
|
|
</script>
|
|
|
|
<style scoped>
|
|
.page { min-height: 100vh; background: #0f172a; }
|
|
.container { max-width: 800px; margin: 0 auto; padding: 2rem; }
|
|
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; }
|
|
h1 { font-size: 1.75rem; font-weight: 700; }
|
|
|
|
.card { background: #1e293b; border-radius: 1rem; padding: 1.5rem; margin-bottom: 1.5rem; }
|
|
.card h3 { margin-bottom: 1.25rem; }
|
|
|
|
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
|
|
.field { margin-bottom: 1rem; }
|
|
.field label { display: block; font-size: 0.85rem; color: #94a3b8; margin-bottom: 0.4rem; }
|
|
.field input, .field select, .field textarea {
|
|
width: 100%;
|
|
padding: 0.65rem 0.9rem;
|
|
background: #0f172a;
|
|
border: 1px solid #334155;
|
|
border-radius: 0.5rem;
|
|
color: #f1f5f9;
|
|
font-size: 0.9rem;
|
|
resize: vertical;
|
|
}
|
|
.form-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 0.5rem; }
|
|
|
|
.filter-bar { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; }
|
|
.filter-bar input {
|
|
padding: 0.5rem 0.75rem;
|
|
background: #1e293b;
|
|
border: 1px solid #334155;
|
|
border-radius: 0.5rem;
|
|
color: #f1f5f9;
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.date-heading {
|
|
font-size: 0.8rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: #475569;
|
|
margin: 1.5rem 0 0.75rem;
|
|
}
|
|
|
|
.event-list { display: flex; flex-direction: column; gap: 0.4rem; }
|
|
|
|
.event-row {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 0.75rem;
|
|
padding: 0.75rem 1rem;
|
|
background: #1e293b;
|
|
border-radius: 0.75rem;
|
|
border-left: 3px solid transparent;
|
|
}
|
|
|
|
.event-row.event { border-left-color: #334155; }
|
|
.event-row.note { border-left-color: #4f46e5; }
|
|
.event-row.editing { border-left-color: #4f46e5; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
|
|
|
|
.edit-field { display: flex; flex-direction: column; gap: 0.25rem; }
|
|
.edit-field label { font-size: 0.75rem; color: #64748b; }
|
|
.edit-field select,
|
|
.edit-field input,
|
|
.edit-field textarea {
|
|
padding: 0.4rem 0.6rem;
|
|
background: #0f172a;
|
|
border: 1px solid #334155;
|
|
border-radius: 0.4rem;
|
|
color: #f1f5f9;
|
|
font-size: 0.85rem;
|
|
}
|
|
.edit-field textarea { resize: vertical; }
|
|
.edit-field-full { flex: 1; min-width: 200px; }
|
|
.edit-actions { display: flex; gap: 0.4rem; align-items: flex-end; margin-left: auto; }
|
|
|
|
.row-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
|
|
|
|
.event-time {
|
|
font-size: 0.78rem;
|
|
color: #475569;
|
|
width: 68px;
|
|
flex-shrink: 0;
|
|
padding-top: 0.15rem;
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
|
|
.event-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
background: #334155;
|
|
flex-shrink: 0;
|
|
margin-top: 0.4rem;
|
|
}
|
|
|
|
.event-dot.dot-note { background: #4f46e5; }
|
|
.event-dot.dot-strike { background: #ef4444; }
|
|
|
|
.event-body { flex: 1; min-width: 0; }
|
|
|
|
.event-label {
|
|
font-size: 0.9rem;
|
|
font-weight: 500;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
}
|
|
|
|
.event-icon { font-size: 0.85rem; }
|
|
|
|
.event-subject {
|
|
font-size: 0.8rem;
|
|
color: #64748b;
|
|
margin-top: 0.15rem;
|
|
}
|
|
|
|
.event-notes {
|
|
font-size: 0.85rem;
|
|
color: #94a3b8;
|
|
margin-top: 0.2rem;
|
|
}
|
|
|
|
.event-child {
|
|
font-size: 0.75rem;
|
|
color: #475569;
|
|
margin-top: 0.15rem;
|
|
}
|
|
|
|
.empty-state { text-align: center; padding: 4rem; color: #64748b; }
|
|
|
|
.btn-primary {
|
|
padding: 0.65rem 1.25rem;
|
|
background: #4f46e5;
|
|
color: #fff;
|
|
border: none;
|
|
border-radius: 0.5rem;
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
transition: background 0.2s;
|
|
}
|
|
.btn-primary:hover { background: #4338ca; }
|
|
|
|
.btn-sm {
|
|
padding: 0.35rem 0.75rem;
|
|
border: 1px solid #334155;
|
|
background: transparent;
|
|
color: #94a3b8;
|
|
border-radius: 0.5rem;
|
|
cursor: pointer;
|
|
font-size: 0.8rem;
|
|
transition: all 0.2s;
|
|
}
|
|
.btn-sm:hover { background: #334155; }
|
|
.btn-sm.btn-danger { border-color: #7f1d1d; color: #fca5a5; }
|
|
.btn-sm.btn-danger:hover { background: #7f1d1d; }
|
|
</style>
|