Files
FabledGrimoire/frontend/src/components/TaskLogSection.vue
T
bvandeusenandClaude Opus 5.5 38bc25a2b7
CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / Python tests (push) Failing after 1m37s
CI & Build / integration (push) Successful in 2m11s
CI & Build / Build & push image (push) Skipped
fix(7736): #N in a body links to the record it names, not to a tag
A purely numeric #N is a record reference everywhere now. The tag
patterns (frontend utils/tags.ts, the editor decoration, the first-line
tag strip, tag autocomplete, backend utils/tags.py) leave digits alone,
so #3127 is no longer drawn as a tag chip linking to /notes?tag=3127.

- utils/recordRefs.ts links #N, milestone N and rule N in rendered
  markdown, with the same patterns and other-numbering word list as
  services/record_refs.py. A drift test reads the TS source and fails
  when the two differ.
- v-record-refs (directives/recordRefs.ts) asks POST
  /api/notes/resolve-refs once per body for what each id is. A link
  gets the route for its kind (task, lesson, snippet, note, milestone,
  rule) and its kind and title on hover. One the reader cannot open is
  drawn as a dead reference, and missing vs not shared read the same.
  Applied on every surface that renders markdown.
- /milestones/:id finds the project and opens its board at that
  milestone (?milestone= expands it, scrolls to it and focuses it).
- Backlinks include records that cite #N in a body or a work log,
  through readable_notes_clause instead of an owner-only filter, and
  route by kind. The graph draws #N citations as dashed reference edges.
- create_note, create_task and add_task_log say which forms link.

There were no numeric tags to clean up: tags are stored only from the
explicit field, and none of the 200 most used is numeric.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:15:15 -05:00

