feat:검사 기준서 동적 필드 + 자동 하이라이트 + 미리보기 개선

- 문서 작성 시 연결 품목 규격(두께/너비/길이) 기반 자동 하이라이트
- 미리보기에서 field_values 동적 필드 데이터 정상 표시
- DocumentTemplateController에서 field_values 직렬화 추가
- DocumentController에 linkedItemSpecs 조회 로직 추가
- Item 모델 attributes JSON cast 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 09:26:13 +09:00
parent 07c22bee03
commit b14b991d1c
7 changed files with 562 additions and 280 deletions

View File

@@ -4,8 +4,10 @@
use App\Models\Documents\Document;
use App\Models\DocumentTemplate;
use App\Models\Items\Item;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class DocumentController extends Controller
@@ -63,6 +65,7 @@ public function create(Request $request): View|Response
'template' => $template,
'templates' => $templates,
'isCreate' => true,
'linkedItemSpecs' => $template ? $this->getLinkedItemSpecs($template) : [],
]);
}
@@ -102,6 +105,7 @@ public function edit(int $id): View|Response
'template' => $document->template,
'templates' => $templates,
'isCreate' => false,
'linkedItemSpecs' => $this->getLinkedItemSpecs($document->template),
]);
}
@@ -154,4 +158,42 @@ public function show(int $id): View
'document' => $document,
]);
}
/**
* 템플릿에 연결된 품목들의 규격 정보 (thickness, width, length) 조회
*/
private function getLinkedItemSpecs(DocumentTemplate $template): array
{
$specs = [];
if (! $template->relationLoaded('links')) {
$template->load('links.linkValues');
}
foreach ($template->links as $link) {
if ($link->source_table !== 'items') {
continue;
}
foreach ($link->linkValues as $lv) {
$item = Item::find($lv->linkable_id);
if (! $item) {
continue;
}
$attrs = $item->attributes ?? [];
if (isset($attrs['thickness']) || isset($attrs['width']) || isset($attrs['length'])) {
$specs[] = [
'id' => $item->id,
'name' => $item->name,
'thickness' => $attrs['thickness'] ?? null,
'width' => $attrs['width'] ?? null,
'length' => $attrs['length'] ?? null,
];
}
}
}
return $specs;
}
}