เพิ่ม editor ต่อ template field — ผู้ดูแลเลือกรูปแบบช่องกรอกในฟอร์มสร้างเอกสารได้: text → textbox/textarea, number/date → control ตาม type (presentation metadata ล้วน — validation ยังยึด Type, ค่า field เป็น string ทั้ง flow, ไม่แตะ generate/sync/add-in) - Backend: TemplateField.Editor (nullable, null = default ของ type) + migration AddTemplateFieldEditor + validate ตาม type ใน PUT templates (ค่าไม่รู้จัก/ไม่เข้ากับ type → 400, normalize-on-write, API คืน resolved เสมอ) - Web: util fieldEditor.ts + editor select หน้าแก้ template (desktop+mobile, ซ่อนเมื่อ type มีทางเดียว) + ฟอร์มสร้างเอกสาร render ตาม editor + แก้ prefill re-generate ของ field date จาก ISO timestamp เต็ม (input[type=date] รับเฉพาะ yyyy-MM-dd เดิมแสดงว่าง) - Docs: spec v6 (FR-14/AC-17) + plan Phase 10 + sub-plan field-editor.md + acceptance-review AC-17 + README/CLAUDE.md - Tests: backend 60/60 (FieldEditorTests ใหม่ 8 กรณี) · web 46/46 + build ผ่าน Co-Authored-By: Claude <noreply@anthropic.com>
42 lines
2 KiB
C#
42 lines
2 KiB
C#
namespace WordVersioning.Api.Models;
|
|
|
|
/// <summary>นิยาม field หนึ่งตัวของ template (FR-9) — Key = content control (SDT) tag ที่ detect ตอน upload</summary>
|
|
public class TemplateField
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
public Guid TemplateId { get; set; }
|
|
|
|
public Template? Template { get; set; }
|
|
|
|
/// <summary>= SDT tag — unique ต่อ template ใช้ค่าเดียวกันทั้ง generate/extract/sync</summary>
|
|
public string Key { get; set; } = string.Empty;
|
|
|
|
/// <summary>ชื่อที่แสดงในฟอร์ม (default = Key จนกว่า admin จะตั้ง)</summary>
|
|
public string Label { get; set; } = string.Empty;
|
|
|
|
/// <summary>text | number | date</summary>
|
|
public string Type { get; set; } = "text";
|
|
|
|
/// <summary>รูปแบบช่องกรอกในฟอร์มสร้างเอกสาร (FR-14): textbox|textarea สำหรับ text · number · date
|
|
/// — presentation metadata เท่านั้น ไม่กระทบ validation ของค่า (ยึด Type) · null = default ของ Type</summary>
|
|
public string? Editor { get; set; }
|
|
|
|
public bool IsRequired { get; set; }
|
|
|
|
/// <summary>ลำดับตอนแสดงฟอร์ม (default = ลำดับที่ปรากฏในไฟล์ตอน detect)</summary>
|
|
public int SortOrder { get; set; }
|
|
|
|
public static readonly string[] ValidTypes = ["text", "number", "date"];
|
|
|
|
/// <summary>editor ที่เลือกได้ต่อ type (FR-14) — ตัวแรกของแต่ละรายการคือ default</summary>
|
|
public static readonly Dictionary<string, string[]> EditorsByType = new()
|
|
{
|
|
["text"] = ["textbox", "textarea"],
|
|
["number"] = ["number"],
|
|
["date"] = ["date"],
|
|
};
|
|
|
|
public static string DefaultEditor(string type) =>
|
|
EditorsByType.TryGetValue(type, out var editors) ? editors[0] : "textbox";
|
|
}
|