Zamiana radioboxów na checkboxy, dodanie działającej edycji - Wyjazdy

This commit is contained in:
czup 2019-12-07 14:44:28 +01:00
parent aab5c69c84
commit 213b279ec6
12 changed files with 211 additions and 78 deletions

View File

@ -8,6 +8,7 @@ use App\operations;
use App\operationsMembers; use App\operationsMembers;
use App\vehicle; use App\vehicle;
use App\operationsDrivers; use App\operationsDrivers;
use App\operationsTrucks;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -17,8 +18,12 @@ class operationsController extends Controller
// //
public function create(){ public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){ if(auth()->user() != null && auth()->user()->fireStationID != null ){
$operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID)
->leftJoin('users', 'operations.commanderID', '=', 'users.id')
->select('operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname')
->get();
return view('operation'); return view('operation', ["operations" => $operations]);
} else{ } else{
return view('operation'); return view('operation');
} }
@ -37,8 +42,23 @@ class operationsController extends Controller
public function editForm(){ public function editForm($id){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$operation = DB::table('operations')->where('operations.id', '=', $id)->first();
// $operation = DB::table('operations')->where('operations.id', '=', $id)
// ->leftJoin('users', 'operations.commanderID', '=', 'users.id')
// ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname')
// ->get();
// if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) {
return view('operationEdit', ["operation" => $operation]);
// } else{
// return "Brak dostepu";
// }
} else{
return view('unit');
}
} }
public function store(){ public function store(){
@ -49,7 +69,10 @@ class operationsController extends Controller
'operationDangerType' => 'required', 'operationDangerType' => 'required',
'operationDescription' => 'required', 'operationDescription' => 'required',
'operationLeader' => 'required', 'operationLeader' => 'required',
'operationDriver' => 'required', 'operationDriver.*' => 'required',
'operationVehicle.*' => 'required',
'attendance.*' => 'required',
'transport.*' => 'required',
], ],
[ [
'required' => ':attribute jest wymagany(e)' 'required' => ':attribute jest wymagany(e)'
@ -63,8 +86,30 @@ class operationsController extends Controller
'dangerType' => $request-> operationDangerType, 'dangerType' => $request-> operationDangerType,
'description' => $request-> operationDescription, 'description' => $request-> operationDescription,
'commanderID' => $request-> operationLeader, 'commanderID' => $request-> operationLeader,
'fireStationID' => auth()->user()->fireStationID,
]); ]);
$operationDriver = $request ->operationDriver;
$operationVehicle = $request -> operationVehicle;
for($count = 0; $count < count($operationDriver); $count++){
$operationsTrucks = operationsTrucks::create([
'operationID' => $operations->id,
'truckID' => $operationDriver[$count],
'driverID' => $operationVehicle[$count]
]);
}
$attendance = $request-> attendance;
for($count = 0; $count < count($attendance); $count++){
if($attendance[$count] != 'false'){
$operationsMembers = operationsMembers::create([
'operationID' => $operations->id,
'memberID' => $attendance[$count],
'privateTransport' => $request->transport[$count],
]);
};
}
return operationsController::create(); return operationsController::create();
} }

View File

@ -9,5 +9,5 @@ class operations extends Model
// //
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $fillable = ['operationDate', 'location', 'target', 'dangerType', 'description', 'commanderID', 'driverID']; protected $fillable = ['fireStationID', 'operationDate', 'location', 'target', 'dangerType', 'description', 'commanderID'];
} }

View File

@ -8,6 +8,7 @@ class operationsMembers extends Model
{ {
// //
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $table = 'operationsMembers';
protected $fillable = ['operationID', 'memberID']; protected $fillable = ['operationID', 'memberID', 'privateTransport'];
} }

View File

@ -8,6 +8,7 @@ class operationsTrucks extends Model
{ {
// //
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $table = 'operationsTrucks';
protected $fillable = ['operationID', 'truckID']; protected $fillable = ['operationID', 'truckID', 'driverID'];
} }

View File

@ -21,7 +21,6 @@ class CreateOperationsTable extends Migration
$table->string('dangerType', 100); $table->string('dangerType', 100);
$table->string('description'); $table->string('description');
$table->integer('commanderID'); $table->integer('commanderID');
$table->integer('driverID');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -17,6 +17,7 @@ class CreateOperationsTrucksTable extends Migration
$table->increments('id'); $table->increments('id');
$table->integer('operationID'); $table->integer('operationID');
$table->integer('truckID'); $table->integer('truckID');
$table->integer('driverID');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -17,6 +17,7 @@ class CreateOperationsMembersTable extends Migration
$table->increments('id'); $table->increments('id');
$table->integer('operationID'); $table->integer('operationID');
$table->integer('memberID'); $table->integer('memberID');
$table->boolean('privateTransport');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFireStationIDColumnToOperationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('operations', function (Blueprint $table) {
//
$table->integer('fireStationID');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('operations', function (Blueprint $table) {
//
});
}
}

View File

