feat:카테고리 관리 기능 추가

- CategoryController: 카테고리 관리 페이지
- CategoryApiController: 테넌트별 카테고리 CRUD API
- GlobalCategoryApiController: 글로벌 카테고리 관리 API
- Category, GlobalCategory 모델 추가
- 카테고리 관리 뷰 (index, partials)
- config/categories.php 설정 파일

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-28 12:50:15 +09:00
parent 2b3612fc60
commit 29949d66eb
12 changed files with 1630 additions and 1 deletions

View File

@@ -0,0 +1,291 @@
<?php
namespace App\Http\Controllers\Api\Admin;
use App\Http\Controllers\Controller;
use App\Models\Category;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class CategoryApiController extends Controller
{
/**
* 목록 조회 (드롭다운용)
*/
public function list(Request $request): JsonResponse
{
$tenantId = session('selected_tenant_id');
if (! $tenantId) {
return response()->json(['success' => false, 'data' => []]);
}
$codeGroup = $request->input('code_group', 'product');
$categories = Category::query()
->where('tenant_id', $tenantId)
->where('code_group', $codeGroup)
->whereNull('deleted_at')
->orderBy('parent_id')
->orderBy('sort_order')
->get(['id', 'parent_id', 'code', 'name']);
return response()->json([
'success' => true,
'data' => $categories,
]);
}
/**
* 트리 데이터 조회 (HTMX)
*/
public function tree(Request $request): View
{
$tenantId = session('selected_tenant_id');
$codeGroup = $request->input('code_group', 'product');
$categories = collect();
if ($tenantId) {
$categories = Category::query()
->where('tenant_id', $tenantId)
->where('code_group', $codeGroup)
->whereNull('parent_id')
->with('childrenRecursive')
->orderBy('sort_order')
->get();
}
return view('categories.partials.tree', [
'categories' => $categories,
'codeGroup' => $codeGroup,
]);
}
/**
* 단일 조회
*/
public function show(int $id): JsonResponse
{
$category = Category::with('children')->findOrFail($id);
return response()->json([
'success' => true,
'data' => $category,
]);
}
/**
* 생성
*/
public function store(Request $request): JsonResponse
{
$tenantId = session('selected_tenant_id');
if (! $tenantId) {
return response()->json(['success' => false, 'message' => '테넌트를 선택해주세요.'], 400);
}
$validated = $request->validate([
'code_group' => 'required|string|max:50',
'parent_id' => 'nullable|integer|exists:categories,id',
'code' => 'required|string|max:50',
'name' => 'required|string|max:100',
'profile_code' => 'nullable|string|max:50',
'description' => 'nullable|string|max:500',
'is_active' => 'boolean',
]);
// 코드 중복 체크
$exists = Category::query()
->where('tenant_id', $tenantId)
->where('code_group', $validated['code_group'])
->where('code', $validated['code'])
->exists();
if ($exists) {
return response()->json(['success' => false, 'message' => '이미 존재하는 코드입니다.'], 400);
}
// 최대 sort_order 조회
$maxSortOrder = Category::query()
->where('tenant_id', $tenantId)
->where('code_group', $validated['code_group'])
->where('parent_id', $validated['parent_id'] ?? null)
->max('sort_order') ?? 0;
$category = Category::create([
'tenant_id' => $tenantId,
'parent_id' => $validated['parent_id'] ?? null,
'code_group' => $validated['code_group'],
'code' => $validated['code'],
'name' => $validated['name'],
'profile_code' => $validated['profile_code'] ?? null,
'description' => $validated['description'] ?? null,
'is_active' => $validated['is_active'] ?? true,
'sort_order' => $maxSortOrder + 1,
'created_by' => Auth::id(),
]);
return response()->json([
'success' => true,
'message' => '카테고리가 생성되었습니다.',
'data' => $category,
]);
}
/**
* 수정
*/
public function update(Request $request, int $id): JsonResponse
{
$category = Category::findOrFail($id);
$validated = $request->validate([
'code' => 'sometimes|required|string|max:50',
'name' => 'sometimes|required|string|max:100',
'profile_code' => 'nullable|string|max:50',
'description' => 'nullable|string|max:500',
'is_active' => 'sometimes|boolean',
]);
// 코드 변경 시 중복 체크
if (isset($validated['code']) && $validated['code'] !== $category->code) {
$exists = Category::query()
->where('tenant_id', $category->tenant_id)
->where('code_group', $category->code_group)
->where('code', $validated['code'])
->where('id', '!=', $id)
->exists();
if ($exists) {
return response()->json(['success' => false, 'message' => '이미 존재하는 코드입니다.'], 400);
}
}
$category->update(array_merge($validated, ['updated_by' => Auth::id()]));
return response()->json([
'success' => true,
'message' => '카테고리가 수정되었습니다.',
'data' => $category->fresh(),
]);
}
/**
* 삭제
*/
public function destroy(int $id): JsonResponse
{
$category = Category::findOrFail($id);
// 하위 카테고리 존재 여부 확인
if ($category->children()->count() > 0) {
return response()->json([
'success' => false,
'message' => '하위 카테고리가 있어 삭제할 수 없습니다.',
], 400);
}
$category->update(['deleted_by' => Auth::id()]);
$category->delete();
return response()->json([
'success' => true,
'message' => '카테고리가 삭제되었습니다.',
]);
}
/**
* 활성 상태 토글
*/
public function toggle(int $id): JsonResponse
{
$category = Category::findOrFail($id);
$category->update([
'is_active' => ! $category->is_active,
'updated_by' => Auth::id(),
]);
return response()->json([
'success' => true,
'message' => $category->is_active ? '활성화되었습니다.' : '비활성화되었습니다.',
'is_active' => $category->is_active,
]);
}
/**
* 이동 (부모 변경)
*/
public function move(Request $request, int $id): JsonResponse
{
$category = Category::findOrFail($id);
$validated = $request->validate([
'parent_id' => 'nullable|integer|exists:categories,id',
]);
$newParentId = $validated['parent_id'] ?? null;
// 자기 자신이나 자식을 부모로 설정 불가
if ($newParentId === $id) {
return response()->json(['success' => false, 'message' => '자기 자신을 부모로 설정할 수 없습니다.'], 400);
}
// 자식 카테고리를 부모로 설정하는 것 방지 (순환 참조)
if ($newParentId) {
$parent = Category::find($newParentId);
while ($parent) {
if ($parent->id === $id) {
return response()->json(['success' => false, 'message' => '하위 카테고리를 부모로 설정할 수 없습니다.'], 400);
}
$parent = $parent->parent;
}
}
$category->update([
'parent_id' => $newParentId,
'updated_by' => Auth::id(),
]);
return response()->json([
'success' => true,
'message' => '카테고리가 이동되었습니다.',
]);
}
/**
* 순서 변경
*/
public function reorder(Request $request): JsonResponse
{
$validated = $request->validate([
'items' => 'required|array',
'items.*.id' => 'required|integer|exists:categories,id',
'items.*.sort_order' => 'required|integer|min:0',
]);
DB::beginTransaction();
try {
foreach ($validated['items'] as $item) {
Category::where('id', $item['id'])->update([
'sort_order' => $item['sort_order'],
'updated_by' => Auth::id(),
]);
}
DB::commit();
return response()->json([
'success' => true,
'message' => '순서가 변경되었습니다.',
]);
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => '순서 변경 중 오류가 발생했습니다.',
], 500);
}
}
}

