refactor: call a heading a title, and its use a placement
`template_field_library` and `template_field` were one word apart and meant
opposite kinds of thing — a catalogue of rows versus one row — and neither name
said what a row actually is. Every row of the library is a **heading**: a piece
of text like 「1. Introduction」 with a level and typography, which is what the
reader sees at the top of a paragraph; and every row of the join table is that
heading *placed* in a template, `sort` included.
template_field_library -> template_title
template_field -> template_title_placement
field_id (the column) -> title_id
TemplateFieldLibrary -> TemplateTitle
TemplateField -> TemplateTitlePlacement
The join table keeps its own name rather than becoming `_link`, because it is
not a bare link: it carries `sort`, the only place display order is stored, and
it deliberately allows the same title twice in one template. `_link` would
describe two foreign keys and hide the column the ordering rule rests on.
Carried through every level, because a half-renamed layer is how the confusing
pair got there in the first place: HTTP paths (`/template-field-library` ->
`/template-titles`), the template payload (`fields`/`field_id` ->
`placements`/`title_id`, and `field_count` -> `placement_count`), the Pydantic
schemas, the CRUD modules, the seed script, the frontend API module and types,
and `docs/OVERVIEW.md`, which now states the naming rules outright.
Two deliberate exceptions:
* `paper_template_filed_sort` is untouched — it is a column of the paper module
and is spelled as the feature was specified.
* The MCP tools keep their agent-facing names (`field_list`, `field_ids`, and
the `fields`/`field_id` keys in their responses). Agents already call them by
those names; the storage names they read underneath have changed.
The migration renames in place (data preserved: 4 templates, 45 titles, 63
placements) and is written to tolerate a database where part of it already ran,
which is not hypothetical — the first attempt renamed the tables and then failed
on the column, because Alembic's MySQL dialect wants an explicit type for
`alter_column` and will not rename a column without one. TiDB carries the
foreign key along with both the renamed table and the renamed column, rehearsed
against the cluster first, and it stays enforced.
Verified: seed re-runs clean, the paper smoke test's 45 checks and the MCP
smoke test's 47 pass, `vue-tsc` and the build are clean, and the UI was driven
in a headless browser through the template list, its preview drawer, the title
library page, the template form (which now posts `placements` with `title_id`)
and the paper document with no console errors.
This commit is contained in:
@@ -12,7 +12,7 @@ import { useRouter } from 'vue-router'
|
||||
import { Files, Notebook, Setting } from '@element-plus/icons-vue'
|
||||
|
||||
import { listPapers } from '@/api/papers'
|
||||
import { listTemplateFieldLibrary } from '@/api/templateFieldLibrary'
|
||||
import { listTemplateTitle } from '@/api/templateTitles'
|
||||
import { listTemplates } from '@/api/templates'
|
||||
import AppLogo from '@/components/AppLogo.vue'
|
||||
|
||||
@@ -20,7 +20,7 @@ const router = useRouter()
|
||||
|
||||
const paperCount = ref<number | null>(null)
|
||||
const templateCount = ref<number | null>(null)
|
||||
const fieldCount = ref<number | null>(null)
|
||||
const titleCount = ref<number | null>(null)
|
||||
|
||||
/** `null` renders as an em dash: unknown, not zero. */
|
||||
function display(value: number | null): string {
|
||||
@@ -30,14 +30,14 @@ function display(value: number | null): string {
|
||||
onMounted(async () => {
|
||||
// `page_size: 1` because only `total` is used. A failure leaves the count as
|
||||
// an em dash rather than blocking the page.
|
||||
const [papers, templates, fields] = await Promise.allSettled([
|
||||
const [papers, templates, titles] = await Promise.allSettled([
|
||||
listPapers({ page: 1, page_size: 1 }),
|
||||
listTemplates({ page: 1, page_size: 1 }),
|
||||
listTemplateFieldLibrary({ page: 1, page_size: 1 }),
|
||||
listTemplateTitle({ page: 1, page_size: 1 }),
|
||||
])
|
||||
if (papers.status === 'fulfilled') paperCount.value = papers.value.total
|
||||
if (templates.status === 'fulfilled') templateCount.value = templates.value.total
|
||||
if (fields.status === 'fulfilled') fieldCount.value = fields.value.total
|
||||
if (titles.status === 'fulfilled') titleCount.value = titles.value.total
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -81,7 +81,7 @@ onMounted(async () => {
|
||||
<div class="stat">
|
||||
<el-icon class="stat-icon"><Setting /></el-icon>
|
||||
<div>
|
||||
<div class="stat-value">{{ display(fieldCount) }}</div>
|
||||
<div class="stat-value">{{ display(titleCount) }}</div>
|
||||
<div class="stat-label">字段库</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -14,18 +14,18 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
batchDeleteTemplateFieldLibrary,
|
||||
deleteTemplateFieldLibrary,
|
||||
listTemplateFieldLibrary,
|
||||
type TemplateFieldLibrary,
|
||||
} from '@/api/templateFieldLibrary'
|
||||
batchDeleteTemplateTitle,
|
||||
deleteTemplateTitle,
|
||||
listTemplateTitle,
|
||||
type TemplateTitle,
|
||||
} from '@/api/templateTitles'
|
||||
import FieldFormDialog from '@/components/fields/FieldFormDialog.vue'
|
||||
import { formatDateTime, levelIndent, typographyStyle } from '@/utils/format'
|
||||
|
||||
const loading = ref(false)
|
||||
const rows = ref<TemplateFieldLibrary[]>([])
|
||||
const rows = ref<TemplateTitle[]>([])
|
||||
const total = ref(0)
|
||||
const selection = ref<TemplateFieldLibrary[]>([])
|
||||
const selection = ref<TemplateTitle[]>([])
|
||||
|
||||
const query = reactive({
|
||||
keyword: '',
|
||||
@@ -35,7 +35,7 @@ const query = reactive({
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const editing = ref<TemplateFieldLibrary | null>(null)
|
||||
const editing = ref<TemplateTitle | null>(null)
|
||||
|
||||
const LEVEL_FILTERS = [
|
||||
{ value: null, label: '全部等级' },
|
||||
@@ -47,7 +47,7 @@ const LEVEL_FILTERS = [
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await listTemplateFieldLibrary(query)
|
||||
const result = await listTemplateTitle(query)
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
|
||||
@@ -81,12 +81,12 @@ function onCreate(): void {
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function onEdit(row: TemplateFieldLibrary): void {
|
||||
function onEdit(row: TemplateTitle): void {
|
||||
editing.value = row
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function onDelete(row: TemplateFieldLibrary): Promise<void> {
|
||||
async function onDelete(row: TemplateTitle): Promise<void> {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除字段「${row.name}」?`, '删除字段', {
|
||||
type: 'warning',
|
||||
@@ -98,7 +98,7 @@ async function onDelete(row: TemplateFieldLibrary): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteTemplateFieldLibrary(row.id)
|
||||
await deleteTemplateTitle(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await load()
|
||||
} catch (error) {
|
||||
@@ -121,7 +121,7 @@ async function onBatchDelete(): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await batchDeleteTemplateFieldLibrary(ids)
|
||||
const result = await batchDeleteTemplateTitle(ids)
|
||||
ElMessage.success(`已删除 ${result.deleted} 个字段`)
|
||||
selection.value = []
|
||||
await load()
|
||||
@@ -195,7 +195,7 @@ onMounted(load)
|
||||
stripe
|
||||
class="table table-fill"
|
||||
height="100%"
|
||||
@selection-change="(value: TemplateFieldLibrary[]) => (selection = value)"
|
||||
@selection-change="(value: TemplateTitle[]) => (selection = value)"
|
||||
>
|
||||
<el-table-column type="selection" width="46" reserve-selection />
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* The full CRUD surface: search, create, edit, single and batch delete, with a
|
||||
* preview drawer that renders a template's outline exactly as it will read.
|
||||
* The drawer is the quickest way to confirm that a template's fields really do
|
||||
* The drawer is the quickest way to confirm that a template's titles really do
|
||||
* come out in `sort` order before committing to write against it.
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
@@ -210,7 +210,7 @@ onMounted(load)
|
||||
|
||||
<el-table-column label="段落数" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" effect="plain">{{ row.field_count }}</el-tag>
|
||||
<el-tag size="small" effect="plain">{{ row.placement_count }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
@@ -262,7 +262,7 @@ onMounted(load)
|
||||
<div class="preview-meta">
|
||||
<el-tag size="small" effect="plain">
|
||||
<el-icon><Files /></el-icon>
|
||||
{{ preview.fields.length }} 个段落
|
||||
{{ preview.placements.length }} 个段落
|
||||
</el-tag>
|
||||
<span class="muted">更新于 {{ formatDateTime(preview.updated_at) }}</span>
|
||||
</div>
|
||||
@@ -274,7 +274,7 @@ onMounted(load)
|
||||
<span class="divider-hint">已按 sort 升序排列</span>
|
||||
</el-divider>
|
||||
|
||||
<TemplateOutline :fields="preview.fields" />
|
||||
<TemplateOutline :placements="preview.placements" />
|
||||
</template>
|
||||
</div>
|
||||
</el-drawer>
|
||||
|
||||
Reference in New Issue
Block a user