feat(schedules): add bulk delete via checkboxes

- Add BulkDeleteSchedulesTask, BulkDeleteSchedulesAction
- Add route DELETE /dashboard/schedules/bulk-destroy
- Add bulkDestroy method to ScheduleController
- Update Index.vue: select all/individual checkboxes, bulk actions bar
- Fix CheckDashboardPermission: replace naive /s$/ regex with Str::singular()
  to resolve irregular plurals (faculties→faculty, categories→category)
This commit is contained in:
F4ilji
2026-08-20 11:16:53 +05:00
parent f8d55092e5
commit 24387d6767
6 changed files with 145 additions and 2 deletions
@@ -0,0 +1,17 @@
<?php
namespace App\Containers\Dashboard\Actions\Schedules;
use App\Containers\Dashboard\Tasks\Schedules\BulkDeleteSchedulesTask;
class BulkDeleteSchedulesAction
{
public function __construct(
private readonly BulkDeleteSchedulesTask $bulkDeleteSchedulesTask,
) {}
public function run(array $ids): int
{
return $this->bulkDeleteSchedulesTask->run($ids);
}
}
@@ -0,0 +1,13 @@
<?php
namespace App\Containers\Dashboard\Tasks\Schedules;
use App\Containers\Schedule\Models\Schedule;
class BulkDeleteSchedulesTask
{
public function run(array $ids): int
{
return Schedule::whereIn('id', $ids)->delete();
}
}
@@ -5,6 +5,7 @@ namespace App\Containers\Dashboard\UI\WEB\Controllers;
use App\Containers\Dashboard\Actions\Schedules\CreateScheduleAction;
use App\Containers\Dashboard\Actions\Schedules\UpdateScheduleAction;
use App\Containers\Dashboard\Actions\Schedules\DeleteScheduleAction;
use App\Containers\Dashboard\Actions\Schedules\BulkDeleteSchedulesAction;
use App\Containers\Dashboard\Actions\Schedules\ListSchedulesAction;
use App\Containers\Dashboard\UI\WEB\Requests\StoreScheduleRequest;
use App\Containers\Dashboard\UI\WEB\Requests\UpdateScheduleRequest;
@@ -23,6 +24,7 @@ class ScheduleController extends Controller
private readonly CreateScheduleAction $createScheduleAction,
private readonly UpdateScheduleAction $updateScheduleAction,
private readonly DeleteScheduleAction $deleteScheduleAction,
private readonly BulkDeleteSchedulesAction $bulkDeleteSchedulesAction,
) {}
/**
@@ -150,4 +152,22 @@ class ScheduleController extends Controller
->with('error', 'Ошибка при удалении расписания: ' . $e->getMessage());
}
}
/**
* Массовое удаление расписаний
*/
public function bulkDestroy(Request $request): RedirectResponse
{
$request->validate(['ids' => 'required|array', 'ids.*' => 'integer|exists:schedules,id']);
try {
$count = $this->bulkDeleteSchedulesAction->run($request->ids);
return redirect()->back()
->with('success', "Удалено {$count} расписаний");
} catch (\Exception $e) {
return back()
->with('error', 'Ошибка при удалении: ' . $e->getMessage());
}
}
}
@@ -198,6 +198,7 @@ Route::middleware(['access-check', 'dashboard.auth', 'dashboard.permission'])->g
Route::get('/', [ScheduleController::class, 'index'])->name('index');
Route::get('/create', [ScheduleController::class, 'create'])->name('create');
Route::post('/', [ScheduleController::class, 'store'])->name('store');
Route::delete('/bulk-destroy', [ScheduleController::class, 'bulkDestroy'])->name('bulk-destroy');
Route::get('/{schedule}/edit', [ScheduleController::class, 'edit'])->name('edit');
Route::put('/{schedule}', [ScheduleController::class, 'update'])->name('update');
Route::delete('/{schedule}', [ScheduleController::class, 'destroy'])->name('destroy');
@@ -4,6 +4,7 @@ namespace App\Ship\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\Response;
class CheckDashboardPermission
@@ -72,7 +73,8 @@ class CheckDashboardPermission
// Convert: additional-educations → additional_education
// Convert: admission-campaigns → admission_campaign
// Convert: main-sections → main_section
$resource = preg_replace('/s$/', '', $resource); // strip trailing 's'
// Convert: faculties → faculty, categories → category
$resource = Str::singular($resource);
$resource = str_replace('-', '_', $resource);
return 'view_any_' . $resource;
@@ -25,6 +25,34 @@
<!-- Flash Messages -->
<FlashMessages />
<!-- Bulk Actions Bar -->
<transition enter-active-class="transition duration-200" enter-from-class="opacity-0 -translate-y-2"
enter-to-class="opacity-100 translate-y-0" leave-active-class="transition duration-150"
leave-from-class="opacity-100 translate-y-0" leave-to-class="opacity-0 -translate-y-2">
<div v-if="selectedSchedules.length > 0"
class="px-6 py-3 bg-primary/5 border-b border-primary/20 flex items-center justify-between">
<div class="flex items-center gap-3">
<span class="text-sm font-medium text-primary">{{ selectedSchedules.length }} выбрано</span>
<button @click="selectAllOnPage"
class="text-xs text-muted-foreground-1 hover:text-primary transition-colors">
Выбрать все на странице
</button>
</div>
<div class="flex items-center gap-2">
<button @click="bulkDelete" :disabled="bulkProcessing"
class="inline-flex items-center gap-1.5 px-3 py-1.5 bg-rose-600 text-white text-xs font-medium rounded-lg hover:bg-rose-700 transition-all disabled:opacity-50 disabled:cursor-not-allowed">
<DashboardIcon name="trash" size="4" />
Удалить
</button>
<button @click="clearSelection"
class="p-1.5 text-muted-foreground-1 hover:text-foreground hover:bg-muted-hover rounded-lg transition-all"
title="Снять выделение">
<DashboardIcon name="x-mark" size="4" />
</button>
</div>
</div>
</transition>
<!-- Filters Card -->
<DataFilters title="Фильтры" @reset="resetFilters">
<SearchInput
@@ -88,6 +116,15 @@
<table class="min-w-full divide-y divide-line-2">
<thead class="bg-surface/50">
<tr>
<th class="w-10 px-6 py-3">
<input
type="checkbox"
:checked="isAllSelected"
:indeterminate.prop="isIndeterminate"
@change="toggleSelectAll"
class="w-4 h-4 text-primary border-layer-line rounded focus:ring-primary/20 cursor-pointer"
/>
</th>
<th class="px-6 py-3 text-left text-xs font-medium text-muted-foreground-1 uppercase tracking-wider">
Название
</th>
@@ -113,7 +150,16 @@
v-for="schedule in schedules.data"
:key="schedule.id"
class="group hover:bg-muted-hover/50 transition-all duration-200"
:class="{ 'bg-primary/5': selectedSchedules.includes(schedule.id) }"
>
<td class="px-6 py-4">
<input
type="checkbox"
:value="schedule.id"
v-model="selectedSchedules"
class="w-4 h-4 text-primary border-layer-line rounded focus:ring-primary/20 cursor-pointer"
/>
</td>
<td class="px-6 py-4">
<div class="flex items-center gap-3">
<div class="w-10 h-10 flex-shrink-0 rounded-lg border border-layer-line bg-surface flex items-center justify-center">
@@ -178,7 +224,7 @@
<!-- Empty State -->
<EmptyState
v-if="schedules.data.length === 0"
:columns="6"
:columns="7"
title="Расписания не найдены"
description="Добавьте первое расписание или измените параметры поиска"
:action-url="route('dashboard.schedules.create')"
@@ -248,10 +294,21 @@ export default {
educationalGroupQuery: this.filters?.educational_group_id || '',
educationFormQuery: this.filters?.education_form_id || '',
deletingSchedule: null,
selectedSchedules: [],
bulkProcessing: false,
EducationForm
}
},
computed: {
isAllSelected() {
return this.schedules.data.length > 0 && this.selectedSchedules.length === this.schedules.data.length;
},
isIndeterminate() {
return this.selectedSchedules.length > 0 && this.selectedSchedules.length < this.schedules.data.length;
},
},
mounted() {
this.SET_DOCUMENT_TITLE('Расписание');
},
@@ -335,6 +392,39 @@ export default {
});
},
toggleSelectAll(event) {
if (event.target.checked) {
this.selectedSchedules = [...new Set([...this.selectedSchedules, ...this.schedules.data.map(s => s.id)])];
} else {
const pageIds = new Set(this.schedules.data.map(s => s.id));
this.selectedSchedules = this.selectedSchedules.filter(id => !pageIds.has(id));
}
},
selectAllOnPage() {
this.selectedSchedules = [...new Set([...this.selectedSchedules, ...this.schedules.data.map(s => s.id)])];
},
clearSelection() {
this.selectedSchedules = [];
},
bulkDelete() {
if (!confirm(`Удалить ${this.selectedSchedules.length} расписаний?`)) return;
this.bulkProcessing = true;
this.$inertia.delete(route('dashboard.schedules.bulk-destroy'), {
data: { ids: this.selectedSchedules },
preserveScroll: true,
onSuccess: () => {
this.selectedSchedules = [];
this.bulkProcessing = false;
},
onError: () => {
this.bulkProcessing = false;
},
});
},
refreshPage() {
this.$inertia.get(route('dashboard.schedules.index'), {
search: this.searchQuery,