View File

@@ -0,0 +1,295 @@
<?php
namespace App\Http\Controllers\Api\Admin;
use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\GlobalCategory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class GlobalCategoryApiController extends Controller
{
/**
* 목록 조회 (드롭다운용)
*/
public function list(Request $request): JsonResponse
{
$codeGroup = $request->input('code_group', 'product');
$categories = GlobalCategory::query()
->where('code_group', $codeGroup)
->whereNull('deleted_at')
->orderBy('parent_id')
->orderBy('sort_order')
->get(['id', 'parent_id', 'code', 'name']);
return response()->json([
'success' => true,
'data' => $categories,
]);
}
/**
* 단일 조회
*/
public function show(int $id): JsonResponse
{
$category = GlobalCategory::findOrFail($id);
return response()->json([
'success' => true,
'data' => $category,
]);
}
/**
* 생성
*/
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'code_group' => 'required|string|max:30',
'parent_id' => 'nullable|integer|exists:global_categories,id',
'code' => 'required|string|max:30',
'name' => 'required|string|max:100',
'profile_code' => 'nullable|string|max:30',
'description' => 'nullable|string|max:255',
'sort_order' => 'nullable|integer|min:0',
]);
// 코드 중복 체크
$exists = GlobalCategory::query()
->where('code_group', $validated['code_group'])
->where('code', $validated['code'])
->whereNull('deleted_at')
->exists();
if ($exists) {
return response()->json(['success' => false, 'message' => '이미 존재하는 코드입니다.'], 400);
}
// 최대 sort_order 조회
$maxSortOrder = GlobalCategory::query()
->where('code_group', $validated['code_group'])
->where('parent_id', $validated['parent_id'] ?? null)
->max('sort_order') ?? 0;
$category = GlobalCategory::create([
'parent_id' => $validated['parent_id'] ?? null,
'code_group' => $validated['code_group'],
'code' => $validated['code'],
'name' => $validated['name'],
'profile_code' => $validated['profile_code'] ?? null,
'description' => $validated['description'] ?? null,
'is_active' => true,
'sort_order' => $validated['sort_order'] ?? ($maxSortOrder + 1),
'created_by' => Auth::id(),
]);
return response()->json([
'success' => true,
'message' => '글로벌 카테고리가 생성되었습니다.',
'data' => $category,
]);
}
/**
* 수정
*/
public function update(Request $request, int $id): JsonResponse
{
$category = GlobalCategory::findOrFail($id);
$validated = $request->validate([
'name' => 'sometimes|required|string|max:100',
'parent_id' => 'nullable|integer|exists:global_categories,id',
'profile_code' => 'nullable|string|max:30',
'description' => 'nullable|string|max:255',
'sort_order' => 'nullable|integer|min:0',
]);
$category->update(array_merge($validated, ['updated_by' => Auth::id()]));
return response()->json([
'success' => true,
'message' => '글로벌 카테고리가 수정되었습니다.',
'data' => $category->fresh(),
]);
}
/**
* 삭제
*/
public function destroy(int $id): JsonResponse
{
$category = GlobalCategory::findOrFail($id);
// 하위 카테고리 존재 여부 확인
if (GlobalCategory::where('parent_id', $id)->whereNull('deleted_at')->exists()) {
return response()->json([
'success' => false,
'message' => '하위 카테고리가 있어 삭제할 수 없습니다.',
], 400);
}
$category->update(['deleted_by' => Auth::id()]);
$category->delete();
return response()->json([
'success' => true,
'message' => '글로벌 카테고리가 삭제되었습니다.',
]);
}
/**
* 활성 상태 토글
*/
public function toggle(int $id): JsonResponse
{
$category = GlobalCategory::findOrFail($id);
$category->update([
'is_active' => ! $category->is_active,
'updated_by' => Auth::id(),
]);
return response()->json([
'success' => true,
'message' => $category->is_active ? '활성화되었습니다.' : '비활성화되었습니다.',
'is_active' => $category->is_active,
]);
}
/**
* 테넌트로 복사
*/
public function copyToTenant(int $id): JsonResponse
{
$tenantId = session('selected_tenant_id');
if (! $tenantId) {
return response()->json(['success' => false, 'message' => '테넌트를 선택해주세요.'], 400);
}
$globalCategory = GlobalCategory::findOrFail($id);
// 이미 존재하는지 확인
$exists = Category::query()
->where('tenant_id', $tenantId)
->where('code_group', $globalCategory->code_group)
->where('code', $globalCategory->code)
->whereNull('deleted_at')
->exists();
if ($exists) {
return response()->json(['success' => false, 'message' => '이미 존재하는 카테고리입니다.'], 400);
}
// 복사 (parent_id는 복사하지 않음 - 개별 복사이므로)
Category::create([
'tenant_id' => $tenantId,
'parent_id' => null,
'code_group' => $globalCategory->code_group,
'code' => $globalCategory->code,
'name' => $globalCategory->name,
'profile_code' => $globalCategory->profile_code,
'description' => $globalCategory->description,
'is_active' => $globalCategory->is_active,
'sort_order' => $globalCategory->sort_order,
'created_by' => Auth::id(),
]);
return response()->json([
'success' => true,
'message' => '테넌트로 복사되었습니다.',
]);
}
/**
* 일괄 테넌트로 복사
*/
public function bulkCopyToTenant(Request $request): JsonResponse
{
$tenantId = session('selected_tenant_id');
if (! $tenantId) {
return response()->json(['success' => false, 'message' => '테넌트를 선택해주세요.'], 400);
}
$validated = $request->validate([
'ids' => 'required|array',
'ids.*' => 'integer|exists:global_categories,id',
]);
$globalCategories = GlobalCategory::whereIn('id', $validated['ids'])
->whereNull('deleted_at')
->orderBy('parent_id')
->orderBy('sort_order')
->get();
$copied = 0;
$skipped = 0;
$idMap = []; // global_id => tenant_id
DB::beginTransaction();
try {
foreach ($globalCategories as $gc) {
// 이미 존재하는지 확인
$exists = Category::query()
->where('tenant_id', $tenantId)
->where('code_group', $gc->code_group)
->where('code', $gc->code)
->whereNull('deleted_at')
->exists();
if ($exists) {
$skipped++;
continue;
}
// parent_id 매핑
$parentId = null;
if ($gc->parent_id && isset($idMap[$gc->parent_id])) {
$parentId = $idMap[$gc->parent_id];
}
$newCategory = Category::create([
'tenant_id' => $tenantId,
'parent_id' => $parentId,
'code_group' => $gc->code_group,
'code' => $gc->code,
'name' => $gc->name,
'profile_code' => $gc->profile_code,
'description' => $gc->description,
'is_active' => $gc->is_active,
'sort_order' => $gc->sort_order,
'created_by' => Auth::id(),
]);
$idMap[$gc->id] = $newCategory->id;
$copied++;
}
DB::commit();
$message = "{$copied}개 카테고리가 복사되었습니다.";
if ($skipped > 0) {
$message .= " ({$skipped}개 중복으로 건너뜀)";
}
return response()->json([
'success' => true,
'message' => $message,
'copied' => $copied,
'skipped' => $skipped,
]);
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => '복사 중 오류가 발생했습니다.',
], 500);
}
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\GlobalCategory;
use App\Models\Tenants\Tenant;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
class CategoryController extends Controller
{
/**
* 카테고리 관리 페이지
*/
public function index(Request $request): View|Response
{
// HTMX 요청 시 전체 페이지 리로드
if ($request->header('HX-Request')) {
return response('', 200)->header('HX-Redirect', route('categories.index'));
}
$tenantId = session('selected_tenant_id');
$tenant = $tenantId ? Tenant::find($tenantId) : null;
$isHQ = $tenantId == 1;
// 모든 code_group 조회 (글로벌 + 테넌트)
$globalGroups = GlobalCategory::whereNull('deleted_at')
->select('code_group')
->distinct()
->pluck('code_group')
->toArray();
$tenantGroups = [];
if ($tenantId) {
$tenantGroups = Category::where('tenant_id', $tenantId)
->whereNull('deleted_at')
->select('code_group')
->distinct()
->pluck('code_group')
->toArray();
}
$allGroups = array_unique(array_merge($globalGroups, $tenantGroups));
sort($allGroups);
$codeGroupLabels = config('categories.code_group_labels', []);
$codeGroups = [];
foreach ($allGroups as $group) {
$codeGroups[$group] = $codeGroupLabels[$group] ?? $group;
}
if (empty($codeGroups)) {
$codeGroups['product'] = $codeGroupLabels['product'] ?? 'product';
}
$selectedGroup = $request->get('group', array_key_first($codeGroups));
if (! isset($codeGroups[$selectedGroup])) {
$selectedGroup = array_key_first($codeGroups);
}
// 글로벌 카테고리 (트리 구조로 평탄화)
$globalCategoriesRaw = GlobalCategory::where('code_group', $selectedGroup)
->whereNull('deleted_at')
->orderBy('sort_order')
->get();
$globalCategories = $this->flattenTree($globalCategoriesRaw);
// 테넌트 카테고리 (트리 구조로 평탄화)
$tenantCategories = collect();
$tenantCodes = [];
if ($tenantId) {
$tenantCategoriesRaw = Category::where('tenant_id', $tenantId)
->where('code_group', $selectedGroup)
->whereNull('deleted_at')
->orderBy('sort_order')
->get();
$tenantCategories = $this->flattenTree($tenantCategoriesRaw);
$tenantCodes = $tenantCategoriesRaw->pluck('code')->toArray();
}
return view('categories.index', [
'codeGroups' => $codeGroups,
'codeGroupLabels' => $codeGroupLabels,
'selectedGroup' => $selectedGroup,
'globalCategories' => $globalCategories,
'tenantCategories' => $tenantCategories,
'tenantCodes' => $tenantCodes,
'tenant' => $tenant,
'isHQ' => $isHQ,
]);
}
/**
* 카테고리 컬렉션을 트리 구조로 평탄화 (부모-자식 순서 유지, depth 추가)
*/
private function flattenTree($categories): \Illuminate\Support\Collection
{
$result = collect();
$byParent = $categories->groupBy(fn($c) => $c->parent_id ?? 0);
$this->addChildrenRecursive($result, $byParent, 0, 0);
return $result;
}
/**
* 재귀적으로 자식 추가
*/
private function addChildrenRecursive(&$result, $byParent, $parentId, $depth): void
{
$children = $byParent->get($parentId, collect());
foreach ($children as $child) {
$child->depth = $depth;
$result->push($child);
$this->addChildrenRecursive($result, $byParent, $child->id, $depth + 1);
}
}
}

