From 26bdfee839f4b8fb18beb1a9770fc758ad20c267 Mon Sep 17 00:00:00 2001 From: Mateja Date: Mon, 16 Nov 2020 20:15:43 +0100 Subject: AJAX filtering reservations on admin panel... --- app/Http/Controllers/ReservationsController.php | 37 ++++++++- public/js/reservations.js | 42 +++++++--- resources/views/pages/reservations.blade.php | 106 ++++++++++++++++-------- routes/api.php | 1 + routes/web.php | 2 +- 5 files changed, 141 insertions(+), 47 deletions(-) diff --git a/app/Http/Controllers/ReservationsController.php b/app/Http/Controllers/ReservationsController.php index b347409..2a46343 100644 --- a/app/Http/Controllers/ReservationsController.php +++ b/app/Http/Controllers/ReservationsController.php @@ -128,8 +128,41 @@ class ReservationsController extends Controller // Administration public function edit(Request $request) { - $data = Reservation::orderBy('id', 'desc')->get(); - return view('pages.reservations', compact('data')); + if ($request->isMethod('post')) { + + $request->validate([ + 'call-sign' => 'required|alphanum' + ]); + + if ($request->input('call-sign') == 'all') { + $activities = Reservation::orderBy('id', 'desc') + ->get() + ->toArray(); + $data = [ + 'status' => 'OK', + 'data' => $activities + ]; + + return response($data); + } else { + $activities = Reservation::where('specialCall', $request->input('call-sign')) + ->orderBy('id', 'desc') + ->get() + ->toArray(); + $data = [ + 'status' => 'OK', + 'data' => $activities + ]; + + return response($data); + } + + } + else { + //$data = Reservation::orderBy('id', 'desc')->get(); + $signs = SpecialCall::all(); + return view('pages.reservations', compact('signs')); + } } public function update(Request $request) diff --git a/public/js/reservations.js b/public/js/reservations.js index 94bee2d..65b2e2e 100644 --- a/public/js/reservations.js +++ b/public/js/reservations.js @@ -9,30 +9,52 @@ jQuery(document).ready(fillTable); function fillTable() { tableData = jQuery('table#ajax-table>tbody').first(); - tableData.html('Loading...'); + tableData.html('Loading...'); sign = jQuery('select#call-sign').first().val(); - jQuery.post('/api/activities', {'call-sign': sign}, function (data, status) { + jQuery.post('/special-calls/reservations', {'call-sign': sign}, function (data, status) { if (status === 'success') { if (data.data.length > 0) { tableData.empty(); for (var i = 0, len = data.data.length; i < len; i++) { - tr = '' + data.data[i].operatorCall + '' + - '' + data.data[i].fromTime + '' + - '' + data.data[i].toTime + '' + - '' + data.data[i].specialCall + '' + - '' + data.data[i].frequencies + '' + - '' + data.data[i].qso + ''; + tr = ''; + tr += '' + data.data[i].id + ''; + if (data.data[i].approved === 1) + tr += ''; + else + tr += ''; + + tr += + '' + data.data[i].operatorCall + '' + + '' + data.data[i].qso + '' + + '' + data.data[i].fromTime + '' + + '' + data.data[i].toTime + '' + + '' + data.data[i].specialCall + '' + + '' + data.data[i].frequencies + '' + + '' + data.data[i].modes + '' + + '' + data.data[i].operatorName + '' + + '' + data.data[i].operatorEmail + '' + + '' + data.data[i].operatorPhone + ''; + tr += ''; + tr += ""; + tr += ""; + tr += ""; + tr += ''; + tr += ''; tableData.append(tr); } } else { - tableData.html('No data...'); + tableData.html('No data...'); } } else { - tableData.html('Error!'); + tableData.html('Error!'); } }); } + +function btnAction(action, btn) { + console.log(action); +} diff --git a/resources/views/pages/reservations.blade.php b/resources/views/pages/reservations.blade.php index 66b4d7e..06c0335 100644 --- a/resources/views/pages/reservations.blade.php +++ b/resources/views/pages/reservations.blade.php @@ -4,10 +4,24 @@ @section('navbar', View::make('inc.navbar')) +@section('scripts') + +@endsection + @section('content') -@if (count($data) > 0) -
- + + + + +
+
@@ -16,47 +30,71 @@ + - - @foreach ($data as $row) - - - @if ($row->approved) - - @else - - @endif - - - - - - - - - - - - - @endforeach
IDQSO From ToSpecial Callsign Frequencies ModesSpecial Callsign Operator Name Operator Email Operator Phone Actions
{{ $row->id }}{{ $row->operatorCall }}{{ $row->qso }}{{ $row->fromTime }}{{ $row->toTime }}{{ $row->frequencies }}{{ $row->modes }}{{ $row->specialCall }}{{ $row->operatorName }}{{ $row->operatorEmail }}{{ $row->operatorPhone }} - - - -
-@else -
- There are currently no reservations. -
-@endif +{{--@if (count($data) > 0)--}} +{{--
--}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{--@foreach ($data as $row)--}} + {{----}} + {{----}} + {{--@if ($row->approved)--}} + {{-- --}} + {{--@else--}} + {{-- --}} + {{--@endif--}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{----}} + {{--@endforeach--}} + {{----}} + {{--
IDApprovedOperator CallsignQSOFromToFrequenciesModesSpecial CallsignOperator NameOperator EmailOperator PhoneActions
{{ $row->id }}{{ $row->operatorCall }}{{ $row->qso }}{{ $row->fromTime }}{{ $row->toTime }}{{ $row->frequencies }}{{ $row->modes }}{{ $row->specialCall }}{{ $row->operatorName }}{{ $row->operatorEmail }}{{ $row->operatorPhone }}--}} + {{----}} + {{----}} + {{----}} + {{--
--}} +{{--
--}} +{{--@else--}} +{{--
--}} + {{--There are currently no reservations.--}} +{{--
--}} +{{--@endif--}} @endsection() diff --git a/routes/api.php b/routes/api.php index d85ea7a..413ea33 100644 --- a/routes/api.php +++ b/routes/api.php @@ -21,3 +21,4 @@ Route::middleware('auth:api')->get('/user', function (Request $request) { }); Route::post('activities', [ReservationsController::class, 'index']); +Route::post('reservations', [ReservationsController::class, 'update'])->middleware(['auth']); diff --git a/routes/web.php b/routes/web.php index bba3ab5..393b226 100644 --- a/routes/web.php +++ b/routes/web.php @@ -41,7 +41,7 @@ Route::get('/special-calls', [ReservationsController::class, 'index'])->name('ac Route::get('/special-calls/reserve', [ReservationsController::class, 'create'])->name('reserve'); Route::post('/special-calls/reserve', [ReservationsController::class, 'store'])->name('reserveForm'); Route::get('/special-calls/reservations', [ReservationsController::class, 'edit'])->name('reservations')->middleware(['auth']); -Route::post('/special-calls/reservations', [ReservationsController::class, 'update'])->name('reservationsForm')->middleware(['auth']); +Route::post('/special-calls/reservations', [ReservationsController::class, 'edit'])->name('reservationsForm')->middleware(['auth']); Route::get('/special-calls/add', [SpecialCallsController::class, 'create'])->name('addSign')->middleware(['auth']); -- cgit v1.2.3