Alexander Musikhin 2 месяцев назад
Родитель
Сommit
2e27be0765

+ 5 - 0
app/Http/Controllers/ScheduleController.php

@@ -115,4 +115,9 @@ class ScheduleController extends Controller
         return redirect()->back();
     }
 
+    public function delete(Schedule $schedule)
+    {
+        $schedule->delete();
+        return redirect()->back();
+    }
 }

+ 0 - 1
app/Models/Role.php

@@ -6,7 +6,6 @@ class Role
 {
     const ADMIN     = 'admin';
     const MANAGER   = 'manager';
-
     const BRIGADIER = 'brigadier';
     const VALID_ROLES = [
         self::ADMIN,

+ 109 - 87
resources/views/schedule/index.blade.php

@@ -1,47 +1,50 @@
 @extends('layouts.app')
 
 @section('content')
-    <div class="row mb-3">
-        <div class="col-6">
-            <h3>График монтажей</h3>
-        </div>
-        <div class="col-6 text-end">
-            <div class="d-flex flex-row justify-content-end">
-                <div class="p-2">
-                    <button @disabled($weekNumber == 1) class="btn btn-sm btn-primary"
-                            onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber - 1]) }}'">
-                        <i class="bi bi-arrow-left"></i>
-                    </button>
-                </div>
-                <label class="p-2 d-block small mt-1">Неделя №</label>
-                <div class="p-2">
-                    <input type="number" style="width: 3rem" value="{{ $weekNumber }}"
-                           class="form-control form-control-sm"
-                           onchange="document.location = '{{ route('schedule.index') }}?week='+this.value"
-                           min="1" max="53" title="№ недели">
-                </div>
+    <div class="table-responsive">
+        <div class="row mb-3">
+            <div class="col-md-6">
+                <h3>График монтажей</h3>
+            </div>
+            <div class="col-md-6 text-end">
+                <div class="d-flex flex-row justify-content-end">
+                    <div class="p-2">
+                        <button @disabled($weekNumber == 1) class="btn btn-sm btn-primary"
+                                onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber - 1]) }}'">
+                            <i class="bi bi-arrow-left"></i>
+                        </button>
+                    </div>
+                    <label class="p-2 d-none d-mb-block small mt-1" for="fromDate">Неделя №</label>
+                    <div class="p-2">
+                        <input type="number" style="width: 3rem" value="{{ $weekNumber }}"
+                               class="form-control form-control-sm" name="weekNumber"
+                               onchange="document.location = '{{ route('schedule.index') }}?week='+this.value"
+                               min="1" max="53" title="№ недели">
+                    </div>
 
-                <div class="p-2">
-                    <input type="date" min="{{ year() . '-01-01' }}" max="{{ year() . '-12-31' }}"
-                           class="form-control form-control-sm" value="{{ $weekDates['mon'] }}" title="начало недели"
-                           onchange="document.location = '{{ route('schedule.index') }}?week=' + getWeekNumber(this.value)">
-                </div>
-                <div class="p-2">
-                    <input type="date" disabled
-                           class="form-control form-control-sm" value="{{ $weekDates['sun'] }}" title="конец недели">
-                </div>
+                    <div class="p-2">
+                        <input type="date" min="{{ year() . '-01-01' }}" max="{{ year() . '-12-31' }}"
+                               class="form-control form-control-sm" value="{{ $weekDates['mon'] }}"
+                               title="начало недели" name="monday" id="fromDate"
+                               onchange="document.location = '{{ route('schedule.index') }}?week=' + getWeekNumber(this.value)">
+                    </div>
+                    <div class="p-2 d-none d-md-block">
+                        <input type="date" disabled name="sunday"
+                               class="form-control form-control-sm" value="{{ $weekDates['sun'] }}"
+                               title="конец недели">
+                    </div>
 
