Merge develop and fix conflicts in routes/web.php (AI config and Categories)

This commit is contained in:
김보곤
2026-01-28 13:57:34 +09:00
18 changed files with 1889 additions and 61 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);
}
}
}

View File

@@ -12,7 +12,14 @@
class MenuSyncController extends Controller
{
protected int $tenantId = 1; // MNG 메뉴는 tenant_id=1
/**
* 현재 선택된 테넌트 ID
*/
protected function getTenantId(): int
{
$tenantId = session('selected_tenant_id');
return ($tenantId && $tenantId !== 'all') ? (int) $tenantId : 1;
}
/**
* 환경 설정 조회
@@ -20,7 +27,7 @@ class MenuSyncController extends Controller
private function getEnvironments(): array
{
$setting = TenantSetting::withoutGlobalScopes()
->where('tenant_id', $this->tenantId)
->where('tenant_id', $this->getTenantId())
->where('setting_group', 'menu_sync')
->where('setting_key', 'environments')
->first();
@@ -85,7 +92,7 @@ public function saveSettings(Request $request): JsonResponse
TenantSetting::withoutGlobalScopes()->updateOrCreate(
[
'tenant_id' => $this->tenantId,
'tenant_id' => $this->getTenantId(),
'setting_group' => 'menu_sync',
'setting_key' => 'environments',
],
@@ -178,7 +185,7 @@ public function push(Request $request): JsonResponse
// 선택된 메뉴 조회
$menus = Menu::withoutGlobalScopes()
->where('tenant_id', $this->tenantId)
->where('tenant_id', $this->getTenantId())
->whereIn('id', $validated['menu_ids'])
->get();
@@ -316,7 +323,7 @@ public function testConnection(Request $request): JsonResponse
private function getMenuTree(?int $parentId = null): array
{
$menus = Menu::withoutGlobalScopes()
->where('tenant_id', $this->tenantId)
->where('tenant_id', $this->getTenantId())
->where('parent_id', $parentId)
->orderBy('sort_order')
->get();
@@ -340,7 +347,7 @@ private function getMenuTree(?int $parentId = null): array
private function getChildrenData(int $parentId): array
{
$children = Menu::withoutGlobalScopes()
->where('tenant_id', $this->tenantId)
->where('tenant_id', $this->getTenantId())
->where('parent_id', $parentId)
->orderBy('sort_order')
->get();
@@ -411,17 +418,20 @@ private function flattenMenuNames(array $menus, string $prefix = ''): array
}
/**
* 이름으로 메뉴 필터링
* 이름으로 메뉴 필터링 (부모 이름 포함)
*/
private function filterMenusByName(array $menus, array $names): array
private function filterMenusByName(array $menus, array $names, ?string $parentName = null): array
{
$result = [];
foreach ($menus as $menu) {
if (in_array($menu['name'], $names)) {
// 부모 이름 추가
$menu['parent_name'] = $parentName;
$result[] = $menu;
}
if (! empty($menu['children'])) {
$result = array_merge($result, $this->filterMenusByName($menu['children'], $names));
// 현재 메뉴를 부모로 전달
$result = array_merge($result, $this->filterMenusByName($menu['children'], $names, $menu['name']));
}
}
return $result;
@@ -435,7 +445,7 @@ private function importMenu(array $data, ?int $parentId = null): void
// 부모 메뉴 찾기
if (! $parentId && ! empty($data['parent_name'])) {
$parent = Menu::withoutGlobalScopes()
->where('tenant_id', $this->tenantId)
->where('tenant_id', $this->getTenantId())
->where('name', $data['parent_name'])
->first();
$parentId = $parent?->id;
@@ -444,7 +454,7 @@ private function importMenu(array $data, ?int $parentId = null): void
// 기존 메뉴 찾기 또는 생성
$menu = Menu::withoutGlobalScopes()->updateOrCreate(
[
'tenant_id' => $this->tenantId,
'tenant_id' => $this->getTenantId(),
'name' => $data['name'],
],
[
@@ -464,4 +474,4 @@ private function importMenu(array $data, ?int $parentId = null): void
}
}
}
}
}

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

