feat: Refactor addon management to use AddonType and AddonInputType enums, update the database schema, and implement a grouped datatable display for addons.

This commit is contained in:
pbao9
2026-02-13 11:31:54 +07:00
parent b127fa7c66
commit 245f5ade37
11 changed files with 684 additions and 216 deletions
@@ -15,35 +15,95 @@
@endphp
<x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection
@php
use App\Enums\AddonType;
@endphp
@section("content")
@if (auth()->guard('admins')->user()->can('manager product'))
<div class="card card-primary card-outline">
<div class="card-header d-flex justify-content-end gap-2">
@include('administrator.pages.block.addon.btn')
</div>
<div class="card-body">
<div class="card-body p-0">
<x-datatable id="addonTable" ajax="{{ route('addon.datatable') }}" :columns="[
['key' => 'name', 'label' => 'Addon Name'],
['key' => 'prefix', 'label' => 'Prefix'],
['key' => 'min', 'label' => 'Min'],
['key' => 'max', 'label' => 'Max'],
['key' => 'step', 'label' => 'Step'],
['key' => 'price', 'label' => 'Price'],
['key' => 'status', 'label' => 'Status'],
['key' => 'action', 'label' => 'Action'],
['key' => 'details_control', 'label' => '', 'orderable' => false, 'searchable' => false, 'className' => 'details-control text-center cursor-pointer'],
['key' => 'name', 'label' => 'Group'],
['key' => 'slug', 'label' => 'Slug'],
['key' => 'is_active', 'label' => 'Status'],
['key' => 'action', 'label' => 'Action', 'searchable' => false],
]" />
</div>
</div>
@else
<div class="alert alert-danger alert-dismissible">
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Product
management department</h5>
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Product management
department</h5>
</div>
@endif
@endsection
@push('plugin-scripts')
@foreach (config('assets.datatable.js') as $datatable)
<script src="{{ asset($datatable) }}"></script>
@endforeach
@endpush
@endpush
@push('custom-styles')
<style>
td.details-control {
text-align: center;
vertical-align: middle;
cursor: pointer;
}
</style>
@endpush
@push('custom-scripts')
<script>
document.addEventListener('DOMContentLoaded', function () {
var tableId = '#addonTable';
$('#addonTable').on('draw.dt', function () {
setTimeout(function () {
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
}, 100);
});
$(tableId + ' tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var table = $(tableId).DataTable();
var row = table.row(tr);
var cell = $(this);
if (row.child.isShown()) {
row.child.hide();
tr.removeClass('shown');
cell.html('<i data-lucide="plus-circle" class="cursor-pointer text-success mx-auto" style="width:15px; height:15px"></i>');
} else {
if (row.data().children && row.data().children.length > 0) {
row.child(format(row.data())).show();
tr.addClass('shown');
cell.html('<i data-lucide="minus-circle" class="cursor-pointer text-danger mx-auto" style="width:15px; height:15px"></i>');
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
}
}
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
});
function format(d) {
return d.children_html;
}
});
</script>
@endpush