82
app/Models/Category.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
namespace App\Models;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model
{
use BelongsToTenant, SoftDeletes;
protected $fillable = [
'tenant_id',
'parent_id',
'code_group',
'profile_code',
'code',
'name',
'is_active',
'sort_order',
'description',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'is_active' => 'boolean',
'sort_order' => 'integer',
];
/**
* 부모 카테고리
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
/**
* 자식 카테고리
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order');
}
/**
* 재귀적으로 자식 카테고리 로드
*/
public function childrenRecursive(): HasMany
{
return $this->children()->with('childrenRecursive');
}
/**
* 코드 그룹 스코프
*/
public function scopeGroup($query, string $group)
{
return $query->where('code_group', $group);
}
/**
* 루트 카테고리만 조회
*/
public function scopeRoot($query)
{
return $query->whereNull('parent_id');
}
/**
* 활성 카테고리만 조회
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class GlobalCategory extends Model
{
use SoftDeletes;
protected $fillable = [
'parent_id',
'code_group',
'profile_code',
'code',
'name',
'is_active',
'sort_order',
'description',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'is_active' => 'boolean',
'sort_order' => 'integer',
];
/**
* 부모 카테고리
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
/**
* 자식 카테고리
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order');
}
/**
* 코드 그룹 스코프
*/
public function scopeGroup($query, string $group)
{
return $query->where('code_group', $group);
}
/**
* 루트 카테고리만 조회
*/
public function scopeRoot($query)
{
return $query->whereNull('parent_id');
}
/**
* 활성 카테고리만 조회
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* 계층 깊이를 포함한 이름 반환
*/
public function getIndentedNameAttribute(): string
{
$depth = 0;
$parent = $this->parent;
while ($parent) {
$depth++;
$parent = $parent->parent;
}
return str_repeat('ㄴ ', $depth).$this->name;
}
}

