diff --git a/CURRENT_WORKS.md b/CURRENT_WORKS.md index 7c9cbaef..c846f015 100644 --- a/CURRENT_WORKS.md +++ b/CURRENT_WORKS.md @@ -225,4 +225,89 @@ ### 개발 프로세스: 3. Phase 3: 컨텐츠 구성 (다음 단계) ### Git 커밋: -- ✅ `9367f61` "feat: 좌측 사이드바 레이아웃 및 메뉴 시스템 구현" \ No newline at end of file +- ✅ `9367f61` "feat: 좌측 사이드바 레이아웃 및 메뉴 시스템 구현" + +--- + +## 2025-11-21 (목) - 테넌트 선택 기능 구현 + +### 주요 작업 +- admin 패널의 테넌트 전환 기능을 MNG로 이식 +- Plain Laravel (Livewire 없이) 방식으로 구현 +- ViewServiceProvider를 통한 전역 테넌트 데이터 제공 + +### 추가된 파일: +- `app/Models/Tenant.php` - 테넌트 모델 (SoftDeletes, active scope) +- `app/Http/Controllers/TenantController.php` - 테넌트 전환 컨트롤러 +- `app/Providers/ViewServiceProvider.php` - 모든 뷰에 테넌트 목록 자동 제공 +- `resources/views/partials/tenant-selector.blade.php` - 테넌트 선택 UI 컴포넌트 + +### 수정된 파일: +- `routes/web.php` - 테넌트 전환 라우트 추가 (`POST /tenant/switch`) +- `bootstrap/providers.php` - ViewServiceProvider 등록 +- `resources/views/dashboard/index.blade.php` - 테넌트 선택기 포함 + +### 기능 상세: + +**테넌트 선택기 구조:** +``` +┌─────────────────────────────────────────────────┐ +│ 좌측 우측 │ +│ [아이콘] 테넌트 선택: [드롭다운] [상태 표시] │ +└─────────────────────────────────────────────────┘ +``` + +**UI 컴포넌트:** +- Welcome Card 위에 배치 (동일한 깊이) +- 좌측: 건물 아이콘 + "테넌트 선택" 라벨 + 셀렉트박스 +- 우측: 현재 테넌트 정보 표시 + - 특정 테넌트 선택: "○○ 데이터만 표시 중" (primary 색상 뱃지) + - 전체 보기: "전체 테넌트 데이터 표시 중" (회색 텍스트) + +**동작 방식:** +1. 드롭다운 변경 시 자동 Form Submit (`onchange`) +2. `POST /tenant/switch` 라우트로 전송 +3. Session에 `selected_tenant_id` 저장 +4. 이전 페이지로 리다이렉트 (`redirect()->back()`) + +**ViewServiceProvider 역할:** +- 모든 인증된 뷰에서 `$tenants` 변수 자동 사용 가능 +- View Composer 패턴 적용 (`View::composer('*', ...)`) +- 활성 테넌트만 회사명 순 정렬 + +**Tenant 모델:** +- SoftDeletes trait 사용 +- `active()` scope: 삭제되지 않은 테넌트만 조회 +- `tenant_st_code` 컬럼 사용 (trial, none 등의 상태값) + +### DB 스키마 분석: +- **테이블**: `tenants` (29개 컬럼) +- **주요 컬럼**: + - `id`, `company_name`, `code` (회사 기본 정보) + - `tenant_st_code` (상태: trial, none 등) + - `deleted_at` (SoftDelete) + - `storage_limit`, `storage_used` (용량 관리) + +### 이슈 해결: +- **문제**: `is_active` 컬럼 없음 (SQLSTATE[42S22]) +- **원인**: admin 패널과 DB 스키마 차이 +- **해결**: `tenant_st_code` 사용 → 삭제되지 않은 모든 테넌트 표시 + +### 테스트 결과: +- ✅ 테넌트 모델 조회 성공 (7개 활성 테넛트) +- ✅ ViewServiceProvider 등록 완료 +- ✅ 테넌트 선택기 UI 렌더링 +- ⏳ 브라우저 테스트 대기 중 + +### 빌드 결과: +- **CSS**: 25.58 KB (gzip: 5.61 KB) +- **파일**: `public/build/assets/app-CQyaIaRP.css` + +### 기술적 결정: +- **Livewire 대신 Plain Laravel**: 심플함, 페이지 새로고침 방식 +- **ViewServiceProvider**: 전역 데이터 제공 패턴 +- **Session 기반**: `selected_tenant_id` 세션 저장 +- **모든 페이지 공통**: `@include('partials.tenant-selector')` 사용 + +### Git 커밋: +- ✅ 예정: "feat: 테넌트 선택 기능 구현" \ No newline at end of file diff --git a/app/Http/Controllers/TenantController.php b/app/Http/Controllers/TenantController.php new file mode 100644 index 00000000..a9e2c711 --- /dev/null +++ b/app/Http/Controllers/TenantController.php @@ -0,0 +1,24 @@ +input('tenant_id'); + + if ($tenantId === 'all') { + $request->session()->forget('selected_tenant_id'); + } else { + $request->session()->put('selected_tenant_id', $tenantId); + } + + return redirect()->back(); + } +} diff --git a/app/Models/Tenant.php b/app/Models/Tenant.php new file mode 100644 index 00000000..ba5ce67e --- /dev/null +++ b/app/Models/Tenant.php @@ -0,0 +1,27 @@ +whereNull('deleted_at'); + } +} diff --git a/app/Providers/ViewServiceProvider.php b/app/Providers/ViewServiceProvider.php new file mode 100644 index 00000000..661a6456 --- /dev/null +++ b/app/Providers/ViewServiceProvider.php @@ -0,0 +1,35 @@ +check()) { + $tenants = Tenant::active() + ->orderBy('company_name') + ->get(['id', 'company_name', 'code']); + + $view->with('tenants', $tenants); + } + }); + } +} diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 38b258d1..6bdee7ed 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -2,4 +2,5 @@ return [ App\Providers\AppServiceProvider::class, + App\Providers\ViewServiceProvider::class, ]; diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index a570f9e6..d3369068 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -4,6 +4,9 @@ @section('page-title', '대시보드') @section('content') + + @include('partials.tenant-selector') +
diff --git a/resources/views/partials/tenant-selector.blade.php b/resources/views/partials/tenant-selector.blade.php new file mode 100644 index 00000000..b6e2d7ba --- /dev/null +++ b/resources/views/partials/tenant-selector.blade.php @@ -0,0 +1,59 @@ + +
+
+
+ +
+
+ + + + +
+ +
+ @csrf + +
+
+ + +
+ @if(session('selected_tenant_id')) + @php + $currentTenant = $tenants->firstWhere('id', session('selected_tenant_id')); + @endphp + @if($currentTenant) + + + + + {{ $currentTenant->company_name }} 데이터만 표시 중 + + @endif + @else + + 전체 테넌트 데이터 표시 중 + + @endif +
+
+
+
diff --git a/routes/web.php b/routes/web.php index ab2b9711..9628af06 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ group(function () { Route::post('/logout', [LoginController::class, 'logout'])->name('logout'); + // 테넌트 전환 + Route::post('/tenant/switch', [TenantController::class, 'switch'])->name('tenant.switch'); + // 대시보드 (임시) Route::get('/dashboard', function () { return view('dashboard.index');