-                <div class="p-2">
-                    <button @disabled($weekNumber > 52) class="btn btn-sm btn-primary"
-                            onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber + 1]) }}'">
-                        <i class="bi bi-arrow-right"></i>
-                    </button>
+                    <div class="p-2">
+                        <button @disabled($weekNumber > 52) class="btn btn-sm btn-primary"
+                                onclick="document.location = '{{ route('schedule.index', ['week' => $weekNumber + 1]) }}'">
+                            <i class="bi bi-arrow-right"></i>
+                        </button>
+                    </div>
                 </div>
             </div>
         </div>
-    </div>
 
-    <div class="schedule">
+
         <table class="table schedules">
             <thead>
             <tr>
@@ -88,14 +91,25 @@
                                 class="align-middle">{{ $schedule->mafs_count }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
                                 class="align-middle">{{ $schedule->brigadier->name }}</td>
-                            <td style="background: {{ $schedule->brigadier->color }}" class="align-middle comment-{{ $schedule->id }}">{{ $schedule->comment }}</td>
+                            <td style="background: {{ $schedule->brigadier->color }}"
+                                class="align-middle comment-{{ $schedule->id }}">{{ $schedule->comment }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
                                 <i class="bi bi-pencil ms-3 cursor-pointer text-primary editSchedule"
-                                   data-schedule-date="{{ $schedule->installation_date }}" data-schedule-id="{{ $schedule->id }}"></i>
+                                   data-schedule-date="{{ $schedule->installation_date }}"
+                                   data-schedule-id="{{ $schedule->id }}"></i>
+                                <i class="bi bi-trash text-danger ms-2 deleteSchedule"
+                                   data-schedule-id="{{ $schedule->id }}"></i>
+                                <div class="visually-hidden ">
+                                    <form action="{{ route('schedule.delete', $schedule->id) }}" method="post"
+                                          class="deleteForm-{{ $schedule->id }}">
+                                        @csrf
+                                        @method('DELETE')
+                                    </form>
+                                </div>
                             </td>
-                            </tr>
-                        @endforeach
-                     @endif
+                </tr>
+            @endforeach
+            @endif
             {!! (!$schs) ? '</tr>': '' !!}
 
             @endforeach
@@ -103,61 +117,61 @@
             </tbody>
         </table>
 
-    </div>
 
-    <!-- Модальное окно редактирования графика -->
-    <div class="modal fade" id="copySchedule" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
-        <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
-            <div class="modal-content">
-                <div class="modal-header">
-                    <h1 class="modal-title fs-5" id="addModalLabel">Изменить запись в графике</h1>
-                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
-                </div>
-                <div class="modal-body">
-                    <form action="{{ route('schedule.update') }}" method="post" id="scheduleEditForm">
-                        @csrf
-                        <input type="hidden" name="id" value="0">
-                        <div>
-                            <input type="date" name="installation_date" value="" class="form-control form-control-sm mb-3">
-                            <textarea name="comment" placeholder="Комментарий для графика"
-                                      class="form-control form-control-sm mb-3"></textarea>
-                            <button type="submit" class="btn btn-primary btn-sm">Обновить</button>
-                        </div>
-                    </form>
+        <!-- Модальное окно редактирования графика -->
+        <div class="modal fade" id="copySchedule" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+            <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
+                <div class="modal-content">
+                    <div class="modal-header">
+                        <h1 class="modal-title fs-5" id="addModalLabel">Изменить запись в графике</h1>
+                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
+                    </div>
+                    <div class="modal-body">
+                        <form action="{{ route('schedule.update') }}" method="post" id="scheduleEditForm">
+                            @csrf
+                            <input type="hidden" name="id" value="0">
+                            <div>
+                                <input type="date" name="installation_date" value=""
+                                       class="form-control form-control-sm mb-3">
+                                <textarea name="comment" placeholder="Комментарий для графика"
+                                          class="form-control form-control-sm mb-3"></textarea>
+                                <button type="submit" class="btn btn-primary btn-sm">Обновить</button>
+                            </div>
+                        </form>
+                    </div>
                 </div>
             </div>
         </div>
-    </div>
 
-    <!-- Модальное окно создания графика -->
-    <div class="modal fade" id="createSchedule" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
-        <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
-            <div class="modal-content">
-                <div class="modal-header">
-                    <h1 class="modal-title fs-5" id="addModalLabel">Изменить запись в графике</h1>
-                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
-                </div>
-                <div class="modal-body">
-                    <form action="{{ route('schedule.create') }}" method="post" id="scheduleCreateForm">
-                        @csrf
-                        <input type="text" class="form-control mb-2" placeholder="Поиск площадки" id="search_order">
-                        <select id="select_order" name="order_id" class="form-select mb-3" size="7" multiple
-                                required></select>
-                        <div>
-                            <input type="date" name="installation_date" value="" class="form-control form-control-sm mb-3">
-                            <textarea name="comment" placeholder="Комментарий для графика"
-                                      class="form-control form-control-sm mb-3"></textarea>
-                            <button type="submit" class="btn btn-primary btn-sm">Создать</button>
-                        </div>
-                    </form>
+        <!-- Модальное окно создания графика -->
+        <div class="modal fade" id="createSchedule" tabindex="-1" aria-labelledby="exampleModalLabel"
+             aria-hidden="true">
+            <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
+                <div class="modal-content">
+                    <div class="modal-header">
+                        <h1 class="modal-title fs-5" id="addModalLabel">Изменить запись в графике</h1>
+                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
+                    </div>
+                    <div class="modal-body">
+                        <form action="{{ route('schedule.create') }}" method="post" id="scheduleCreateForm">
+                            @csrf
+                            <input type="text" class="form-control mb-2" placeholder="Поиск площадки" id="search_order">
+                            <select id="select_order" name="order_id" class="form-select mb-3" size="7" multiple
+                                    required></select>
+                            <div>
+                                <input type="date" name="installation_date" value=""
+                                       class="form-control form-control-sm mb-3">
+                                <textarea name="comment" placeholder="Комментарий для графика"
+                                          class="form-control form-control-sm mb-3"></textarea>
+                                <button type="submit" class="btn btn-primary btn-sm">Создать</button>
+                            </div>
+                        </form>
+                    </div>
                 </div>
             </div>
         </div>
-    </div>
 
-    @if($errors->any())
-        @dump($errors)
-    @endif
+    </div>
 @endsection
 
 @push('scripts')
@@ -165,7 +179,7 @@
         $('.editSchedule').on('click', function () {
             let scheduleId = $(this).attr('data-schedule-id');
             let scheduleDate = $(this).attr('data-schedule-date');
-            let scheduleComment = $('.comment-'+scheduleId).text();
+            let scheduleComment = $('.comment-' + scheduleId).text();
             $('form#scheduleEditForm input[name=id]').val(scheduleId);
             $('form#scheduleEditForm input[name=installation_date]').val(scheduleDate);
             $('form#scheduleEditForm textarea').text(scheduleComment);
@@ -173,6 +187,14 @@
             myModalEditSchedule.show();
         });
 
+        $('.deleteSchedule').on('click', function () {
+            if (confirm('Удалить запись?')) {
+                let scheduleId = $(this).attr('data-schedule-id');
+                $('.deleteForm-' + scheduleId).submit();
+            }
+
+        });
+
         $('.createSchedule').on('click', function () {
             let scheduleDate = $(this).attr('data-schedule-date');
 

+ 1 - 0
routes/web.php

@@ -149,6 +149,7 @@ Route::middleware('auth:web')->group(function () {
     Route::post('schedule/create_from_order', [ScheduleController::class, 'createFromOrder'])->name('schedule.create-from-order');
     Route::post('schedule/update', [ScheduleController::class, 'update'])->name('schedule.update');
     Route::post('schedule/create', [ScheduleController::class, 'create'])->name('schedule.create');
+    Route::delete('schedule/delete/{schedule}', [ScheduleController::class, 'delete'])->name('schedule.delete');
 
     // ajax search products
     Route::get('product/search', [ProductController::class, 'search'])->name('product.search');