27
config/categories.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| 카테고리 코드 그룹 라벨
|--------------------------------------------------------------------------
|
| code_group 코드에 대한 한글 라벨 매핑
| 새로운 code_group 추가 시 여기에 라벨을 등록하세요.
|
*/
'code_group_labels' => [
'product' => '제품 카테고리',
'material' => '자재 카테고리',
'item' => '품목 카테고리',
'item_category' => '품목 분류',
'item_group' => '품목 그룹',
'item_type' => '품목 유형',
'item_feature1' => '품목 특성1',
'item_feature2' => '품목 특성2',
'account_type' => '계정 유형',
'estimate' => '견적 유형',
'process_type' => '공정 유형',
'procurement_type' => '조달 유형',
],
];

View File

@@ -0,0 +1,572 @@
@extends('layouts.app')
@section('title', '카테고리 관리')
@section('content')
<div class="flex flex-col h-full">
<!-- 페이지 헤더 -->
<div class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4 mb-6 flex-shrink-0">
<div>
<h1 class="text-2xl font-bold text-gray-800">카테고리 관리</h1>
<p class="text-sm text-gray-500 mt-1">
@if($tenant)
<span class="inline-flex items-center gap-1">
<span class="px-2 py-0.5 bg-blue-100 text-blue-700 rounded text-xs font-medium">{{ $tenant->company_name }}</span>
@if($isHQ)
<span class="px-2 py-0.5 bg-purple-100 text-purple-700 rounded text-xs font-medium">본사</span>
@endif
카테고리를 관리합니다.
</span>
@else
테넌트별 카테고리를 관리합니다.
@endif
</p>
</div>
@if($tenant)
<button type="button"
onclick="openAddModal()"
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 text-sm">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg>
카테고리 추가
</button>
@endif
</div>
<!-- 테넌트 미선택 경고 -->
@if(!$tenant)
<div class="mb-4 bg-yellow-50 border border-yellow-200 text-yellow-700 px-4 py-3 rounded-lg flex items-center gap-2">
<svg class="w-5 h-5 text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
헤더에서 테넌트를 선택해주세요.
</div>
@else
<!-- 코드 그룹 -->
<div class="bg-white rounded-lg shadow-sm mb-4">
<div class="border-b border-gray-200 overflow-x-auto">
<nav class="flex -mb-px min-w-max" aria-label="Tabs">
@foreach($codeGroups as $group => $label)
<a href="{{ route('categories.index', ['group' => $group]) }}"
class="px-4 py-3 border-b-2 whitespace-nowrap transition-colors flex flex-col items-center
{{ $selectedGroup === $group
? 'border-blue-500 text-blue-600'
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300' }}">
<span class="text-sm font-medium">{{ $label }}</span>
<span class="text-xs font-mono {{ $selectedGroup === $group ? 'text-blue-400' : 'text-gray-400' }}">{{ $group }}</span>
</a>
@endforeach
</nav>
</div>
</div>
<!-- 카테고리 목록 -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- 글로벌 카테고리 -->
<div class="bg-white rounded-lg shadow-sm">
<div class="px-4 py-3 border-b border-gray-200 flex items-center justify-between">
<div class="flex items-center gap-2">
<span class="w-6 h-6 bg-purple-100 rounded flex items-center justify-center">
<svg class="w-4 h-4 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</span>
<h3 class="font-semibold text-gray-800">글로벌 카테고리</h3>
<span class="text-xs text-gray-500">({{ $globalCategories->count() }})</span>
</div>
<div class="flex items-center gap-2">
@if($globalCategories->count() > 0)
<button type="button"
id="bulkCopyBtn"
onclick="bulkCopy()"
class="hidden px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-xs font-medium rounded-lg transition-colors items-center gap-1">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
<span id="bulkCopyCount">0</span> 선택 복사
</button>
@endif
@if(!$isHQ)
<span class="text-xs text-gray-400">본사만 편집 가능</span>
@endif
</div>
</div>
<div class="overflow-auto max-h-[600px] p-2">
@forelse($globalCategories as $cat)
@php
$existsInTenant = in_array($cat->code, $tenantCodes);
@endphp
<div class="border rounded-lg mb-1 {{ !$cat->is_active ? 'opacity-50 bg-gray-50' : ($existsInTenant ? 'hover:bg-gray-50' : 'bg-green-50 hover:bg-green-100') }}" style="margin-left: {{ $cat->depth * 1.5 }}rem">
<div class="flex items-center gap-2 px-3 py-2">
<input type="checkbox" name="global_ids[]" value="{{ $cat->id }}"
onchange="updateBulkCopyButton()"
class="global-checkbox w-4 h-4 rounded focus:ring-green-500 {{ $existsInTenant ? 'bg-gray-200 border-gray-300 cursor-not-allowed' : 'text-green-600 border-gray-300' }}"
{{ $existsInTenant ? 'disabled' : '' }}>
<span class="font-mono text-xs bg-gray-100 px-1.5 py-0.5 rounded text-gray-600">{{ $cat->code }}</span>
<span class="flex-1 text-sm {{ $cat->depth > 0 ? 'text-gray-600' : 'font-medium text-gray-800' }}">{{ $cat->name }}</span>
@if($cat->depth > 0)
<span class="text-[10px] text-gray-400 bg-gray-100 px-1 rounded">Lv.{{ $cat->depth + 1 }}</span>
@endif
@if($existsInTenant)
<span class="text-[10px] text-blue-600 bg-blue-100 px-1.5 py-0.5 rounded font-medium">복사됨</span>
@else
<span class="text-[10px] text-green-600 bg-green-100 px-1.5 py-0.5 rounded font-medium">NEW</span>
@endif
<span class="text-xs text-gray-400">{{ $cat->sort_order }}</span>
@if($isHQ)
<button type="button"
onclick="toggleGlobalActive({{ $cat->id }})"
class="relative inline-flex h-4 w-7 items-center rounded-full transition-colors {{ $cat->is_active ? 'bg-green-500' : 'bg-gray-300' }}">
<span class="inline-block h-3 w-3 transform rounded-full bg-white transition-transform {{ $cat->is_active ? 'translate-x-3' : 'translate-x-0.5' }}"></span>
</button>
@else
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs {{ $cat->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-500' }}">
{{ $cat->is_active ? 'ON' : 'OFF' }}
</span>
@endif
<div class="flex items-center gap-1">
@if($isHQ)
<button type="button" onclick="openEditGlobalModal({{ $cat->id }})" class="p-1 text-gray-400 hover:text-blue-600" title="수정">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" /></svg>
</button>
@endif
<button type="button" onclick="copyToTenant({{ $cat->id }})" class="p-1 text-gray-400 hover:text-green-600" title="테넌트로 복사">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" /></svg>
</button>
@if($isHQ)
<button type="button" onclick="deleteGlobalCategory({{ $cat->id }}, '{{ $cat->name }}')" class="p-1 text-gray-400 hover:text-red-600" title="삭제">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /></svg>
</button>
@endif
</div>
</div>
</div>
@empty
<div class="text-center text-gray-400 py-8">글로벌 카테고리가 없습니다.</div>
@endforelse
</div>
</div>
<!-- 테넌트 카테고리 -->
<div class="bg-white rounded-lg shadow-sm">
<div class="px-4 py-3 border-b border-gray-200 flex items-center justify-between">
<div class="flex items-center gap-2">
<span class="w-6 h-6 bg-blue-100 rounded flex items-center justify-center">
<svg class="w-4 h-4 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
</svg>
</span>
<h3 class="font-semibold text-gray-800">테넌트 카테고리</h3>
<span class="text-xs text-gray-500">({{ $tenantCategories->count() }})</span>
</div>
</div>
<div class="overflow-auto max-h-[600px] p-2">
@forelse($tenantCategories as $cat)
<div class="border rounded-lg mb-1 {{ !$cat->is_active ? 'opacity-50 bg-gray-50' : 'hover:bg-blue-50' }}" style="margin-left: {{ $cat->depth * 1.5 }}rem">
<div class="flex items-center gap-2 px-3 py-2">
<span class="font-mono text-xs bg-blue-50 text-blue-700 px-1.5 py-0.5 rounded">{{ $cat->code }}</span>
<span class="flex-1 text-sm {{ $cat->depth > 0 ? 'text-gray-600' : 'font-medium text-gray-800' }}">{{ $cat->name }}</span>
@if($cat->depth > 0)
<span class="text-[10px] text-blue-400 bg-blue-50 px-1 rounded">Lv.{{ $cat->depth + 1 }}</span>
@endif
<span class="text-xs text-gray-400">{{ $cat->sort_order }}</span>
<button type="button"
onclick="toggleTenantActive({{ $cat->id }})"
class="relative inline-flex h-4 w-7 items-center rounded-full transition-colors {{ $cat->is_active ? 'bg-green-500' : 'bg-gray-300' }}">
<span class="inline-block h-3 w-3 transform rounded-full bg-white transition-transform {{ $cat->is_active ? 'translate-x-3' : 'translate-x-0.5' }}"></span>
</button>
<div class="flex items-center gap-1">
<button type="button" onclick="openEditModal({{ $cat->id }})" class="p-1 text-gray-400 hover:text-blue-600" title="수정">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" /></svg>
</button>
<button type="button" onclick="deleteTenantCategory({{ $cat->id }}, '{{ $cat->name }}')" class="p-1 text-gray-400 hover:text-red-600" title="삭제">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /></svg>
</button>
</div>
</div>
</div>
@empty
<div class="text-center text-gray-400 py-8">
테넌트 카테고리가 없습니다.<br>
<span class="text-xs">글로벌 카테고리를 복사하거나 새로 추가하세요.</span>
</div>
@endforelse
</div>
</div>
</div>
@endif
</div>
<!-- 카테고리 추가/수정 모달 -->
<div id="categoryModal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md mx-4">
<form id="categoryForm" onsubmit="saveCategory(event)">
<input type="hidden" id="categoryId" value="">
<input type="hidden" id="categoryType" value="tenant">
<div class="px-6 py-4 border-b border-gray-200">
<h3 id="modalTitle" class="text-lg font-semibold text-gray-800">카테고리 추가</h3>
</div>
<div class="px-6 py-4 space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">코드 *</label>
<input type="text" id="categoryCode" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="예: ELEVATOR">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">이름 *</label>
<input type="text" id="categoryName" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="예: 엘리베이터">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">상위 카테고리</label>
<select id="categoryParentId"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<option value="">최상위 카테고리</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">정렬 순서</label>
<input type="number" id="categorySortOrder" value="1" min="0" max="9999"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">설명</label>
<textarea id="categoryDescription" rows="2"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="카테고리 설명 (선택)"></textarea>
</div>
@if($isHQ)
<div class="flex items-center gap-2">
<input type="checkbox" id="isGlobal" value="1"
class="w-4 h-4 text-purple-600 border-gray-300 rounded focus:ring-purple-500">
<label for="isGlobal" class="text-sm text-gray-700">글로벌 카테고리로 생성</label>
</div>
@endif
</div>
<div class="px-6 py-4 border-t border-gray-200 flex justify-end gap-3">
<button type="button" onclick="closeModal()"
class="px-4 py-2 text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-lg text-sm font-medium transition-colors">
취소
</button>
<button type="submit"
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm font-medium transition-colors">
저장
</button>
</div>
</form>
</div>
</div>
@endsection
@push('scripts')
<script>
const selectedGroup = '{{ $selectedGroup }}';
const csrfToken = '{{ csrf_token() }}';
// 모달 열기 (추가)
function openAddModal() {
document.getElementById('modalTitle').textContent = '카테고리 추가';
document.getElementById('categoryId').value = '';
document.getElementById('categoryType').value = 'tenant';
document.getElementById('categoryCode').value = '';
document.getElementById('categoryCode').disabled = false;
document.getElementById('categoryName').value = '';
document.getElementById('categoryParentId').value = '';
document.getElementById('categorySortOrder').value = '1';
document.getElementById('categoryDescription').value = '';
if (document.getElementById('isGlobal')) {
document.getElementById('isGlobal').checked = false;
}
loadParentOptions('tenant');
openModal();
}
// 모달 열기 (수정 - 테넌트)
function openEditModal(id) {
fetch(`/api/admin/categories/${id}`, {
headers: { 'Accept': 'application/json', 'X-CSRF-TOKEN': csrfToken }
})
.then(r => r.json())
.then(data => {
if (data.success) {
const cat = data.data;
document.getElementById('modalTitle').textContent = '카테고리 수정';
document.getElementById('categoryId').value = cat.id;
document.getElementById('categoryType').value = 'tenant';
document.getElementById('categoryCode').value = cat.code;
document.getElementById('categoryCode').disabled = true;
document.getElementById('categoryName').value = cat.name;
document.getElementById('categorySortOrder').value = cat.sort_order || 1;
document.getElementById('categoryDescription').value = cat.description || '';
if (document.getElementById('isGlobal')) {
document.getElementById('isGlobal').checked = false;
document.getElementById('isGlobal').disabled = true;
}
loadParentOptions('tenant', cat.parent_id);
openModal();
}
});
}
// 모달 열기 (수정 - 글로벌)
function openEditGlobalModal(id) {
fetch(`/api/admin/global-categories/${id}`, {
headers: { 'Accept': 'application/json', 'X-CSRF-TOKEN': csrfToken }
})
.then(r => r.json())
.then(data => {
if (data.success) {
const cat = data.data;
document.getElementById('modalTitle').textContent = '글로벌 카테고리 수정';
document.getElementById('categoryId').value = cat.id;
document.getElementById('categoryType').value = 'global';
document.getElementById('categoryCode').value = cat.code;
document.getElementById('categoryCode').disabled = true;
document.getElementById('categoryName').value = cat.name;
document.getElementById('categorySortOrder').value = cat.sort_order || 1;
document.getElementById('categoryDescription').value = cat.description || '';
if (document.getElementById('isGlobal')) {
document.getElementById('isGlobal').checked = true;
document.getElementById('isGlobal').disabled = true;
}
loadParentOptions('global', cat.parent_id);
openModal();
}
});
}
function openModal() {
document.getElementById('categoryModal').classList.remove('hidden');
document.getElementById('categoryModal').classList.add('flex');
}
function closeModal() {
document.getElementById('categoryModal').classList.add('hidden');
document.getElementById('categoryModal').classList.remove('flex');
if (document.getElementById('isGlobal')) {
document.getElementById('isGlobal').disabled = false;
}
document.getElementById('categoryCode').disabled = false;
}
// 상위 카테고리 옵션 로드
function loadParentOptions(type, selectedId = null) {
const select = document.getElementById('categoryParentId');
const url = type === 'global'
? `/api/admin/global-categories/list?code_group=${selectedGroup}`
: `/api/admin/categories/list?code_group=${selectedGroup}`;
fetch(url, { headers: { 'Accept': 'application/json', 'X-CSRF-TOKEN': csrfToken } })
.then(r => r.json())
.then(data => {
select.innerHTML = '<option value="">최상위 카테고리</option>';
if (data.success && data.data) {
data.data.forEach(cat => {
const opt = document.createElement('option');
opt.value = cat.id;
opt.textContent = (cat.parent_id ? 'ㄴ ' : '') + cat.name;
if (cat.id == selectedId) opt.selected = true;
select.appendChild(opt);
});
}
});
}
// 저장
function saveCategory(event) {
event.preventDefault();
const id = document.getElementById('categoryId').value;
const isEdit = !!id;
const isGlobal = document.getElementById('isGlobal')?.checked ||
document.getElementById('categoryType').value === 'global';
const data = {
code_group: selectedGroup,
code: document.getElementById('categoryCode').value,
name: document.getElementById('categoryName').value,
parent_id: document.getElementById('categoryParentId').value || null,
sort_order: parseInt(document.getElementById('categorySortOrder').value) || 1,
description: document.getElementById('categoryDescription').value || null,
};
let url, method;
if (isGlobal) {
url = isEdit ? `/api/admin/global-categories/${id}` : '/api/admin/global-categories';
} else {
url = isEdit ? `/api/admin/categories/${id}` : '/api/admin/categories';
}
method = isEdit ? 'PUT' : 'POST';
fetch(url, {
method: method,
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrfToken,
'Accept': 'application/json'
},
body: JSON.stringify(data)
})
.then(r => r.json())
.then(result => {
if (result.success) {
showToast(result.message || '저장되었습니다.', 'success');
closeModal();
location.reload();
} else {
showToast(result.message || '저장에 실패했습니다.', 'error');
}
})
.catch(() => showToast('저장 중 오류가 발생했습니다.', 'error'));
}
// 글로벌 → 테넌트 복사
function copyToTenant(globalId) {
if (!confirm('이 글로벌 카테고리를 테넌트로 복사하시겠습니까?')) return;
fetch(`/api/admin/global-categories/${globalId}/copy-to-tenant`, {
method: 'POST',
headers: { 'X-CSRF-TOKEN': csrfToken, 'Accept': 'application/json' }
})
.then(r => r.json())
.then(result => {
if (result.success) {
showToast(result.message || '복사되었습니다.', 'success');
location.reload();
} else {
showToast(result.message || '복사에 실패했습니다.', 'error');
}
})
.catch(() => showToast('복사 중 오류가 발생했습니다.', 'error'));
}
// 전체 선택
function toggleSelectAll(checkbox) {
document.querySelectorAll('.global-checkbox').forEach(cb => cb.checked = checkbox.checked);
updateBulkCopyButton();
}
function updateBulkCopyButton() {
const checked = document.querySelectorAll('.global-checkbox:checked');
const btn = document.getElementById('bulkCopyBtn');
if (btn) {
if (checked.length > 0) {
btn.classList.remove('hidden');
btn.classList.add('flex');
document.getElementById('bulkCopyCount').textContent = checked.length;
} else {
btn.classList.add('hidden');
btn.classList.remove('flex');
}
}
}
// 일괄 복사
function bulkCopy() {
const ids = Array.from(document.querySelectorAll('.global-checkbox:checked')).map(cb => cb.value);
if (ids.length === 0) return;
if (!confirm(`선택한 ${ids.length}개 글로벌 카테고리를 테넌트로 복사하시겠습니까?`)) return;
fetch('/api/admin/global-categories/bulk-copy-to-tenant', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrfToken,
'Accept': 'application/json'
},
body: JSON.stringify({ ids: ids })
})
.then(r => r.json())
.then(result => {
if (result.success) {
showToast(result.message || '복사되었습니다.', 'success');
location.reload();
} else {
showToast(result.message || '복사에 실패했습니다.', 'error');
}
})
.catch(() => showToast('복사 중 오류가 발생했습니다.', 'error'));
}
// 활성 토글 (테넌트)
function toggleTenantActive(id) {
fetch(`/api/admin/categories/${id}/toggle`, {
method: 'POST',
headers: { 'X-CSRF-TOKEN': csrfToken, 'Accept': 'application/json' }
})
.then(r => r.json())
.then(result => {
if (result.success) location.reload();
else showToast(result.message || '상태 변경에 실패했습니다.', 'error');
});
}
// 활성 토글 (글로벌)
function toggleGlobalActive(id) {
fetch(`/api/admin/global-categories/${id}/toggle`, {
method: 'POST',
headers: { 'X-CSRF-TOKEN': csrfToken, 'Accept': 'application/json' }
})
.then(r => r.json())
.then(result => {
if (result.success) location.reload();
else showToast(result.message || '상태 변경에 실패했습니다.', 'error');
});
}
// 삭제 (테넌트)
function deleteTenantCategory(id, name) {
showDeleteConfirm(name, () => {
fetch(`/api/admin/categories/${id}`, {
method: 'DELETE',
headers: { 'X-CSRF-TOKEN': csrfToken, 'Accept': 'application/json' }
})
.then(r => r.json())
.then(result => {
if (result.success) {
showToast(result.message || '삭제되었습니다.', 'success');
location.reload();
} else {
showToast(result.message || '삭제에 실패했습니다.', 'error');
}
});
});
}
// 삭제 (글로벌)
function deleteGlobalCategory(id, name) {
showDeleteConfirm(name, () => {
fetch(`/api/admin/global-categories/${id}`, {
method: 'DELETE',
headers: { 'X-CSRF-TOKEN': csrfToken, 'Accept': 'application/json' }
})
.then(r => r.json())
.then(result => {
if (result.success) {
showToast(result.message || '삭제되었습니다.', 'success');
location.reload();
} else {
showToast(result.message || '삭제에 실패했습니다.', 'error');
}
});
});
}
// 모달 외부 클릭 시 닫기
document.getElementById('categoryModal').addEventListener('click', function(e) {
if (e.target === this) closeModal();
});
// ESC 키로 모달 닫기
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeModal();
});
</script>
@endpush

