From 406605de39aec5acac79b46e3bc1360927c562e2 Mon Sep 17 00:00:00 2001 From: czup Date: Fri, 24 Jan 2020 23:05:55 +0100 Subject: [PATCH] Dodanie paginacji --- .idea/workspace.xml | 19 +++++--- app/Http/Controllers/operationsController.php | 13 +++++- app/operations.php | 3 +- ...9_11_12_235707_create_operations_table.php | 1 + resources/views/operation.blade.php | 46 +++++++++++++++++-- resources/views/operationAdd.blade.php | 45 +----------------- resources/views/trainings.blade.php | 3 +- .../views/trainingsAddFireFighters.blade.php | 3 -- routes/web.php | 1 + 9 files changed, 73 insertions(+), 61 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2538e00..f5a381a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,15 @@ - - + + - + + + @@ -185,10 +188,10 @@ - + - + @@ -197,6 +200,10 @@ + + + + diff --git a/app/Http/Controllers/operationsController.php b/app/Http/Controllers/operationsController.php index 478a0e6..f0c5e92 100644 --- a/app/Http/Controllers/operationsController.php +++ b/app/Http/Controllers/operationsController.php @@ -20,10 +20,10 @@ class operationsController extends Controller public function create(){ if(auth()->user() != null && auth()->user()->fireStationID != null ){ $operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID) + ->whereNull('deleted_at') ->leftJoin('users', 'operations.commanderID', '=', 'users.id') ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.name', 'users.surname') - ->get(); - + ->paginate(10); $fireFighters = array(); $trucks = array(); foreach($operations as $operation){ @@ -257,4 +257,13 @@ class operationsController extends Controller return operationsController::create(); } + + public function destroy($id) + { + operations::find($id)->delete($id); + + return response()->json([ + 'success' => 'Record deleted successfully!' + ]); + } } diff --git a/app/operations.php b/app/operations.php index bf4360a..8e27d17 100644 --- a/app/operations.php +++ b/app/operations.php @@ -4,12 +4,13 @@ namespace App; use Illuminate\Database\Eloquent\Model; use Carbon\Carbon; +use Illuminate\Database\Eloquent\SoftDeletes; class operations extends Model { // + use SoftDeletes; protected $primaryKey = 'id'; - protected $fillable = ['fireStationID', 'operationDate', 'location', 'target', 'dangerType', 'description', 'commanderID']; } diff --git a/database/migrations/2019_11_12_235707_create_operations_table.php b/database/migrations/2019_11_12_235707_create_operations_table.php index 3d51b7f..9b794cb 100644 --- a/database/migrations/2019_11_12_235707_create_operations_table.php +++ b/database/migrations/2019_11_12_235707_create_operations_table.php @@ -21,6 +21,7 @@ class CreateOperationsTable extends Migration $table->string('dangerType', 100); $table->string('description'); $table->integer('commanderID'); + $table->softDeletes(); $table->timestamps(); }); } diff --git a/resources/views/operation.blade.php b/resources/views/operation.blade.php index 63911c3..adddd89 100644 --- a/resources/views/operation.blade.php +++ b/resources/views/operation.blade.php @@ -1,5 +1,6 @@ @extends('layout.app') + @section('left-menu') @parent
    @@ -8,6 +9,7 @@ @stop @section('center-area') + @parent @if( auth()->check()) @if( auth()->user()->fireStationID == NULL) @@ -39,8 +41,13 @@ {{ $operation->target }} {{ $operation->dangerType }} {{$operation->name}} {{$operation->surname}} - - + + + + + + + {{-- bgcolor="#C0C0C0"--}} @@ -110,7 +117,7 @@ @endforeach - + {{ $operations->links() }} @endif @else Brak autoryzacji @@ -129,6 +136,39 @@ } } + + + function deleteButton(operationID){ + swal.fire({ + title: "Czy chcesz usunąć wyjazd?", + width: 'auto', + confirmButtonText: 'Tak', + cancelButtonText: 'Nie', + showCancelButton: true, + }).then((result) => { + if(result.value){ + + $.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } + }); + + $.ajax({ + url: "wyjazdy/"+operationID, + type: 'DELETE', + data: { + "id": operationID, + }, + success: function (){ + console.log("it Works"); + location.reload(); + } + }); + } + }) + + } diff --git a/resources/views/operationAdd.blade.php b/resources/views/operationAdd.blade.php index d1e1a5b..12b01e2 100644 --- a/resources/views/operationAdd.blade.php +++ b/resources/views/operationAdd.blade.php @@ -53,20 +53,7 @@
    -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} +

    @@ -173,36 +160,6 @@ }); }); - {{--$('#dynamic_form').on('submit', function(event){--}} - {{-- event.preventDefault();--}} - {{-- $.ajax({--}} - {{-- url:'{{ route("operationController.store") }}',--}} - {{-- method:'post',--}} - {{-- data:$(this).serialize(),--}} - {{-- dataType:'json',--}} - {{-- beforeSend:function(){--}} - {{-- $('#save').attr('disabled','disabled');--}} - {{-- },--}} - {{-- success:function(data)--}} - {{-- {--}} - {{-- if(data.error)--}} - {{-- {--}} - {{-- var error_html = '';--}} - {{-- for(var count = 0; count < data.error.length; count++)--}} - {{-- {--}} - {{-- error_html += '

    '+data.error[count]+'

    ';--}} - {{-- }--}} - {{-- $('#result').html('
    '+error_html+'
    ');--}} - {{-- }--}} - {{-- else--}} - {{-- {--}} - {{-- dynamic_field(1);--}} - {{-- $('#result').html('
    '+data.success+'
    ');--}} - {{-- }--}} - {{-- $('#save').attr('disabled', false);--}} - {{-- }--}} - {{-- })--}} - {{--});--}} }); diff --git a/resources/views/trainings.blade.php b/resources/views/trainings.blade.php index ce4c5cd..8af36c8 100644 --- a/resources/views/trainings.blade.php +++ b/resources/views/trainings.blade.php @@ -1,7 +1,6 @@ @extends('layout.app') -Add Edit Delete Table Row Example using JQuery - ItSolutionStuff.com - + diff --git a/resources/views/trainingsAddFireFighters.blade.php b/resources/views/trainingsAddFireFighters.blade.php index 19c7b77..bf4cfd1 100644 --- a/resources/views/trainingsAddFireFighters.blade.php +++ b/resources/views/trainingsAddFireFighters.blade.php @@ -1,8 +1,5 @@ @extends('layout.app') - -Add Edit Delete Table Row Example using JQuery - ItSolutionStuff.com - diff --git a/routes/web.php b/routes/web.php index d6f8555..878b5bc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -37,6 +37,7 @@ Route::get('/wyjazdy/add/', 'operationsController@addForm'); Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store'); Route::post('/wyjazdy/edit/', 'operationsController@update')->name('operationController.update'); Route::get('/wyjazdy/edit/{id}', 'operationsController@editForm'); +Route::delete('wyjazdy/{id}', 'operationsController@destroy')->name('operationController.destroy'); Route::get('/register', 'RegistrationController@create'); Route::post('/register', 'RegistrationController@store');