@ -11,6 +11,34 @@
@section('center-area') @section('center-area')
@parent @parent
Strona w budowie @if( auth()->check())
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
<table class='firefighterViewTable'>
<tr class='table-header'>
<td>Data</td>
<td>Miejsce</td>
<td>Cel</td>
<td>Rodzaj zagrożenia</td>
<td>Dowódca</td>
</tr>
@foreach($operations as $operation)
<tr>
<td id="operationDate{{ $operation->id }}">{{ $operation->operationDate }}</td>
<td id="operationLocation{{ $operation->id }}">{{ $operation->location }}</td>
<td id="operationTarget{{ $operation->id }}">{{ $operation->target }}</td>
<td id="operationDangerType{{ $operation->id }}">{{ $operation->dangerType }}</td>
<td id="operationCommander{{ $operation->id }}">{{$operation->name}} {{$operation->surname}}</td>
<td><a href="{{ URL::asset('wyjazdy/edit/'.$operation->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td>
</tr>
@endforeach
</table>"
@endif
@else
Brak autoryzacji
@endif
@stop @stop

View File

@ -52,23 +52,43 @@
<div class=form-group"> <div class=form-group">
<div id="drivers"> <div id="drivers">
<label for="location">Kierowca:</label> {{-- <label for="location">Kierowca:</label>--}}
<select name="operationDriver" class="form-control"> {{-- <select name="operationDriver" class="form-control">--}}
<option value="">--- Wybierz kierowcę ---</option> {{-- <option value="">--- Wybierz kierowcę ---</option>--}}
@foreach ($fireFighters as $fireFighter) {{-- @foreach ($fireFighters as $fireFighter)--}}
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option> {{-- <option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>--}}
@endforeach {{-- @endforeach--}}
</select> {{-- </select>--}}
<label for="location">Pojazd:</label> {{-- <label for="location">Pojazd:</label>--}}
<select name="operationVehicle" class="form-control"> {{-- <select name="operationVehicle" class="form-control">--}}
<option value="">--- Wybierz pojazd ---</option> {{-- <option value="">--- Wybierz pojazd ---</option>--}}
@foreach ($vehicles as $vehicle) {{-- @foreach ($vehicles as $vehicle)--}}
<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option> {{-- <option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>--}}
@endforeach {{-- @endforeach--}}
</select> {{-- </select>--}}
</div> </div>
</div> </div>
<div class="form-group">
<table>
<tr>
<td>Imię i nazwisko: [</td><td></td><td>Obecność:</td><td>[][][]</td><td>Transport własny:</td>
</tr>
@php
$i = 0;
@endphp
@foreach($fireFighters as $fireFighterChecklist)
<tr>
<td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td> </td><td>Tak <input type="radio" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}">Nie<input type="radio" name="attendance[{{$i}}]" value="false" checked></td><td> </td><td>Tak <input type="radio" name="transport[{{$i}}]" value="1">Nie <input type="radio" name="transport[{{$i}}]" value="0" checked></td>
</tr>
@php
$i++;
@endphp
@endforeach
</table>
</div>
<div class="form-group"> <div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button> <button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button>
</div> </div>

View File