281 lines
6.8 KiB
Vue

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { apiGet, apiPost, apiPatch, apiDelete } from "@/api/client";
import { renderMarkdown } from "@/utils/markdown";
import { vRecordRefs } from "@/directives/recordRefs";
import type { TaskLog } from "@/types/task";
import { fmtStamp } from "@/utils/dateFormat";
const props = defineProps<{ taskId: number }>();
const logs = ref<TaskLog[]>([]);
const newContent = ref("");
const newDuration = ref("");
const submitting = ref(false);
const editingId = ref<number | null>(null);
const editContent = ref("");
const editDuration = ref("");
function formatDuration(minutes: number): string {
if (minutes < 60) return `${minutes} min`;
const h = Math.floor(minutes / 60);
const m = minutes % 60;
return m > 0 ? `${h}h ${m}m` : `${h}h`;
}
async function loadLogs() {
try {
const data = await apiGet<{ logs: TaskLog[] }>(`/api/tasks/${props.taskId}/logs`);
logs.value = data.logs;
} catch {
// silent
}
}
async function submitLog() {
const content = newContent.value.trim();
if (!content || submitting.value) return;
submitting.value = true;
try {
const duration = newDuration.value ? parseInt(newDuration.value) : null;
const log = await apiPost<TaskLog>(`/api/tasks/${props.taskId}/logs`, {
content,
duration_minutes: isNaN(duration as number) ? null : duration,
});
logs.value = [...logs.value, log];
newContent.value = "";
newDuration.value = "";
} catch {
// silent
} finally {
submitting.value = false;
}
}
function startEdit(log: TaskLog) {
editingId.value = log.id;
editContent.value = log.content;
editDuration.value = log.duration_minutes != null ? String(log.duration_minutes) : "";
}
function cancelEdit() {
editingId.value = null;
editContent.value = "";
editDuration.value = "";
}
async function saveEdit(log: TaskLog) {
const content = editContent.value.trim();
if (!content) return;
const duration = editDuration.value ? parseInt(editDuration.value) : null;
try {
const updated = await apiPatch<TaskLog>(`/api/tasks/${props.taskId}/logs/${log.id}`, {
content,
duration_minutes: isNaN(duration as number) ? null : duration,
});
const idx = logs.value.findIndex((l) => l.id === log.id);
if (idx !== -1) logs.value[idx] = updated;
cancelEdit();
} catch {
// silent
}
}
async function deleteLog(log: TaskLog) {
try {
await apiDelete(`/api/tasks/${props.taskId}/logs/${log.id}`);
logs.value = logs.value.filter((l) => l.id !== log.id);
} catch {
// silent
}
}
onMounted(loadLogs);
</script>
<template>
<div class="log-section">
<div class="log-header">Work Log</div>
<div v-if="logs.length === 0" class="log-empty">No entries yet.</div>
<div v-for="log in logs" :key="log.id" class="log-entry">
<template v-if="editingId === log.id">
<textarea
v-model="editContent"
class="log-textarea"
rows="3"
placeholder="What did you do?"
@keydown.ctrl.enter="saveEdit(log)"
></textarea>
<div class="log-edit-controls">
<input
v-model="editDuration"
type="number"
min="1"
class="log-duration-input"
placeholder="min"
/>
<button class="btn-primary btn-compact" @click="saveEdit(log)">Save</button>
<button class="btn-ghost btn-compact" @click="cancelEdit">Cancel</button>
</div>
</template>
<template v-else>
<div class="log-entry-meta">
<span class="log-date">{{ fmtStamp(log.created_at) }}</span>
<span v-if="log.duration_minutes" class="log-duration-badge">
{{ formatDuration(log.duration_minutes) }}
</span>
<div class="log-entry-actions">
<button class="btn-text" @click="startEdit(log)" title="Edit">Edit</button>
<button class="btn-text" aria-label="Delete log entry" @click="deleteLog(log)">&times;</button>
</div>
</div>
<div class="log-content prose" v-html="renderMarkdown(log.content)" v-record-refs></div>
</template>
</div>
<div class="log-add">
<textarea
v-model="newContent"
class="log-textarea"
rows="3"
placeholder="What did you do?..."
@keydown.ctrl.enter="submitLog"
autofocus
></textarea>
<div class="log-add-controls">
<label class="log-duration-label">
min:
<input
v-model="newDuration"
type="number"
min="1"
class="log-duration-input"
placeholder="—"
/>
</label>
<button
class="btn-primary btn-compact"
@click="submitLog"
:disabled="!newContent.trim() || submitting"
>
{{ submitting ? "Saving..." : "Log entry" }}
</button>
</div>
</div>
</div>
</template>
<style scoped>
.log-section {
border: 1px solid var(--fs-border-color);
border-radius: var(--fs-radius-sm);
background: var(--fs-surface-raised);
padding: 0.6rem 0.75rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.log-header {
font-size: 0.8rem;
font-weight: 600;
color: var(--fs-text-secondary);
text-transform: uppercase;
letter-spacing: 0.04em;
margin-bottom: 0.15rem;
}
.log-empty {
font-size: 0.8rem;
color: var(--fs-text-tertiary);
}
.log-entry {
border-top: 1px solid var(--fs-border-color);
padding-top: 0.5rem;
}
.log-entry-meta {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.25rem;
font-size: 0.8rem;
}
.log-date {
color: var(--fs-text-tertiary);
}
.log-duration-badge {
background: var(--fs-accent);
color: var(--fs-text-on-action);
border-radius: 99px;
padding: 0.1rem 0.5rem;
font-size: 0.72rem;
font-weight: 600;
}
.log-entry-actions {
margin-left: auto;
display: flex;
gap: 0.25rem;
}
.log-textarea {
width: 100%;
padding: 0.4rem 0.5rem;
border: 1px solid var(--fs-border-color);
border-radius: var(--fs-radius-sm);
background: var(--fs-surface-page);
color: var(--fs-text-primary);
font-size: 0.875rem;
font-family: inherit;
resize: vertical;
box-sizing: border-box;
}
.log-textarea:focus {
outline: none;
border-color: var(--fs-accent);
}
.log-add-controls,
.log-edit-controls {
display: flex;
align-items: center;
gap: 0.5rem;
}
.log-duration-label {
font-size: 0.8rem;
color: var(--fs-text-tertiary);
display: flex;
align-items: center;
gap: 0.25rem;
}
.log-duration-input {
width: 5rem;
padding: 0.3rem 0.4rem;
border: 1px solid var(--fs-border-color);
border-radius: var(--fs-radius-sm);
background: var(--fs-surface-page);
color: var(--fs-text-primary);
font-size: 0.875rem;
}
.log-duration-input:focus {
outline: none;
border-color: var(--fs-accent);
}
</style>