Files
portal-api/resources/views/frontend/service/README.md
T
2025-07-29 10:24:14 +07:00

116 lines
3.8 KiB
Markdown

# 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)