View File

@@ -0,0 +1,6 @@
<option value="{{ $category->id }}">{{ str_repeat('ㄴ ', $depth) }}{{ $category->name }}</option>
@if($category->childrenRecursive->count() > 0)
@foreach($category->childrenRecursive as $child)
@include('categories.partials.option', ['category' => $child, 'depth' => $depth + 1])
@endforeach
@endif

View File

@@ -0,0 +1,81 @@
<div class="category-item border border-gray-200 rounded-lg bg-white" data-id="{{ $category->id }}">
<div class="flex items-center justify-between px-4 py-3 hover:bg-gray-50">
<div class="flex items-center gap-3 flex-1">
<!-- 드래그 핸들 -->
<div class="drag-handle cursor-move text-gray-400 hover:text-gray-600">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8h16M4 16h16" />
</svg>
</div>
<!-- 들여쓰기 -->
@if($depth > 0)
<div style="width: {{ $depth * 24 }}px"></div>
@endif
<!-- 펼침/접힘 버튼 -->
@if($category->childrenRecursive->count() > 0)
<button type="button" onclick="toggleChildren(this)" class="text-gray-500 hover:text-gray-700">
<svg class="w-4 h-4 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
</svg>
</button>
@else
<div class="w-4"></div>
@endif
<!-- 카테고리 정보 -->
<div class="flex items-center gap-2 flex-1">
<span class="font-medium text-gray-800">{{ $category->name }}</span>
<span class="text-sm text-gray-500">({{ $category->code }})</span>
@if($category->description)
<span class="text-sm text-gray-400 hidden sm:inline">- {{ Str::limit($category->description, 30) }}</span>
@endif
</div>
</div>
<div class="flex items-center gap-2">
<!-- 활성 토글 -->
<button type="button" onclick="toggleCategory({{ $category->id }}, this)"
class="relative inline-flex h-6 w-10 items-center rounded-full transition {{ $category->is_active ? 'bg-blue-500' : 'bg-gray-400' }}">
<span class="inline-block h-4 w-4 transform rounded-full bg-white shadow transition {{ $category->is_active ? 'translate-x-4' : 'translate-x-0.5' }}"></span>
</button>
<!-- 하위 카테고리 추가 -->
<button type="button" onclick="addChildCategory({{ $category->id }})"
class="p-1.5 text-gray-400 hover:text-blue-600 hover:bg-blue-50 rounded transition"
title="하위 카테고리 추가">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg>
</button>
<!-- 수정 -->
<button type="button" onclick="openEditModal({{ $category->id }})"
class="p-1.5 text-gray-400 hover:text-yellow-600 hover:bg-yellow-50 rounded transition"
title="수정">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
</svg>
</button>
<!-- 삭제 -->
<button type="button" onclick="deleteCategory({{ $category->id }}, '{{ $category->name }}')"
class="p-1.5 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded transition"
title="삭제">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
</div>
</div>
<!-- 하위 카테고리 -->
@if($category->childrenRecursive->count() > 0)
<div class="children-container pl-4 pb-2 space-y-2" id="sortable-{{ $category->id }}">
@foreach($category->childrenRecursive as $child)
@include('categories.partials.tree-item', ['category' => $child, 'depth' => $depth + 1])
@endforeach
</div>
@endif
</div>

