feat:문서 템플릿 기본필드 field_key 연동키 드롭다운 추가

- DocumentTemplateController: common_codes(doc_template_basic_field) 조회하여 뷰에 전달
- prepareTemplateData: basic_fields에 field_key 포함
- DocumentTemplateApiController: basic_fields 저장 시 field_key 포함
- edit.blade.php: 기본필드 행에 '연동키 선택' 드롭다운 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 14:24:25 +09:00
parent 007abbfc44
commit f74288e5e5
5 changed files with 25 additions and 7 deletions

View File

@@ -593,6 +593,7 @@ private function saveRelations(DocumentTemplate $template, array $data, bool $de
DocumentTemplateBasicField::create([
'template_id' => $template->id,
'label' => $field['label'] ?? '',
'field_key' => $field['field_key'] ?? null,
'field_type' => $field['field_type'] ?? 'text',
'default_value' => $field['default_value'] ?? '',
'sort_order' => $index,

View File

@@ -4,6 +4,7 @@
use App\Models\DocumentTemplate;
use App\Models\DocumentTemplateFieldPreset;
use App\Models\Products\CommonCode;
use App\Models\Tenants\Tenant;
use App\Models\User;
use Illuminate\Http\Request;
@@ -39,6 +40,7 @@ public function create(): View
'categories' => $this->getCategories(),
'tenant' => $this->getCurrentTenant(),
'presets' => DocumentTemplateFieldPreset::orderBy('sort_order')->get(),
'basicFieldKeys' => $this->getBasicFieldKeys(),
]);
}
@@ -66,6 +68,7 @@ public function edit(int $id): View
'categories' => $this->getCategories(),
'tenant' => $this->getCurrentTenant(),
'presets' => DocumentTemplateFieldPreset::orderBy('sort_order')->get(),
'basicFieldKeys' => $this->getBasicFieldKeys(),
]);
}
@@ -79,6 +82,19 @@ private function getCurrentTenant(): ?Tenant
return $tenantId ? Tenant::find($tenantId) : null;
}
/**
* 기본필드 키 옵션 조회 (common_codes 기반)
*/
private function getBasicFieldKeys(): array
{
return CommonCode::query()
->where('code_group', 'doc_template_basic_field')
->where('is_active', true)
->orderBy('sort_order')
->get(['code', 'name'])
->toArray();
}
/**
* 문서분류 목록 조회 (common_codes 기반 + 기존 데이터 폴백)
*/
@@ -167,6 +183,7 @@ private function prepareTemplateData(DocumentTemplate $template): array
return [
'id' => $f->id,
'label' => $f->label,
'field_key' => $f->field_key,
'field_type' => $f->field_type,
'default_value' => $f->default_value,
];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -307,6 +307,7 @@ class="w-full px-3 py-1.5 border border-gray-300 rounded-lg text-sm focus:outlin
// 시스템 프리셋
const fieldPresets = @json($presets ?? []);
const basicFieldKeys = @json($basicFieldKeys ?? []);
// 고유 ID 생성
let uniqueId = 0;
@@ -529,6 +530,7 @@ function addBasicField() {
templateState.basic_fields.push({
id: generateId(),
label: '',
field_key: null,
field_type: 'text',
default_value: ''
});
@@ -563,6 +565,11 @@ function renderBasicFields() {
<input type="text" value="${escapeHtml(field.label)}" placeholder="필드명 (예: 품명, LOT NO)"
onchange="updateBasicField('${field.id}', 'label', this.value)"
class="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm">
<select onchange="updateBasicField('${field.id}', 'field_key', this.value || null)"
class="w-36 px-3 py-2 border border-gray-300 rounded-lg text-sm">
<option value="">연동키 선택</option>
${basicFieldKeys.map(k => `<option value="${k.code}" ${field.field_key === k.code ? 'selected' : ''}>${k.name} (${k.code})</option>`).join('')}
</select>
<select onchange="updateBasicField('${field.id}', 'field_type', this.value)"
class="w-28 px-3 py-2 border border-gray-300 rounded-lg text-sm">
<option value="text" ${field.field_type === 'text' ? 'selected' : ''}>텍스트</option>