feat: Implement new admin API endpoints for product, customer, vCenter, and authentication, and add vCenter resource management UI.
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
# Infrastructure Management Module - Action Items
|
||||
|
||||
## 🔴 P0 - CRITICAL (Ngay lập tức)
|
||||
|
||||
### 1. Authorization - Implement Laravel Policies
|
||||
- [ ] Tạo Policy classes cho: vCenter, Datacenter, Host, Datastore, Network, Folder
|
||||
- [ ] Thêm middleware `can:` vào tất cả infrastructure routes trong `routes/admin.php`
|
||||
- [ ] Xóa view-level RBAC checks trong Blade files
|
||||
- [ ] Định nghĩa permission constants thay vì hard-coded strings
|
||||
|
||||
### 2. Database - FK Constraints & Indexes
|
||||
- [ ] Thêm FK constraint cho `module_folder.module_datacenter_id`
|
||||
- [ ] Thêm index cho `module_network.module_host_id`
|
||||
- [ ] Thêm index cho `module_datastore.module_host_id`
|
||||
- [ ] Thêm composite index: `(vcenter_id, status)`, `(datacenter_id, status)`
|
||||
|
||||
### 3. Database - Soft Deletes
|
||||
- [ ] Thêm soft deletes cho bảng: module_vcenter, module_datacenter, module_host, module_datastore, module_network, module_folder
|
||||
- [ ] Update Models thêm `SoftDeletes` trait
|
||||
- [ ] Update Repositories xử lý soft delete queries
|
||||
|
||||
---
|
||||
|
||||
## 🟡 P1 - HIGH PRIORITY (Trong 30 ngày)
|
||||
|
||||
### 4. API Design - Versioning & Authentication
|
||||
- [ ] Tạo API route group `/api/v1/`
|
||||
- [ ] Implement API Resources/Transformers cho các entities
|
||||
- [ ] Thêm Sanctum authentication cho API
|
||||
- [ ] Thêm rate limiting cho sync endpoints
|
||||
|
||||
### 5. Performance - Caching & Queries
|
||||
- [ ] Implement Redis cache với tags theo vCenter/datacenter
|
||||
- [ ] Fix cache invalidation khi có updates
|
||||
- [ ] Thêm eager loading `with(['vCenter'])` trong controllers
|
||||
- [ ] Tạo index cho `findByName` (full-text hoặc index)
|
||||
|
||||
### 6. Tree Explorer - Lazy Loading
|
||||
- [ ] Tạo API endpoint cho tree lazy-load: `/api/v1/infrastructure/tree`
|
||||
- [ ] Implement expand-on-demand pattern
|
||||
- [ ] Cache tree structure với short TTL
|
||||
|
||||
---
|
||||
|
||||
## 🟢 P2 - MEDIUM PRIORITY (Trong 60 ngày)
|
||||
|
||||
### 7. Domain Modeling - Refactoring
|
||||
- [ ] Tạo module/Infrastructure/Resources thay thế presentation logic trong Models
|
||||
- [ ] Di chuyển `getStatus()` HTML rendering từ Model sang Resource
|
||||
- [ ] Thêm scope methods cho common queries
|
||||
|
||||
### 8. Multi-tenancy Preparation
|
||||
- [ ] Thêm cột `tenant_id` vào tất cả infrastructure tables
|
||||
- [ ] Tạo global scope cho tenant filtering
|
||||
- [ ] Update repositories handle tenant context
|
||||
|
||||
### 9. Sync Jobs - Event Driven
|
||||
- [ ] Tạo Infrastructure events: DatacenterSynced, HostSynced, etc.
|
||||
- [ ] Implement event listeners cho cache invalidation
|
||||
- [ ] Thêm queue prioritization cho sync jobs
|
||||
- [ ] Implement job locking tránh race conditions
|
||||
|
||||
---
|
||||
|
||||
## 🔵 P3 - FUTURE (60-90 ngày)
|
||||
|
||||
### 10. Technical Debt
|
||||
- [ ] Tạo constants class cho permissions
|
||||
- [ ] Refactor password handling (统一 encryption approach)
|
||||
- [ ] Thêm API documentation (Swagger/OpenAPI)
|
||||
- [ ] Tách biệt Read/Write repositories
|
||||
|
||||
### 11. SPA Migration Preparation
|
||||
- [ ] Tạo dedicated API controllers cho SPA
|
||||
- [ ] Implement proper JSON error responses
|
||||
- [ ] Thêm pagination metadata vào responses
|
||||
- [ ] Tạo API documentation
|
||||
|
||||
---
|
||||
|
||||
## 📊 Progress Tracking
|
||||
|
||||
| Category | Total | Completed | In Progress | Pending |
|
||||
|----------|-------|-----------|-------------|---------|
|
||||
| P0 - Critical | 10 | | | |
|
||||
| P1 - High | 10 | | | |
|
||||
| P2 - Medium | 10 | | | |
|
||||
| P3 - Future | 4 | | | |
|
||||
|
||||
---
|
||||
|
||||
## 📝 Notes
|
||||
|
||||
### Database Migrations Needed:
|
||||
```
|
||||
1. add_soft_deletes_to_infrastructure_tables.php
|
||||
2. add_missing_indexes_and_fk.php
|
||||
3. add_tenant_id_to_infrastructure_tables.php
|
||||
```
|
||||
|
||||
### Files to Create:
|
||||
```
|
||||
app/Policies/vCenterPolicy.php
|
||||
app/Policies/DatacenterPolicy.php
|
||||
app/Policies/HostPolicy.php
|
||||
app/Policies/DatastorePolicy.php
|
||||
app/Policies/NetworkPolicy.php
|
||||
app/Policies/FolderPolicy.php
|
||||
app/Http/Resources/Api/v1/vCenterResource.php
|
||||
app/Http/Resources/Api/v1/DatacenterResource.php
|
||||
app/Events/Infrastructure/DatacenterSynced.php
|
||||
app/Listeners/Infrastructure/InvalidateDatacenterCache.php
|
||||
```
|
||||
|
||||
### Key Dependencies:
|
||||
- Laravel Sanctum (API auth)
|
||||
- Redis (caching)
|
||||
- Spatie Laravel-permission (RBAC) - optionally
|
||||
@@ -1,353 +0,0 @@
|
||||
# Project Structure - Laravel Portal
|
||||
|
||||
## 📊 Project Overview
|
||||
|
||||
| Metric | Count |
|
||||
|--------|-------|
|
||||
| **Models** | 61 |
|
||||
| **Controllers** | 46 |
|
||||
| **Migrations** | 90 |
|
||||
| **Views** | 311 |
|
||||
| **Repositories** | 153 |
|
||||
| **Routes** | 7 |
|
||||
|
||||
---
|
||||
|
||||
## 🗂️ Directory Structure
|
||||
|
||||
```
|
||||
portal/
|
||||
├── app/
|
||||
│ ├── Console/ # Artisan commands
|
||||
│ │ ├── Commands/
|
||||
│ │ └── Kernel.php
|
||||
│ │
|
||||
│ ├── Enums/ # Enum classes
|
||||
│ │ ├── Order/
|
||||
│ │ ├── Product/
|
||||
│ │ ├── Client/
|
||||
│ │ └── Invoice/
|
||||
│ │
|
||||
│ ├── Events/ # Event classes
|
||||
│ │
|
||||
│ ├── Exceptions/ # Exception handlers
|
||||
│ │
|
||||
│ ├── Exports/ # Excel exports
|
||||
│ │
|
||||
│ ├── Helpers/ # Helper functions
|
||||
│ │
|
||||
│ ├── Http/
|
||||
│ │ ├── Controllers/
|
||||
│ │ │ ├── admin/ # Admin controllers
|
||||
│ │ │ │ ├── ModulevCenterController.php
|
||||
│ │ │ │ ├── ModuleHostingController.php
|
||||
│ │ │ │ ├── CustomerController.php
|
||||
│ │ │ │ ├── OrderController.php
|
||||
│ │ │ │ ├── InvoiceController.php
|
||||
│ │ │ │ ├── UserController.php
|
||||
│ │ │ │ ├── AddonController.php
|
||||
│ │ │ │ ├── TemplateController.php
|
||||
│ │ │ │ ├── SupportController.php
|
||||
│ │ │ │ ├── package/ # Package modules
|
||||
│ │ │ │ │ ├── Datacenter.php
|
||||
│ │ │ │ │ ├── Host.php
|
||||
│ │ │ │ │ ├── Datastore.php
|
||||
│ │ │ │ │ ├── Network.php
|
||||
│ │ │ │ │ ├── Folder.php
|
||||
│ │ │ │ │ ├── Group.php
|
||||
│ │ │ │ │ ├── IPMapping.php
|
||||
│ │ │ │ │ ├── OsVersion.php
|
||||
│ │ │ │ │ └── vm/
|
||||
│ │ │ │ │ └── VirtualMachineController.php
|
||||
│ │ │ │ ├── product/
|
||||
│ │ │ │ ├── vm/
|
||||
│ │ │ │ └── Api/ # API controllers
|
||||
│ │ │ └── rest/
|
||||
│ │ ├── Middleware/ # Custom middleware
|
||||
│ │ ├── Requests/ # Form requests
|
||||
│ │ ├── Services/ # Services
|
||||
│ │ │ ├── vCenter/
|
||||
│ │ │ │ ├── Client.php
|
||||
│ │ │ │ ├── PowerShellService.php
|
||||
│ │ │ │ ├── SnapshotService.php
|
||||
│ │ │ │ ├── VirtualMachineService.php
|
||||
│ │ │ │ └── ...
|
||||
│ │ │ ├── Upload.php
|
||||
│ │ │ └── ...
|
||||
│ │ ├── Kernel.php
|
||||
│ │ └── ...
|
||||
│ │
|
||||
│ ├── Imports/ # Excel imports
|
||||
│ │
|
||||
│ ├── Jobs/ # Queue jobs
|
||||
│ │ ├── Hosting/
|
||||
│ │ ├── Mail/
|
||||
│ │ ├── Payment/
|
||||
│ │ ├── Ticket/
|
||||
│ │ └── VirtualMachine/
|
||||
│ │ └── Sync/
|
||||
│ │ ├── SyncDatacenter.php
|
||||
│ │ ├── SyncHost.php
|
||||
│ │ ├── SyncDatastore.php
|
||||
│ │ ├── SyncNetwork.php
|
||||
│ │ ├── SyncFolder.php
|
||||
│ │ └── SyncAllPackage.php
|
||||
│ │
|
||||
│ ├── Mail/ # Mails
|
||||
│ │ └── Customer/
|
||||
│ │
|
||||
│ ├── Models/ # Eloquent models (61 files)
|
||||
│ │ ├── User.php
|
||||
│ │ ├── Customer.php
|
||||
│ │ ├── Staff.php
|
||||
│ │ ├── Order.php
|
||||
│ │ ├── Invoice.php
|
||||
│ │ ├── Product.php
|
||||
│ │ ├── Hosting.php
|
||||
│ │ ├── vCenter.php
|
||||
│ │ ├── ModuleDatacenter.php
|
||||
│ │ ├── ModuleHost.php
|
||||
│ │ ├── ModuleDatastore.php
|
||||
│ │ ├── ModuleNetwork.php
|
||||
│ │ ├── ModuleFolder.php
|
||||
│ │ ├── VirtualMachines.php
|
||||
│ │ └── ...
|
||||
│ │
|
||||
│ ├── Notifications/
|
||||
│ │
|
||||
│ ├── Observers/ # Model observers
|
||||
│ │
|
||||
│ ├── Providers/ # Service providers
|
||||
│ │ ├── AppServiceProvider.php
|
||||
│ │ ├── AuthServiceProvider.php
|
||||
│ │ ├── RouteServiceProvider.php
|
||||
│ │ └── ...
|
||||
│ │
|
||||
│ ├── Repositories/ # Repository pattern (153 files)
|
||||
│ │ ├── vCenter/
|
||||
│ │ │ ├── vCenterRepository.php
|
||||
│ │ │ ├── vCenterCachedRepository.php
|
||||
│ │ │ └── vCenterRepositoryInterface.php
|
||||
│ │ ├── Module/
|
||||
│ │ │ ├── Datacenter/
|
||||
│ │ │ ├── Host/
|
||||
│ │ │ ├── Datastore/
|
||||
│ │ │ ├── Network/
|
||||
│ │ │ ├── Folder/
|
||||
│ │ │ ├── IpAddress/
|
||||
│ │ │ ├── VirtualMachine/
|
||||
│ │ │ ├── Hosting/
|
||||
│ │ │ ├── HostingServer/
|
||||
│ │ │ ├── DnsServer/
|
||||
│ │ │ ├── Domain/
|
||||
│ │ │ ├── IPPool/
|
||||
│ │ │ └── Snapshot/
|
||||
│ │ ├── User/
|
||||
│ │ ├── Order/
|
||||
│ │ ├── Invoice/
|
||||
│ │ ├── Product/
|
||||
│ │ ├── Admin/
|
||||
│ │ └── ...
|
||||
│ │
|
||||
│ ├── Services/
|
||||
│ │
|
||||
│ ├── Support/
|
||||
│ │
|
||||
│ ├── Traits/
|
||||
│ │
|
||||
│ └── View/
|
||||
│ └── Components/ # Blade components
|
||||
│ └── Module/
|
||||
│
|
||||
├── bootstrap/
|
||||
│ ├── app.php
|
||||
│ ├── cache/
|
||||
│ └── providers.php
|
||||
│
|
||||
├── config/ # Configuration files (33 dirs)
|
||||
│ ├── app.php
|
||||
│ ├── auth.php
|
||||
│ ├── cache.php
|
||||
│ ├── database.php
|
||||
│ ├── filesystems.php
|
||||
│ ├── logging.php
|
||||
│ ├── mail.php
|
||||
│ ├── queue.php
|
||||
│ ├── session.php
|
||||
│ ├── queue.php
|
||||
│ └── ...
|
||||
│
|
||||
├── database/
|
||||
│ ├── factories/
|
||||
│ ├── migrations/ # 90 migration files
|
||||
│ │ ├── 2024_01_31_165959_module_hosting_server.php
|
||||
│ │ ├── 2024_02_01_080844_module_hosting.php
|
||||
│ │ ├── 2024_02_01_082942_v_center.php
|
||||
│ │ ├── 2024_02_01_090134_module_datacenter.php
|
||||
│ │ ├── 2024_02_01_090537_module_host.php
|
||||
│ │ ├── 2024_02_01_091327_module_folder.php
|
||||
│ │ ├── 2024_02_01_091707_module_datastore.php
|
||||
│ │ ├── 2024_02_01_092104_module_network.php
|
||||
│ │ └── ...
|
||||
│ └── seeders/
|
||||
│
|
||||
├── docs/
|
||||
│
|
||||
├── lang/ # Language files
|
||||
│ ├── en/
|
||||
│ └── vi/
|
||||
│
|
||||
├── public/ # Public assets
|
||||
│ ├── assets/
|
||||
│ ├── css/
|
||||
│ ├── js/
|
||||
│ ├── images/
|
||||
│ ├── build/
|
||||
│ ├── libraries/
|
||||
│ └── index.php
|
||||
│
|
||||
├── resources/
|
||||
│ ├── views/
|
||||
│ │ ├── administrator/ # Admin views
|
||||
│ │ │ ├── layout/
|
||||
│ │ │ ├── pages/
|
||||
│ │ │ │ ├── module/ # Module pages
|
||||
│ │ │ │ │ ├── vcenter/
|
||||
│ │ │ │ │ ├── hosting/
|
||||
│ │ │ │ │ └── ippool/
|
||||
│ │ │ │ ├── package/ # Package pages
|
||||
│ │ │ │ │ ├── vcenter/
|
||||
│ │ │ │ │ ├── datacenter/
|
||||
│ │ │ │ │ ├── host/
|
||||
│ │ │ │ │ ├── datastore/
|
||||
│ │ │ │ │ ├── network/
|
||||
│ │ │ │ │ ├── folder/
|
||||
│ │ │ │ │ ├── vm/
|
||||
│ │ │ │ │ ├── group/
|
||||
│ │ │ │ │ ├── ipaddress/
|
||||
│ │ │ │ │ └── version/
|
||||
│ │ │ │ ├── customer/
|
||||
│ │ │ │ ├── order/
|
||||
│ │ │ │ ├── invoice/
|
||||
│ │ │ │ ├── product/
|
||||
│ │ │ │ └── ...
|
||||
│ │ │ └── blocks/
|
||||
│ │ ├── components/ # Blade components
|
||||
│ │ ├── livewire/ # Livewire components
|
||||
│ │ ├── emails/ # Email templates
|
||||
│ │ ├── form/
|
||||
│ │ ├── vendor/
|
||||
│ │ └── errors/
|
||||
│ ├── js/
|
||||
│ ├── css/
|
||||
│ └── sass/
|
||||
│
|
||||
├── routes/
|
||||
│ ├── admin.php # Admin routes (30,829 bytes)
|
||||
│ ├── api.php # API routes
|
||||
│ ├── web.php # Web routes
|
||||
│ ├── client.php # Client routes
|
||||
│ ├── administrator.php
|
||||
│ ├── channels.php
|
||||
│ └── console.php
|
||||
│
|
||||
├── scripts/
|
||||
│
|
||||
├── storage/
|
||||
│ ├── app/
|
||||
│ ├── framework/
|
||||
│ │ ├── cache/
|
||||
│ │ ├── sessions/
|
||||
│ │ └── views/
|
||||
│ └── logs/
|
||||
│
|
||||
├── tests/
|
||||
│ ├── Feature/
|
||||
│ ├── Unit/
|
||||
│ └── ...
|
||||
│
|
||||
├── vendor/ # Composer dependencies
|
||||
│
|
||||
├── .env # Environment config
|
||||
├── .env.example
|
||||
├── artisan
|
||||
├── composer.json
|
||||
├── package.json
|
||||
├── vite.config.js
|
||||
├── webpack.mix.js
|
||||
├── docker-compose.yml
|
||||
└── INFRASTRUCTURE_ACTION_ITEMS.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🏗️ Architecture Overview
|
||||
|
||||
### Pattern: Repository Pattern
|
||||
```
|
||||
Controller → Repository Interface → Repository → Model
|
||||
```
|
||||
|
||||
### Key Modules
|
||||
|
||||
| Module | Purpose | Key Files |
|
||||
|--------|---------|-----------|
|
||||
| **vCenter Management** | Connect & manage vCenter servers | vCenter.php, ModulevCenterController |
|
||||
| **Infrastructure** | Datacenter, Host, Datastore, Network, Folder | Module* models, package/* controllers |
|
||||
| **Virtual Machines** | VM lifecycle management | VirtualMachines.php, Sync* jobs |
|
||||
| **Orders & Billing** | Order processing, Invoices | Order.php, Invoice.php |
|
||||
| **Customer Management** | Customer accounts, Auth | Customer.php, CustomerController |
|
||||
| **Hosting** | Hosting services | ModuleHosting.php, Hosting.php |
|
||||
|
||||
---
|
||||
|
||||
## 🎨 Tech Stack
|
||||
|
||||
- **Backend**: Laravel 10.x
|
||||
- **Frontend**: Bootstrap 5, jQuery AJAX, Livewire
|
||||
- **Database**: MySQL
|
||||
- **Cache**: Redis
|
||||
- **Queue**: Database/Broadcast (laravel-echo-server)
|
||||
- **Auth**: Session-based + Sanctum for API
|
||||
|
||||
---
|
||||
|
||||
## 📁 Key Configuration Files
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| `config/app.php` | App name, locale, timezone |
|
||||
| `config/database.php` | MySQL connection |
|
||||
| `config/cache.php` | Redis cache config |
|
||||
| `config/queue.php` | Queue connection |
|
||||
| `config/sanctum.php` | API auth |
|
||||
| `routes/admin.php` | All admin routes (~30KB) |
|
||||
|
||||
---
|
||||
|
||||
## 🔗 Route Structure (routes/admin.php ~575 lines)
|
||||
|
||||
```
|
||||
/admin
|
||||
├── /vcenter → ModulevCenterController
|
||||
├── /module
|
||||
│ ├── /dns → ModuleDNSController
|
||||
│ ├── /hosting → ModuleHostingController
|
||||
│ └── /ippool → ModuleIPPoolController
|
||||
├── /package
|
||||
│ ├── /datacenter → DatacenterController
|
||||
│ ├── /host → HostController
|
||||
│ ├── /datastore → DatastoreController
|
||||
│ ├── /network → NetworkController
|
||||
│ ├── /folder → FolderController
|
||||
│ ├── /vm → VirtualMachineController
|
||||
│ └── ...
|
||||
├── /customer → CustomerController
|
||||
├── /order → OrderController
|
||||
├── /invoice → InvoiceController
|
||||
└── ...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*Generated: Mar 2026*
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Admin\AdminUserResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use Tymon\JWTAuth\Exceptions\JWTException;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
]);
|
||||
|
||||
$token = Auth::guard('admins-api')->attempt($request->only('username', 'password'));
|
||||
|
||||
if (!$token) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Thông tin đăng nhập không chính xác.',
|
||||
], 401);
|
||||
}
|
||||
|
||||
$user = Auth::guard('admins-api')->user();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'token' => $token,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => config('jwt.ttl') * 60,
|
||||
'user' => new AdminUserResource($user),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function me(): JsonResponse
|
||||
{
|
||||
$user = Auth::guard('admins-api')->user();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => ['user' => new AdminUserResource($user)],
|
||||
]);
|
||||
}
|
||||
|
||||
public function refresh(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$newToken = JWTAuth::parseToken()->refresh();
|
||||
$user = JWTAuth::setToken($newToken)->toUser();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'token' => $newToken,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => config('jwt.ttl') * 60,
|
||||
'user' => new AdminUserResource($user),
|
||||
],
|
||||
]);
|
||||
} catch (JWTException) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Không thể làm mới phiên đăng nhập. Vui lòng đăng nhập lại.',
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function logout(): JsonResponse
|
||||
{
|
||||
Auth::guard('admins-api')->logout();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã đăng xuất thành công.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Customer;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Admin\CustomerResource;
|
||||
use App\Repositories\Admin\Customer\AdminCustomerRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AdminCustomerRepositoryInterface $customers,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
$paginator = $this->customers->paginate($request->only('filter', 'status'), $perPage);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => CustomerResource::collection($paginator->items()),
|
||||
'total' => $paginator->total(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Invoice;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Admin\InvoiceResource;
|
||||
use App\Repositories\Admin\Invoice\AdminInvoiceRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AdminInvoiceRepositoryInterface $invoices,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
$paginator = $this->invoices->paginate($request->only('filter', 'status'), $perPage);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => InvoiceResource::collection($paginator->items()),
|
||||
'total' => $paginator->total(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Order;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Admin\OrderResource;
|
||||
use App\Repositories\Admin\Order\AdminOrderRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AdminOrderRepositoryInterface $orders,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
$paginator = $this->orders->paginate($request->only('filter', 'status'), $perPage);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => OrderResource::collection($paginator->items()),
|
||||
'total' => $paginator->total(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Product;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Admin\ProductResource;
|
||||
use App\Repositories\Admin\Product\AdminProductRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AdminProductRepositoryInterface $products,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
$paginator = $this->products->paginate(
|
||||
$request->only('filter', 'type', 'is_active'),
|
||||
$perPage
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => ProductResource::collection($paginator->items()),
|
||||
'total' => $paginator->total(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$product = $this->products->findWithPricings($id);
|
||||
|
||||
if (!$product) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy sản phẩm.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => new ProductResource($product),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\VCenter;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ModuleFolder;
|
||||
use App\Models\ModuleHost;
|
||||
use App\Models\vCenter;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class VCenterController extends Controller
|
||||
{
|
||||
public function tree(Request $request): JsonResponse
|
||||
{
|
||||
$vcenters = vCenter::with(['datacenters'])->get();
|
||||
$allHosts = ModuleHost::with(['datastore', 'network'])->get()->groupBy('module_datacenter_id');
|
||||
$allFolders = ModuleFolder::all()->groupBy('module_datacenter_id');
|
||||
|
||||
$tree = $vcenters->map(function ($vc) use ($allHosts, $allFolders) {
|
||||
$dcGroups = ($vc->datacenters ?? collect())->groupBy('datacenter_id');
|
||||
$datacenters = $dcGroups->map(function ($dcGroup) use ($allHosts, $allFolders) {
|
||||
$dc = $dcGroup->first();
|
||||
$dcIds = $dcGroup->pluck('id');
|
||||
$uniqueHosts = $dcIds->flatMap(fn($id) => $allHosts->get($id) ?? collect())
|
||||
->unique('host_id')->values();
|
||||
|
||||
$dcNetworks = $uniqueHosts
|
||||
->flatMap(fn($host) => $host->network ?? collect())
|
||||
->unique('network')
|
||||
->map(fn($net) => [
|
||||
'id' => 'network-' . $net->id,
|
||||
'name' => $net->name,
|
||||
'type' => 'network',
|
||||
'meta' => ['db_id' => $net->id, 'network_id' => $net->network, 'net_type' => $net->type],
|
||||
]);
|
||||
|
||||
$dcHosts = $uniqueHosts->map(function ($host) {
|
||||
$datastores = ($host->datastore ?? collect())
|
||||
->unique('datastore')
|
||||
->map(fn($ds) => [
|
||||
'id' => 'datastore-' . $ds->id,
|
||||
'name' => $ds->name,
|
||||
'type' => 'datastore',
|
||||
'meta' => [
|
||||
'db_id' => $ds->id,
|
||||
'datastore_id' => $ds->datastore,
|
||||
'store_type' => $ds->type,
|
||||
'space_gb' => $ds->space ? round($ds->space / 1024, 1) : null,
|
||||
'status' => $ds->status,
|
||||
],
|
||||
]);
|
||||
|
||||
return [
|
||||
'id' => 'host-' . $host->id,
|
||||
'name' => $host->name,
|
||||
'type' => 'host',
|
||||
'meta' => ['db_id' => $host->id, 'host_id' => $host->host_id, 'console' => $host->console],
|
||||
'children' => array_values($datastores->toArray()),
|
||||
];
|
||||
});
|
||||
|
||||
$dcFolders = $dcIds
|
||||
->flatMap(fn($id) => $allFolders->get($id) ?? collect())
|
||||
->unique('folder')
|
||||
->map(fn($f) => [
|
||||
'id' => 'folder-' . $f->id,
|
||||
'name' => $f->name,
|
||||
'type' => 'folder',
|
||||
'meta' => ['db_id' => $f->id, 'folder_id' => $f->folder, 'folder_type' => $f->type],
|
||||
]);
|
||||
|
||||
return [
|
||||
'id' => 'datacenter-' . $dc->id,
|
||||
'name' => $dc->name,
|
||||
'type' => 'datacenter',
|
||||
'meta' => ['db_id' => $dc->id, 'datacenter_id' => $dc->datacenter_id],
|
||||
'children' => array_values($dcFolders->concat($dcNetworks)->concat($dcHosts)->toArray()),
|
||||
];
|
||||
})->values();
|
||||
|
||||
return [
|
||||
'id' => 'vcenter-' . $vc->id,
|
||||
'name' => $vc->host,
|
||||
'type' => 'vcenter',
|
||||
'meta' => ['db_id' => $vc->id, 'host' => $vc->host, 'status' => $vc->status],
|
||||
'children' => array_values($datacenters->toArray()),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json(['error' => false, 'data' => $tree->values()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ModuleIpAddress;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Repositories\Module\Datacenter\DatacenterRepositoryInterface;
|
||||
use App\Repositories\Module\Datastore\DatastoreRepositoryInterface;
|
||||
use App\Repositories\Module\Folder\FolderRepositoryInterface;
|
||||
use App\Repositories\Module\Host\HostRepositoryInterface;
|
||||
use App\Repositories\Module\IpAddress\IpAddressRepositoryInterface;
|
||||
use App\Repositories\Module\Network\NetworkRepositoryInterface;
|
||||
use App\Repositories\vCenter\vCenterRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class VCenterManagerController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly vCenterRepositoryInterface $vCenterRepo,
|
||||
private readonly DatacenterRepositoryInterface $datacenterRepo,
|
||||
private readonly HostRepositoryInterface $hostRepo,
|
||||
private readonly DatastoreRepositoryInterface $datastoreRepo,
|
||||
private readonly NetworkRepositoryInterface $networkRepo,
|
||||
private readonly FolderRepositoryInterface $folderRepo,
|
||||
private readonly IpAddressRepositoryInterface $ipRepo,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main view — server-render vCenters + their datacenters for initial tree.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$vcenters = $this->vCenterRepo->filter(
|
||||
[],
|
||||
['datacenters'],
|
||||
['datacenters'],
|
||||
['id', 'host', 'status']
|
||||
);
|
||||
|
||||
return view('administrator.pages.vcenter.manager', compact('vcenters'));
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX — Lazy-load children of a tree node.
|
||||
*
|
||||
* GET vcenter-manager/tree/children?type=datacenter&id=1
|
||||
* Returns JSON array of { id, type, name, icon, has_children, meta }
|
||||
*/
|
||||
public function treeChildren(Request $request)
|
||||
{
|
||||
$type = $request->input('type');
|
||||
$id = (int) $request->input('id');
|
||||
|
||||
return match ($type) {
|
||||
'vcenter' => $this->vcenterNodes($id),
|
||||
'datacenter' => $this->hostNodes($id),
|
||||
'host' => $this->hostChildNodes($id),
|
||||
default => response()->json([]),
|
||||
};
|
||||
}
|
||||
|
||||
private function vcenterNodes(int $vcenterId)
|
||||
{
|
||||
$datacenters = $this->datacenterRepo->filter(
|
||||
['vcenter_id' => $vcenterId],
|
||||
[],
|
||||
[],
|
||||
['id', 'name']
|
||||
);
|
||||
|
||||
return response()->json($datacenters->map(fn ($dc) => [
|
||||
'id' => $dc->id,
|
||||
'type' => 'datacenter',
|
||||
'name' => $dc->name,
|
||||
'icon' => 'fas fa-building',
|
||||
'has_children' => true,
|
||||
'meta' => [],
|
||||
]));
|
||||
}
|
||||
|
||||
private function hostNodes(int $datacenterId)
|
||||
{
|
||||
$hosts = $this->hostRepo->filter(
|
||||
['module_datacenter_id' => $datacenterId],
|
||||
[],
|
||||
['datastore', 'network'],
|
||||
['id', 'name', 'template']
|
||||
);
|
||||
|
||||
return response()->json($hosts->map(fn ($h) => [
|
||||
'id' => $h->id,
|
||||
'type' => 'host',
|
||||
'name' => $h->name,
|
||||
'icon' => 'fas fa-server',
|
||||
'has_children' => true,
|
||||
'meta' => [
|
||||
'datastores' => $h->datastore_count ?? 0,
|
||||
'networks' => $h->network_count ?? 0,
|
||||
'template' => (bool) $h->template,
|
||||
],
|
||||
]));
|
||||
}
|
||||
|
||||
private function hostChildNodes(int $hostId)
|
||||
{
|
||||
$datastores = $this->datastoreRepo->filter(
|
||||
['module_host_id' => $hostId],
|
||||
[],
|
||||
[],
|
||||
['id', 'name', 'type', 'space', 'status']
|
||||
);
|
||||
|
||||
$networks = $this->networkRepo->filter(
|
||||
['module_host_id' => $hostId],
|
||||
[],
|
||||
['ipAddresses'],
|
||||
['id', 'name', 'type']
|
||||
);
|
||||
|
||||
$children = [];
|
||||
|
||||
foreach ($datastores as $ds) {
|
||||
$children[] = [
|
||||
'id' => $ds->id,
|
||||
'type' => 'datastore',
|
||||
'name' => $ds->name,
|
||||
'icon' => 'fas fa-hdd',
|
||||
'has_children' => false,
|
||||
'meta' => ['space' => $ds->space, 'type' => $ds->type, 'status' => $ds->status],
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($networks as $net) {
|
||||
$children[] = [
|
||||
'id' => $net->id,
|
||||
'type' => 'network',
|
||||
'name' => $net->name,
|
||||
'icon' => 'fas fa-network-wired',
|
||||
'has_children' => false,
|
||||
'meta' => ['type' => $net->type, 'ips' => $net->ip_addresses_count ?? 0],
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($children);
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX — Return rendered detail panel HTML for a tree node.
|
||||
*
|
||||
* GET vcenter-manager/tree/detail?type=host&id=3
|
||||
* Returns JSON { html, type, id }
|
||||
*/
|
||||
public function nodeDetail(Request $request)
|
||||
{
|
||||
$type = $request->input('type');
|
||||
$id = (int) $request->input('id');
|
||||
|
||||
$data = match ($type) {
|
||||
'vcenter' => $this->vCenterDetail($id),
|
||||
'datacenter' => $this->datacenterDetail($id),
|
||||
'host' => $this->hostDetail($id),
|
||||
'datastore' => $this->datastoreDetail($id),
|
||||
'network' => $this->networkDetail($id),
|
||||
default => null,
|
||||
};
|
||||
|
||||
if (! $data) {
|
||||
return response()->json(['error' => 'Not found'], 404);
|
||||
}
|
||||
|
||||
$html = view("administrator.pages.vcenter.partials.detail-{$type}", $data)->render();
|
||||
|
||||
return response()->json(compact('html', 'type', 'id'));
|
||||
}
|
||||
|
||||
private function vCenterDetail(int $id): array
|
||||
{
|
||||
$item = $this->vCenterRepo->find($id);
|
||||
$datacenterCount = $this->datacenterRepo->filter(['vcenter_id' => $id])->count();
|
||||
$vmCount = ModuleVmware::where('vcenter_id', $id)->count();
|
||||
|
||||
return compact('item', 'datacenterCount', 'vmCount');
|
||||
}
|
||||
|
||||
private function datacenterDetail(int $id): array
|
||||
{
|
||||
$item = $this->datacenterRepo->find($id);
|
||||
$hosts = $this->hostRepo->filter(
|
||||
['module_datacenter_id' => $id],
|
||||
[],
|
||||
['datastore', 'network'],
|
||||
['id', 'name', 'template']
|
||||
);
|
||||
$folders = $this->folderRepo->filter(
|
||||
['module_datacenter_id' => $id],
|
||||
[],
|
||||
[],
|
||||
['id', 'name', 'type', 'folder']
|
||||
);
|
||||
|
||||
return compact('item', 'hosts', 'folders');
|
||||
}
|
||||
|
||||
private function hostDetail(int $id): array
|
||||
{
|
||||
$item = $this->hostRepo->find($id);
|
||||
$datastores = $this->datastoreRepo->filter(['module_host_id' => $id]);
|
||||
$networks = $this->networkRepo->filter(
|
||||
['module_host_id' => $id],
|
||||
[],
|
||||
['ipAddresses'],
|
||||
['id', 'name', 'type']
|
||||
);
|
||||
$ipTotal = ModuleIpAddress::where('module_host_id', $id)->count();
|
||||
$ipFree = ModuleIpAddress::where('module_host_id', $id)->where('status', 0)->count();
|
||||
|
||||
return compact('item', 'datastores', 'networks', 'ipTotal', 'ipFree');
|
||||
}
|
||||
|
||||
private function datastoreDetail(int $id): array
|
||||
{
|
||||
$item = $this->datastoreRepo->find($id);
|
||||
return compact('item');
|
||||
}
|
||||
|
||||
private function networkDetail(int $id): array
|
||||
{
|
||||
$item = $this->networkRepo->find($id);
|
||||
$ips = $this->ipRepo->filter(
|
||||
['module_network_id' => $id],
|
||||
[],
|
||||
[],
|
||||
['id', 'ip', 'gateway', 'netmask', 'dns', 'status']
|
||||
);
|
||||
|
||||
return compact('item', 'ips');
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX — DataTables JSON for Virtual Machines scoped by tree node.
|
||||
*
|
||||
* GET vcenter-manager/vms/datatable?scope_type=host&scope_id=2
|
||||
*/
|
||||
public function vmDatatable(Request $request)
|
||||
{
|
||||
$scopeType = $request->input('scope_type', 'all');
|
||||
$scopeId = (int) $request->input('scope_id', 0);
|
||||
|
||||
$query = ModuleVmware::with(['customer', 'ipAddress', 'vCenter', 'os']);
|
||||
|
||||
if ($scopeType === 'vcenter' && $scopeId) {
|
||||
$query->where('vcenter_id', $scopeId);
|
||||
} elseif ($scopeType === 'datacenter' && $scopeId) {
|
||||
$hostIds = $this->hostRepo
|
||||
->filter(['module_datacenter_id' => $scopeId], [], [], ['id'])
|
||||
->pluck('id');
|
||||
$query->whereHas('ipAddress', fn ($q) => $q->whereIn('module_host_id', $hostIds));
|
||||
} elseif ($scopeType === 'host' && $scopeId) {
|
||||
$query->whereHas('ipAddress', fn ($q) => $q->where('module_host_id', $scopeId));
|
||||
}
|
||||
|
||||
return DataTables::of($query)
|
||||
->addColumn('customer_name', fn ($vm) => $vm->customer?->fullname ?? 'N/A')
|
||||
->addColumn('ip_address', fn ($vm) => $vm->ipAddress?->ip ?? 'N/A')
|
||||
->addColumn('vcenter_host', fn ($vm) => $vm->vCenter?->host ?? 'N/A')
|
||||
->addColumn('os_name', fn ($vm) => $vm->os?->version ?? 'N/A')
|
||||
->addColumn('status_badge', fn ($vm) => $vm->getStatus())
|
||||
->rawColumns(['status_badge'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function wizardVcenters()
|
||||
{
|
||||
$vcenters = $this->vCenterRepo->filter(['status' => 1], [], [], ['id', 'host', 'user']);
|
||||
return response()->json($vcenters);
|
||||
}
|
||||
|
||||
public function wizardStoreVcenter(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'host' => 'required|string',
|
||||
'user' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
'status' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
try {
|
||||
$vcenter = \App\Models\Vcenter::create([
|
||||
'host' => $data['host'],
|
||||
'user' => $data['user'],
|
||||
'password' => $data['password'],
|
||||
'status' => $data['status'] ?? 1,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'vcenter' => ['id' => $vcenter->id, 'host' => $vcenter->host, 'user' => $vcenter->user]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function wizardDatacenters(Request $request)
|
||||
{
|
||||
$vcenterId = $request->input('vcenter_id');
|
||||
$vcenter = $this->vCenterRepo->find($vcenterId);
|
||||
|
||||
if (!$vcenter) {
|
||||
return response()->json(['error' => 'vCenter not found'], 404);
|
||||
}
|
||||
|
||||
$vcenterService = new \App\Http\Services\vCenter();
|
||||
$loginResult = $vcenterService->loginServer($vcenter);
|
||||
|
||||
if (!$loginResult) {
|
||||
return response()->json(['error' => 'Cannot login to vCenter'], 400);
|
||||
}
|
||||
|
||||
$datacenters = $vcenterService->getAllDatacenter();
|
||||
|
||||
if ($datacenters === false || $datacenters === 'Login_Again') {
|
||||
return response()->json(['error' => 'Cannot get datacenters'], 400);
|
||||
}
|
||||
|
||||
return response()->json(array_map(fn($dc) => [
|
||||
'datacenter_id' => $dc['datacenter'] ?? $dc['datacenter_id'] ?? '',
|
||||
'name' => $dc['name'] ?? $dc['datacenter'] ?? '',
|
||||
], $datacenters));
|
||||
}
|
||||
|
||||
public function wizardHosts(Request $request)
|
||||
{
|
||||
$vcenterId = $request->input('vcenter_id');
|
||||
$datacenterId = $request->input('datacenter_id');
|
||||
|
||||
$vcenter = $this->vCenterRepo->find($vcenterId);
|
||||
|
||||
if (!$vcenter) {
|
||||
return response()->json(['error' => 'vCenter not found'], 404);
|
||||
}
|
||||
|
||||
$vcenterService = new \App\Http\Services\vCenter();
|
||||
$vcenterService->loginServer($vcenter);
|
||||
|
||||
$hosts = $vcenterService->getAllHost($datacenterId);
|
||||
|
||||
if ($hosts === false || $hosts === 'Login_Again') {
|
||||
return response()->json(['error' => 'Cannot get hosts'], 400);
|
||||
}
|
||||
|
||||
return response()->json(array_map(fn($host) => [
|
||||
'host_id' => $host['host'] ?? $host['host_id'] ?? '',
|
||||
'name' => $host['name'] ?? $host['host'] ?? '',
|
||||
], $hosts));
|
||||
}
|
||||
|
||||
public function wizardDatastoreNetwork(Request $request)
|
||||
{
|
||||
$vcenterId = $request->input('vcenter_id');
|
||||
$hostId = $request->input('host_id');
|
||||
|
||||
$vcenter = $this->vCenterRepo->find($vcenterId);
|
||||
|
||||
if (!$vcenter) {
|
||||
return response()->json(['error' => 'vCenter not found'], 404);
|
||||
}
|
||||
|
||||
$vcenterService = new \App\Http\Services\vCenter();
|
||||
$vcenterService->loginServer($vcenter);
|
||||
|
||||
$datastores = $vcenterService->getAllDataStore($hostId);
|
||||
$networks = $vcenterService->getNetwork($hostId);
|
||||
|
||||
return response()->json([
|
||||
'datastores' => $datastores ? array_map(fn($ds) => [
|
||||
'datastore' => $ds['datastore'] ?? $ds['name'] ?? '',
|
||||
'name' => $ds['name'] ?? $ds['datastore'] ?? '',
|
||||
'type' => $ds['type'] ?? 'UNKNOWN',
|
||||
], $datastores) : [],
|
||||
'networks' => $networks ? array_map(fn($net) => [
|
||||
'network_id' => $net['network'] ?? $net['name'] ?? '',
|
||||
'name' => $net['name'] ?? $net['network'] ?? '',
|
||||
'type' => $net['type'] ?? 'UNKNOWN',
|
||||
], $networks) : [],
|
||||
]);
|
||||
}
|
||||
|
||||
public function wizardSave(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'vcenter_id' => 'required|integer',
|
||||
'datacenter' => 'required|array',
|
||||
'host' => 'required|array',
|
||||
'datastores' => 'nullable|array',
|
||||
'networks' => 'nullable|array',
|
||||
]);
|
||||
|
||||
try {
|
||||
$datacenter = \App\Models\ModuleDatacenter::create([
|
||||
'name' => $data['datacenter']['name'],
|
||||
'datacenter_id' => $data['datacenter']['datacenter_id'],
|
||||
'vcenter_id' => $data['vcenter_id'],
|
||||
]);
|
||||
|
||||
$host = \App\Models\ModuleHost::create([
|
||||
'name' => $data['host']['name'],
|
||||
'host_id' => $data['host']['host_id'],
|
||||
'module_datacenter_id' => $datacenter->id,
|
||||
]);
|
||||
|
||||
foreach ($data['datastores'] ?? [] as $ds) {
|
||||
\App\Models\ModuleDatastore::create([
|
||||
'name' => $ds['name'],
|
||||
'datastore' => $ds['datastore'],
|
||||
'type' => $ds['type'],
|
||||
'module_host_id' => $host->id,
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($data['networks'] ?? [] as $net) {
|
||||
\App\Models\ModuleNetwork::create([
|
||||
'name' => $net['name'],
|
||||
'network' => $net['network_id'],
|
||||
'type' => $net['type'],
|
||||
'module_host_id' => $host->id,
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Thêm mới infrastructure thành công!']);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AdminUserResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'email' => $this->email,
|
||||
'firstname' => $this->firstname,
|
||||
'lastname' => $this->lastname,
|
||||
'roles' => $this->getRoleNames(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'fullname' => $this->fullname,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->phone,
|
||||
'company' => $this->company,
|
||||
'status' => match ((int) $this->status) {
|
||||
1 => 'active',
|
||||
2 => 'inactive',
|
||||
3 => 'suspended',
|
||||
default => 'pending',
|
||||
},
|
||||
'total' => (int) $this->total,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InvoiceResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'order_num' => $this->order_num,
|
||||
'customer' => $this->whenLoaded('customer', fn() => [
|
||||
'id' => $this->customer->id,
|
||||
'fullname' => $this->customer->fullname,
|
||||
'email' => $this->customer->email,
|
||||
]),
|
||||
'sub_total' => $this->sub_total,
|
||||
'tax' => $this->tax,
|
||||
'total' => $this->total,
|
||||
'status' => $this->status,
|
||||
'date' => $this->date,
|
||||
'due_date' => $this->due_date,
|
||||
'date_paid' => $this->date_paid,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'order_num' => $this->order_num,
|
||||
'customer' => $this->whenLoaded('customer', fn() => [
|
||||
'id' => $this->customer->id,
|
||||
'fullname' => $this->customer->fullname,
|
||||
'email' => $this->customer->email,
|
||||
]),
|
||||
'amount' => $this->amount,
|
||||
'status' => $this->status,
|
||||
'date' => $this->date,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$minPrice = $this->whenLoaded('pricings', function () {
|
||||
return $this->pricings->min('price');
|
||||
});
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'name' => $this->name,
|
||||
'product_type' => $this->product_type,
|
||||
'category' => $this->whenLoaded('category', fn() => $this->category?->name),
|
||||
'cpu' => $this->cpu,
|
||||
'ram' => $this->ram,
|
||||
'disk' => $this->disk,
|
||||
'bandwidth' => $this->bandwidth,
|
||||
'setup_fee' => $this->setup_fee,
|
||||
'min_price' => $minPrice,
|
||||
'is_active' => $this->is_active,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -283,6 +283,11 @@ class vCenter
|
||||
return "Login_Again";
|
||||
}
|
||||
|
||||
public function getNetwork($host = ''): array|bool|string
|
||||
{
|
||||
return $this->getAllNetwork($host);
|
||||
}
|
||||
|
||||
protected function Command($cmd)
|
||||
{
|
||||
$auth = $this->LoginAuth();
|
||||
|
||||
@@ -28,4 +28,8 @@ class ModuleHost extends Model
|
||||
{
|
||||
return $this->hasMany(\App\Models\ModuleDatastore::class);
|
||||
}
|
||||
public function network()
|
||||
{
|
||||
return $this->hasMany(\App\Models\ModuleNetwork::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,8 @@ class ModuleNetwork extends Model
|
||||
{
|
||||
return $this->belongsTo(\App\Models\ModuleHost::class,'module_host_id','id');
|
||||
}
|
||||
public function ipAddresses()
|
||||
{
|
||||
return $this->hasMany(\App\Models\ModuleIpAddress::class, 'module_network_id');
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -8,8 +8,9 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
use HasRoles;
|
||||
@@ -48,4 +49,14 @@ class User extends Authenticatable
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class vCenter extends Model
|
||||
];
|
||||
public function datacenters()
|
||||
{
|
||||
return $this->hasMany(\App\Models\ModuleDatacenter::class);
|
||||
return $this->hasMany(\App\Models\ModuleDatacenter::class, 'vcenter_id');
|
||||
}
|
||||
public function getStatus()
|
||||
{
|
||||
|
||||
@@ -36,6 +36,24 @@ class AppServiceProvider extends ServiceProvider
|
||||
\App\Repositories\Whois\CachedWhoisRepository::class
|
||||
);
|
||||
|
||||
// Admin API Repositories
|
||||
$this->app->bind(
|
||||
\App\Repositories\Admin\Customer\AdminCustomerRepositoryInterface::class,
|
||||
\App\Repositories\Admin\Customer\AdminCustomerRepository::class
|
||||
);
|
||||
$this->app->bind(
|
||||
\App\Repositories\Admin\Order\AdminOrderRepositoryInterface::class,
|
||||
\App\Repositories\Admin\Order\AdminOrderRepository::class
|
||||
);
|
||||
$this->app->bind(
|
||||
\App\Repositories\Admin\Invoice\AdminInvoiceRepositoryInterface::class,
|
||||
\App\Repositories\Admin\Invoice\AdminInvoiceRepository::class
|
||||
);
|
||||
$this->app->bind(
|
||||
\App\Repositories\Admin\Product\AdminProductRepositoryInterface::class,
|
||||
\App\Repositories\Admin\Product\AdminProductRepository::class
|
||||
);
|
||||
|
||||
if (File::exists(base_path('app/Http/Helpers/function_helper.php'))) {
|
||||
File::requireOnce(base_path('app/Http/Helpers/function_helper.php'));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Customer;
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminCustomerRepository implements AdminCustomerRepositoryInterface
|
||||
{
|
||||
private const STATUS_MAP = [
|
||||
'active' => 1,
|
||||
'inactive' => 2,
|
||||
'pending' => 0,
|
||||
'suspended' => 3,
|
||||
];
|
||||
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Customer::query()->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
->orWhere('phone', 'like', "%{$filter}%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($status = $filters['status'] ?? null) {
|
||||
$statusInt = self::STATUS_MAP[$status] ?? null;
|
||||
if ($statusInt !== null) {
|
||||
$query->where('status', $statusInt);
|
||||
}
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Customer;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminCustomerRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Invoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminInvoiceRepository implements AdminInvoiceRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Invoice::with('customer')->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('order_num', 'like', "%{$filter}%")
|
||||
->orWhereHas('customer', fn($q2) =>
|
||||
$q2->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (($status = $filters['status'] ?? null) !== null && $status !== '') {
|
||||
$query->where('status', (int) $status);
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Invoice;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminInvoiceRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Order;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminOrderRepository implements AdminOrderRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Order::with('customer')->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('order_num', 'like', "%{$filter}%")
|
||||
->orWhereHas('customer', fn($q2) =>
|
||||
$q2->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (($status = $filters['status'] ?? null) !== null && $status !== '') {
|
||||
$query->where('status', (int) $status);
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Order;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminOrderRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Product;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminProductRepository implements AdminProductRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Product::with(['category', 'pricings' => fn($q) => $q->where('is_active', true)])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where('name', 'like', "%{$filter}%");
|
||||
}
|
||||
|
||||
if ($type = $filters['type'] ?? null) {
|
||||
$query->where('product_type', $type);
|
||||
}
|
||||
|
||||
if (isset($filters['is_active']) && $filters['is_active'] !== '') {
|
||||
$query->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN));
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function findWithPricings(int $id): ?Product
|
||||
{
|
||||
return Product::with(['category', 'pricings'])->find($id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Product;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminProductRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
public function findWithPricings(int $id): ?Product;
|
||||
}
|
||||
@@ -64,6 +64,10 @@ return [
|
||||
'driver' => 'sanctum',
|
||||
'provider' => 'users',
|
||||
],
|
||||
'admins-api' => [
|
||||
'driver' => 'jwt',
|
||||
'provider' => 'admins',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|
||||
+3
-33
@@ -6,29 +6,9 @@ return [
|
||||
'icon' => 'fas fa-cubes',
|
||||
'children' => [
|
||||
[
|
||||
'title' => 'Datacenter',
|
||||
'route' => 'package.datacenter.index',
|
||||
'icon' => 'fas fa-database',
|
||||
],
|
||||
[
|
||||
'title' => 'Host',
|
||||
'route' => 'package.host.index',
|
||||
'icon' => 'fas fa-street-view',
|
||||
],
|
||||
[
|
||||
'title' => 'Datastore',
|
||||
'route' => 'package.datastore.index',
|
||||
'icon' => 'fas fa-hdd',
|
||||
],
|
||||
[
|
||||
'title' => 'Folder',
|
||||
'route' => 'package.folder.index',
|
||||
'icon' => 'far fa-folder',
|
||||
],
|
||||
[
|
||||
'title' => 'Network Adapter',
|
||||
'route' => 'package.network.index',
|
||||
'icon' => 'fas fa-network-wired',
|
||||
'title' => 'Infrastructure',
|
||||
'route' => 'vcenter.manager',
|
||||
'icon' => 'fas fa-sitemap',
|
||||
],
|
||||
[
|
||||
'title' => 'Group Os',
|
||||
@@ -40,16 +20,6 @@ return [
|
||||
'route' => 'package.version.index',
|
||||
'icon' => 'fas fa-code-branch',
|
||||
],
|
||||
[
|
||||
'title' => 'IP Mapping',
|
||||
'route' => 'package.ipaddress.index',
|
||||
'icon' => 'fas fa-map-marker-alt',
|
||||
],
|
||||
[
|
||||
'title' => 'Virtual Machines',
|
||||
'route' => 'package.vm.index',
|
||||
'icon' => 'fas fa-server',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('module_ip_address', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('module_host_id')->nullable()->after('module_network_id');
|
||||
$table->foreign('module_host_id', 'fk_module_ip_host')
|
||||
->references('id')
|
||||
->on('module_host')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('module_ip_address', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 297 B |
Binary file not shown.
|
After Width: | Height: | Size: 301 B |
+554
-335
File diff suppressed because it is too large
Load Diff
+3
-3
File diff suppressed because one or more lines are too long
Vendored
+442
-198
File diff suppressed because it is too large
Load Diff
+5
-10
File diff suppressed because one or more lines are too long
+3
-3
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
|
||||
{"/livewire.js":"df3a17f2"}
|
||||
{"/livewire.js":"61e33937"}
|
||||
|
||||
@@ -0,0 +1,916 @@
|
||||
@extends('administrator.layout.master')
|
||||
|
||||
@push('plugin-styles')
|
||||
@foreach (config('assets.datatable.css') as $css)
|
||||
<link href="{{ asset($css) }}" rel="stylesheet" />
|
||||
@endforeach
|
||||
{{-- AimaraJS --}}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/rafaelthca/aimaraJS@master/css/Aimara.css" />
|
||||
{{-- bs-stepper --}}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bs-stepper/dist/css/bs-stepper.min.css" />
|
||||
<style>
|
||||
/* ── Layout ──────────────────────────────────────────── */
|
||||
#vcenter-manager {
|
||||
display: flex;
|
||||
height: calc(100vh - 180px);
|
||||
min-height: 540px;
|
||||
border: 1px solid var(--bs-border-color);
|
||||
border-radius: .5rem;
|
||||
overflow: hidden;
|
||||
background: var(--bs-body-bg);
|
||||
}
|
||||
|
||||
/* ── Tree Panel ──────────────────────────────────────── */
|
||||
#tree-panel {
|
||||
width: 270px;
|
||||
flex-shrink: 0;
|
||||
border-right: 1px solid var(--bs-border-color);
|
||||
overflow-y: auto;
|
||||
background: var(--bs-tertiary-bg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.tree-header {
|
||||
padding: .6rem 1rem;
|
||||
font-size: .7rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: .07em;
|
||||
text-transform: uppercase;
|
||||
color: var(--bs-secondary-color);
|
||||
border-bottom: 1px solid var(--bs-border-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .4rem;
|
||||
}
|
||||
.tree-header svg { width: 13px; height: 13px; }
|
||||
#tree-body { flex: 1; padding: .3rem 0; overflow-y: auto; }
|
||||
|
||||
/* ── AimaraJS overrides for Bootstrap theme ──────────── */
|
||||
#tree-body ul.tree { margin: 0; padding: 0; }
|
||||
#tree-body ul.tree li { font-size: .8rem; color: var(--bs-body-color); }
|
||||
#tree-body span.node {
|
||||
color: var(--bs-body-color);
|
||||
border-radius: 4px;
|
||||
padding: 2px 4px;
|
||||
}
|
||||
#tree-body span.node:hover {
|
||||
background-color: var(--bs-secondary-bg) !important;
|
||||
cursor: pointer;
|
||||
}
|
||||
#tree-body span.node_selected {
|
||||
background-color: var(--bs-primary) !important;
|
||||
color: #fff !important;
|
||||
border-color: var(--bs-primary) !important;
|
||||
}
|
||||
#tree-body a { color: inherit !important; text-decoration: none !important; }
|
||||
#tree-body span.node_selected a { color: #fff !important; }
|
||||
|
||||
/* ── Detail Panel ────────────────────────────────────── */
|
||||
#detail-panel {
|
||||
flex: 1; min-width: 0;
|
||||
display: flex; flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
#detail-toolbar {
|
||||
padding: .45rem .9rem;
|
||||
border-bottom: 1px solid var(--bs-border-color);
|
||||
background: var(--bs-tertiary-bg);
|
||||
display: flex; align-items: center; gap: .5rem;
|
||||
min-height: 42px;
|
||||
}
|
||||
#detail-breadcrumb { font-size: .78rem; }
|
||||
#detail-content { flex: 1; overflow-y: auto; padding: 1.1rem 1.25rem; }
|
||||
|
||||
/* empty state */
|
||||
.detail-empty {
|
||||
height: 100%;
|
||||
display: flex; flex-direction: column;
|
||||
align-items: center; justify-content: center;
|
||||
color: var(--bs-secondary-color); gap: .6rem;
|
||||
}
|
||||
.detail-empty svg { width: 40px; height: 40px; opacity: .25; }
|
||||
|
||||
/* ── Stat strip ──────────────────────────────────────── */
|
||||
.stat-strip {
|
||||
display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.1rem;
|
||||
}
|
||||
.stat-card {
|
||||
display: flex; flex-direction: column; align-items: center;
|
||||
padding: .6rem .9rem;
|
||||
border: 1px solid var(--bs-border-color);
|
||||
border-radius: .4rem; min-width: 88px; text-align: center;
|
||||
}
|
||||
.stat-val { font-size: 1.35rem; font-weight: 700; line-height: 1; }
|
||||
.stat-lbl { font-size: .68rem; color: var(--bs-secondary-color); margin-top: .2rem; }
|
||||
|
||||
/* ── Node header ─────────────────────────────────────── */
|
||||
.node-header {
|
||||
display: flex; align-items: center; gap: .75rem; margin-bottom: .9rem;
|
||||
}
|
||||
.node-avatar {
|
||||
width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.node-avatar svg { width: 22px; height: 22px; }
|
||||
.node-title { font-size: 1rem; font-weight: 700; margin: 0; line-height: 1.2; }
|
||||
.node-sub { font-size: .75rem; color: var(--bs-secondary-color); margin-top: .1rem; }
|
||||
|
||||
/* ip usage bar */
|
||||
.ip-bar { height: 6px; border-radius: 3px; background: var(--bs-secondary-bg); overflow: hidden; }
|
||||
.ip-bar-fill { height: 100%; background: #dc3545; border-radius: 3px; }
|
||||
|
||||
/* ── bs-stepper customise ────────────────────────────── */
|
||||
.bs-stepper-header { padding: 1rem 1.25rem .5rem; border-bottom: 1px solid var(--bs-border-color); }
|
||||
.bs-stepper-content { padding: 1.25rem; }
|
||||
.bs-stepper .step-trigger:focus { box-shadow: none; }
|
||||
.bs-stepper-circle { background-color: var(--bs-secondary); }
|
||||
.step.active .bs-stepper-circle { background-color: var(--bs-primary); }
|
||||
|
||||
/* mode selection card */
|
||||
.mode-card { cursor: pointer; border: 2px solid transparent !important; transition: border-color .15s; }
|
||||
.mode-card.selected { border-color: var(--bs-primary) !important; }
|
||||
.mode-card:hover { border-color: var(--bs-primary) !important; opacity: .85; }
|
||||
</style>
|
||||
@endpush
|
||||
|
||||
@section('breadcrumb')
|
||||
@php
|
||||
$breadcrumbItems = [
|
||||
['label' => 'Infrastructure'],
|
||||
['label' => 'vCenter Manager', 'active' => true],
|
||||
];
|
||||
@endphp
|
||||
<x-admin-breadcrumb :items="$breadcrumbItems" />
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
@if (auth()->guard('admins')->user()->can('manager package module'))
|
||||
|
||||
<div id="vcenter-manager">
|
||||
|
||||
{{-- ═══════ LEFT TREE (AimaraJS) ═══════ --}}
|
||||
<div id="tree-panel">
|
||||
<div class="tree-header d-flex justify-content-between align-items-center">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<i data-lucide="network"></i>
|
||||
Navigator
|
||||
</div>
|
||||
<button class="btn btn-sm btn-primary p-0 px-1"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#wizardModal"
|
||||
title="Thêm mới Infrastructure">
|
||||
<i data-lucide="plus" style="width:14px;height:14px"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div id="tree-body"></div>
|
||||
</div>
|
||||
|
||||
{{-- ═══════ RIGHT DETAIL ═══════ --}}
|
||||
<div id="detail-panel">
|
||||
<div id="detail-toolbar">
|
||||
<span id="detail-breadcrumb" class="text-muted">
|
||||
Select an item from the tree
|
||||
</span>
|
||||
</div>
|
||||
<div id="detail-content">
|
||||
<div class="detail-empty">
|
||||
<i data-lucide="monitor-dot"></i>
|
||||
<span class="small">Select an item from the tree to view details</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@else
|
||||
<div class="alert alert-danger d-flex align-items-center gap-2">
|
||||
<i data-lucide="shield-off"></i>
|
||||
Access Denied — You are not assigned to any Module Package management department.
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- ═══════ WIZARD MODAL (Bootstrap Modal + bs-stepper) ═══════ --}}
|
||||
<div class="modal fade" id="wizardModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i data-lucide="plus-circle" class="me-2" style="width:18px;height:18px"></i>
|
||||
Thêm mới Infrastructure
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body p-0">
|
||||
{{-- bs-stepper --}}
|
||||
<div id="addInfraWizard" class="bs-stepper">
|
||||
<div class="bs-stepper-header" role="tablist">
|
||||
<div class="step" data-target="#step-vcenter">
|
||||
<button type="button" class="step-trigger" role="tab"
|
||||
aria-controls="step-vcenter" id="step-vcenter-trigger">
|
||||
<span class="bs-stepper-circle">1</span>
|
||||
<span class="bs-stepper-label">vCenter</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="line"></div>
|
||||
<div class="step" data-target="#step-dc-host">
|
||||
<button type="button" class="step-trigger" role="tab"
|
||||
aria-controls="step-dc-host" id="step-dc-host-trigger">
|
||||
<span class="bs-stepper-circle">2</span>
|
||||
<span class="bs-stepper-label">DC / Host</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="line"></div>
|
||||
<div class="step" data-target="#step-ds-nw">
|
||||
<button type="button" class="step-trigger" role="tab"
|
||||
aria-controls="step-ds-nw" id="step-ds-nw-trigger">
|
||||
<span class="bs-stepper-circle">3</span>
|
||||
<span class="bs-stepper-label">DS / Network</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bs-stepper-content">
|
||||
{{-- Step 1: vCenter --}}
|
||||
<div id="step-vcenter" class="content fade" role="tabpanel"
|
||||
aria-labelledby="step-vcenter-trigger">
|
||||
<div class="text-center mb-4">
|
||||
<i data-lucide="cloud" class="text-primary" style="width:40px;height:40px"></i>
|
||||
<h6 class="mt-2 mb-0">Chọn vCenter</h6>
|
||||
</div>
|
||||
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-6">
|
||||
<div class="card h-100 text-center p-4 mode-card"
|
||||
data-wiz-mode="create" data-wiz-section="wvc-create-section">
|
||||
<i data-lucide="plus-circle" class="text-primary mb-2" style="width:28px;height:28px"></i>
|
||||
<h6 class="mb-0">Tạo mới</h6>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="card h-100 text-center p-4 mode-card"
|
||||
data-wiz-mode="existing" data-wiz-section="wvc-existing-section">
|
||||
<i data-lucide="server" class="text-secondary mb-2" style="width:28px;height:28px"></i>
|
||||
<h6 class="mb-0">vCenter có sẵn</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wvc-create-section" class="d-none mt-3">
|
||||
<h6 class="mb-3">Tạo vCenter mới</h6>
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Host / IP *</label>
|
||||
<input type="text" class="form-control" id="wvc-host" placeholder="vcsa.thegioiso.com">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Username *</label>
|
||||
<input type="text" class="form-control" id="wvc-user" placeholder="administrator@vsphere.local">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Password *</label>
|
||||
<input type="password" class="form-control" id="wvc-password">
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<label class="form-label">Trạng thái</label>
|
||||
<select class="form-select" id="wvc-status">
|
||||
<option value="1">Hoạt động</option>
|
||||
<option value="0">Không hoạt động</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wvc-existing-section" class="d-none mt-3">
|
||||
<h6 class="mb-3">Chọn vCenter có sẵn</h6>
|
||||
<label class="form-label">vCenter Server</label>
|
||||
<select class="form-select" id="wvc-select">
|
||||
<option value="">-- Chọn vCenter --</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Step 2: Datacenter & Host --}}
|
||||
<div id="step-dc-host" class="content fade" role="tabpanel"
|
||||
aria-labelledby="step-dc-host-trigger">
|
||||
<div class="text-center mb-4">
|
||||
<i data-lucide="database" class="text-warning" style="width:40px;height:40px"></i>
|
||||
<h6 class="mt-2 mb-0">Thêm Datacenter & Host</h6>
|
||||
</div>
|
||||
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-6">
|
||||
<div class="card h-100 text-center p-4 mode-card"
|
||||
data-wiz-submode="manual" data-wiz-section="wdc-manual-section">
|
||||
<i data-lucide="edit-3" class="text-info mb-2" style="width:28px;height:28px"></i>
|
||||
<h6 class="mb-0">Nhập thủ công</h6>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="card h-100 text-center p-4 mode-card"
|
||||
data-wiz-submode="sync" data-wiz-section="wdc-sync-section">
|
||||
<i data-lucide="refresh-cw" class="text-success mb-2" style="width:28px;height:28px"></i>
|
||||
<h6 class="mb-0">Sync từ vSphere</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wdc-manual-section" class="d-none mt-3">
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Tên Datacenter *</label>
|
||||
<input type="text" class="form-control" id="wdc-name" placeholder="DC1">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Datacenter ID *</label>
|
||||
<input type="text" class="form-control" id="wdc-id" placeholder="datacenter-1">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Tên Host *</label>
|
||||
<input type="text" class="form-control" id="whost-name" placeholder="esxi-01">
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<label class="form-label">Host ID *</label>
|
||||
<input type="text" class="form-control" id="whost-id" placeholder="host-1">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wdc-sync-section" class="d-none mt-3">
|
||||
<div id="wdc-sync-loading" class="text-center py-2 d-none">
|
||||
<div class="spinner-border spinner-border-sm text-primary"></div>
|
||||
<span class="ms-2 small">Đang tải...</span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Datacenter</label>
|
||||
<select class="form-select" id="wdc-sync-select">
|
||||
<option value="">-- Chọn Datacenter --</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="whost-sync-wrap" class="d-none">
|
||||
<label class="form-label">Host</label>
|
||||
<select class="form-select" id="whost-sync-select">
|
||||
<option value="">-- Chọn Host --</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Step 3: Datastore & Network --}}
|
||||
<div id="step-ds-nw" class="content fade" role="tabpanel"
|
||||
aria-labelledby="step-ds-nw-trigger">
|
||||
<div class="text-center mb-4">
|
||||
<i data-lucide="hard-drive" class="text-success" style="width:40px;height:40px"></i>
|
||||
<h6 class="mt-2 mb-0">Chọn Datastore & Network</h6>
|
||||
</div>
|
||||
|
||||
<div id="wds-loading" class="text-center py-3 d-none">
|
||||
<div class="spinner-border spinner-border-sm text-primary"></div>
|
||||
<span class="ms-2 small">Đang tải...</span>
|
||||
</div>
|
||||
|
||||
<div id="wds-content" class="row">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-semibold">
|
||||
<i data-lucide="database" class="me-1" style="width:13px;height:13px"></i>
|
||||
Datastores
|
||||
</label>
|
||||
<div class="border rounded" id="wds-list"
|
||||
style="max-height:200px;overflow-y:auto">
|
||||
<div class="p-3 text-muted small">Chưa có dữ liệu</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small fw-semibold">
|
||||
<i data-lucide="network" class="me-1" style="width:13px;height:13px"></i>
|
||||
Networks
|
||||
</label>
|
||||
<div class="border rounded" id="wnw-list"
|
||||
style="max-height:200px;overflow-y:auto">
|
||||
<div class="p-3 text-muted small">Chưa có dữ liệu</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>{{-- /.bs-stepper-content --}}
|
||||
</div>{{-- /#addInfraWizard --}}
|
||||
</div>{{-- /.modal-body --}}
|
||||
|
||||
<div class="modal-footer" id="wizardFooter">
|
||||
<div id="wiz-error" class="alert alert-danger py-1 px-3 small me-auto mb-0 d-none"></div>
|
||||
<button type="button" id="btn-wiz-prev" class="btn btn-secondary d-none">
|
||||
<i data-lucide="chevron-left" style="width:15px;height:15px"></i> Quay lại
|
||||
</button>
|
||||
<button type="button" id="btn-wiz-next" class="btn btn-primary">
|
||||
Tiếp theo <i data-lucide="chevron-right" style="width:15px;height:15px"></i>
|
||||
</button>
|
||||
<button type="button" id="btn-wiz-save" class="btn btn-success d-none">
|
||||
<i data-lucide="check" style="width:15px;height:15px"></i> Lưu
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('plugin-scripts')
|
||||
@foreach (config('assets.datatable.js') as $js)
|
||||
<script src="{{ asset($js) }}"></script>
|
||||
@endforeach
|
||||
{{-- AimaraJS --}}
|
||||
<script src="https://cdn.jsdelivr.net/gh/rafaelthca/aimaraJS@master/lib/Aimara.js"></script>
|
||||
{{-- bs-stepper --}}
|
||||
<script src="https://cdn.jsdelivr.net/npm/bs-stepper/dist/js/bs-stepper.min.js"></script>
|
||||
|
||||
<script>
|
||||
/* ════════════════════════════════════════════════════════
|
||||
Constants
|
||||
════════════════════════════════════════════════════════ */
|
||||
const CSRF = document.querySelector('meta[name="_token"]').content;
|
||||
const ROUTE_CHILDREN = @json(route('vcenter.manager.tree.children'));
|
||||
const ROUTE_DETAIL = @json(route('vcenter.manager.tree.detail'));
|
||||
const ROUTE_VM_TABLE = @json(route('vcenter.manager.vm.datatable'));
|
||||
const WIZ_ROUTES = {
|
||||
vcenters : @json(route('vcenter.manager.wizard.vcenters')),
|
||||
vcenterStore : @json(route('vcenter.manager.wizard.vcenter.store')),
|
||||
datacenters : @json(route('vcenter.manager.wizard.datacenters')),
|
||||
hosts : @json(route('vcenter.manager.wizard.hosts')),
|
||||
datastoreNetwork: @json(route('vcenter.manager.wizard.datastore-network')),
|
||||
save : @json(route('vcenter.manager.wizard.save')),
|
||||
};
|
||||
|
||||
/* ════════════════════════════════════════════════════════
|
||||
Helpers
|
||||
════════════════════════════════════════════════════════ */
|
||||
function reloadIcons(el) {
|
||||
if (window.lucide) lucide.createIcons({ nameAttr: 'data-lucide', nodes: el ? [el] : undefined });
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════════
|
||||
AimaraJS Tree
|
||||
════════════════════════════════════════════════════════ */
|
||||
let tree = null;
|
||||
let vmTable = null;
|
||||
|
||||
function initTree() {
|
||||
tree = createTree('tree-body', '', null);
|
||||
|
||||
/* ── override selectNode to load detail panel ── */
|
||||
const _origSelect = tree.selectNode.bind(tree);
|
||||
tree.selectNode = function (node) {
|
||||
_origSelect(node);
|
||||
if (!node || !node.tag || node.tag.type === '_placeholder_') return;
|
||||
const labels = {
|
||||
vcenter: 'vCenter', datacenter: 'Datacenter',
|
||||
host: 'Host', datastore: 'Datastore', network: 'Network',
|
||||
};
|
||||
document.getElementById('detail-breadcrumb').textContent =
|
||||
(labels[node.tag.type] ?? node.tag.type) + ': ' + node.text;
|
||||
loadDetail(node.tag.type, node.tag.id);
|
||||
};
|
||||
|
||||
/* ── lazy-load children after node is opened ── */
|
||||
tree.nodeAfterOpenEvent = function (node) {
|
||||
if (!node || !node.tag || node.tag.loaded || node.tag.type === '_placeholder_') return;
|
||||
node.tag.loaded = true;
|
||||
|
||||
fetch(`${ROUTE_CHILDREN}?type=${node.tag.type}&id=${node.tag.id}`, {
|
||||
headers: { 'X-CSRF-TOKEN': CSRF, 'Accept': 'application/json' },
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(nodes => {
|
||||
node.removeChildNodes();
|
||||
if (!nodes.length) {
|
||||
tree.createNode('(trống)', false, null, node, { type: '_placeholder_' }, null);
|
||||
return;
|
||||
}
|
||||
nodes.forEach(child => {
|
||||
const childNode = tree.createNode(
|
||||
child.name, false, null, node,
|
||||
{ type: child.type, id: child.id, loaded: !child.has_children, hasChildren: child.has_children },
|
||||
null
|
||||
);
|
||||
if (child.has_children) {
|
||||
tree.createNode('Đang tải...', false, null, childNode, { type: '_placeholder_' }, null);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
node.removeChildNodes();
|
||||
tree.createNode('Lỗi tải dữ liệu', false, null, node, { type: '_placeholder_' }, null);
|
||||
});
|
||||
};
|
||||
|
||||
/* ── build initial tree from PHP data ── */
|
||||
@forelse($vcenters as $vc)
|
||||
(function () {
|
||||
const vcNode = tree.createNode(
|
||||
@json($vc->host),
|
||||
false, null, null,
|
||||
{ type: 'vcenter', id: {{ $vc->id }}, loaded: true },
|
||||
null
|
||||
);
|
||||
@foreach($vc->datacenters as $dc)
|
||||
(function () {
|
||||
const dcNode = tree.createNode(
|
||||
@json($dc->name),
|
||||
false, null, vcNode,
|
||||
{ type: 'datacenter', id: {{ $dc->id }}, loaded: false, hasChildren: true },
|
||||
null
|
||||
);
|
||||
tree.createNode('Đang tải...', false, null, dcNode, { type: '_placeholder_' }, null);
|
||||
})();
|
||||
@endforeach
|
||||
})();
|
||||
@empty
|
||||
@endforelse
|
||||
|
||||
tree.drawTree();
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════════
|
||||
Detail Panel
|
||||
════════════════════════════════════════════════════════ */
|
||||
function loadDetail(type, id) {
|
||||
const content = document.getElementById('detail-content');
|
||||
content.innerHTML = `
|
||||
<div style="height:180px;display:flex;align-items:center;justify-content:center">
|
||||
<div class="spinner-border text-primary" style="width:1.8rem;height:1.8rem"></div>
|
||||
</div>`;
|
||||
|
||||
if (vmTable) { vmTable.destroy(); vmTable = null; }
|
||||
|
||||
fetch(`${ROUTE_DETAIL}?type=${type}&id=${id}`, {
|
||||
headers: { 'X-CSRF-TOKEN': CSRF, 'Accept': 'application/json' },
|
||||
})
|
||||
.then(r => { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json(); })
|
||||
.then(data => {
|
||||
content.innerHTML = data.html;
|
||||
reloadIcons(content);
|
||||
|
||||
const activeVmTab = content.querySelector('#tab-vms.active.show');
|
||||
if (activeVmTab) initVmTable(type, id);
|
||||
|
||||
content.querySelectorAll('[data-bs-toggle="tab"]').forEach(tab => {
|
||||
tab.addEventListener('shown.bs.tab', e => {
|
||||
if (e.target.getAttribute('data-bs-target') === '#tab-vms') {
|
||||
initVmTable(type, id, true);
|
||||
}
|
||||
vmTable?.columns.adjust();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
content.innerHTML = `<div class="alert alert-danger">Lỗi tải: ${err.message}</div>`;
|
||||
});
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════════
|
||||
VM DataTable
|
||||
════════════════════════════════════════════════════════ */
|
||||
function initVmTable(scopeType, scopeId, force = false) {
|
||||
const el = document.getElementById('vm-datatable');
|
||||
if (!el) return;
|
||||
if (vmTable && !force) return;
|
||||
if (vmTable) { vmTable.destroy(); vmTable = null; }
|
||||
|
||||
vmTable = $('#vm-datatable').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url : ROUTE_VM_TABLE,
|
||||
data: d => { d.scope_type = scopeType; d.scope_id = scopeId; },
|
||||
},
|
||||
columns: [
|
||||
{ data: 'name', title: 'VM Name' },
|
||||
{ data: 'customer_name',title: 'Khách hàng' },
|
||||
{ data: 'ip_address', title: 'IP Address' },
|
||||
{ data: 'vcenter_host', title: 'vCenter' },
|
||||
{ data: 'os_name', title: 'OS' },
|
||||
{ data: 'status_badge', title: 'Trạng thái', orderable: false, searchable: false },
|
||||
],
|
||||
pageLength: 10,
|
||||
language: { processing: 'Đang tải…' },
|
||||
});
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════════
|
||||
Wizard (bs-stepper + Bootstrap Modal)
|
||||
════════════════════════════════════════════════════════ */
|
||||
let wStepper = null;
|
||||
let wStepIndex = 0;
|
||||
let wMode = '';
|
||||
let wSubMode = '';
|
||||
let wSelectedVcenterId = '';
|
||||
let wVcenters = [];
|
||||
let wDatacenters = [];
|
||||
let wSelectedDatacenterId = '';
|
||||
let wHosts = [];
|
||||
let wDatastores = [];
|
||||
let wNetworks = [];
|
||||
let wSelectedDs = []; /* indices */
|
||||
let wSelectedNw = []; /* indices */
|
||||
let wManualDc = {};
|
||||
let wManualHost = {};
|
||||
|
||||
/* ── error helper ── */
|
||||
function wizError(msg) {
|
||||
const el = document.getElementById('wiz-error');
|
||||
if (msg) { el.textContent = msg; el.classList.remove('d-none'); }
|
||||
else el.classList.add('d-none');
|
||||
}
|
||||
|
||||
/* ── footer buttons visibility ── */
|
||||
function wizUpdateFooter() {
|
||||
document.getElementById('btn-wiz-prev').classList.toggle('d-none', wStepIndex === 0);
|
||||
document.getElementById('btn-wiz-next').classList.toggle('d-none', wStepIndex === 2);
|
||||
document.getElementById('btn-wiz-save').classList.toggle('d-none', wStepIndex !== 2);
|
||||
}
|
||||
|
||||
/* ── reset all wizard state ── */
|
||||
function wizReset() {
|
||||
wMode = ''; wSubMode = '';
|
||||
wSelectedVcenterId = ''; wVcenters = [];
|
||||
wDatacenters = []; wSelectedDatacenterId = '';
|
||||
wHosts = []; wDatastores = []; wNetworks = [];
|
||||
wSelectedDs = []; wSelectedNw = [];
|
||||
wManualDc = {}; wManualHost = {};
|
||||
wizError('');
|
||||
|
||||
/* reset form fields */
|
||||
document.querySelectorAll('#addInfraWizard input').forEach(el => {
|
||||
el.type === 'checkbox' ? (el.checked = false) : (el.value = '');
|
||||
});
|
||||
document.querySelectorAll('#addInfraWizard select').forEach(el => { el.selectedIndex = 0; });
|
||||
document.querySelectorAll('#addInfraWizard .mode-card').forEach(c => c.classList.remove('selected'));
|
||||
document.querySelectorAll('#wvc-create-section,#wvc-existing-section,#wdc-manual-section,#wdc-sync-section')
|
||||
.forEach(s => s.classList.add('d-none'));
|
||||
document.getElementById('whost-sync-wrap').classList.add('d-none');
|
||||
document.getElementById('wds-list').innerHTML = '<div class="p-3 text-muted small">Chưa có dữ liệu</div>';
|
||||
document.getElementById('wnw-list').innerHTML = '<div class="p-3 text-muted small">Chưa có dữ liệu</div>';
|
||||
}
|
||||
|
||||
/* ── Step 1: load vcenters into select ── */
|
||||
async function wizLoadVcenters() {
|
||||
try {
|
||||
const res = await fetch(WIZ_ROUTES.vcenters, { headers: { 'X-CSRF-TOKEN': CSRF } });
|
||||
wVcenters = await res.json();
|
||||
const sel = document.getElementById('wvc-select');
|
||||
sel.innerHTML = '<option value="">-- Chọn vCenter --</option>';
|
||||
wVcenters.forEach(vc => {
|
||||
const o = new Option(vc.host + ' (' + vc.user + ')', vc.id);
|
||||
sel.appendChild(o);
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/* ── Step 2 (sync): load datacenters ── */
|
||||
async function wizLoadDatacenters() {
|
||||
if (!wSelectedVcenterId) return;
|
||||
document.getElementById('wdc-sync-loading').classList.remove('d-none');
|
||||
wizError('');
|
||||
try {
|
||||
const res = await fetch(WIZ_ROUTES.datacenters + '?vcenter_id=' + wSelectedVcenterId,
|
||||
{ headers: { 'X-CSRF-TOKEN': CSRF } });
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Lỗi');
|
||||
wDatacenters = data;
|
||||
const sel = document.getElementById('wdc-sync-select');
|
||||
sel.innerHTML = '<option value="">-- Chọn Datacenter --</option>';
|
||||
data.forEach(dc => sel.appendChild(new Option(dc.name, dc.datacenter_id)));
|
||||
} catch (e) { wizError(e.message); }
|
||||
document.getElementById('wdc-sync-loading').classList.add('d-none');
|
||||
}
|
||||
|
||||
/* ── Step 2 (sync): load hosts on DC change ── */
|
||||
async function wizLoadHosts() {
|
||||
wSelectedDatacenterId = document.getElementById('wdc-sync-select').value;
|
||||
if (!wSelectedVcenterId || !wSelectedDatacenterId) return;
|
||||
document.getElementById('whost-sync-wrap').classList.add('d-none');
|
||||
wizError('');
|
||||
try {
|
||||
const url = WIZ_ROUTES.hosts + '?vcenter_id=' + wSelectedVcenterId
|
||||
+ '&datacenter_id=' + wSelectedDatacenterId;
|
||||
const res = await fetch(url, { headers: { 'X-CSRF-TOKEN': CSRF } });
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Lỗi');
|
||||
wHosts = data;
|
||||
const sel = document.getElementById('whost-sync-select');
|
||||
sel.innerHTML = '<option value="">-- Chọn Host --</option>';
|
||||
data.forEach(h => sel.appendChild(new Option(h.name, h.host_id)));
|
||||
document.getElementById('whost-sync-wrap').classList.remove('d-none');
|
||||
} catch (e) { wizError(e.message); }
|
||||
}
|
||||
|
||||
/* ── Step 3: load datastores & networks ── */
|
||||
async function wizLoadDsNw() {
|
||||
const hostSel = document.getElementById('whost-sync-select');
|
||||
const hostId = hostSel ? hostSel.value : '';
|
||||
if (!wSelectedVcenterId || !hostId) return;
|
||||
|
||||
document.getElementById('wds-loading').classList.remove('d-none');
|
||||
document.getElementById('wds-content').classList.add('d-none');
|
||||
wizError('');
|
||||
try {
|
||||
const url = WIZ_ROUTES.datastoreNetwork + '?vcenter_id=' + wSelectedVcenterId
|
||||
+ '&host_id=' + hostId;
|
||||
const res = await fetch(url, { headers: { 'X-CSRF-TOKEN': CSRF } });
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Lỗi');
|
||||
wDatastores = data.datastores || [];
|
||||
wNetworks = data.networks || [];
|
||||
renderDsNwCheckboxes();
|
||||
} catch (e) { wizError(e.message); }
|
||||
document.getElementById('wds-loading').classList.add('d-none');
|
||||
document.getElementById('wds-content').classList.remove('d-none');
|
||||
reloadIcons(document.getElementById('wds-content'));
|
||||
}
|
||||
|
||||
function renderDsNwCheckboxes() {
|
||||
const mkList = (items, prefix) => items.length
|
||||
? items.map((it, i) => `
|
||||
<div class="form-check px-3 py-1 border-bottom">
|
||||
<input class="form-check-input" type="checkbox" id="${prefix}${i}" value="${i}"
|
||||
onchange="toggleCheck(${i},'${prefix}')">
|
||||
<label class="form-check-label small" for="${prefix}${i}">${it.name} (${it.type})</label>
|
||||
</div>`).join('')
|
||||
: '<div class="p-3 text-muted small">Không có dữ liệu</div>';
|
||||
|
||||
document.getElementById('wds-list').innerHTML = mkList(wDatastores, 'wds-');
|
||||
document.getElementById('wnw-list').innerHTML = mkList(wNetworks, 'wnw-');
|
||||
}
|
||||
|
||||
function toggleCheck(i, prefix) {
|
||||
const target = prefix === 'wds-' ? wSelectedDs : wSelectedNw;
|
||||
const idx = target.indexOf(i);
|
||||
idx >= 0 ? target.splice(idx, 1) : target.push(i);
|
||||
}
|
||||
|
||||
/* ── Next step handler (with validation) ── */
|
||||
async function wizNext() {
|
||||
wizError('');
|
||||
|
||||
/* ── Step 1 validation ── */
|
||||
if (wStepIndex === 0) {
|
||||
if (!wMode) { wizError('Vui lòng chọn phương thức'); return; }
|
||||
|
||||
if (wMode === 'create') {
|
||||
const host = document.getElementById('wvc-host').value.trim();
|
||||
const user = document.getElementById('wvc-user').value.trim();
|
||||
const pass = document.getElementById('wvc-password').value;
|
||||
if (!host || !user || !pass) { wizError('Vui lòng nhập đầy đủ thông tin vCenter'); return; }
|
||||
try {
|
||||
document.getElementById('btn-wiz-next').disabled = true;
|
||||
const res = await fetch(WIZ_ROUTES.vcenterStore, {
|
||||
method: 'POST',
|
||||
headers: { 'X-CSRF-TOKEN': CSRF, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
host, user, password: pass,
|
||||
status: document.getElementById('wvc-status').value,
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Lỗi');
|
||||
wSelectedVcenterId = data.vcenter.id;
|
||||
wVcenters.push(data.vcenter);
|
||||
} catch (e) {
|
||||
wizError(e.message);
|
||||
document.getElementById('btn-wiz-next').disabled = false;
|
||||
return;
|
||||
}
|
||||
document.getElementById('btn-wiz-next').disabled = false;
|
||||
} else {
|
||||
wSelectedVcenterId = document.getElementById('wvc-select').value;
|
||||
if (!wSelectedVcenterId) { wizError('Vui lòng chọn vCenter'); return; }
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Step 2 validation ── */
|
||||
if (wStepIndex === 1) {
|
||||
if (!wSubMode) { wizError('Vui lòng chọn phương thức'); return; }
|
||||
|
||||
if (wSubMode === 'manual') {
|
||||
wManualDc.name = document.getElementById('wdc-name').value.trim();
|
||||
wManualDc.datacenter_id = document.getElementById('wdc-id').value.trim();
|
||||
wManualHost.name = document.getElementById('whost-name').value.trim();
|
||||
wManualHost.host_id = document.getElementById('whost-id').value.trim();
|
||||
if (!wManualDc.name || !wManualDc.datacenter_id || !wManualHost.name || !wManualHost.host_id) {
|
||||
wizError('Vui lòng nhập đầy đủ thông tin'); return;
|
||||
}
|
||||
} else {
|
||||
wSelectedDatacenterId = document.getElementById('wdc-sync-select').value;
|
||||
const hostId = document.getElementById('whost-sync-select').value;
|
||||
if (!wSelectedDatacenterId || !hostId) {
|
||||
wizError('Vui lòng chọn Datacenter và Host'); return;
|
||||
}
|
||||
await wizLoadDsNw();
|
||||
}
|
||||
}
|
||||
|
||||
wStepper.next();
|
||||
}
|
||||
|
||||
/* ── Save handler ── */
|
||||
async function wizSave() {
|
||||
wizError('');
|
||||
document.getElementById('btn-wiz-save').disabled = true;
|
||||
|
||||
let datacenter, host, datastores, networks;
|
||||
if (wSubMode === 'manual') {
|
||||
datacenter = wManualDc;
|
||||
host = wManualHost;
|
||||
datastores = [];
|
||||
networks = [];
|
||||
} else {
|
||||
datacenter = wDatacenters.find(d => d.datacenter_id == wSelectedDatacenterId);
|
||||
host = wHosts.find(h => h.host_id == document.getElementById('whost-sync-select').value);
|
||||
datastores = wSelectedDs.map(i => wDatastores[i]);
|
||||
networks = wSelectedNw.map(i => wNetworks[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(WIZ_ROUTES.save, {
|
||||
method: 'POST',
|
||||
headers: { 'X-CSRF-TOKEN': CSRF, 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ vcenter_id: wSelectedVcenterId, datacenter, host, datastores, networks }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Lỗi');
|
||||
bootstrap.Modal.getInstance(document.getElementById('wizardModal')).hide();
|
||||
location.reload();
|
||||
} catch (e) {
|
||||
wizError(e.message);
|
||||
document.getElementById('btn-wiz-save').disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── wizard: mode-card click listeners ── */
|
||||
function initModeCards() {
|
||||
/* Step 1 cards */
|
||||
document.querySelectorAll('#step-vcenter .mode-card').forEach(card => {
|
||||
card.addEventListener('click', function () {
|
||||
wMode = this.dataset.wizMode;
|
||||
document.querySelectorAll('#step-vcenter .mode-card').forEach(c => c.classList.remove('selected'));
|
||||
document.querySelectorAll('#wvc-create-section,#wvc-existing-section')
|
||||
.forEach(s => s.classList.add('d-none'));
|
||||
this.classList.add('selected');
|
||||
document.getElementById(this.dataset.wizSection).classList.remove('d-none');
|
||||
reloadIcons(document.getElementById(this.dataset.wizSection));
|
||||
});
|
||||
});
|
||||
|
||||
/* Step 2 cards */
|
||||
document.querySelectorAll('#step-dc-host .mode-card').forEach(card => {
|
||||
card.addEventListener('click', function () {
|
||||
wSubMode = this.dataset.wizSubmode;
|
||||
document.querySelectorAll('#step-dc-host .mode-card').forEach(c => c.classList.remove('selected'));
|
||||
document.querySelectorAll('#wdc-manual-section,#wdc-sync-section')
|
||||
.forEach(s => s.classList.add('d-none'));
|
||||
this.classList.add('selected');
|
||||
document.getElementById(this.dataset.wizSection).classList.remove('d-none');
|
||||
if (wSubMode === 'sync') wizLoadDatacenters();
|
||||
});
|
||||
});
|
||||
|
||||
/* dc select change → load hosts */
|
||||
document.getElementById('wdc-sync-select')
|
||||
.addEventListener('change', wizLoadHosts);
|
||||
}
|
||||
|
||||
/* ── wizard: modal events ── */
|
||||
document.getElementById('wizardModal').addEventListener('show.bs.modal', () => {
|
||||
if (!wStepper) {
|
||||
wStepper = new Stepper(document.getElementById('addInfraWizard'), {
|
||||
linear: false,
|
||||
animation: true,
|
||||
});
|
||||
}
|
||||
wizReset();
|
||||
wStepper.to(1);
|
||||
wStepIndex = 0;
|
||||
wizUpdateFooter();
|
||||
wizLoadVcenters();
|
||||
reloadIcons(document.getElementById('addInfraWizard'));
|
||||
});
|
||||
|
||||
document.getElementById('addInfraWizard').addEventListener('show.bs-stepper', e => {
|
||||
wStepIndex = e.detail.indexStep;
|
||||
wizUpdateFooter();
|
||||
wizError('');
|
||||
});
|
||||
|
||||
document.getElementById('btn-wiz-prev').addEventListener('click', () => { wizError(''); wStepper.previous(); });
|
||||
document.getElementById('btn-wiz-next').addEventListener('click', wizNext);
|
||||
document.getElementById('btn-wiz-save').addEventListener('click', wizSave);
|
||||
|
||||
/* ════════════════════════════════════════════════════════
|
||||
Init
|
||||
════════════════════════════════════════════════════════ */
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initTree();
|
||||
initModeCards();
|
||||
reloadIcons();
|
||||
});
|
||||
|
||||
/* spin keyframe for any spinner svg */
|
||||
const _style = document.createElement('style');
|
||||
_style.textContent = '@keyframes spin { to { transform: rotate(360deg); } }';
|
||||
document.head.appendChild(_style);
|
||||
</script>
|
||||
@endpush
|
||||
@@ -0,0 +1,84 @@
|
||||
{{-- Detail: Datacenter --}}
|
||||
<div class="node-header">
|
||||
<div class="node-avatar bg-warning bg-opacity-10">
|
||||
<i data-lucide="database" class="text-warning"></i>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<p class="node-title">{{ $item->name }}</p>
|
||||
<p class="node-sub">Datacenter · ID: <code>{{ $item->datacenter_id }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-strip">
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-info">{{ $hosts->count() }}</span>
|
||||
<span class="stat-lbl">Hosts</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-secondary">{{ $folders->count() }}</span>
|
||||
<span class="stat-lbl">Folders</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#tab-hosts">
|
||||
<i data-lucide="server" style="width:14px;height:14px"></i>
|
||||
Hosts ({{ $hosts->count() }})
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tab-folders">
|
||||
<i data-lucide="folder" style="width:14px;height:14px"></i>
|
||||
Folders ({{ $folders->count() }})
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tab-vms">
|
||||
<i data-lucide="monitor" style="width:14px;height:14px"></i>
|
||||
Virtual Machines
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content border border-top-0 rounded-bottom p-3">
|
||||
{{-- Hosts tab --}}
|
||||
<div class="tab-pane fade show active" id="tab-hosts">
|
||||
@forelse ($hosts as $host)
|
||||
<div class="d-flex align-items-center gap-3 py-2 border-bottom">
|
||||
<i data-lucide="server" style="width:16px;height:16px" class="text-info flex-shrink-0"></i>
|
||||
<div class="flex-1">
|
||||
<div class="fw-semibold">{{ $host->name }}</div>
|
||||
<small class="text-muted">
|
||||
{{ $host->datastore_count ?? 0 }} Datastores ·
|
||||
{{ $host->network_count ?? 0 }} Networks
|
||||
@if ($host->template) · <span class="badge bg-secondary">Template</span> @endif
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-muted mb-0">No hosts configured in this datacenter.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
{{-- Folders tab --}}
|
||||
<div class="tab-pane fade" id="tab-folders">
|
||||
@forelse ($folders as $folder)
|
||||
<div class="d-flex align-items-center gap-3 py-2 border-bottom">
|
||||
<i data-lucide="folder" style="width:16px;height:16px" class="text-secondary flex-shrink-0"></i>
|
||||
<div class="flex-1">
|
||||
<div class="fw-semibold">{{ $folder->name }}</div>
|
||||
<small class="text-muted font-monospace">{{ $folder->folder }}</small>
|
||||
</div>
|
||||
<span class="badge bg-light text-dark border">{{ $folder->type }}</span>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-muted mb-0">No folders in this datacenter.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
{{-- VMs tab --}}
|
||||
<div class="tab-pane fade" id="tab-vms">
|
||||
<table id="vm-datatable" class="table table-sm table-hover w-100"></table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
{{-- Detail: Datastore --}}
|
||||
<div class="node-header">
|
||||
<div class="node-avatar bg-success bg-opacity-10">
|
||||
<i data-lucide="hard-drive" class="text-success"></i>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<p class="node-title">{{ $item->name }}</p>
|
||||
<p class="node-sub">Datastore · <code>{{ $item->datastore }}</code></p>
|
||||
</div>
|
||||
<div>{!! $item->status == 1 ? '<span class="badge bg-success">Active</span>' : '<span class="badge bg-secondary">Inactive</span>' !!}</div>
|
||||
</div>
|
||||
|
||||
<div class="card border shadow-none mb-0">
|
||||
<div class="card-header py-2 small fw-semibold bg-transparent d-flex align-items-center gap-2">
|
||||
<i data-lucide="settings" style="width:14px;height:14px"></i> Properties
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<tbody>
|
||||
<tr><th class="ps-3" style="width:140px">Name</th><td>{{ $item->name }}</td></tr>
|
||||
<tr><th class="ps-3">Datastore ID</th><td class="font-monospace">{{ $item->datastore }}</td></tr>
|
||||
<tr><th class="ps-3">Type</th><td><span class="badge bg-light text-dark border">{{ $item->type }}</span></td></tr>
|
||||
<tr><th class="ps-3">Allocated Space</th><td>{{ $item->space ? number_format($item->space) . ' GB' : '—' }}</td></tr>
|
||||
<tr><th class="ps-3">Status</th><td>{!! $item->status == 1 ? '<span class="badge bg-success">Active</span>' : '<span class="badge bg-secondary">Inactive</span>' !!}</td></tr>
|
||||
<tr><th class="ps-3">Created</th><td>{{ $item->created_at?->format('d/m/Y H:i') ?? '—' }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,144 @@
|
||||
{{-- Detail: Host --}}
|
||||
<div class="node-header">
|
||||
<div class="node-avatar bg-info bg-opacity-10">
|
||||
<i data-lucide="server" class="text-info"></i>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<p class="node-title">{{ $item->name }}</p>
|
||||
<p class="node-sub">
|
||||
ESXi Host · ID: <code>{{ $item->host_id }}</code>
|
||||
@if ($item->template)
|
||||
<span class="badge bg-secondary ms-1">Template Host</span>
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-strip">
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-success">{{ $datastores->count() }}</span>
|
||||
<span class="stat-lbl">Datastores</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-warning">{{ $networks->count() }}</span>
|
||||
<span class="stat-lbl">Networks</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-primary">{{ $ipTotal }}</span>
|
||||
<span class="stat-lbl">Total IPs</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-success">{{ $ipFree }}</span>
|
||||
<span class="stat-lbl">Free IPs</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-danger">{{ $ipTotal - $ipFree }}</span>
|
||||
<span class="stat-lbl">Used IPs</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#tab-summary">
|
||||
<i data-lucide="info" style="width:14px;height:14px"></i>
|
||||
Summary
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tab-datastores">
|
||||
<i data-lucide="hard-drive" style="width:14px;height:14px"></i>
|
||||
Datastores ({{ $datastores->count() }})
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tab-networks">
|
||||
<i data-lucide="network" style="width:14px;height:14px"></i>
|
||||
Networks ({{ $networks->count() }})
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#tab-vms">
|
||||
<i data-lucide="monitor" style="width:14px;height:14px"></i>
|
||||
Virtual Machines
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content border border-top-0 rounded-bottom p-3">
|
||||
|
||||
{{-- Summary tab --}}
|
||||
<div class="tab-pane fade show active" id="tab-summary">
|
||||
<div class="card border shadow-none mb-0">
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<tbody>
|
||||
<tr><th class="ps-3" style="width:140px">Host ID</th><td class="font-monospace">{{ $item->host_id }}</td></tr>
|
||||
<tr><th class="ps-3">Console</th><td>{{ $item->console ?? '—' }}</td></tr>
|
||||
<tr><th class="ps-3">ISO Path</th><td class="font-monospace small">{{ $item->iso_path ?? '—' }}</td></tr>
|
||||
<tr><th class="ps-3">Template Host</th><td>{{ $item->template ? 'Yes' : 'No' }}</td></tr>
|
||||
<tr><th class="ps-3">Created</th><td>{{ $item->created_at?->format('d/m/Y H:i') ?? '—' }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Datastores tab --}}
|
||||
<div class="tab-pane fade" id="tab-datastores">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Datastore ID</th>
|
||||
<th>Type</th>
|
||||
<th>Space</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($datastores as $ds)
|
||||
<tr>
|
||||
<td class="fw-semibold">{{ $ds->name }}</td>
|
||||
<td class="font-monospace small">{{ $ds->datastore }}</td>
|
||||
<td><span class="badge bg-light text-dark border">{{ $ds->type }}</span></td>
|
||||
<td>{{ $ds->space ? number_format($ds->space) . ' GB' : '—' }}</td>
|
||||
<td>{!! $ds->status == 1 ? '<span class="badge bg-success">Active</span>' : '<span class="badge bg-secondary">Inactive</span>' !!}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="5" class="text-center text-muted">No datastores.</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{{-- Networks tab --}}
|
||||
<div class="tab-pane fade" id="tab-networks">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Network ID</th>
|
||||
<th>Type</th>
|
||||
<th>IPs</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($networks as $net)
|
||||
<tr>
|
||||
<td class="fw-semibold">{{ $net->name }}</td>
|
||||
<td class="font-monospace small">{{ $net->network }}</td>
|
||||
<td><span class="badge bg-light text-dark border">{{ $net->type }}</span></td>
|
||||
<td>{{ $net->ip_addresses_count ?? 0 }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="4" class="text-center text-muted">No networks.</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{{-- VMs tab --}}
|
||||
<div class="tab-pane fade" id="tab-vms">
|
||||
<table id="vm-datatable" class="table table-sm table-hover w-100"></table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,81 @@
|
||||
{{-- Detail: Network --}}
|
||||
<div class="node-header">
|
||||
<div class="node-avatar bg-warning bg-opacity-10">
|
||||
<i data-lucide="network" class="text-warning"></i>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<p class="node-title">{{ $item->name }}</p>
|
||||
<p class="node-sub">Network · <code>{{ $item->network }}</code></p>
|
||||
</div>
|
||||
<div><span class="badge bg-light text-dark border">{{ $item->type }}</span></div>
|
||||
</div>
|
||||
|
||||
@php
|
||||
$total = $ips->count();
|
||||
$free = $ips->where('status', 0)->count();
|
||||
$assigned = $ips->where('status', 1)->count();
|
||||
@endphp
|
||||
|
||||
<div class="stat-strip">
|
||||
<div class="stat-card">
|
||||
<span class="stat-val">{{ $total }}</span>
|
||||
<span class="stat-lbl">Total IPs</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-success">{{ $free }}</span>
|
||||
<span class="stat-lbl">Free</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-danger">{{ $assigned }}</span>
|
||||
<span class="stat-lbl">Assigned</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border shadow-none mb-0">
|
||||
<div class="card-header py-2 fw-semibold small bg-transparent d-flex align-items-center gap-2">
|
||||
<i data-lucide="list" style="width:14px;height:14px"></i>
|
||||
<span>IP Pool</span>
|
||||
@if ($total)
|
||||
<div class="ms-auto" style="width:160px; height:8px; background:var(--bs-secondary-bg); border-radius:4px; overflow:hidden;">
|
||||
<div style="width:{{ round($assigned / $total * 100) }}%; height:100%; background:#dc3545;"></div>
|
||||
</div>
|
||||
<small class="ms-2 text-muted">{{ round($assigned / $total * 100) }}% used</small>
|
||||
@endif
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div style="max-height:400px; overflow-y:auto;">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-light sticky-top">
|
||||
<tr>
|
||||
<th class="ps-3">IP Address</th>
|
||||
<th>Gateway</th>
|
||||
<th>Netmask</th>
|
||||
<th>DNS</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($ips as $ip)
|
||||
<tr>
|
||||
<td class="ps-3 font-monospace fw-semibold">{{ $ip->ip }}</td>
|
||||
<td class="font-monospace small">{{ $ip->gateway ?? '—' }}</td>
|
||||
<td class="font-monospace small">{{ $ip->netmask ?? '—' }}</td>
|
||||
<td class="font-monospace small">{{ $ip->dns ?? '—' }}</td>
|
||||
<td>
|
||||
@if ($ip->status == 0)
|
||||
<span class="badge bg-success">Free</span>
|
||||
@else
|
||||
<span class="badge bg-danger">Assigned</span>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="text-center text-muted py-3">No IP addresses in this network.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,52 @@
|
||||
{{-- Detail: vCenter --}}
|
||||
<div class="node-header">
|
||||
<div class="node-avatar bg-primary bg-opacity-10">
|
||||
<i data-lucide="cloud" class="text-primary"></i>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<p class="node-title">{{ $item->host }}</p>
|
||||
<p class="node-sub">vCenter Server</p>
|
||||
</div>
|
||||
<div>{!! $item->getStatus() !!}</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-strip">
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-warning">{{ $datacenterCount }}</span>
|
||||
<span class="stat-lbl">Datacenters</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-val text-primary">{{ $vmCount }}</span>
|
||||
<span class="stat-lbl">Virtual Machines</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border shadow-none mb-3">
|
||||
<div class="card-header py-2 small fw-semibold bg-transparent d-flex align-items-center gap-2">
|
||||
<i data-lucide="link" style="width:14px;height:14px"></i> Connection
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<tbody>
|
||||
<tr><th class="ps-3" style="width:130px">Host</th><td class="font-monospace">{{ $item->host }}</td></tr>
|
||||
<tr><th class="ps-3">User</th><td class="font-monospace">{{ $item->user }}</td></tr>
|
||||
<tr><th class="ps-3">Status</th><td>{!! $item->getStatus() !!}</td></tr>
|
||||
<tr><th class="ps-3">Created</th><td>{{ $item->created_at?->format('d/m/Y H:i') ?? '—' }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#tab-vms">
|
||||
<i data-lucide="monitor" style="width:14px;height:14px"></i>
|
||||
Virtual Machines
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content border border-top-0 rounded-bottom p-3">
|
||||
<div class="tab-pane fade show active" id="tab-vms">
|
||||
<table id="vm-datatable" class="table table-sm table-hover w-100"></table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -14,6 +14,7 @@ use App\Http\Controllers\admin\ModuleDNSController;
|
||||
use App\Http\Controllers\admin\ModuleHostingController;
|
||||
use App\Http\Controllers\admin\ModuleIPPoolController;
|
||||
use App\Http\Controllers\admin\ModulevCenterController;
|
||||
use App\Http\Controllers\admin\VCenterManagerController;
|
||||
use App\Http\Controllers\admin\OrderController;
|
||||
use App\Http\Controllers\admin\package\Datacenter;
|
||||
use App\Http\Controllers\admin\package\Datastore;
|
||||
@@ -227,6 +228,22 @@ Route::prefix('')->group(function () {
|
||||
Route::delete('remove-server-ip-pool/{id}', 'destroy')->name('module.ippool.destroy');
|
||||
});
|
||||
|
||||
// vCenter Manager — Unified tree view
|
||||
Route::controller(VCenterManagerController::class)->prefix('vcenter-manager')->group(function () {
|
||||
Route::get('/', 'index')->name('vcenter.manager');
|
||||
Route::get('tree/children', 'treeChildren')->name('vcenter.manager.tree.children');
|
||||
Route::get('tree/detail', 'nodeDetail')->name('vcenter.manager.tree.detail');
|
||||
Route::get('vms/datatable', 'vmDatatable')->name('vcenter.manager.vm.datatable');
|
||||
|
||||
// Wizard API
|
||||
Route::get('wizard/vcenters', 'wizardVcenters')->name('vcenter.manager.wizard.vcenters');
|
||||
Route::post('wizard/vcenter', 'wizardStoreVcenter')->name('vcenter.manager.wizard.vcenter.store');
|
||||
Route::get('wizard/datacenters', 'wizardDatacenters')->name('vcenter.manager.wizard.datacenters');
|
||||
Route::get('wizard/hosts', 'wizardHosts')->name('vcenter.manager.wizard.hosts');
|
||||
Route::get('wizard/datastore-network', 'wizardDatastoreNetwork')->name('vcenter.manager.wizard.datastore-network');
|
||||
Route::post('wizard/save', 'wizardSave')->name('vcenter.manager.wizard.save');
|
||||
});
|
||||
|
||||
//Module vCenter Server
|
||||
Route::controller(ModulevCenterController::class)->prefix('vcenter')->group(function () {
|
||||
Route::get('list-all-vcenter', 'index')->name('module.vcenter.index');
|
||||
|
||||
+44
-29
@@ -1,39 +1,17 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Api\Client\ClientController;
|
||||
use App\Http\Controllers\rest\ModuleController;
|
||||
use App\Http\Controllers\Api\Admin\Auth\AuthController;
|
||||
use App\Http\Controllers\Api\Admin\Customer\CustomerController;
|
||||
use App\Http\Controllers\Api\Admin\Invoice\InvoiceController;
|
||||
use App\Http\Controllers\Api\Admin\Order\OrderController;
|
||||
use App\Http\Controllers\Api\Admin\Product\ProductController;
|
||||
use App\Http\Controllers\Api\Admin\VCenter\VCenterController;
|
||||
use App\Http\Services\Media;
|
||||
use App\Http\Services\vCenter as ServiceVCenter;
|
||||
use App\Jobs\Hosting\CreateHostingJobs;
|
||||
use App\Jobs\VirtualMachine\Create\CreateVMJobs;
|
||||
use App\Jobs\VirtualMachine\Upgrade\UpgradeVirtualMachine;
|
||||
use App\Models\Addon;
|
||||
use App\Models\Customer;
|
||||
use App\Models\File;
|
||||
use App\Models\Hosting;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceItem;
|
||||
use App\Models\ModuleDatacenter;
|
||||
use App\Models\ModuleHost;
|
||||
use App\Models\ModuleHosting;
|
||||
use App\Models\ModuleHostingServer;
|
||||
use App\Models\ModuleIpAddress;
|
||||
use App\Models\ModuleSnapshot;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\Os;
|
||||
use App\Models\OsGroup;
|
||||
use App\Models\Type;
|
||||
use App\Models\vCenter;
|
||||
use App\Models\VPS;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -49,6 +27,42 @@ use Illuminate\Support\Str;
|
||||
Route::prefix('v1')
|
||||
/* Api for Admin */
|
||||
->group(function () {
|
||||
Route::prefix('administrator')->group(function () {
|
||||
Route::post('login', [AuthController::class, 'login']);
|
||||
|
||||
Route::middleware('api.auth:admins-api')->group(function () {
|
||||
Route::post('logout', [AuthController::class, 'logout']);
|
||||
Route::post('refresh', [AuthController::class, 'refresh']);
|
||||
Route::get('me', [AuthController::class, 'me']);
|
||||
|
||||
// Customers
|
||||
Route::prefix('customers')->group(function () {
|
||||
Route::get('/', [CustomerController::class, 'index']);
|
||||
});
|
||||
|
||||
// Products
|
||||
Route::prefix('products')->group(function () {
|
||||
Route::get('/', [ProductController::class, 'index']);
|
||||
Route::get('{id}', [ProductController::class, 'show']);
|
||||
});
|
||||
|
||||
// Orders
|
||||
Route::prefix('orders')->group(function () {
|
||||
Route::get('/', [OrderController::class, 'index']);
|
||||
});
|
||||
|
||||
// Invoices
|
||||
Route::prefix('invoices')->group(function () {
|
||||
Route::get('/', [InvoiceController::class, 'index']);
|
||||
});
|
||||
|
||||
// vCenter
|
||||
Route::prefix('vcenter')->group(function () {
|
||||
Route::get('tree', [VCenterController::class, 'tree']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Route::prefix('system')->middleware(['api.auth'])->group(function () {
|
||||
|
||||
Route::post('get-all-image', function (Media $media) {
|
||||
@@ -123,6 +137,7 @@ Route::prefix('v1')
|
||||
})->name('api.GetConsoleTicket');
|
||||
});
|
||||
});
|
||||
|
||||
Route::any('{any}', function () {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
|
||||
Reference in New Issue
Block a user