View File

@@ -0,0 +1,15 @@
@if($categories->isEmpty())
<div class="text-center py-12 text-gray-500">
<svg class="w-16 h-16 mx-auto text-gray-300 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
</svg>
<p class="text-lg font-medium">등록된 카테고리가 없습니다.</p>
<p class="text-sm mt-1"> 카테고리를 추가해주세요.</p>
</div>
@else
<div class="space-y-2" id="sortable-root">
@foreach($categories as $category)
@include('categories.partials.tree-item', ['category' => $category, 'depth' => 0])
@endforeach
</div>
@endif

View File

@@ -3,7 +3,10 @@
use App\Http\Controllers\Api\Admin\BoardController;
use App\Http\Controllers\Api\Admin\CustomerCenterController;
use App\Http\Controllers\Api\Admin\DailyLogController;
use App\Http\Controllers\Api\Admin\DepartmentController;use App\Http\Controllers\Api\Admin\DocumentTemplateApiController;
use App\Http\Controllers\Api\Admin\DepartmentController;
use App\Http\Controllers\Api\Admin\DocumentTemplateApiController;
use App\Http\Controllers\Api\Admin\CategoryApiController;
use App\Http\Controllers\Api\Admin\GlobalCategoryApiController;
use App\Http\Controllers\Api\Admin\GlobalMenuController;
use App\Http\Controllers\Api\Admin\ItemFieldController;
use App\Http\Controllers\Api\Admin\MeetingLogController;
@@ -787,6 +790,49 @@
Route::post('/upload-image', [DocumentTemplateApiController::class, 'uploadImage'])->name('upload-image');
});
/*
|--------------------------------------------------------------------------
| 카테고리 관리 API
|--------------------------------------------------------------------------
*/
Route::middleware(['web', 'auth', 'hq.member'])->prefix('admin/categories')->name('api.admin.categories.')->group(function () {
// 고정 경로
Route::get('/list', [CategoryApiController::class, 'list'])->name('list');
Route::get('/tree', [CategoryApiController::class, 'tree'])->name('tree');
Route::post('/reorder', [CategoryApiController::class, 'reorder'])->name('reorder');
// 기본 CRUD
Route::get('/{id}', [CategoryApiController::class, 'show'])->name('show');
Route::post('/', [CategoryApiController::class, 'store'])->name('store');
Route::put('/{id}', [CategoryApiController::class, 'update'])->name('update');
Route::delete('/{id}', [CategoryApiController::class, 'destroy'])->name('destroy');
// 추가 액션
Route::post('/{id}/toggle', [CategoryApiController::class, 'toggle'])->name('toggle');
Route::post('/{id}/move', [CategoryApiController::class, 'move'])->name('move');
});
/*
|--------------------------------------------------------------------------
| 글로벌 카테고리 관리 API
|--------------------------------------------------------------------------
*/
Route::middleware(['web', 'auth', 'hq.member'])->prefix('admin/global-categories')->name('api.admin.global-categories.')->group(function () {
// 고정 경로
Route::get('/list', [GlobalCategoryApiController::class, 'list'])->name('list');
Route::post('/bulk-copy-to-tenant', [GlobalCategoryApiController::class, 'bulkCopyToTenant'])->name('bulkCopyToTenant');
// 기본 CRUD
Route::get('/{id}', [GlobalCategoryApiController::class, 'show'])->name('show');
Route::post('/', [GlobalCategoryApiController::class, 'store'])->name('store');
Route::put('/{id}', [GlobalCategoryApiController::class, 'update'])->name('update');
Route::delete('/{id}', [GlobalCategoryApiController::class, 'destroy'])->name('destroy');
// 추가 액션
Route::post('/{id}/toggle', [GlobalCategoryApiController::class, 'toggle'])->name('toggle');
Route::post('/{id}/copy-to-tenant', [GlobalCategoryApiController::class, 'copyToTenant'])->name('copyToTenant');
});
/*
|--------------------------------------------------------------------------
| 웹 녹음 AI 요약 API

View File

@@ -27,6 +27,7 @@
use App\Http\Controllers\TenantSettingController;
use App\Http\Controllers\CommonCodeController;
use App\Http\Controllers\DocumentTemplateController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\MenuSyncController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;
@@ -316,6 +317,9 @@
Route::get('/{id}/edit', [DocumentTemplateController::class, 'edit'])->name('edit');
});
// 카테고리 관리
Route::get('/categories', [CategoryController::class, 'index'])->name('categories.index');
/*
|--------------------------------------------------------------------------
| 바로빌 Routes