feat: ✨ add published status filter to packages listing
This commit is contained in:
parent
1794076c91
commit
e0e6147576
11 changed files with 151 additions and 8 deletions
|
|
@ -79,7 +79,7 @@ class InvoiceController extends Controller
|
|||
*/
|
||||
public function create(Invoice $invoice): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$packageModels = Package::get();
|
||||
$packageModels = Package::where('published', true)->get();
|
||||
$taskRowModel = Invoice::getTaskStructure();
|
||||
$siteModels = Site::orderBy('name', 'ASC')->get();
|
||||
$companyModels = Company::get();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,15 @@ class PackageController extends Controller
|
|||
/** @var \Illuminate\Database\Eloquent\Builder $packageModels */
|
||||
$packageModels = Package::query();
|
||||
|
||||
$status = $request->status;
|
||||
if ($status === null) {
|
||||
$packageModels->where('published', true);
|
||||
} elseif ($status === '0') {
|
||||
$packageModels->where('published', false);
|
||||
} elseif ($status === '1') {
|
||||
$packageModels->where('published', true);
|
||||
}
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
|
|
@ -42,7 +51,7 @@ class PackageController extends Controller
|
|||
/** Custom pagination */
|
||||
$packageModels = $this->customPaginate($packageModels, $request->pagination);
|
||||
|
||||
return view('bo.pages.packages.index', compact('packageModels', 'search', 'searchFields'));
|
||||
return view('bo.pages.packages.index', compact('packageModels', 'search', 'searchFields', 'status'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,4 +162,16 @@ class PackageController extends Controller
|
|||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Change model published.
|
||||
*
|
||||
* @param \App\Models\Package $package
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function changePublished(Package $package)
|
||||
{
|
||||
$package->update(['published' => !$package->getOriginal('published')]);
|
||||
return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,18 @@ class StorePackageRequest extends FormRequest
|
|||
return Gate::allows('isAdmin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
|
|
@ -27,6 +39,7 @@ class StorePackageRequest extends FormRequest
|
|||
return [
|
||||
'name' => 'required|string|min:3|max:255',
|
||||
'amount' => 'required|numeric|min:0|regex:/^\d+(\.\d{1,2})?$/',
|
||||
'published' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +53,7 @@ class StorePackageRequest extends FormRequest
|
|||
return [
|
||||
'name' => trans('Nom'),
|
||||
'amount' => trans('Montant (par jour)'),
|
||||
'published' => trans('Publication')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,5 +28,16 @@ class Package extends Model
|
|||
protected $fillable = [
|
||||
'name',
|
||||
'amount',
|
||||
'published'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'published' => 'boolean',
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?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('packages', function (Blueprint $table) {
|
||||
$table->boolean('published')->after('amount');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('packages', function (Blueprint $table) {
|
||||
$table->dropColumn('published');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -221,6 +221,8 @@ return [
|
|||
'order' => 'order',
|
||||
'priority' => 'priority',
|
||||
'default' => 'default',
|
||||
'date_mep' => 'Desired Launch'
|
||||
'date_mep' => 'Desired Launch',
|
||||
'published' => 'Publication',
|
||||
'all' => 'All'
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -257,6 +257,8 @@ return [
|
|||
'order' => 'ordre',
|
||||
'priority' => 'priorité',
|
||||
'default' => 'défaut',
|
||||
'date_mep' => 'MEP souhaitée'
|
||||
'date_mep' => 'MEP souhaitée',
|
||||
'published' => 'publication',
|
||||
'all' => 'Tout'
|
||||
]
|
||||
];
|
||||
|
|
|
|||
14
resources/views/bo/modules/change-published-status.blade.php
Normal file
14
resources/views/bo/modules/change-published-status.blade.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<td class="text-center align-middle">
|
||||
<form action="{{ route('bo.' . $routeName . '.change-published', $model->getRouteKey()) }}" method="POST">
|
||||
@csrf
|
||||
@method('PATCH')
|
||||
<button class="btn btn-sm @if ($model->published) btn-primary @else btn-danger @endif" data-bs-toggle="tooltip"
|
||||
type="submit" title="{{ __($model->published ? __('crud.other.unpublish') : __('crud.other.publish')) }}">
|
||||
@if ($model->published)
|
||||
<i class="fa-solid fa-circle-check"></i>
|
||||
@else
|
||||
<i class="fa-solid fa-circle-xmark"></i>
|
||||
@endif
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
|
|
@ -61,6 +61,28 @@
|
|||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- PUBLISHED --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border bg-white p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.custom.published')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
@include('bo.partials.inputs.tinyint-boolean', [
|
||||
'id' => 'packagePublished',
|
||||
'label' => __(':field du :model', [
|
||||
'field' => str(__('validation.custom.published'))->ucFirst(),
|
||||
'model' => __('models.classes.packages'),
|
||||
]),
|
||||
'name' => 'published',
|
||||
'model' => $packageModel ?? null,
|
||||
'helper' => __('validation.boolean', [
|
||||
'attribute' => str(__('validation.custom.published'))->ucFirst()
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
|
|
|
|||
|
|
@ -6,10 +6,32 @@
|
|||
@section('content')
|
||||
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap">
|
||||
@include('breadcrumbs.breadcrumb-body')
|
||||
<a class="btn btn-primary float-right" data-bs-toggle="tooltip" data-bs-placement="top" href="{{ route('bo.packages.create') }}"
|
||||
title="{{ __('crud.helpers.create_model', ['model' => Str::singular(__('models.classes.packages'))]) }}">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</a>
|
||||
<form id="packageStatus" action="{{ route('bo.packages.index') }}">
|
||||
<div class="input-group justify-content-end">
|
||||
<select class="form-select w-fit" id="selectpackageStatus" name="status">
|
||||
<option value="-1" @if ($status === '-1') selected @endif>
|
||||
{{ __('validation.custom.all') }}
|
||||
</option>
|
||||
<option value="1" @if ($status === '1') selected @endif>
|
||||
{{ __('crud.other.publish') }}
|
||||
</option>
|
||||
<option value="0" @if ($status === '0') selected @endif>
|
||||
{{ __('crud.other.unpublish') }}
|
||||
</option>
|
||||
</select>
|
||||
@push('scripts')
|
||||
<script nonce="{{ $nonce }}">
|
||||
document.getElementById('selectpackageStatus').addEventListener('change', function(e) {
|
||||
document.getElementById('packageStatus').submit();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
<a class="btn btn-primary float-right" data-bs-toggle="tooltip" data-bs-placement="top" href="{{ route('bo.packages.create') }}"
|
||||
title="{{ __('crud.helpers.create_model', ['model' => Str::singular(__('models.classes.packages'))]) }}">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@include('bo.modules.search-bar')
|
||||
<table class="table-hover table">
|
||||
|
|
@ -19,6 +41,7 @@
|
|||
'cols' => [
|
||||
'name' => Str::ucfirst(__('validation.attributes.name')),
|
||||
'amount' => Str::ucfirst(__('validation.attributes.day')),
|
||||
'published' => Str::ucfirst(__('validation.custom.published')),
|
||||
],
|
||||
])
|
||||
</thead>
|
||||
|
|
@ -27,6 +50,10 @@
|
|||
<tr class="border-bottom list-item">
|
||||
<td class="text-center align-middle">{{ $packageModel->name }}</td>
|
||||
<td class="text-center align-middle">{{ $packageModel->amount }}</td>
|
||||
@include('bo.modules.change-published-status', [
|
||||
'routeName' => 'packages',
|
||||
'model' => $packageModel,
|
||||
])
|
||||
<td class="text-end align-middle">
|
||||
<form class="btn-group confirmDeleteTS" action="{{ route('bo.packages.destroy', $packageModel->id) }}"
|
||||
method="POST" novalidate>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ Route::middleware('admin-secure')
|
|||
->middleware('htmlsanitize:template')
|
||||
->parameters(['ticket_types' => 'ticket_type']);
|
||||
Route::resource('packages', PackageController::class)->except('show');
|
||||
Route::patch('/packages/{package}/change-published', [PackageController::class, 'changePublished'])
|
||||
->name('packages.change-published');
|
||||
Route::resource('invoices', InvoiceController::class)
|
||||
->withoutMiddleware('htmlsanitize')
|
||||
->middleware(['htmlsanitize:comment']);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue