feat:테넌트설정, 공통코드관리, 메뉴동기화 기능 추가
- 테넌트 설정 페이지 (재고관리 품목유형 등) - 공통코드 관리 페이지 (글로벌/테넌트별 코드 관리) - 메뉴 동기화 기능 (로컬↔개발↔운영 환경간 메뉴 Push/Pull)
This commit is contained in:
373
app/Http/Controllers/CommonCodeController.php
Normal file
373
app/Http/Controllers/CommonCodeController.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Products\CommonCode;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CommonCodeController extends Controller
|
||||
{
|
||||
/**
|
||||
* 코드 그룹 라벨
|
||||
*/
|
||||
private const CODE_GROUP_LABELS = [
|
||||
'item_type' => '품목유형',
|
||||
'material_type' => '자재유형',
|
||||
'client_type' => '거래처유형',
|
||||
'order_status' => '주문상태',
|
||||
'order_type' => '주문유형',
|
||||
'delivery_method' => '배송방법',
|
||||
'tenant_type' => '테넌트유형',
|
||||
'product_category' => '제품분류',
|
||||
'motor_type' => '모터유형',
|
||||
'controller_type' => '컨트롤러유형',
|
||||
'painting_type' => '도장유형',
|
||||
'position_type' => '위치유형',
|
||||
'capability_profile' => '생산능력',
|
||||
'bad_debt_progress' => '대손진행',
|
||||
'height_construction_cost' => '높이시공비',
|
||||
'width_construction_cost' => '폭시공비',
|
||||
];
|
||||
|
||||
/**
|
||||
* 공통코드 관리 페이지
|
||||
*/
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
// HTMX 요청 시 전체 페이지 리로드
|
||||
if ($request->header('HX-Request')) {
|
||||
return response('', 200)->header('HX-Redirect', route('common-codes.index'));
|
||||
}
|
||||
|
||||
$tenantId = session('selected_tenant_id');
|
||||
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
||||
$isHQ = $tenant?->tenant_type === 'HQ';
|
||||
|
||||
// 선택된 코드 그룹 (기본: item_type)
|
||||
$selectedGroup = $request->get('group', 'item_type');
|
||||
|
||||
// 코드 그룹 목록 (실제 존재하는 그룹만)
|
||||
$existingGroups = CommonCode::query()
|
||||
->select('code_group')
|
||||
->distinct()
|
||||
->pluck('code_group')
|
||||
->toArray();
|
||||
|
||||
$codeGroups = collect(self::CODE_GROUP_LABELS)
|
||||
->filter(fn($label, $group) => in_array($group, $existingGroups))
|
||||
->toArray();
|
||||
|
||||
// 선택된 그룹의 코드 목록
|
||||
$globalCodes = collect();
|
||||
$tenantCodes = collect();
|
||||
|
||||
if ($tenantId && isset($codeGroups[$selectedGroup])) {
|
||||
// 글로벌 코드 (tenant_id IS NULL)
|
||||
$globalCodes = CommonCode::query()
|
||||
->whereNull('tenant_id')
|
||||
->where('code_group', $selectedGroup)
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
// 테넌트 코드
|
||||
$tenantCodes = CommonCode::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('code_group', $selectedGroup)
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
}
|
||||
|
||||
return view('common-codes.index', [
|
||||
'tenant' => $tenant,
|
||||
'isHQ' => $isHQ,
|
||||
'codeGroups' => $codeGroups,
|
||||
'selectedGroup' => $selectedGroup,
|
||||
'globalCodes' => $globalCodes,
|
||||
'tenantCodes' => $tenantCodes,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드 저장 (신규/수정)
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
||||
|
||||
if (! $tenantId) {
|
||||
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
||||
}
|
||||
|
||||
$isHQ = $tenant?->tenant_type === 'HQ';
|
||||
$isGlobal = $request->boolean('is_global');
|
||||
|
||||
// 글로벌 코드는 HQ만 생성 가능
|
||||
if ($isGlobal && ! $isHQ) {
|
||||
return redirect()->back()->with('error', '글로벌 코드는 본사만 생성할 수 있습니다.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'code_group' => 'required|string|max:50',
|
||||
'code' => 'required|string|max:50',
|
||||
'name' => 'required|string|max:100',
|
||||
'sort_order' => 'nullable|integer|min:0|max:9999',
|
||||
'attributes' => 'nullable|json',
|
||||
'is_global' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
// 중복 체크
|
||||
$targetTenantId = $isGlobal ? null : $tenantId;
|
||||
$exists = CommonCode::query()
|
||||
->where('tenant_id', $targetTenantId)
|
||||
->where('code_group', $validated['code_group'])
|
||||
->where('code', $validated['code'])
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
return redirect()->back()
|
||||
->with('error', '이미 존재하는 코드입니다.')
|
||||
->withInput();
|
||||
}
|
||||
|
||||
CommonCode::create([
|
||||
'tenant_id' => $targetTenantId,
|
||||
'code_group' => $validated['code_group'],
|
||||
'code' => $validated['code'],
|
||||
'name' => $validated['name'],
|
||||
'sort_order' => $validated['sort_order'] ?? 0,
|
||||
'attributes' => $validated['attributes'] ? json_decode($validated['attributes'], true) : null,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->route('common-codes.index', ['group' => $validated['code_group']])
|
||||
->with('success', '코드가 추가되었습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드 수정
|
||||
*/
|
||||
public function update(Request $request, int $id): RedirectResponse|JsonResponse
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
||||
|
||||
if (! $tenantId) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
||||
}
|
||||
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
||||
}
|
||||
|
||||
$isHQ = $tenant?->tenant_type === 'HQ';
|
||||
|
||||
$code = CommonCode::find($id);
|
||||
if (! $code) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '코드를 찾을 수 없습니다.'], 404);
|
||||
}
|
||||
return redirect()->back()->with('error', '코드를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
// 권한 체크: 글로벌 코드는 HQ만, 테넌트 코드는 해당 테넌트만
|
||||
if ($code->tenant_id === null && ! $isHQ) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '글로벌 코드는 본사만 수정할 수 있습니다.'], 403);
|
||||
}
|
||||
return redirect()->back()->with('error', '글로벌 코드는 본사만 수정할 수 있습니다.');
|
||||
}
|
||||
|
||||
if ($code->tenant_id !== null && $code->tenant_id !== $tenantId) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '다른 테넌트의 코드는 수정할 수 없습니다.'], 403);
|
||||
}
|
||||
return redirect()->back()->with('error', '다른 테넌트의 코드는 수정할 수 없습니다.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'sometimes|required|string|max:100',
|
||||
'sort_order' => 'sometimes|nullable|integer|min:0|max:9999',
|
||||
'attributes' => 'sometimes|nullable|json',
|
||||
'is_active' => 'sometimes|boolean',
|
||||
]);
|
||||
|
||||
// 필드별 업데이트
|
||||
if (isset($validated['name'])) {
|
||||
$code->name = $validated['name'];
|
||||
}
|
||||
if (array_key_exists('sort_order', $validated)) {
|
||||
$code->sort_order = $validated['sort_order'] ?? 0;
|
||||
}
|
||||
if (array_key_exists('attributes', $validated)) {
|
||||
$code->attributes = $validated['attributes'] ? json_decode($validated['attributes'], true) : null;
|
||||
}
|
||||
if (isset($validated['is_active'])) {
|
||||
$code->is_active = $validated['is_active'];
|
||||
}
|
||||
|
||||
$code->save();
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => true, 'message' => '수정되었습니다.']);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('common-codes.index', ['group' => $code->code_group])
|
||||
->with('success', '코드가 수정되었습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성화 토글 (AJAX)
|
||||
*/
|
||||
public function toggle(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
||||
|
||||
if (! $tenantId) {
|
||||
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
||||
}
|
||||
|
||||
$isHQ = $tenant?->tenant_type === 'HQ';
|
||||
|
||||
$code = CommonCode::find($id);
|
||||
if (! $code) {
|
||||
return response()->json(['error' => '코드를 찾을 수 없습니다.'], 404);
|
||||
}
|
||||
|
||||
// 권한 체크
|
||||
if ($code->tenant_id === null && ! $isHQ) {
|
||||
return response()->json(['error' => '글로벌 코드는 본사만 수정할 수 있습니다.'], 403);
|
||||
}
|
||||
|
||||
if ($code->tenant_id !== null && $code->tenant_id !== $tenantId) {
|
||||
return response()->json(['error' => '다른 테넌트의 코드는 수정할 수 없습니다.'], 403);
|
||||
}
|
||||
|
||||
$code->is_active = ! $code->is_active;
|
||||
$code->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'is_active' => $code->is_active,
|
||||
'message' => $code->is_active ? '활성화되었습니다.' : '비활성화되었습니다.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 글로벌 코드를 테넌트용으로 복사
|
||||
*/
|
||||
public function copy(Request $request, int $id): RedirectResponse|JsonResponse
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
|
||||
if (! $tenantId) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
||||
}
|
||||
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
||||
}
|
||||
|
||||
$globalCode = CommonCode::whereNull('tenant_id')->find($id);
|
||||
if (! $globalCode) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '글로벌 코드를 찾을 수 없습니다.'], 404);
|
||||
}
|
||||
return redirect()->back()->with('error', '글로벌 코드를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
// 이미 복사된 코드가 있는지 확인
|
||||
$exists = CommonCode::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('code_group', $globalCode->code_group)
|
||||
->where('code', $globalCode->code)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '이미 복사된 코드가 있습니다.'], 400);
|
||||
}
|
||||
return redirect()->back()->with('error', '이미 복사된 코드가 있습니다.');
|
||||
}
|
||||
|
||||
// 복사
|
||||
CommonCode::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'code_group' => $globalCode->code_group,
|
||||
'code' => $globalCode->code,
|
||||
'name' => $globalCode->name,
|
||||
'sort_order' => $globalCode->sort_order,
|
||||
'attributes' => $globalCode->attributes,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => true, 'message' => '코드가 복사되었습니다.']);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('common-codes.index', ['group' => $globalCode->code_group])
|
||||
->with('success', '글로벌 코드가 테넌트용으로 복사되었습니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드 삭제 (테넌트 코드만)
|
||||
*/
|
||||
public function destroy(Request $request, int $id): RedirectResponse|JsonResponse
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
||||
|
||||
if (! $tenantId) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '테넌트를 먼저 선택해주세요.'], 400);
|
||||
}
|
||||
return redirect()->back()->with('error', '테넌트를 먼저 선택해주세요.');
|
||||
}
|
||||
|
||||
$isHQ = $tenant?->tenant_type === 'HQ';
|
||||
|
||||
$code = CommonCode::find($id);
|
||||
if (! $code) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '코드를 찾을 수 없습니다.'], 404);
|
||||
}
|
||||
return redirect()->back()->with('error', '코드를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
// 글로벌 코드 삭제는 HQ만
|
||||
if ($code->tenant_id === null && ! $isHQ) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '글로벌 코드는 본사만 삭제할 수 있습니다.'], 403);
|
||||
}
|
||||
return redirect()->back()->with('error', '글로벌 코드는 본사만 삭제할 수 있습니다.');
|
||||
}
|
||||
|
||||
// 다른 테넌트 코드 삭제 불가
|
||||
if ($code->tenant_id !== null && $code->tenant_id !== $tenantId) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => '다른 테넌트의 코드는 삭제할 수 없습니다.'], 403);
|
||||
}
|
||||
return redirect()->back()->with('error', '다른 테넌트의 코드는 삭제할 수 없습니다.');
|
||||
}
|
||||
|
||||
$codeGroup = $code->code_group;
|
||||
$code->delete();
|
||||
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['success' => true, 'message' => '코드가 삭제되었습니다.']);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('common-codes.index', ['group' => $codeGroup])
|
||||
->with('success', '코드가 삭제되었습니다.');
|
||||
}
|
||||
}
|
||||
467
app/Http/Controllers/MenuSyncController.php
Normal file
467
app/Http/Controllers/MenuSyncController.php
Normal file
@@ -0,0 +1,467 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Commons\Menu;
|
||||
use App\Models\Tenants\TenantSetting;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class MenuSyncController extends Controller
|
||||
{
|
||||
protected int $tenantId = 1; // MNG 메뉴는 tenant_id=1
|
||||
|
||||
/**
|
||||
* 환경 설정 조회
|
||||
*/
|
||||
private function getEnvironments(): array
|
||||
{
|
||||
$setting = TenantSetting::withoutGlobalScopes()
|
||||
->where('tenant_id', $this->tenantId)
|
||||
->where('setting_group', 'menu_sync')
|
||||
->where('setting_key', 'environments')
|
||||
->first();
|
||||
|
||||
return $setting?->setting_value ?? [
|
||||
'dev' => ['name' => '개발', 'url' => '', 'api_key' => ''],
|
||||
'prod' => ['name' => '운영', 'url' => '', 'api_key' => ''],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 동기화 페이지
|
||||
*/
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
if ($request->header('HX-Request')) {
|
||||
return response('', 200)->header('HX-Redirect', route('menus.sync.index'));
|
||||
}
|
||||
|
||||
$environments = $this->getEnvironments();
|
||||
$selectedEnv = $request->get('env', 'dev');
|
||||
|
||||
// 로컬 메뉴 조회 (트리 구조)
|
||||
$localMenus = $this->getMenuTree();
|
||||
|
||||
// 원격 메뉴 조회
|
||||
$remoteMenus = [];
|
||||
$remoteError = null;
|
||||
|
||||
if (! empty($environments[$selectedEnv]['url'])) {
|
||||
try {
|
||||
$remoteMenus = $this->fetchRemoteMenus($environments[$selectedEnv]);
|
||||
} catch (\Exception $e) {
|
||||
$remoteError = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// 차이점 계산
|
||||
$diff = $this->calculateDiff($localMenus, $remoteMenus);
|
||||
|
||||
return view('menus.sync', [
|
||||
'environments' => $environments,
|
||||
'selectedEnv' => $selectedEnv,
|
||||
'localMenus' => $localMenus,
|
||||
'remoteMenus' => $remoteMenus,
|
||||
'remoteError' => $remoteError,
|
||||
'diff' => $diff,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 환경 설정 저장
|
||||
*/
|
||||
public function saveSettings(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'environments' => 'required|array',
|
||||
'environments.*.name' => 'required|string|max:50',
|
||||
'environments.*.url' => 'nullable|url|max:255',
|
||||
'environments.*.api_key' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
TenantSetting::withoutGlobalScopes()->updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $this->tenantId,
|
||||
'setting_group' => 'menu_sync',
|
||||
'setting_key' => 'environments',
|
||||
],
|
||||
[
|
||||
'setting_value' => $validated['environments'],
|
||||
'description' => '메뉴 동기화 환경 설정',
|
||||
]
|
||||
);
|
||||
|
||||
return response()->json(['success' => true, 'message' => '환경 설정이 저장되었습니다.']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 Export API (다른 환경에서 호출)
|
||||
*/
|
||||
public function export(Request $request): JsonResponse
|
||||
{
|
||||
// API Key 검증
|
||||
$apiKey = $request->header('X-Menu-Sync-Key');
|
||||
$validKey = config('app.menu_sync_api_key', env('MENU_SYNC_API_KEY'));
|
||||
|
||||
if (empty($validKey) || $apiKey !== $validKey) {
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
$menus = $this->getMenuTree();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'environment' => config('app.env'),
|
||||
'exported_at' => now()->toIso8601String(),
|
||||
'menus' => $menus,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 Import API (다른 환경에서 호출)
|
||||
*/
|
||||
public function import(Request $request): JsonResponse
|
||||
{
|
||||
// API Key 검증
|
||||
$apiKey = $request->header('X-Menu-Sync-Key');
|
||||
$validKey = config('app.menu_sync_api_key', env('MENU_SYNC_API_KEY'));
|
||||
|
||||
if (empty($validKey) || $apiKey !== $validKey) {
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'menus' => 'required|array',
|
||||
'menus.*.name' => 'required|string|max:100',
|
||||
'menus.*.url' => 'required|string|max:255',
|
||||
'menus.*.icon' => 'nullable|string|max:50',
|
||||
'menus.*.sort_order' => 'nullable|integer',
|
||||
'menus.*.options' => 'nullable|array',
|
||||
'menus.*.parent_name' => 'nullable|string', // 부모 메뉴 이름으로 연결
|
||||
'menus.*.children' => 'nullable|array',
|
||||
]);
|
||||
|
||||
$imported = 0;
|
||||
foreach ($validated['menus'] as $menuData) {
|
||||
$this->importMenu($menuData);
|
||||
$imported++;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "{$imported}개 메뉴가 동기화되었습니다.",
|
||||
'imported' => $imported,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 개별 메뉴 Push (로컬 → 원격)
|
||||
*/
|
||||
public function push(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'env' => 'required|string|in:dev,prod',
|
||||
'menu_ids' => 'required|array|min:1',
|
||||
'menu_ids.*' => 'integer',
|
||||
]);
|
||||
|
||||
$environments = $this->getEnvironments();
|
||||
$env = $environments[$validated['env']] ?? null;
|
||||
|
||||
if (! $env || empty($env['url'])) {
|
||||
return response()->json(['error' => '환경 설정이 없습니다.'], 400);
|
||||
}
|
||||
|
||||
// 선택된 메뉴 조회
|
||||
$menus = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $this->tenantId)
|
||||
->whereIn('id', $validated['menu_ids'])
|
||||
->get();
|
||||
|
||||
if ($menus->isEmpty()) {
|
||||
return response()->json(['error' => '선택된 메뉴가 없습니다.'], 400);
|
||||
}
|
||||
|
||||
// 메뉴 데이터 준비 (부모 정보 포함)
|
||||
$menuData = $menus->map(function ($menu) {
|
||||
$parent = $menu->parent_id
|
||||
? Menu::withoutGlobalScopes()->find($menu->parent_id)
|
||||
: null;
|
||||
|
||||
return [
|
||||
'name' => $menu->name,
|
||||
'url' => $menu->url,
|
||||
'icon' => $menu->icon,
|
||||
'sort_order' => $menu->sort_order,
|
||||
'options' => $menu->options,
|
||||
'parent_name' => $parent?->name,
|
||||
'children' => $this->getChildrenData($menu->id),
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
// 원격 서버로 전송
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $env['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->post(rtrim($env['url'], '/') . '/menu-sync/import', [
|
||||
'menus' => $menuData,
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $response->json('message', '동기화 완료'),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => $response->json('error', '원격 서버 오류'),
|
||||
], $response->status());
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => '연결 실패: ' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 개별 메뉴 Pull (원격 → 로컬)
|
||||
*/
|
||||
public function pull(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'env' => 'required|string|in:dev,prod',
|
||||
'menu_names' => 'required|array|min:1',
|
||||
'menu_names.*' => 'string',
|
||||
]);
|
||||
|
||||
$environments = $this->getEnvironments();
|
||||
$env = $environments[$validated['env']] ?? null;
|
||||
|
||||
if (! $env || empty($env['url'])) {
|
||||
return response()->json(['error' => '환경 설정이 없습니다.'], 400);
|
||||
}
|
||||
|
||||
// 원격 메뉴 조회
|
||||
try {
|
||||
$remoteMenus = $this->fetchRemoteMenus($env);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
// 선택된 메뉴만 필터링
|
||||
$selectedMenus = $this->filterMenusByName($remoteMenus, $validated['menu_names']);
|
||||
|
||||
if (empty($selectedMenus)) {
|
||||
return response()->json(['error' => '선택된 메뉴를 찾을 수 없습니다.'], 400);
|
||||
}
|
||||
|
||||
// 로컬에 Import
|
||||
$imported = 0;
|
||||
foreach ($selectedMenus as $menuData) {
|
||||
$this->importMenu($menuData);
|
||||
$imported++;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "{$imported}개 메뉴가 동기화되었습니다.",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 연결 테스트
|
||||
*/
|
||||
public function testConnection(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'url' => 'required|url',
|
||||
'api_key' => 'required|string',
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $validated['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->timeout(10)->get(rtrim($validated['url'], '/') . '/menu-sync/export');
|
||||
|
||||
if ($response->successful()) {
|
||||
$data = $response->json();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => '연결 성공',
|
||||
'environment' => $data['environment'] ?? 'unknown',
|
||||
'menu_count' => count($data['menus'] ?? []),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'API 오류: ' . $response->status(),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '연결 실패: ' . $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 트리 조회
|
||||
*/
|
||||
private function getMenuTree(?int $parentId = null): array
|
||||
{
|
||||
$menus = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $this->tenantId)
|
||||
->where('parent_id', $parentId)
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
return $menus->map(function ($menu) {
|
||||
return [
|
||||
'id' => $menu->id,
|
||||
'name' => $menu->name,
|
||||
'url' => $menu->url,
|
||||
'icon' => $menu->icon,
|
||||
'sort_order' => $menu->sort_order,
|
||||
'options' => $menu->options,
|
||||
'children' => $this->getMenuTree($menu->id),
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 자식 메뉴 데이터 조회
|
||||
*/
|
||||
private function getChildrenData(int $parentId): array
|
||||
{
|
||||
$children = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $this->tenantId)
|
||||
->where('parent_id', $parentId)
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
return $children->map(function ($menu) {
|
||||
return [
|
||||
'name' => $menu->name,
|
||||
'url' => $menu->url,
|
||||
'icon' => $menu->icon,
|
||||
'sort_order' => $menu->sort_order,
|
||||
'options' => $menu->options,
|
||||
'children' => $this->getChildrenData($menu->id),
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 원격 메뉴 조회
|
||||
*/
|
||||
private function fetchRemoteMenus(array $env): array
|
||||
{
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $env['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->timeout(10)->get(rtrim($env['url'], '/') . '/menu-sync/export');
|
||||
|
||||
if (! $response->successful()) {
|
||||
throw new \Exception('API 오류: HTTP ' . $response->status());
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
if (! isset($data['menus'])) {
|
||||
throw new \Exception('잘못된 응답 형식');
|
||||
}
|
||||
|
||||
return $data['menus'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 차이점 계산
|
||||
*/
|
||||
private function calculateDiff(array $localMenus, array $remoteMenus): array
|
||||
{
|
||||
$localNames = $this->flattenMenuNames($localMenus);
|
||||
$remoteNames = $this->flattenMenuNames($remoteMenus);
|
||||
|
||||
return [
|
||||
'local_only' => array_diff($localNames, $remoteNames),
|
||||
'remote_only' => array_diff($remoteNames, $localNames),
|
||||
'both' => array_intersect($localNames, $remoteNames),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 이름 평탄화
|
||||
*/
|
||||
private function flattenMenuNames(array $menus, string $prefix = ''): array
|
||||
{
|
||||
$names = [];
|
||||
foreach ($menus as $menu) {
|
||||
$fullName = $prefix ? "{$prefix} > {$menu['name']}" : $menu['name'];
|
||||
$names[] = $menu['name'];
|
||||
if (! empty($menu['children'])) {
|
||||
$names = array_merge($names, $this->flattenMenuNames($menu['children'], $fullName));
|
||||
}
|
||||
}
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* 이름으로 메뉴 필터링
|
||||
*/
|
||||
private function filterMenusByName(array $menus, array $names): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($menus as $menu) {
|
||||
if (in_array($menu['name'], $names)) {
|
||||
$result[] = $menu;
|
||||
}
|
||||
if (! empty($menu['children'])) {
|
||||
$result = array_merge($result, $this->filterMenusByName($menu['children'], $names));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 메뉴 Import
|
||||
*/
|
||||
private function importMenu(array $data, ?int $parentId = null): void
|
||||
{
|
||||
// 부모 메뉴 찾기
|
||||
if (! $parentId && ! empty($data['parent_name'])) {
|
||||
$parent = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $this->tenantId)
|
||||
->where('name', $data['parent_name'])
|
||||
->first();
|
||||
$parentId = $parent?->id;
|
||||
}
|
||||
|
||||
// 기존 메뉴 찾기 또는 생성
|
||||
$menu = Menu::withoutGlobalScopes()->updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $this->tenantId,
|
||||
'name' => $data['name'],
|
||||
],
|
||||
[
|
||||
'parent_id' => $parentId,
|
||||
'url' => $data['url'],
|
||||
'icon' => $data['icon'] ?? null,
|
||||
'sort_order' => $data['sort_order'] ?? 0,
|
||||
'options' => $data['options'] ?? null,
|
||||
'is_active' => true,
|
||||
]
|
||||
);
|
||||
|
||||
// 자식 메뉴 처리
|
||||
if (! empty($data['children'])) {
|
||||
foreach ($data['children'] as $child) {
|
||||
$this->importMenu($child, $menu->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
127
app/Http/Controllers/TenantSettingController.php
Normal file
127
app/Http/Controllers/TenantSettingController.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Products\CommonCode;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use App\Models\Tenants\TenantSetting;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class TenantSettingController extends Controller
|
||||
{
|
||||
/**
|
||||
* 설정 목록 (재고 설정 페이지)
|
||||
*/
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
// HTMX 요청 시 전체 페이지 리로드
|
||||
if ($request->header('HX-Request')) {
|
||||
return response('', 200)->header('HX-Redirect', route('tenant-settings.index'));
|
||||
}
|
||||
|
||||
$tenantId = session('selected_tenant_id');
|
||||
$tenant = $tenantId ? Tenant::find($tenantId) : null;
|
||||
|
||||
// 품목유형 목록 (common_codes에서 조회)
|
||||
$itemTypeLabels = $tenantId ? CommonCode::getItemTypes($tenantId) : [];
|
||||
|
||||
// 테넌트 미선택 시 빈 설정
|
||||
$stockSettings = collect();
|
||||
if ($tenantId) {
|
||||
$stockSettings = TenantSetting::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('setting_group', 'stock')
|
||||
->get()
|
||||
->keyBy('setting_key');
|
||||
}
|
||||
|
||||
// 설정값 (저장된 값이 없으면 빈 배열/기본값)
|
||||
$hasSettings = $stockSettings->isNotEmpty();
|
||||
$stockItemTypes = $stockSettings->get('stock_item_types')?->setting_value ?? [];
|
||||
$defaultSafetyStock = $stockSettings->get('default_safety_stock')?->setting_value ?? 10;
|
||||
$lowStockAlert = $stockSettings->get('low_stock_alert')?->setting_value ?? true;
|
||||
|
||||
return view('tenant-settings.index', [
|
||||
'tenant' => $tenant,
|
||||
'hasSettings' => $hasSettings,
|
||||
'itemTypeLabels' => $itemTypeLabels,
|
||||
'stockItemTypes' => $stockItemTypes,
|
||||
'defaultSafetyStock' => $defaultSafetyStock,
|
||||
'lowStockAlert' => $lowStockAlert,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 설정 저장
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
|
||||
if (! $tenantId) {
|
||||
return redirect()->route('tenant-settings.index')
|
||||
->with('error', '테넌트를 먼저 선택해주세요.');
|
||||
}
|
||||
|
||||
$userId = Auth::id();
|
||||
|
||||
// 유효한 품목유형 목록 조회
|
||||
$validItemTypes = array_keys(CommonCode::getItemTypes($tenantId));
|
||||
|
||||
$validated = $request->validate([
|
||||
'stock_item_types' => 'required|array|min:1',
|
||||
'stock_item_types.*' => 'string|in:'.implode(',', $validItemTypes),
|
||||
'default_safety_stock' => 'required|integer|min:0|max:9999',
|
||||
'low_stock_alert' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
// 재고관리 품목유형 저장
|
||||
TenantSetting::withoutGlobalScopes()->updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenantId,
|
||||
'setting_group' => 'stock',
|
||||
'setting_key' => 'stock_item_types',
|
||||
],
|
||||
[
|
||||
'setting_value' => $validated['stock_item_types'],
|
||||
'description' => '재고관리 대상 품목유형',
|
||||
'updated_by' => $userId,
|
||||
]
|
||||
);
|
||||
|
||||
// 기본 안전재고 저장
|
||||
TenantSetting::withoutGlobalScopes()->updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenantId,
|
||||
'setting_group' => 'stock',
|
||||
'setting_key' => 'default_safety_stock',
|
||||
],
|
||||
[
|
||||
'setting_value' => (int) $validated['default_safety_stock'],
|
||||
'description' => '안전재고 기본값',
|
||||
'updated_by' => $userId,
|
||||
]
|
||||
);
|
||||
|
||||
// 재고부족 알림 저장
|
||||
TenantSetting::withoutGlobalScopes()->updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenantId,
|
||||
'setting_group' => 'stock',
|
||||
'setting_key' => 'low_stock_alert',
|
||||
],
|
||||
[
|
||||
'setting_value' => isset($validated['low_stock_alert']) && $validated['low_stock_alert'],
|
||||
'description' => '재고부족 알림 활성화',
|
||||
'updated_by' => $userId,
|
||||
]
|
||||
);
|
||||
|
||||
return redirect()->route('tenant-settings.index')
|
||||
->with('success', '설정이 저장되었습니다.');
|
||||
}
|
||||
}
|
||||
49
app/Models/Products/CommonCode.php
Normal file
49
app/Models/Products/CommonCode.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Products;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CommonCode extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'common_codes';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'code_group',
|
||||
'code',
|
||||
'name',
|
||||
'parent_id',
|
||||
'attributes',
|
||||
'description',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'attributes' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* 테넌트별 품목유형 목록 조회 (tenant_id 또는 글로벌)
|
||||
*
|
||||
* @return array<string, string> [code => name]
|
||||
*/
|
||||
public static function getItemTypes(int $tenantId): array
|
||||
{
|
||||
return static::query()
|
||||
->where(function ($query) use ($tenantId) {
|
||||
$query->where('tenant_id', $tenantId)
|
||||
->orWhereNull('tenant_id');
|
||||
})
|
||||
->where('code_group', 'item_type')
|
||||
->where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->pluck('name', 'code')
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
36
app/Models/Tenants/TenantSetting.php
Normal file
36
app/Models/Tenants/TenantSetting.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* 테넌트 설정 모델
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $tenant_id
|
||||
* @property string $setting_group
|
||||
* @property string $setting_key
|
||||
* @property array|null $setting_value
|
||||
* @property string|null $description
|
||||
* @property int|null $updated_by
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
*/
|
||||
class TenantSetting extends Model
|
||||
{
|
||||
protected $table = 'tenant_settings';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'setting_group',
|
||||
'setting_key',
|
||||
'setting_value',
|
||||
'description',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'setting_value' => 'array',
|
||||
];
|
||||
}
|
||||
@@ -143,6 +143,14 @@ protected function seedMainMenus(): void
|
||||
'sort_order' => $systemSubOrder++,
|
||||
'options' => ['route_name' => 'menus.index', 'section' => 'main'],
|
||||
]);
|
||||
$this->createMenu([
|
||||
'parent_id' => $systemGroup->id,
|
||||
'name' => '메뉴 동기화',
|
||||
'url' => '/menus/sync',
|
||||
'icon' => 'refresh',
|
||||
'sort_order' => $systemSubOrder++,
|
||||
'options' => ['route_name' => 'menus.sync.index', 'section' => 'main'],
|
||||
]);
|
||||
|
||||
// ========================================
|
||||
// 권한 관리 그룹
|
||||
@@ -239,6 +247,22 @@ protected function seedMainMenus(): void
|
||||
'sort_order' => $prodSubOrder++,
|
||||
'options' => ['route_name' => 'quote-formulas.index', 'section' => 'main'],
|
||||
]);
|
||||
$this->createMenu([
|
||||
'parent_id' => $productionGroup->id,
|
||||
'name' => '재고 설정',
|
||||
'url' => '/tenant-settings',
|
||||
'icon' => 'cog',
|
||||
'sort_order' => $prodSubOrder++,
|
||||
'options' => ['route_name' => 'tenant-settings.index', 'section' => 'main'],
|
||||
]);
|
||||
$this->createMenu([
|
||||
'parent_id' => $productionGroup->id,
|
||||
'name' => '공통코드 관리',
|
||||
'url' => '/common-codes',
|
||||
'icon' => 'collection',
|
||||
'sort_order' => $prodSubOrder++,
|
||||
'options' => ['route_name' => 'common-codes.index', 'section' => 'main'],
|
||||
]);
|
||||
$this->createMenu([
|
||||
'parent_id' => $productionGroup->id,
|
||||
'name' => '제품 관리',
|
||||
|
||||
454
resources/views/common-codes/index.blade.php
Normal file
454
resources/views/common-codes/index.blade.php
Normal file
@@ -0,0 +1,454 @@
|
||||
@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
|
||||
<!-- 성공/에러 메시지 -->
|
||||
@if(session('success'))
|
||||
<div class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg flex items-center gap-2">
|
||||
<svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
@endif
|
||||
@if(session('error'))
|
||||
<div class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg flex items-center gap-2">
|
||||
<svg class="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- 코드 그룹 탭 -->
|
||||
<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('common-codes.index', ['group' => $group]) }}"
|
||||
class="px-4 py-3 text-sm font-medium border-b-2 whitespace-nowrap transition-colors
|
||||
{{ $selectedGroup === $group
|
||||
? 'border-blue-500 text-blue-600'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300' }}">
|
||||
{{ $label }}
|
||||
</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">({{ $globalCodes->count() }})</span>
|
||||
</div>
|
||||
@if(!$isHQ)
|
||||
<span class="text-xs text-gray-400">본사만 편집 가능</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">코드</th>
|
||||
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">이름</th>
|
||||
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">순서</th>
|
||||
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">활성</th>
|
||||
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-24">액션</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
@forelse($globalCodes as $code)
|
||||
<tr class="hover:bg-gray-50 {{ !$code->is_active ? 'opacity-50' : '' }}">
|
||||
<td class="px-3 py-2">
|
||||
<span class="font-mono text-xs bg-gray-100 px-1.5 py-0.5 rounded">{{ $code->code }}</span>
|
||||
</td>
|
||||
<td class="px-3 py-2">{{ $code->name }}</td>
|
||||
<td class="px-3 py-2 text-center text-gray-500">{{ $code->sort_order }}</td>
|
||||
<td class="px-3 py-2 text-center">
|
||||
@if($isHQ)
|
||||
<button type="button"
|
||||
onclick="toggleActive({{ $code->id }})"
|
||||
class="relative inline-flex h-5 w-9 items-center rounded-full transition-colors {{ $code->is_active ? 'bg-green-500' : 'bg-gray-300' }}">
|
||||
<span class="inline-block h-4 w-4 transform rounded-full bg-white transition-transform {{ $code->is_active ? 'translate-x-4' : 'translate-x-0.5' }}"></span>
|
||||
</button>
|
||||
@else
|
||||
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs {{ $code->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-500' }}">
|
||||
{{ $code->is_active ? 'ON' : 'OFF' }}
|
||||
</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-3 py-2 text-center">
|
||||
<div class="flex items-center justify-center gap-1">
|
||||
@if($isHQ)
|
||||
<button type="button"
|
||||
onclick="openEditModal({{ json_encode($code) }})"
|
||||
class="p-1 text-gray-400 hover:text-blue-600 transition-colors"
|
||||
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="copyCode({{ $code->id }})"
|
||||
class="p-1 text-gray-400 hover:text-green-600 transition-colors"
|
||||
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="deleteCode({{ $code->id }}, '{{ $code->code }}')"
|
||||
class="p-1 text-gray-400 hover:text-red-600 transition-colors"
|
||||
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>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="px-3 py-8 text-center text-gray-400">
|
||||
글로벌 코드가 없습니다.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</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">({{ $tenantCodes->count() }})</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">코드</th>
|
||||
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500">이름</th>
|
||||
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">순서</th>
|
||||
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-16">활성</th>
|
||||
<th class="px-3 py-2 text-center text-xs font-medium text-gray-500 w-24">액션</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
@forelse($tenantCodes as $code)
|
||||
<tr class="hover:bg-gray-50 {{ !$code->is_active ? 'opacity-50' : '' }}">
|
||||
<td class="px-3 py-2">
|
||||
<span class="font-mono text-xs bg-blue-50 text-blue-700 px-1.5 py-0.5 rounded">{{ $code->code }}</span>
|
||||
</td>
|
||||
<td class="px-3 py-2">{{ $code->name }}</td>
|
||||
<td class="px-3 py-2 text-center text-gray-500">{{ $code->sort_order }}</td>
|
||||
<td class="px-3 py-2 text-center">
|
||||
<button type="button"
|
||||
onclick="toggleActive({{ $code->id }})"
|
||||
class="relative inline-flex h-5 w-9 items-center rounded-full transition-colors {{ $code->is_active ? 'bg-green-500' : 'bg-gray-300' }}">
|
||||
<span class="inline-block h-4 w-4 transform rounded-full bg-white transition-transform {{ $code->is_active ? 'translate-x-4' : 'translate-x-0.5' }}"></span>
|
||||
</button>
|
||||
</td>
|
||||
<td class="px-3 py-2 text-center">
|
||||
<div class="flex items-center justify-center gap-1">
|
||||
<button type="button"
|
||||
onclick="openEditModal({{ json_encode($code) }})"
|
||||
class="p-1 text-gray-400 hover:text-blue-600 transition-colors"
|
||||
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="deleteCode({{ $code->id }}, '{{ $code->code }}')"
|
||||
class="p-1 text-gray-400 hover:text-red-600 transition-colors"
|
||||
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>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="px-3 py-8 text-center text-gray-400">
|
||||
테넌트 코드가 없습니다.<br>
|
||||
<span class="text-xs">글로벌 코드를 복사하거나 새로 추가하세요.</span>
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<!-- 코드 추가 모달 -->
|
||||
<div id="addModal" 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 action="{{ route('common-codes.store') }}" method="POST">
|
||||
@csrf
|
||||
<input type="hidden" name="code_group" value="{{ $selectedGroup }}">
|
||||
|
||||
<div class="px-6 py-4 border-b border-gray-200">
|
||||
<h3 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" name="code" 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="예: NEW_CODE">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">이름 *</label>
|
||||
<input type="text" name="name" 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>
|
||||
<input type="number" name="sort_order" value="0" 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">속성 (JSON)</label>
|
||||
<textarea name="attributes" rows="3"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
placeholder='{"key": "value"}'></textarea>
|
||||
</div>
|
||||
@if($isHQ)
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" name="is_global" value="1" id="addIsGlobal"
|
||||
class="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500">
|
||||
<label for="addIsGlobal" 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="closeAddModal()"
|
||||
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>
|
||||
|
||||
<!-- 코드 수정 모달 -->
|
||||
<div id="editModal" 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="editForm" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="px-6 py-4 border-b border-gray-200">
|
||||
<h3 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="editCode" disabled
|
||||
class="w-full px-3 py-2 border border-gray-200 rounded-lg text-sm bg-gray-50 text-gray-500">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">이름 *</label>
|
||||
<input type="text" name="name" id="editName" 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">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">정렬 순서</label>
|
||||
<input type="number" name="sort_order" id="editSortOrder" 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">속성 (JSON)</label>
|
||||
<textarea name="attributes" id="editAttributes" rows="3"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm font-mono focus:ring-2 focus:ring-blue-500 focus:border-blue-500"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-6 py-4 border-t border-gray-200 flex justify-end gap-3">
|
||||
<button type="button" onclick="closeEditModal()"
|
||||
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>
|
||||
|
||||
<!-- 삭제 확인 폼 (hidden) -->
|
||||
<form id="deleteForm" method="POST" class="hidden">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
</form>
|
||||
|
||||
<!-- 복사 폼 (hidden) -->
|
||||
<form id="copyForm" method="POST" class="hidden">
|
||||
@csrf
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
// 모달 열기/닫기
|
||||
function openAddModal() {
|
||||
document.getElementById('addModal').classList.remove('hidden');
|
||||
document.getElementById('addModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeAddModal() {
|
||||
document.getElementById('addModal').classList.add('hidden');
|
||||
document.getElementById('addModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
function openEditModal(code) {
|
||||
document.getElementById('editForm').action = `/common-codes/${code.id}`;
|
||||
document.getElementById('editCode').value = code.code;
|
||||
document.getElementById('editName').value = code.name;
|
||||
document.getElementById('editSortOrder').value = code.sort_order || 0;
|
||||
document.getElementById('editAttributes').value = code.attributes ? JSON.stringify(code.attributes, null, 2) : '';
|
||||
|
||||
document.getElementById('editModal').classList.remove('hidden');
|
||||
document.getElementById('editModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeEditModal() {
|
||||
document.getElementById('editModal').classList.add('hidden');
|
||||
document.getElementById('editModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
// 활성화 토글
|
||||
function toggleActive(id) {
|
||||
fetch(`/common-codes/${id}/toggle`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.error || '오류가 발생했습니다.');
|
||||
}
|
||||
})
|
||||
.catch(() => alert('오류가 발생했습니다.'));
|
||||
}
|
||||
|
||||
// 코드 복사
|
||||
function copyCode(id) {
|
||||
if (!confirm('이 글로벌 코드를 테넌트용으로 복사하시겠습니까?')) return;
|
||||
|
||||
const form = document.getElementById('copyForm');
|
||||
form.action = `/common-codes/${id}/copy`;
|
||||
form.submit();
|
||||
}
|
||||
|
||||
// 코드 삭제
|
||||
function deleteCode(id, code) {
|
||||
if (!confirm(`'${code}' 코드를 삭제하시겠습니까?`)) return;
|
||||
|
||||
const form = document.getElementById('deleteForm');
|
||||
form.action = `/common-codes/${id}`;
|
||||
form.submit();
|
||||
}
|
||||
|
||||
// 모달 외부 클릭 시 닫기
|
||||
document.getElementById('addModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) closeAddModal();
|
||||
});
|
||||
document.getElementById('editModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) closeEditModal();
|
||||
});
|
||||
|
||||
// ESC 키로 모달 닫기
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
closeAddModal();
|
||||
closeEditModal();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
99
resources/views/menus/_sync_menu_item.blade.php
Normal file
99
resources/views/menus/_sync_menu_item.blade.php
Normal file
@@ -0,0 +1,99 @@
|
||||
@php
|
||||
$isLocalOnly = $side === 'local' && in_array($menu['name'], $diff['local_only'] ?? []);
|
||||
$isRemoteOnly = $side === 'remote' && in_array($menu['name'], $diff['remote_only'] ?? []);
|
||||
$isBoth = in_array($menu['name'], $diff['both'] ?? []);
|
||||
|
||||
$bgClass = '';
|
||||
$badgeClass = '';
|
||||
$badgeText = '';
|
||||
|
||||
if ($isLocalOnly) {
|
||||
$bgClass = 'bg-green-50 border-green-200';
|
||||
$badgeClass = 'bg-green-100 text-green-700';
|
||||
$badgeText = 'NEW';
|
||||
} elseif ($isRemoteOnly) {
|
||||
$bgClass = 'bg-purple-50 border-purple-200';
|
||||
$badgeClass = 'bg-purple-100 text-purple-700';
|
||||
$badgeText = 'NEW';
|
||||
} else {
|
||||
$bgClass = 'bg-white 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;">
|
||||
<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">
|
||||
@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">
|
||||
@endif
|
||||
|
||||
<!-- 아이콘 -->
|
||||
@if(!empty($menu['icon']))
|
||||
<span class="w-5 h-5 flex items-center justify-center text-gray-400">
|
||||
@switch($menu['icon'])
|
||||
@case('home')
|
||||
<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="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
|
||||
</svg>
|
||||
@break
|
||||
@case('folder')
|
||||
<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="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
|
||||
</svg>
|
||||
@break
|
||||
@case('cog')
|
||||
<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="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
</svg>
|
||||
@break
|
||||
@case('cube')
|
||||
<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="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
|
||||
</svg>
|
||||
@break
|
||||
@case('collection')
|
||||
<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 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
@break
|
||||
@default
|
||||
<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="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
@endswitch
|
||||
</span>
|
||||
@endif
|
||||
|
||||
<!-- 메뉴 이름 -->
|
||||
<span class="flex-1 text-sm text-gray-800">{{ $menu['name'] }}</span>
|
||||
|
||||
<!-- 배지 -->
|
||||
@if($badgeText)
|
||||
<span class="px-1.5 py-0.5 text-xs font-medium rounded {{ $badgeClass }}">{{ $badgeText }}</span>
|
||||
@endif
|
||||
|
||||
<!-- URL -->
|
||||
@if($menu['url'] !== '#')
|
||||
<span class="text-xs text-gray-400 font-mono">{{ Str::limit($menu['url'], 20) }}</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 자식 메뉴 -->
|
||||
@if(!empty($menu['children']))
|
||||
@foreach($menu['children'] as $child)
|
||||
@include('menus._sync_menu_item', [
|
||||
'menu' => $child,
|
||||
'side' => $side,
|
||||
'diff' => $diff,
|
||||
'depth' => $depth + 1
|
||||
])
|
||||
@endforeach
|
||||
@endif
|
||||
450
resources/views/menus/sync.blade.php
Normal file
450
resources/views/menus/sync.blade.php
Normal file
@@ -0,0 +1,450 @@
|
||||
@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">로컬과 원격 환경 간 메뉴를 동기화합니다.</p>
|
||||
</div>
|
||||
<button type="button" onclick="openSettingsModal()"
|
||||
class="px-4 py-2 bg-gray-600 hover:bg-gray-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="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
</svg>
|
||||
환경 설정
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 환경 선택 탭 -->
|
||||
<div class="bg-white rounded-lg shadow-sm mb-4">
|
||||
<div class="border-b border-gray-200">
|
||||
<nav class="flex -mb-px" aria-label="Tabs">
|
||||
@foreach($environments as $key => $env)
|
||||
<a href="{{ route('menus.sync.index', ['env' => $key]) }}"
|
||||
class="px-6 py-3 text-sm font-medium border-b-2 transition-colors
|
||||
{{ $selectedEnv === $key
|
||||
? 'border-blue-500 text-blue-600'
|
||||
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300' }}">
|
||||
로컬 ↔ {{ $env['name'] ?? strtoupper($key) }}
|
||||
@if(empty($env['url']))
|
||||
<span class="ml-1 text-xs text-gray-400">(미설정)</span>
|
||||
@endif
|
||||
</a>
|
||||
@endforeach
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if($remoteError)
|
||||
<div class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg flex items-center gap-2">
|
||||
<svg class="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
원격 서버 연결 실패: {{ $remoteError }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(empty($environments[$selectedEnv]['url']))
|
||||
<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>
|
||||
환경 설정에서 {{ $environments[$selectedEnv]['name'] ?? strtoupper($selectedEnv) }} 서버 URL을 설정해주세요.
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- 동기화 요약 -->
|
||||
@if(!empty($environments[$selectedEnv]['url']) && !$remoteError)
|
||||
<div class="grid grid-cols-3 gap-4 mb-4">
|
||||
<div class="bg-green-50 border border-green-200 rounded-lg p-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-8 h-8 bg-green-100 rounded-full flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
</span>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-green-800">로컬에만 있음</p>
|
||||
<p class="text-2xl font-bold text-green-600">{{ count($diff['local_only']) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
|
||||
</svg>
|
||||
</span>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-blue-800">양쪽 모두</p>
|
||||
<p class="text-2xl font-bold text-blue-600">{{ count($diff['both']) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-purple-50 border border-purple-200 rounded-lg p-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-8 h-8 bg-purple-100 rounded-full flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16l-4-4m0 0l4-4m-4 4h18" />
|
||||
</svg>
|
||||
</span>
|
||||
<div>
|
||||
<p class="text-sm font-medium text-purple-800">원격에만 있음</p>
|
||||
<p class="text-2xl font-bold text-purple-600">{{ count($diff['remote_only']) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- 메뉴 비교 테이블 -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 flex-1 min-h-0">
|
||||
<!-- 로컬 메뉴 -->
|
||||
<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">
|
||||
<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" />
|
||||
</svg>
|
||||
</span>
|
||||
<h3 class="font-semibold text-gray-800">로컬 (현재)</h3>
|
||||
<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>
|
||||
@endif
|
||||
</div>
|
||||
<div class="overflow-auto flex-1 p-2">
|
||||
@foreach($localMenus as $menu)
|
||||
@include('menus._sync_menu_item', [
|
||||
'menu' => $menu,
|
||||
'side' => 'local',
|
||||
'diff' => $diff,
|
||||
'depth' => 0
|
||||
])
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 원격 메뉴 -->
|
||||
<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">
|
||||
<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" />
|
||||
</svg>
|
||||
</span>
|
||||
<h3 class="font-semibold text-gray-800">{{ $environments[$selectedEnv]['name'] ?? strtoupper($selectedEnv) }}</h3>
|
||||
<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>
|
||||
@endif
|
||||
</div>
|
||||
<div class="overflow-auto flex-1 p-2">
|
||||
@if(empty($environments[$selectedEnv]['url']))
|
||||
<div class="flex items-center justify-center h-full text-gray-400">
|
||||
<p>환경을 설정해주세요</p>
|
||||
</div>
|
||||
@elseif($remoteError)
|
||||
<div class="flex items-center justify-center h-full text-red-400">
|
||||
<p>연결 실패</p>
|
||||
</div>
|
||||
@elseif(empty($remoteMenus))
|
||||
<div class="flex items-center justify-center h-full text-gray-400">
|
||||
<p>메뉴가 없습니다</p>
|
||||
</div>
|
||||
@else
|
||||
@foreach($remoteMenus as $menu)
|
||||
@include('menus._sync_menu_item', [
|
||||
'menu' => $menu,
|
||||
'side' => 'remote',
|
||||
'diff' => $diff,
|
||||
'depth' => 0
|
||||
])
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 환경 설정 모달 -->
|
||||
<div id="settingsModal" 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-lg mx-4">
|
||||
<div class="px-6 py-4 border-b border-gray-200 flex items-center justify-between">
|
||||
<h3 class="text-lg font-semibold text-gray-800">환경 설정</h3>
|
||||
<button type="button" onclick="closeSettingsModal()" class="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="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="px-6 py-4 space-y-6">
|
||||
<!-- 개발 환경 -->
|
||||
<div class="space-y-3">
|
||||
<h4 class="font-medium text-gray-700 flex items-center gap-2">
|
||||
<span class="w-2 h-2 bg-yellow-500 rounded-full"></span>
|
||||
개발 환경
|
||||
</h4>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs text-gray-500 mb-1">URL</label>
|
||||
<input type="url" id="devUrl" value="{{ $environments['dev']['url'] ?? '' }}"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="https://dev-mng.example.com">
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs text-gray-500 mb-1">API Key</label>
|
||||
<input type="password" id="devApiKey" value="{{ $environments['dev']['api_key'] ?? '' }}"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="API Key">
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="testConnection('dev')"
|
||||
class="text-xs text-blue-600 hover:text-blue-800 flex items-center gap-1">
|
||||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
|
||||
</svg>
|
||||
연결 테스트
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 운영 환경 -->
|
||||
<div class="space-y-3">
|
||||
<h4 class="font-medium text-gray-700 flex items-center gap-2">
|
||||
<span class="w-2 h-2 bg-red-500 rounded-full"></span>
|
||||
운영 환경
|
||||
</h4>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs text-gray-500 mb-1">URL</label>
|
||||
<input type="url" id="prodUrl" value="{{ $environments['prod']['url'] ?? '' }}"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="https://mng.example.com">
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<label class="block text-xs text-gray-500 mb-1">API Key</label>
|
||||
<input type="password" id="prodApiKey" value="{{ $environments['prod']['api_key'] ?? '' }}"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500"
|
||||
placeholder="API Key">
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="testConnection('prod')"
|
||||
class="text-xs text-blue-600 hover:text-blue-800 flex items-center gap-1">
|
||||
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
|
||||
</svg>
|
||||
연결 테스트
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-50 rounded-lg p-3 text-xs text-gray-600">
|
||||
<p class="font-medium mb-1">API Key 설정 방법</p>
|
||||
<p>각 환경의 <code class="bg-gray-200 px-1 rounded">.env</code> 파일에 다음을 추가하세요:</p>
|
||||
<code class="block bg-gray-200 px-2 py-1 rounded mt-1">MENU_SYNC_API_KEY=your-secret-key</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-6 py-4 border-t border-gray-200 flex justify-end gap-3">
|
||||
<button type="button" onclick="closeSettingsModal()"
|
||||
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="button" onclick="saveSettings()"
|
||||
class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm font-medium transition-colors">
|
||||
저장
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
const selectedEnv = '{{ $selectedEnv }}';
|
||||
const csrfToken = '{{ csrf_token() }}';
|
||||
|
||||
// 설정 모달
|
||||
function openSettingsModal() {
|
||||
document.getElementById('settingsModal').classList.remove('hidden');
|
||||
document.getElementById('settingsModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeSettingsModal() {
|
||||
document.getElementById('settingsModal').classList.add('hidden');
|
||||
document.getElementById('settingsModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
// 설정 저장
|
||||
async function saveSettings() {
|
||||
const data = {
|
||||
environments: {
|
||||
dev: {
|
||||
name: '개발',
|
||||
url: document.getElementById('devUrl').value,
|
||||
api_key: document.getElementById('devApiKey').value
|
||||
},
|
||||
prod: {
|
||||
name: '운영',
|
||||
url: document.getElementById('prodUrl').value,
|
||||
api_key: document.getElementById('prodApiKey').value
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('{{ route("menus.sync.settings") }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
alert('설정이 저장되었습니다.');
|
||||
location.reload();
|
||||
} else {
|
||||
alert(result.error || '저장 실패');
|
||||
}
|
||||
} catch (e) {
|
||||
alert('오류 발생: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 연결 테스트
|
||||
async function testConnection(env) {
|
||||
const url = document.getElementById(env + 'Url').value;
|
||||
const apiKey = document.getElementById(env + 'ApiKey').value;
|
||||
|
||||
if (!url || !apiKey) {
|
||||
alert('URL과 API Key를 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('{{ route("menus.sync.test") }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ url, api_key: apiKey })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
alert(`연결 성공!\n환경: ${result.environment}\n메뉴 수: ${result.menu_count}개`);
|
||||
} else {
|
||||
alert('연결 실패: ' + result.message);
|
||||
}
|
||||
} catch (e) {
|
||||
alert('오류 발생: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 선택된 메뉴 Push
|
||||
async function pushSelected() {
|
||||
const checkboxes = document.querySelectorAll('input[name="local_menu"]:checked');
|
||||
if (checkboxes.length === 0) {
|
||||
alert('Push할 메뉴를 선택해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
const menuIds = Array.from(checkboxes).map(cb => cb.value);
|
||||
|
||||
if (!confirm(`${menuIds.length}개 메뉴를 ${selectedEnv === 'dev' ? '개발' : '운영'} 서버로 Push 하시겠습니까?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('{{ route("menus.sync.push") }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ env: selectedEnv, menu_ids: menuIds })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
alert(result.message);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(result.error || 'Push 실패');
|
||||
}
|
||||
} catch (e) {
|
||||
alert('오류 발생: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 선택된 메뉴 Pull
|
||||
async function pullSelected() {
|
||||
const checkboxes = document.querySelectorAll('input[name="remote_menu"]:checked');
|
||||
if (checkboxes.length === 0) {
|
||||
alert('Pull할 메뉴를 선택해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
const menuNames = Array.from(checkboxes).map(cb => cb.value);
|
||||
|
||||
if (!confirm(`${menuNames.length}개 메뉴를 로컬로 Pull 하시겠습니까?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('{{ route("menus.sync.pull") }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ env: selectedEnv, menu_names: menuNames })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
alert(result.message);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(result.error || 'Pull 실패');
|
||||
}
|
||||
} catch (e) {
|
||||
alert('오류 발생: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 모달 외부 클릭 시 닫기
|
||||
document.getElementById('settingsModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) closeSettingsModal();
|
||||
});
|
||||
|
||||
// ESC 키로 모달 닫기
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') closeSettingsModal();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
181
resources/views/tenant-settings/index.blade.php
Normal file
181
resources/views/tenant-settings/index.blade.php
Normal file
@@ -0,0 +1,181 @@
|
||||
@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>
|
||||
설정을 관리합니다.
|
||||
</span>
|
||||
@else
|
||||
테넌트별 시스템 설정을 관리합니다.
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
</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>
|
||||
@elseif(!$hasSettings)
|
||||
<div class="mb-4 bg-blue-50 border border-blue-200 text-blue-700 px-4 py-3 rounded-lg flex items-center gap-2">
|
||||
<svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
이 테넌트는 아직 설정이 저장되지 않았습니다. 재고관리할 품목유형을 선택해주세요.
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- 성공 메시지 -->
|
||||
@if(session('success'))
|
||||
<div class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg flex items-center gap-2">
|
||||
<svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- 에러 메시지 -->
|
||||
@if(session('error'))
|
||||
<div class="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg flex items-center gap-2">
|
||||
<svg class="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- 설정 폼 -->
|
||||
<form action="{{ route('tenant-settings.store') }}" method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-6">
|
||||
<!-- 재고관리 품목유형 -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-5">
|
||||
<div class="flex items-center gap-3 mb-4">
|
||||
<div class="w-9 h-9 bg-blue-100 rounded-lg flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="font-semibold text-gray-800">재고관리 품목유형</h3>
|
||||
<p class="text-xs text-gray-500">재고현황에 표시할 품목유형</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@error('stock_item_types')
|
||||
<div class="mb-3 text-red-600 text-xs">{{ $message }}</div>
|
||||
@enderror
|
||||
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
@foreach($itemTypeLabels as $code => $label)
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-50 rounded-lg cursor-pointer hover:bg-gray-100 transition border border-transparent has-[:checked]:border-blue-400 has-[:checked]:bg-blue-50">
|
||||
<input type="checkbox"
|
||||
name="stock_item_types[]"
|
||||
value="{{ $code }}"
|
||||
{{ in_array($code, $stockItemTypes) ? 'checked' : '' }}
|
||||
class="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500">
|
||||
<span class="text-sm">
|
||||
<span class="font-medium text-gray-800">{{ $code }}</span>
|
||||
<span class="text-gray-500 text-xs">({{ $label }})</span>
|
||||
</span>
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 안전재고 설정 -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-5">
|
||||
<div class="flex items-center gap-3 mb-4">
|
||||
<div class="w-9 h-9 bg-yellow-100 rounded-lg flex items-center justify-center">
|
||||
<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>
|
||||
<div>
|
||||
<h3 class="font-semibold text-gray-800">안전재고 설정</h3>
|
||||
<p class="text-xs text-gray-500">품목별 설정 없을 시 적용</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label for="default_safety_stock" class="block text-sm font-medium text-gray-600 mb-1">기본 안전재고</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
id="default_safety_stock"
|
||||
name="default_safety_stock"
|
||||
value="{{ old('default_safety_stock', $defaultSafetyStock) }}"
|
||||
min="0"
|
||||
max="9999"
|
||||
class="w-28 px-3 py-2 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 @error('default_safety_stock') border-red-500 @enderror">
|
||||
<span class="text-sm text-gray-500">개</span>
|
||||
</div>
|
||||
@error('default_safety_stock')
|
||||
<div class="mt-1 text-red-600 text-xs">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 알림 설정 -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-5">
|
||||
<div class="flex items-center gap-3 mb-4">
|
||||
<div class="w-9 h-9 bg-green-100 rounded-lg flex items-center justify-center">
|
||||
<svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="font-semibold text-gray-800">알림 설정</h3>
|
||||
<p class="text-xs text-gray-500">재고 관련 알림</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
|
||||
<div>
|
||||
<p class="text-sm font-medium text-gray-700">재고부족 알림</p>
|
||||
<p class="text-xs text-gray-500">안전재고 이하 시 알림</p>
|
||||
</div>
|
||||
<label class="relative inline-flex items-center cursor-pointer">
|
||||
<input type="checkbox"
|
||||
name="low_stock_alert"
|
||||
value="1"
|
||||
{{ $lowStockAlert ? 'checked' : '' }}
|
||||
class="sr-only peer">
|
||||
<div class="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-green-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-green-600"></div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 저장 버튼 -->
|
||||
<div class="flex justify-end gap-3 mt-6">
|
||||
<button type="submit"
|
||||
@if(!$tenant) disabled @endif
|
||||
class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 text-sm disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
<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="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
저장
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -24,6 +24,9 @@
|
||||
use App\Http\Controllers\RoleController;
|
||||
use App\Http\Controllers\RolePermissionController;
|
||||
use App\Http\Controllers\TenantController;
|
||||
use App\Http\Controllers\TenantSettingController;
|
||||
use App\Http\Controllers\CommonCodeController;
|
||||
use App\Http\Controllers\MenuSyncController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@@ -48,6 +51,16 @@
|
||||
Route::post('/auth/refresh-session', [LoginController::class, 'refreshSession'])
|
||||
->name('auth.refresh-session');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Menu Sync API (외부 서버 호출용, API Key 인증)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
Route::prefix('menu-sync')->group(function () {
|
||||
Route::get('/export', [MenuSyncController::class, 'export']);
|
||||
Route::post('/import', [MenuSyncController::class, 'import']);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authenticated Routes (인증 필요)
|
||||
@@ -107,6 +120,15 @@
|
||||
Route::get('/global', [MenuController::class, 'globalIndex'])->name('global.index');
|
||||
Route::get('/global/create', [MenuController::class, 'globalCreate'])->name('global.create');
|
||||
Route::get('/global/{id}/edit', [MenuController::class, 'globalEdit'])->name('global.edit');
|
||||
|
||||
// 메뉴 동기화
|
||||
Route::prefix('sync')->name('sync.')->group(function () {
|
||||
Route::get('/', [MenuSyncController::class, 'index'])->name('index');
|
||||
Route::post('/settings', [MenuSyncController::class, 'saveSettings'])->name('settings');
|
||||
Route::post('/test', [MenuSyncController::class, 'testConnection'])->name('test');
|
||||
Route::post('/push', [MenuSyncController::class, 'push'])->name('push');
|
||||
Route::post('/pull', [MenuSyncController::class, 'pull'])->name('pull');
|
||||
});
|
||||
});
|
||||
|
||||
// 권한 관리 (Blade 화면만)
|
||||
@@ -269,6 +291,22 @@
|
||||
Route::get('/simulator', [QuoteFormulaController::class, 'simulator'])->name('simulator');
|
||||
});
|
||||
|
||||
// 테넌트 설정 (재고 설정 등)
|
||||
Route::prefix('tenant-settings')->name('tenant-settings.')->group(function () {
|
||||
Route::get('/', [TenantSettingController::class, 'index'])->name('index');
|
||||
Route::post('/', [TenantSettingController::class, 'store'])->name('store');
|
||||
});
|
||||
|
||||
// 공통코드 관리
|
||||
Route::prefix('common-codes')->name('common-codes.')->group(function () {
|
||||
Route::get('/', [CommonCodeController::class, 'index'])->name('index');
|
||||
Route::post('/', [CommonCodeController::class, 'store'])->name('store');
|
||||
Route::put('/{id}', [CommonCodeController::class, 'update'])->name('update');
|
||||
Route::post('/{id}/toggle', [CommonCodeController::class, 'toggle'])->name('toggle');
|
||||
Route::post('/{id}/copy', [CommonCodeController::class, 'copy'])->name('copy');
|
||||
Route::delete('/{id}', [CommonCodeController::class, 'destroy'])->name('destroy');
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 바로빌 Routes
|
||||
|
||||
Reference in New Issue
Block a user