update os

This commit is contained in:
pbao9
2026-02-02 10:17:51 +07:00
parent 34575b2d96
commit d3b264262b
4 changed files with 45 additions and 10 deletions
@@ -14,6 +14,7 @@ use App\Http\Services\vCenter as ServiceVCenter;
use App\Repositories\Os\OsRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Yajra\DataTables\Facades\DataTables;
@@ -241,9 +241,9 @@ class ModuleController extends Controller
[
'module_host_id' => $host_id
],
['host'], // Include host relationship
[],
[],
['id', 'name']
['id', 'name', 'module_host_id'] // Add module_host_id to select
);
if (count($groups) > 0) {
return response()->json(['error' => false, 'data' => $groups]);
@@ -3,6 +3,10 @@
<link href="{{ asset('build/plugins/select2/select2.min.css') }}" rel="stylesheet" />
@endpush
@php
use App\Enums\Status;
@endphp
@section('breadcrumb')
@php
$breadcrumbItems = [
@@ -35,7 +39,7 @@
<x-module.datacenter :model="$version->osGroup->host" />
<x-module.host :model="$version->osGroup" />
<x-module.os :model="$version" />
<x-module.os-server-version :model="$version" />
<div class="row form-group align-items-center mb-0">
<label for="version" class="col-md-3 text-right">Template</label>
<div class="col-md-9 p-1 bg-customer">
@@ -46,9 +50,12 @@
<div class="row form-group align-items-center mb-0">
<label for="status" class="col-md-3 text-right">Status</label>
<div class="col-md-9 p-1 bg-customer">
<select class="custom-select" id="status" name="status">
<option value="1" @selected($version->status === 1)>Active</option>
<option value="0" @selected($version->status === 0)>No Active</option>
<select class="custom-select select2" id="status" name="status">
@foreach(Status::getOptions() as $value => $label)
<option value="{{ $value }}" @selected($version->status == $value)>
{{ $label }}
</option>
@endforeach
</select>
</div>
</div>
@@ -69,6 +76,22 @@
@endif
@endsection
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
// Initialize Select2 using global function
if (typeof window.initSelect2 === 'function') {
window.initSelect2();
}
// Initialize other Select2 elements
$('.select2').select2({
theme: 'bootstrap4',
width: '100%'
});
});
</script>
@endpush
@push('plugin-scripts')
<script src="{{ asset('build/plugins/jquery/jquery.min.js') }}"></script>
+15 -4
View File
@@ -1,6 +1,11 @@
@php
// Fix: Get os_group_id from the relationship correctly
$selectedOsGroupId = old('os_group_id') ?? ($model?->os?->os_group_id ?? null);
$selectedOsGroupId = old('os_group_id') ?? ($model?->os_group_id ?? null);
$lists = collect();
if ($model && $model->osGroup) {
$lists = collect([$model->osGroup]);
}
@endphp
@@ -12,7 +17,12 @@ $selectedOsGroupId = old('os_group_id') ?? ($model?->os?->os_group_id ?? null);
@if ($selectedOsGroupId && $lists)
@foreach ($lists->all() as $item)
@if ($item->id == $selectedOsGroupId)
<option value="{{ $item->id }}" selected>{{ $item->name }}</option>
<option value="{{ $item->id }}" selected>
{{ $item->name }}
@if($item->host)
- {{ $item->host->name }} ({{ $item->host->host_id }})
@endif
</option>
@endif
@endforeach
@endif
@@ -72,8 +82,9 @@ $selectedOsGroupId = old('os_group_id') ?? ($model?->os?->os_group_id ?? null);
let options = '<option value="">--- Chọn OS Group ---</option>';
response.data.forEach(os => {
const selected = preselect == os.id ? 'selected' : '';
const hostInfo = os.host ? ` - ${os.host.name} (${os.host.host_id})` : '';
options +=
`<option value="${os.id}" ${selected}>${os.name}</option>`;
`<option value="${os.id}" ${selected}>${os.name}${hostInfo}</option>`;
});
$osGroup.html(options).prop('disabled', false);