@@ -28,7 +28,7 @@ class="sidebar-group-header w-full flex items-center justify-between px-3 py-2 t
</span>
<svg
id="{{ $groupId }}-icon"
class="w-3 h-3 transition-transform sidebar-text {{ $hasChildren ? 'rotate-180' : '' }}"
class="w-3 h-3 transition-transform sidebar-text rotate-180"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
@@ -37,7 +37,8 @@ class="w-3 h-3 transition-transform sidebar-text {{ $hasChildren ? 'rotate-180'
</svg>
</button>
<ul id="{{ $groupId }}" class="space-y-1 mt-1" style="display: {{ $hasChildren ? 'block' : 'none' }};">
{{-- 기본 펼침 상태, CSS에서 localStorage 기반으로 즉시 제어 --}}
<ul id="{{ $groupId }}" class="menu-group-content space-y-1 mt-1">
@foreach($children as $child)
@if($child->menuChildren && $child->menuChildren->isNotEmpty())
<x-sidebar.menu-group :menu="$child" :depth="$depth + 1" />
@@ -63,7 +64,7 @@ class="sidebar-subgroup-header w-full flex items-center justify-between px-3 py-
</span>
<svg
id="{{ $groupId }}-icon"
class="w-3 h-3 transition-transform sidebar-text {{ $isExpanded ? 'rotate-180' : '' }}"
class="w-3 h-3 transition-transform sidebar-text rotate-180"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
@@ -72,7 +73,8 @@ class="w-3 h-3 transition-transform sidebar-text {{ $isExpanded ? 'rotate-180' :
</svg>
</button>
<ul id="{{ $groupId }}" class="space-y-1 mt-1" style="display: {{ $isExpanded ? 'block' : 'none' }};">
{{-- 기본 펼침 상태, CSS에서 localStorage 기반으로 즉시 제어 --}}
<ul id="{{ $groupId }}" class="menu-group-content space-y-1 mt-1">
@foreach($children as $child)
@if($child->menuChildren && $child->menuChildren->isNotEmpty())
<x-sidebar.menu-group :menu="$child" :depth="$depth + 1" />

View File