@ -14,40 +14,42 @@
@parent @parent
<form method="POST" action="/wyjazdy" id="dynamic_form"> <form method="POST" action="/wyjazdy" id="dynamic_form">
{{ csrf_field() }} {{ csrf_field() }}
<input type="hidden" class="form-control" name="operationID" value="{{ $operation->id }}">
<div class="form-group"> <div class="form-group">
<label for="date">Data wyjazdu: </label> <label for="date">Data wyjazdu: </label>
<input type="datetime-local" id="operationDate" name="operationDate"> <input type="datetime-local" id="operationDate" name="operationDate" value="{{$operation->operationDate}}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Miejsce akcji:</label> <label for="location">Miejsce akcji:</label>
<input type="text" class="form-control" id="operationLocation" name="operationLocation"> <input type="text" class="form-control" id="operationLocation" name="operationLocation" value="{{ $operation->location }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Cel wyjazdu:</label> <label for="location">Cel wyjazdu:</label>
<input type="text" class="form-control" id="operationTarget" name="operationTarget"> <input type="text" class="form-control" id="operationTarget" name="operationTarget" value="{{ $operation->target }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Rodzaj zagrożenia:</label> <label for="location">Rodzaj zagrożenia:</label>
<input type="text" class="form-control" id="operationDangerType" name="operationDangerType"> <input type="text" class="form-control" id="operationDangerType" name="operationDangerType" value="{{ $operation->dangerType }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="location">Opis akcji:</label> <label for="location">Opis akcji:</label>
<textarea class="form-control" id="'operationDescription" name="operationDescription">Enter text here...</textarea> <textarea class="form-control" id="'operationDescription" name="operationDescription">{{ $operation->description }}</textarea>
</div> </div>
<div class=form-group"> {{-- <div class=form-group">--}}
<label for="location">Dowodzący:</label> {{-- <label for="location">Dowodzący:</label>--}}
<select name="operationLeader" class="form-control"> {{-- <select name="operationLeader" class="form-control">--}}
<option value="">--- Wybierz dowódcę ---</option> {{-- <option value="">--- Wybierz dowódcę ---</option>--}}
@foreach ($fireFighters as $fireFighter) {{-- @foreach ($fireFighters as $fireFighter)--}}
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option> {{-- <option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>--}}
@endforeach {{-- @endforeach--}}
</select> {{-- </select>--}}
</div> {{-- </div>--}}
<div class=form-group"> <div class=form-group">
@ -69,24 +71,24 @@
</div> </div>
</div> </div>
<div class="form-group"> {{-- <div class="form-group">--}}
<table> {{-- <table>--}}
<tr> {{-- <tr>--}}
<td>Imię i nazwisko: [</td><td></td><td>Obecność:</td><td>[][][]</td><td>Transport własny:</td> {{-- <td>Imię i nazwisko: [</td><td></td><td>Obecność:</td><td>[][][]</td><td>Transport własny:</td>--}}
</tr> {{-- </tr>--}}
@php {{-- @php--}}
$i = 0; {{-- $i = 0;--}}
@endphp {{-- @endphp--}}
@foreach($fireFighters as $fireFighterChecklist) {{-- @foreach($fireFighters as $fireFighterChecklist)--}}
<tr> {{-- <tr>--}}
<td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td> </td><td>Tak <input type="radio" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}">Nie<input type="radio" name="attendance[{{$i}}]" value="false" checked></td><td> </td><td>Tak <input type="radio" name="transport[{{$i}}]" value="1">Nie <input type="radio" name="transport[{{$i}}]" value="0" checked></td> {{-- <td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td> </td><td>Tak <input type="radio" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}">Nie<input type="radio" name="attendance[{{$i}}]" value="false" checked></td><td> </td><td>Tak <input type="radio" name="transport[{{$i}}]" value="1">Nie <input type="radio" name="transport[{{$i}}]" value="0" checked></td>--}}
</tr> {{-- </tr>--}}
@php {{-- @php--}}
$i++; {{-- $i++;--}}
@endphp {{-- @endphp--}}
@endforeach {{-- @endforeach--}}
</table> {{-- </table>--}}
</div> {{-- </div>--}}
<div class="form-group"> <div class="form-group">
@ -107,31 +109,31 @@
function dynamic_field(number) function dynamic_field(number)
{ {
html = '<div id="singleDriver"><label for="location">Kierowca:</label>'; {{--html = '<div id="singleDriver"><label for="location">Kierowca:</label>';--}}
html += '<select name="operationDriver[]" class="form-control">'; {{--html += '<select name="operationDriver[]" class="form-control">';--}}
html += '<option value="">--- Wybierz kierowcę ---</option>'; {{--html += '<option value="">--- Wybierz kierowcę ---</option>';--}}
html += '@foreach ($fireFighters as $fireFighter)'; {{--html += '@foreach ($fireFighters as $fireFighter)';--}}
html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>'; {{--html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';--}}
html += '@endforeach'; {{--html += '@endforeach';--}}
html += '</select>'; {{--html += '</select>';--}}
html += '<label for="location">Pojazd:</label>'; {{--html += '<label for="location">Pojazd:</label>';--}}
html += '<select name="operationVehicle[]" class="form-control">'; {{--html += '<select name="operationVehicle[]" class="form-control">';--}}
html += '<option value="">--- Wybierz pojazd ---</option>'; {{--html += '<option value="">--- Wybierz pojazd ---</option>';--}}
html += '@foreach ($vehicles as $vehicle)'; {{--html += '@foreach ($vehicles as $vehicle)';--}}
html += '<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>'; {{--html += '<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>';--}}
html += '@endforeach'; {{--html += '@endforeach';--}}
html += '</select>'; {{--html += '</select>';--}}
if(number > 1) {{--if(number > 1)--}}
{ {{--{--}}
html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>'; {{-- html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';--}}
$('#drivers').append(html); {{-- $('#drivers').append(html);--}}
} {{--}--}}
else {{--else--}}
{ {{--{--}}
html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>'; {{-- html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';--}}
$('#drivers').html(html); {{-- $('#drivers').html(html);--}}
} {{--}--}}
} }
$(document).on('click', '#add', function(){ $(document).on('click', '#add', function(){

View File

@ -33,6 +33,8 @@ Route::get('/pojazdy', function(){
Route::get('/wyjazdy', 'operationsController@create'); Route::get('/wyjazdy', 'operationsController@create');
Route::get('/wyjazdy/add/', 'operationsController@addForm'); Route::get('/wyjazdy/add/', 'operationsController@addForm');
Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store'); Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store');
Route::get('/wyjazdy/edit/{id}', 'operationsController@editForm');
Route::post('/wyjazdy/edit', 'operationsController@update');
Route::get('/register', 'RegistrationController@create'); Route::get('/register', 'RegistrationController@create');
Route::post('/register', 'RegistrationController@store'); Route::post('/register', 'RegistrationController@store');