feat:문서 데이터 입력 UI 구현 (Phase 2.2)
- 섹션별 동적 검사 테이블 렌더링 (complex/select/check/measurement/text) - 정적 컬럼 자동 매핑 (NO, 검사항목, 검사기준, 검사방식, 검사주기) - complex 컬럼 서브 라벨 행 (측정치 n1/n2/n3) - 종합판정 + 비고 Footer 영역 - JS 폼 데이터 수집 (기본필드 + 섹션 테이블 데이터 + 체크박스) - saveDocumentData() 공통 메서드 (section_id/column_id/row_index EAV 저장) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -87,6 +87,9 @@ public function store(Request $request): JsonResponse
|
||||
'data' => 'nullable|array',
|
||||
'data.*.field_key' => 'required|string',
|
||||
'data.*.field_value' => 'nullable|string',
|
||||
'data.*.section_id' => 'nullable|integer',
|
||||
'data.*.column_id' => 'nullable|integer',
|
||||
'data.*.row_index' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
try {
|
||||
@@ -121,18 +124,8 @@ public function store(Request $request): JsonResponse
|
||||
}
|
||||
}
|
||||
|
||||
// 문서 데이터 저장
|
||||
if ($request->filled('data')) {
|
||||
foreach ($request->data as $item) {
|
||||
if (! empty($item['field_value'])) {
|
||||
DocumentData::create([
|
||||
'document_id' => $document->id,
|
||||
'field_key' => $item['field_key'],
|
||||
'field_value' => $item['field_value'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 문서 데이터 저장 (기본필드 + 섹션 테이블 데이터)
|
||||
$this->saveDocumentData($document, $request->input('data', []));
|
||||
|
||||
DB::commit();
|
||||
|
||||
@@ -174,6 +167,9 @@ public function update(int $id, Request $request): JsonResponse
|
||||
'data' => 'nullable|array',
|
||||
'data.*.field_key' => 'required|string',
|
||||
'data.*.field_value' => 'nullable|string',
|
||||
'data.*.section_id' => 'nullable|integer',
|
||||
'data.*.column_id' => 'nullable|integer',
|
||||
'data.*.row_index' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$document->update([
|
||||
@@ -181,21 +177,10 @@ public function update(int $id, Request $request): JsonResponse
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
// 문서 데이터 업데이트
|
||||
// 문서 데이터 업데이트 (기존 삭제 후 재저장)
|
||||
if ($request->has('data')) {
|
||||
// 기존 데이터 삭제
|
||||
$document->data()->delete();
|
||||
|
||||
// 새 데이터 저장
|
||||
foreach ($request->data as $item) {
|
||||
if (! empty($item['field_value'])) {
|
||||
DocumentData::create([
|
||||
'document_id' => $document->id,
|
||||
'field_key' => $item['field_key'],
|
||||
'field_value' => $item['field_value'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
$this->saveDocumentData($document, $request->input('data', []));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
@@ -230,6 +215,28 @@ public function destroy(int $id): JsonResponse
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 문서 데이터 저장 (기본필드 + 섹션 테이블 데이터)
|
||||
*/
|
||||
private function saveDocumentData(Document $document, array $dataItems): void
|
||||
{
|
||||
foreach ($dataItems as $item) {
|
||||
if (empty($item['field_key'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 빈 값도 저장 (섹션 데이터 편집 시 빈값으로 클리어 가능)
|
||||
DocumentData::create([
|
||||
'document_id' => $document->id,
|
||||
'section_id' => $item['section_id'] ?? null,
|
||||
'column_id' => $item['column_id'] ?? null,
|
||||
'row_index' => $item['row_index'] ?? 0,
|
||||
'field_key' => $item['field_key'],
|
||||
'field_value' => $item['field_value'] ?? '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 문서 번호 생성
|
||||
* 형식: {카테고리prefix}-{YYMMDD}-{순번}
|
||||
|
||||
Reference in New Issue
Block a user