@@ -37,12 +37,86 @@
sessionStorage.removeItem('api_token_expires_at');
@endif
</script>
<!-- 사이드바 상태 즉시 적용 (깜빡임 방지) -->
<!-- 페이지 로딩 오버레이 스타일 -->
<style id="page-loader-styles">
.page-loader-overlay {
position: fixed;
inset: 0;
z-index: 99999;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.page-loader-content {
text-align: center;
}
.page-loader-bar {
width: 200px;
height: 4px;
background: #e5e7eb;
border-radius: 2px;
overflow: hidden;
}
.page-loader-progress {
height: 100%;
background: linear-gradient(90deg, #3b82f6, #8b5cf6);
border-radius: 2px;
animation: loader-progress 1.5s ease-in-out infinite;
}
@keyframes loader-progress {
0% { width: 0%; margin-left: 0; }
50% { width: 60%; margin-left: 20%; }
100% { width: 0%; margin-left: 100%; }
}
.page-loader-text {
margin-top: 12px;
font-size: 14px;
color: #6b7280;
}
/* 블러 해제 애니메이션 */
.page-loader-overlay.fade-out {
animation: loader-fade-out 0.3s ease-out forwards;
}
@keyframes loader-fade-out {
to {
opacity: 0;
visibility: hidden;
}
}
</style>
<!-- 사이드바 + 메뉴 상태 즉시 적용 -->
<script>
(function() {
// 사이드바 접힘 상태
if (localStorage.getItem('sidebar-collapsed') === 'true') {
document.documentElement.classList.add('sidebar-is-collapsed');
}
// 메뉴 그룹: hidden 상태인 것만 CSS로 숨김
var style = document.createElement('style');
style.id = 'menu-group-preload-styles';
var css = '';
var iconCss = '';
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
if (key && key.startsWith('menu-group-menu-group-')) {
var groupId = key.replace('menu-group-', '');
var state = localStorage.getItem(key);
if (state === 'hidden') {
css += '#' + groupId + '{display:none!important}';
iconCss += '#' + groupId + '-icon{transform:rotate(0deg)!important}';
}
}
}
if (css || iconCss) {
style.textContent = css + iconCss;
document.head.appendChild(style);
}
// 스크롤 위치 미리 저장
window._savedSidebarScroll = localStorage.getItem('sidebar-scroll-top');
window._savedSidebarScrollBottom = localStorage.getItem('sidebar-scroll-bottom');
})();
</script>
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
@@ -181,7 +255,17 @@ function initPageScripts() {
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
@stack('styles')
</head>
<body class="bg-gray-100">
<body class="bg-gray-100 no-transition">
<!-- 페이지 로딩 오버레이 -->
<div id="page-loader" class="page-loader-overlay">
<div class="page-loader-content">
<div class="page-loader-bar">
<div class="page-loader-progress"></div>
</div>
<div class="page-loader-text">Loading...</div>
</div>
</div>
<div class="flex h-screen overflow-hidden" id="app-container">
<!-- 모바일 사이드바 백드롭 (lg 미만에서만 동작) -->
<div id="sidebar-backdrop"

View File

@@ -3,34 +3,48 @@
$isRemoteOnly = $side === 'remote' && in_array($menu['name'], $diff['remote_only'] ?? []);
$isBoth = in_array($menu['name'], $diff['both'] ?? []);
// 동기화 필요 여부 (로컬에서는 local_only만, 원격에서는 remote_only만 체크 가능)
$needsSync = $isLocalOnly || $isRemoteOnly;
$bgClass = '';
$badgeClass = '';
$badgeText = '';
if ($isLocalOnly) {
$bgClass = 'bg-green-50 border-green-200';
$bgClass = 'bg-green-50';
$badgeClass = 'bg-green-100 text-green-700';
$badgeText = 'NEW';
} elseif ($isRemoteOnly) {
$bgClass = 'bg-purple-50 border-purple-200';
$bgClass = 'bg-purple-50';
$badgeClass = 'bg-purple-100 text-purple-700';
$badgeText = 'NEW';
} else {
$bgClass = 'bg-white hover:bg-gray-50';
$bgClass = 'hover:bg-gray-50';
}
$paddingLeft = ($depth * 1.5) + 0.5;
@endphp
<div class="border rounded-lg mb-1 {{ $bgClass }}" style="margin-left: {{ $depth * 1 }}rem;">
@php
$menuKey = $side . '_' . ($menu['id'] ?? Str::slug($menu['name']));
@endphp
<div class="menu-group" data-menu-key="{{ $menuKey }}">
<div class="border rounded-lg mb-1 {{ $bgClass }}" style="margin-left: {{ $depth * 2 }}rem;">
<div class="flex items-center gap-2 px-3 py-2">
<!-- 체크박스 -->
<!-- 체크박스 (동기화 필요한 메뉴만 활성화) - 양쪽 모두 이름으로 매핑 -->
@if($side === 'local')
<input type="checkbox" name="local_menu" value="{{ $menu['id'] }}"
class="w-4 h-4 text-green-600 border-gray-300 rounded focus:ring-green-500">
<input type="checkbox" name="local_menu" value="{{ $menu['name'] }}"
data-menu-id="{{ $menu['id'] }}"
data-menu-key="{{ $menuKey }}"
data-has-children="{{ !empty($menu['children']) ? 'true' : 'false' }}"
onchange="toggleChildren(this)"
class="w-4 h-4 rounded focus:ring-green-500 {{ $needsSync ? 'text-green-600 border-gray-300' : 'bg-gray-200 border-gray-300 cursor-not-allowed' }}"
{{ !$needsSync ? 'disabled' : '' }}>
@else
<input type="checkbox" name="remote_menu" value="{{ $menu['name'] }}"
class="w-4 h-4 text-purple-600 border-gray-300 rounded focus:ring-purple-500">
data-menu-key="{{ $menuKey }}"
data-has-children="{{ !empty($menu['children']) ? 'true' : 'false' }}"
onchange="toggleChildren(this)"
class="w-4 h-4 rounded focus:ring-purple-500 {{ $needsSync ? 'text-purple-600 border-gray-300' : 'bg-gray-200 border-gray-300 cursor-not-allowed' }}"
{{ !$needsSync ? 'disabled' : '' }}>
@endif
<!-- 아이콘 -->
@@ -71,8 +85,13 @@ class="w-4 h-4 text-purple-600 border-gray-300 rounded focus:ring-purple-500">
</span>
@endif
<!-- 메뉴 이름 -->
<span class="flex-1 text-sm text-gray-800">{{ $menu['name'] }}</span>
<!-- 메뉴 이름 + 뎁스 레벨 -->
<span class="flex-1 text-sm text-gray-800 flex items-center gap-2">
{{ $menu['name'] }}
@if($depth > 0)
<span class="text-[10px] text-gray-400 bg-gray-100 px-1 rounded">Lv.{{ $depth + 1 }}</span>
@endif
</span>
<!-- 배지 -->
@if($badgeText)
@@ -88,6 +107,7 @@ class="w-4 h-4 text-purple-600 border-gray-300 rounded focus:ring-purple-500">
<!-- 자식 메뉴 -->
@if(!empty($menu['children']))
<div class="children-container">
@foreach($menu['children'] as $child)
@include('menus._sync_menu_item', [
'menu' => $child,
@@ -96,4 +116,6 @@ class="w-4 h-4 text-purple-600 border-gray-300 rounded focus:ring-purple-500">
'depth' => $depth + 1
])
@endforeach
@endif
</div>
@endif
</div>

View File

@@ -109,6 +109,8 @@ class="px-6 py-3 text-sm font-medium border-b-2 transition-colors
<div class="bg-white rounded-lg shadow-sm flex flex-col">
<div class="px-4 py-3 border-b border-gray-200 flex items-center justify-between flex-shrink-0">
<div class="flex items-center gap-2">
<input type="checkbox" id="selectAllLocal" onchange="toggleSelectAll('local', this.checked)"
class="w-4 h-4 text-green-600 border-gray-300 rounded focus:ring-green-500">
<span class="w-6 h-6 bg-green-100 rounded flex items-center justify-center">
<svg class="w-4 h-4 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
@@ -118,10 +120,13 @@ class="px-6 py-3 text-sm font-medium border-b-2 transition-colors
<span class="text-xs text-gray-500">({{ count($localMenus) }} 그룹)</span>
</div>
@if(!empty($environments[$selectedEnv]['url']) && !$remoteError)
<button type="button" onclick="pushSelected()"
class="px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-xs font-medium rounded transition-colors flex items-center gap-1">
Push
</button>
<div class="flex items-center gap-2">
<span id="localSelectedCount" class="text-xs text-gray-500">0 선택</span>
<button type="button" onclick="pushSelected()"
class="px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-xs font-medium rounded transition-colors flex items-center gap-1">
Push
</button>
</div>
@endif
</div>
<div class="overflow-auto flex-1 p-2">
@@ -140,6 +145,8 @@ class="px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-xs font-mediu
<div class="bg-white rounded-lg shadow-sm flex flex-col">
<div class="px-4 py-3 border-b border-gray-200 flex items-center justify-between flex-shrink-0">
<div class="flex items-center gap-2">
<input type="checkbox" id="selectAllRemote" onchange="toggleSelectAll('remote', this.checked)"
class="w-4 h-4 text-purple-600 border-gray-300 rounded focus:ring-purple-500">
<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 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z" />
@@ -149,10 +156,13 @@ class="px-3 py-1.5 bg-green-600 hover:bg-green-700 text-white text-xs font-mediu
<span class="text-xs text-gray-500">({{ count($remoteMenus) }} 그룹)</span>
</div>
@if(!empty($environments[$selectedEnv]['url']) && !$remoteError)
<button type="button" onclick="pullSelected()"
class="px-3 py-1.5 bg-purple-600 hover:bg-purple-700 text-white text-xs font-medium rounded transition-colors flex items-center gap-1">
Pull
</button>
<div class="flex items-center gap-2">
<span id="remoteSelectedCount" class="text-xs text-gray-500">0 선택</span>
<button type="button" onclick="pullSelected()"
class="px-3 py-1.5 bg-purple-600 hover:bg-purple-700 text-white text-xs font-medium rounded transition-colors flex items-center gap-1">
Pull
</button>
</div>
@endif
</div>
<div class="overflow-auto flex-1 p-2">
@@ -446,5 +456,48 @@ function closeSettingsModal() {
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeSettingsModal();
});
// 전체 선택 (활성화된 체크박스만)
function toggleSelectAll(side, checked) {
const checkboxes = document.querySelectorAll(`input[name="${side}_menu"]:not(:disabled)`);
checkboxes.forEach(cb => cb.checked = checked);
updateSelectedCount(side);
}
// 선택된 개수 업데이트
function updateSelectedCount(side) {
const checkboxes = document.querySelectorAll(`input[name="${side}_menu"]:checked`);
const countEl = document.getElementById(`${side}SelectedCount`);
if (countEl) {
countEl.textContent = `${checkboxes.length}개 선택`;
}
}
// 체크박스 변경 이벤트 리스너
document.addEventListener('change', function(e) {
if (e.target.name === 'local_menu') {
updateSelectedCount('local');
} else if (e.target.name === 'remote_menu') {
updateSelectedCount('remote');
}
});
// 상위 메뉴 체크 시 하위 메뉴도 선택/해제
function toggleChildren(checkbox) {
const menuGroup = checkbox.closest('.menu-group');
if (!menuGroup) return;
const childrenContainer = menuGroup.querySelector(':scope > .children-container');
if (!childrenContainer) return;
const childCheckboxes = childrenContainer.querySelectorAll('input[type="checkbox"]:not(:disabled)');
childCheckboxes.forEach(cb => {
cb.checked = checkbox.checked;
});
// 선택 개수 업데이트
const side = checkbox.name.replace('_menu', '');
updateSelectedCount(side);
}
</script>
@endpush
@endpush

View File

@@ -93,6 +93,14 @@ class="w-full border-gray-300 rounded-lg text-sm focus:ring-primary focus:border
</aside>
<style>
/* ========== 초기 로드 시 transition 비활성화 (깜빡임 방지) ========== */
body.no-transition .sidebar,
body.no-transition .sidebar *,
body.no-transition .sidebar-nav,
body.no-transition [id^="menu-group-"] {
transition: none !important;
}
/* ========== 사이드바 기본 스타일 ========== */
.sidebar {
width: 16rem;
@@ -545,18 +553,19 @@ function toggleMenuGroup(groupId) {
if (!group) return;
const isHidden = group.style.display === 'none' || group.style.display === '';
// computed style로 실제 표시 상태 확인
const isHidden = window.getComputedStyle(group).display === 'none';
if (isHidden) {
group.style.display = 'block';
if (icon) {
icon.classList.add('rotate-180');
icon.style.transform = 'rotate(180deg)';
}
localStorage.setItem('menu-group-' + groupId, 'visible');
} else {
group.style.display = 'none';
if (icon) {
icon.classList.remove('rotate-180');
icon.style.transform = 'rotate(0deg)';
}
localStorage.setItem('menu-group-' + groupId, 'hidden');
}
@@ -578,22 +587,20 @@ function scrollSidebarToBottom() {
}
}
// 저장된 스크롤 위치 복원
// 저장된 스크롤 위치 복원 (즉시 적용, 깜빡임 방지)
function restoreSidebarScroll() {
const sidebarNav = document.querySelector('.sidebar-nav');
if (!sidebarNav) return;
const scrollToBottom = localStorage.getItem('sidebar-scroll-bottom');
const savedScrollTop = localStorage.getItem('sidebar-scroll-top');
// head에서 미리 읽은 값 사용 (더 빠른 적용)
const scrollToBottom = window._savedSidebarScrollBottom || localStorage.getItem('sidebar-scroll-bottom');
const savedScrollTop = window._savedSidebarScroll || localStorage.getItem('sidebar-scroll-top');
// 즉시 적용 (setTimeout 제거)
if (scrollToBottom === 'true') {
setTimeout(function() {
sidebarNav.scrollTop = sidebarNav.scrollHeight;
}, 100);
sidebarNav.scrollTop = sidebarNav.scrollHeight;
} else if (savedScrollTop) {
setTimeout(function() {
sidebarNav.scrollTop = parseInt(savedScrollTop, 10);
}, 100);
sidebarNav.scrollTop = parseInt(savedScrollTop, 10);
}
}
@@ -814,6 +821,9 @@ function initSidebarTooltips() {
// 페이지 로드 시 상태 복원
document.addEventListener('DOMContentLoaded', function() {
// 스크롤 위치 먼저 복원 (가장 먼저 실행)
restoreSidebarScroll();
// 사이드바 상태 복원
const isCollapsed = localStorage.getItem('sidebar-collapsed') === 'true';
if (isCollapsed) {
@@ -832,22 +842,29 @@ function initSidebarTooltips() {
}
});
// 메뉴 그룹 상태 복원 (동적 메뉴) - inline style로 통일
// CSS preload 스타일을 inline style로 교체 (이후 JS 토글이 정상 동작하도록)
document.querySelectorAll('[id^="menu-group-"]').forEach(function(group) {
const groupId = group.id;
const savedState = localStorage.getItem('menu-group-' + groupId);
const icon = document.getElementById(groupId + '-icon');
// CSS에서 설정한 상태를 inline style로 이전
if (savedState === 'hidden') {
group.style.display = 'none';
icon?.classList.remove('rotate-180');
} else if (savedState === 'visible') {
if (icon) icon.style.transform = 'rotate(0deg)';
} else {
// visible 또는 미설정: 펼침 상태 유지
group.style.display = 'block';
icon?.classList.add('rotate-180');
if (icon) icon.style.transform = 'rotate(180deg)';
}
// savedState가 없으면 서버에서 렌더링한 초기 상태 유지
});
// preload 스타일 제거 (이제 inline style이 적용됨)
const preloadStyle = document.getElementById('menu-group-preload-styles');
if (preloadStyle) {
preloadStyle.remove();
}
// R&D Labs 탭 상태 복원
const savedTab = localStorage.getItem('lab-active-tab');
if (savedTab && ['s', 'a', 'm'].includes(savedTab)) {
@@ -860,12 +877,23 @@ function initSidebarTooltips() {
// 플라이아웃 위치 초기화
initLabFlyoutPosition();
// 스크롤 위치 복원
restoreSidebarScroll();
// 사이드바 툴팁 초기화
initSidebarTooltips();
// transition 활성화 + 로딩 오버레이 제거
requestAnimationFrame(function() {
document.body.classList.remove('no-transition');
// 로딩 오버레이 fade-out 후 제거
const loader = document.getElementById('page-loader');
if (loader) {
loader.classList.add('fade-out');
loader.addEventListener('animationend', function() {
loader.remove();
});
}
});
// R&D Labs 메뉴 클릭 시 스크롤
const labMenuContainer = document.getElementById('lab-menu-container');
if (labMenuContainer) {

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

@@ -29,6 +29,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;
@@ -331,6 +332,9 @@
// 명함 OCR API
Route::post('/api/business-card-ocr', [BusinessCardOcrController::class, 'process'])->name('api.business-card-ocr');
// 카테고리 관리
Route::get('/categories', [CategoryController::class, 'index'])->name('categories.index');
/*
|--------------------------------------------------------------------------
| 바로빌 Routes