update optimize code
This commit is contained in:
@@ -1,116 +0,0 @@
|
||||
# Service Views Optimization
|
||||
|
||||
## Overview
|
||||
This module contains optimized service-related views following the established coding rules and best practices.
|
||||
|
||||
## Structure
|
||||
|
||||
### Main Files
|
||||
- `show.blade.php` - Main service detail view (optimized and modularized)
|
||||
- `list-snapshot.blade.php` - Snapshot management component
|
||||
|
||||
### Partials Directory (`partials/`)
|
||||
- `service-header.blade.php` - Service name and status display
|
||||
- `configuration-info.blade.php` - VM configuration details
|
||||
- `transaction-info.blade.php` - Billing and transaction information
|
||||
- `vm-control-panel.blade.php` - VM control interface
|
||||
- `no-vm-info.blade.php` - Error state when VM info is unavailable
|
||||
- `control-notes.blade.php` - User guidance and warnings
|
||||
|
||||
### Control Buttons (`partials/control-buttons/`)
|
||||
- `renewal-button.blade.php` - Service renewal control
|
||||
- `restart-button.blade.php` - VM restart control
|
||||
- `pause-button.blade.php` - VM pause control
|
||||
- `start-button.blade.php` - VM start control
|
||||
- `stop-button.blade.php` - VM stop control
|
||||
- `config-button.blade.php` - Configuration management
|
||||
- `reinstall-button.blade.php` - VM reinstallation
|
||||
- `snapshot-button.blade.php` - Snapshot creation
|
||||
- `console-button.blade.php` - Console access
|
||||
- `reset-password-button.blade.php` - Password reset
|
||||
|
||||
## Optimizations Applied
|
||||
|
||||
### 1. Component Extraction
|
||||
- Separated large monolithic view into reusable components
|
||||
- Each component has a single responsibility
|
||||
- Improved maintainability and reusability
|
||||
|
||||
### 2. Performance Improvements
|
||||
- Pre-computed variables in PHP blocks to reduce template processing
|
||||
- Optimized conditional logic with early returns
|
||||
- Reduced database queries through efficient data access
|
||||
|
||||
### 3. Code Organization
|
||||
- Consistent naming conventions (camelCase for functions)
|
||||
- Proper separation of concerns
|
||||
- Clear component hierarchy
|
||||
|
||||
### 4. Internationalization
|
||||
- All user-facing text wrapped with `__()` helper
|
||||
- Consistent translation keys
|
||||
- Support for multiple languages
|
||||
|
||||
### 5. Caching Strategy
|
||||
- Helper service for frequently accessed data
|
||||
- Optimized data processing in service layer
|
||||
- Reduced template complexity
|
||||
|
||||
### 6. UI/UX Improvements
|
||||
- Clean, minimalistic design following Tailwind CSS
|
||||
- Consistent color scheme and spacing
|
||||
- Responsive design for mobile and desktop
|
||||
- Proper accessibility attributes
|
||||
|
||||
## Helper Service
|
||||
|
||||
### VMHelperService
|
||||
Located at `app/Services/VMHelperService.php`
|
||||
|
||||
**Key Methods:**
|
||||
- `getVmStatusInfo()` - VM status information
|
||||
- `getVmConnectionInfo()` - Connection details (IP, port, user)
|
||||
- `getVmSpecs()` - VM specifications
|
||||
- `formatDate()` - Date formatting
|
||||
- `formatCurrency()` - Currency formatting
|
||||
- `getServiceStatus()` - Service status information
|
||||
|
||||
## Usage Example
|
||||
|
||||
```php
|
||||
// In controller
|
||||
use App\Services\VMHelperService;
|
||||
|
||||
public function show($invoiceId)
|
||||
{
|
||||
$invoice = $this->invoiceRepository->findById($invoiceId);
|
||||
$vmInfo = $this->vmService->getVmInfo($invoice->vm_id);
|
||||
|
||||
// Pre-process data for better performance
|
||||
$vmStatus = VMHelperService::getVmStatusInfo($vmInfo);
|
||||
$connectionInfo = VMHelperService::getVmConnectionInfo($vmInfo, $invoice);
|
||||
|
||||
return view('frontend.service.show', compact('invoice', 'vmInfo', 'vmStatus', 'connectionInfo'));
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Always use partials for reusable components**
|
||||
2. **Pre-compute variables in PHP blocks**
|
||||
3. **Use helper services for complex logic**
|
||||
4. **Implement proper caching strategies**
|
||||
5. **Follow internationalization guidelines**
|
||||
6. **Maintain consistent UI/UX patterns**
|
||||
7. **Use semantic HTML and accessibility features**
|
||||
|
||||
## Cache Keys
|
||||
- `service.vm.info.{vm_id}` - VM information cache
|
||||
- `service.invoice.{invoice_id}` - Invoice data cache
|
||||
- `service.config.{service_id}` - Service configuration cache
|
||||
|
||||
## Dependencies
|
||||
- Laravel Framework
|
||||
- Tailwind CSS
|
||||
- Alpine.js (for interactive components)
|
||||
- SweetAlert (for notifications)
|
||||
@@ -0,0 +1,13 @@
|
||||
<div class="bg-gray-50 hover:bg-gray-100 rounded-lg p-4 text-center cursor-pointer transition-colors duration-200 border border-gray-200 hover:border-green-300"
|
||||
@click="showNotification('{{ __('Chức năng đang phát triển') }}', 'info')">
|
||||
<div class="flex flex-col items-center">
|
||||
<div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mb-3">
|
||||
<svg class="w-6 h-6 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
</div>
|
||||
<span class="text-sm font-medium text-gray-700">{{ __('Cài lại') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,13 +1,29 @@
|
||||
{{-- Restart Button Component --}}
|
||||
<div id="restartVMButton"
|
||||
<div
|
||||
class="bg-gray-50 hover:bg-gray-100 rounded-lg p-4 text-center cursor-pointer transition-colors duration-200 border border-gray-200 hover:border-red-300">
|
||||
<div class="flex flex-col items-center">
|
||||
|
||||
<button x-data
|
||||
@click="
|
||||
fetch('{{ route('service.reboot.vm') }}', {
|
||||
method: 'POST',
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
body: new URLSearchParams({ product_id: '{{ $invoice->vm_id }}' })
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
showNotification(data.message);
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 300);
|
||||
});
|
||||
"
|
||||
class="flex flex-col items-center w-full cursor-pointer">
|
||||
<div class="w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mb-3">
|
||||
<svg class="w-6 h-6 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
</div>
|
||||
<span class="text-sm font-medium text-gray-700">{{ __('Khởi động lại') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{ __('Khởi động lại VM') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,29 @@
|
||||
<div id="startVMButton"
|
||||
class="bg-green-50 hover:bg-green-100 rounded-lg p-4 text-center cursor-pointer transition-colors duration-200 border border-green-200 hover:border-green-400">
|
||||
<div class="flex flex-col items-center justify-center">
|
||||
{{-- Stop Button Component --}}
|
||||
<div
|
||||
class="bg-gray-50 hover:bg-gray-100 rounded-lg p-4 text-center cursor-pointer transition-colors duration-200 border border-gray-200 hover:border-green-300">
|
||||
|
||||
<button x-data
|
||||
@click="
|
||||
fetch('{{ route('service.start.vm') }}', {
|
||||
method: 'POST',
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
body: new URLSearchParams({ product_id: '{{ $invoice->vm_id }}' })
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
showNotification(data.message);
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 300);
|
||||
});
|
||||
"
|
||||
class="flex flex-col items-center w-full cursor-pointer">
|
||||
<div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mb-3">
|
||||
<svg class="w-6 h-6 text-green-600" fill="currentColor" viewBox="0 0 24 24">
|
||||
<path
|
||||
d="M13 3h-2v10h2V3zm4.83 2.17l-1.42 1.42C17.99 7.86 19 9.81 19 12c0 3.87-3.13 7-7 7s-7-3.13-7-7c0-2.19 1.01-4.14 2.58-5.42L6.17 5.17C4.23 6.82 3 9.26 3 12c0 4.97 4.03 9 9 9s9-4.03 9-9c0-2.74-1.23-5.18-3.17-6.83z" />
|
||||
</svg>
|
||||
</div>
|
||||
<span class="font-medium text-green-700">{{ __('Khởi động máy ảo') }}</span>
|
||||
</div>
|
||||
{{ __('Khởi động máy ảo') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,29 @@
|
||||
<div id="stopVMButton"
|
||||
{{-- Stop Button Component --}}
|
||||
<div
|
||||
class="bg-gray-50 hover:bg-gray-100 rounded-lg p-4 text-center cursor-pointer transition-colors duration-200 border border-gray-200 hover:border-red-300">
|
||||
<div class="flex flex-col items-center">
|
||||
|
||||
<button x-data
|
||||
@click="
|
||||
fetch('{{ route('service.stop.vm') }}', {
|
||||
method: 'POST',
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
body: new URLSearchParams({ product_id: '{{ $invoice->vm_id }}' })
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
showNotification(data.message);
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 300);
|
||||
});
|
||||
"
|
||||
class="flex flex-col items-center w-full cursor-pointer">
|
||||
<div class="w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mb-3">
|
||||
<svg class="w-6 h-6 text-red-600" fill="currentColor" viewBox="0 0 24 24">
|
||||
<path
|
||||
d="M13 3h-2v10h2V3zm4.83 2.17l-1.42 1.42C17.99 7.86 19 9.81 19 12c0 3.87-3.13 7-7 7s-7-3.13-7-7c0-2.19 1.01-4.14 2.58-5.42L6.17 5.17C4.23 6.82 3 9.26 3 12c0 4.97 4.03 9 9 9s9-4.03 9-9c0-2.74-1.23-5.18-3.17-6.83z" />
|
||||
</svg>
|
||||
</div>
|
||||
<span class="text-sm font-medium text-gray-700">{{ __('Tắt nguồn') }}</span>
|
||||
</div>
|
||||
{{ __('Tắt nguồn') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -2,9 +2,15 @@
|
||||
@php
|
||||
$serverName = $invoice->invoiceItem->first()->server_name ?? 'Cloud VPS';
|
||||
$vmStatus = $vmInfo['status'] ?? null;
|
||||
$statusBg = match ($vmStatus) {
|
||||
'POWERED_ON' => 'bg-green-600',
|
||||
'POWERED_OFF' => 'bg-red-600',
|
||||
default => 'bg-gray-600',
|
||||
};
|
||||
@endphp
|
||||
|
||||
<div class="bg-gray-100 rounded-lg shadow-lg p-8 flex flex-col items-center justify-center">
|
||||
<div class="bg-gray-100 rounded-xl shadow-lg p-8 flex flex-col items-center justify-center relative">
|
||||
<span class="text-sm text-gray-600">{{ $invoice->invoiceItem->first()?->getProductAttribute()?->name }}</span>
|
||||
<div class="bg-white rounded-lg p-6 mb-4 shadow-md">
|
||||
<svg class="w-16 h-16 text-gray-700" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
|
||||
@@ -18,12 +24,19 @@
|
||||
{{ $serverName }}
|
||||
</p>
|
||||
<div class="mt-4">
|
||||
@if ($vmStatus == 'POWERED_ON')
|
||||
<span class="bg-green-500 text-white px-4 py-2 rounded-full text-sm font-medium">{{ __('RUNNING') }}</span>
|
||||
@elseif($vmStatus == 'POWERED_OFF')
|
||||
<span class="bg-red-500 text-white px-4 py-2 rounded-full text-sm font-medium">{{ __('STOPPED') }}</span>
|
||||
@else
|
||||
<span class="bg-gray-500 text-white px-4 py-2 rounded-full text-sm font-medium">{{ __('UNKNOWN') }}</span>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="h-10 w-full rounded-b-lg absolute bottom-0 left-0 flex items-center justify-center {{ $statusBg }}">
|
||||
<span class="text-center text-white">
|
||||
@if ($vmStatus == 'POWERED_ON')
|
||||
{{ __('RUNNING') }}
|
||||
@elseif($vmStatus == 'POWERED_OFF')
|
||||
{{ __('STOPPED') }}
|
||||
@else
|
||||
{{ __('UNKNOWN') }}
|
||||
@endif
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -19,23 +19,23 @@
|
||||
<div class="grid grid-cols-6 gap-4">
|
||||
{{-- Row 1: Basic Controls --}}
|
||||
@include('frontend.service.partials.control-buttons.renewal-button')
|
||||
@include('frontend.service.partials.control-buttons.restart-button')
|
||||
{{-- @include('frontend.service.partials.control-buttons.pause-button') --}}
|
||||
|
||||
@if ($isPoweredOff)
|
||||
@include('frontend.service.partials.control-buttons.start-button')
|
||||
@elseif ($isPoweredOn)
|
||||
@include('frontend.service.partials.control-buttons.restart-button')
|
||||
@include('frontend.service.partials.control-buttons.stop-button')
|
||||
@include('frontend.service.partials.control-buttons.console-button', ['invoice' => $invoice])
|
||||
@endif
|
||||
|
||||
{{-- @include('frontend.service.partials.control-buttons.config-button') --}}
|
||||
{{-- @include('frontend.service.partials.control-buttons.reinstall-button') --}}
|
||||
@include('frontend.service.partials.control-buttons.reinstall-button')
|
||||
|
||||
@if ($isPoweredOn)
|
||||
@include('frontend.service.partials.control-buttons.snapshot-button')
|
||||
@endif
|
||||
|
||||
@include('frontend.service.partials.control-buttons.console-button', ['invoice' => $invoice])
|
||||
|
||||
{{-- @include('frontend.service.partials.control-buttons.reset-password-button') --}}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
@push('viewStyles')
|
||||
<link rel="stylesheet" href="{{ asset('lib/sweetalert/sweetalert.css') }}">
|
||||
<meta name="invoice-ordernum" content="{{ $invoice->order_num }}">
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
|
||||
Reference in New Issue
Block a user