1
0
forked from s421507/eOSP2

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\vehicle;
use App\operationsDrivers;
use App\operationsTrucks;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -17,8 +18,12 @@ 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)
->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{
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(){
@ -49,7 +69,10 @@ class operationsController extends Controller
'operationDangerType' => 'required',
'operationDescription' => 'required',
'operationLeader' => 'required',
'operationDriver' => 'required',
'operationDriver.*' => 'required',
'operationVehicle.*' => 'required',
'attendance.*' => 'required',
'transport.*' => 'required',
],
[
'required' => ':attribute jest wymagany(e)'
@ -63,8 +86,30 @@ class operationsController extends Controller
'dangerType' => $request-> operationDangerType,
'description' => $request-> operationDescription,
'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();
}

View File

@ -9,5 +9,5 @@ class operations extends Model
//
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 $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 $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('description');
$table->integer('commanderID');
$table->integer('driverID');
$table->timestamps();
});
}

View File

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

View File

@ -17,6 +17,7 @@ class CreateOperationsMembersTable extends Migration
$table->increments('id');
$table->integer('operationID');
$table->integer('memberID');
$table->boolean('privateTransport');
$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')
@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

View File

@ -52,23 +52,43 @@
<div class=form-group">
<div id="drivers">
<label for="location">Kierowca:</label>
<select name="operationDriver" class="form-control">
<option value="">--- Wybierz kierowcę ---</option>
@foreach ($fireFighters as $fireFighter)
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
@endforeach
</select>
<label for="location">Pojazd:</label>
<select name="operationVehicle" class="form-control">
<option value="">--- Wybierz pojazd ---</option>
@foreach ($vehicles as $vehicle)
<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>
@endforeach
</select>
{{-- <label for="location">Kierowca:</label>--}}
{{-- <select name="operationDriver" class="form-control">--}}
{{-- <option value="">--- Wybierz kierowcę ---</option>--}}
{{-- @foreach ($fireFighters as $fireFighter)--}}
{{-- <option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>--}}
{{-- @endforeach--}}
{{-- </select>--}}
{{-- <label for="location">Pojazd:</label>--}}
{{-- <select name="operationVehicle" class="form-control">--}}
{{-- <option value="">--- Wybierz pojazd ---</option>--}}
{{-- @foreach ($vehicles as $vehicle)--}}
{{-- <option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>--}}
{{-- @endforeach--}}
{{-- </select>--}}
</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">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button>
</div>

View File

@ -14,40 +14,42 @@
@parent
<form method="POST" action="/wyjazdy" id="dynamic_form">
{{ csrf_field() }}
<input type="hidden" class="form-control" name="operationID" value="{{ $operation->id }}">
<div class="form-group">
<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 class="form-group">
<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 class="form-group">
<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 class="form-group">
<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 class="form-group">
<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 class=form-group">
<label for="location">Dowodzący:</label>
<select name="operationLeader" class="form-control">
<option value="">--- Wybierz dowódcę ---</option>
@foreach ($fireFighters as $fireFighter)
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
@endforeach
</select>
</div>
{{-- <div class=form-group">--}}
{{-- <label for="location">Dowodzący:</label>--}}
{{-- <select name="operationLeader" class="form-control">--}}
{{-- <option value="">--- Wybierz dowódcę ---</option>--}}
{{-- @foreach ($fireFighters as $fireFighter)--}}
{{-- <option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>--}}
{{-- @endforeach--}}
{{-- </select>--}}
{{-- </div>--}}
<div class=form-group">
@ -69,24 +71,24 @@
</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">--}}
{{-- <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">
@ -107,31 +109,31 @@
function dynamic_field(number)
{
html = '<div id="singleDriver"><label for="location">Kierowca:</label>';
html += '<select name="operationDriver[]" class="form-control">';
html += '<option value="">--- Wybierz kierowcę ---</option>';
html += '@foreach ($fireFighters as $fireFighter)';
html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';
html += '@endforeach';
html += '</select>';
html += '<label for="location">Pojazd:</label>';
html += '<select name="operationVehicle[]" class="form-control">';
html += '<option value="">--- Wybierz pojazd ---</option>';
html += '@foreach ($vehicles as $vehicle)';
html += '<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>';
html += '@endforeach';
html += '</select>';
{{--html = '<div id="singleDriver"><label for="location">Kierowca:</label>';--}}
{{--html += '<select name="operationDriver[]" class="form-control">';--}}
{{--html += '<option value="">--- Wybierz kierowcę ---</option>';--}}
{{--html += '@foreach ($fireFighters as $fireFighter)';--}}
{{--html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';--}}
{{--html += '@endforeach';--}}
{{--html += '</select>';--}}
{{--html += '<label for="location">Pojazd:</label>';--}}
{{--html += '<select name="operationVehicle[]" class="form-control">';--}}
{{--html += '<option value="">--- Wybierz pojazd ---</option>';--}}
{{--html += '@foreach ($vehicles as $vehicle)';--}}
{{--html += '<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>';--}}
{{--html += '@endforeach';--}}
{{--html += '</select>';--}}
if(number > 1)
{
html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';
$('#drivers').append(html);
}
else
{
html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';
$('#drivers').html(html);
}
{{--if(number > 1)--}}
{{--{--}}
{{-- html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';--}}
{{-- $('#drivers').append(html);--}}
{{--}--}}
{{--else--}}
{{--{--}}
{{-- html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';--}}
{{-- $('#drivers').html(html);--}}
{{--}--}}
}
$(document).on('click', '#add', function(){

View File

@ -33,6 +33,8 @@ Route::get('/pojazdy', function(){
Route::get('/wyjazdy', 'operationsController@create');
Route::get('/wyjazdy/add/', 'operationsController@addForm');
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::post('/register', 'RegistrationController@store');