diff --git a/app/Http/Controllers/Admin/PirepController.php b/app/Http/Controllers/Admin/PirepController.php index 6536fdca..6baf2afc 100644 --- a/app/Http/Controllers/Admin/PirepController.php +++ b/app/Http/Controllers/Admin/PirepController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreatePirepRequest; use App\Http\Requests\UpdatePirepRequest; +use App\Repositories\AircraftRepository; use App\Repositories\PirepRepository; use Illuminate\Http\Request; use Flash; @@ -12,11 +13,24 @@ use Response; class PirepController extends BaseController { - private $pirepRepository; + private $pirepRepo, $aircraftRepo; - public function __construct(PirepRepository $pirepRepo) + public function __construct(PirepRepository $pirepRepo, AircraftRepository $aircraftRepo) { - $this->pirepRepository = $pirepRepo; + $this->aircraftRepo = $aircraftRepo; + $this->pirepRepo = $pirepRepo; + } + + public function aircraftList() + { + $retval = []; + $all_aircraft = $this->aircraftRepo->all(); + + foreach ($all_aircraft as $ac) { + $retval[$ac->id] = $ac->subfleet->name.' - '.$ac->name.' ('.$ac->registration.')'; + } + + return $retval; } /** @@ -27,8 +41,8 @@ class PirepController extends BaseController */ public function index(Request $request) { - $this->pirepRepository->pushCriteria(new RequestCriteria($request)); - $pireps = $this->pirepRepository->all(); + $this->pirepRepo->pushCriteria(new RequestCriteria($request)); + $pireps = $this->pirepRepo->all(); return view('admin.pireps.index', [ 'pireps' => $pireps @@ -55,7 +69,7 @@ class PirepController extends BaseController public function store(CreatePirepRequest $request) { $input = $request->all(); - $pirep = $this->pirepRepository->create($input); + $pirep = $this->pirepRepo->create($input); Flash::success('Pirep saved successfully.'); return redirect(route('admin.pireps.index')); @@ -70,7 +84,7 @@ class PirepController extends BaseController */ public function show($id) { - $pirep = $this->pirepRepository->findWithoutFail($id); + $pirep = $this->pirepRepo->findWithoutFail($id); if (empty($pirep)) { Flash::error('Pirep not found'); @@ -91,7 +105,7 @@ class PirepController extends BaseController */ public function edit($id) { - $pirep = $this->pirepRepository->findWithoutFail($id); + $pirep = $this->pirepRepo->findWithoutFail($id); if (empty($pirep)) { Flash::error('Pirep not found'); @@ -100,6 +114,7 @@ class PirepController extends BaseController return view('admin.pireps.edit', [ 'pirep' => $pirep, + 'aircraft' => $this->aircraftList(), ]); } @@ -113,14 +128,14 @@ class PirepController extends BaseController */ public function update($id, UpdatePirepRequest $request) { - $pirep = $this->pirepRepository->findWithoutFail($id); + $pirep = $this->pirepRepo->findWithoutFail($id); if (empty($pirep)) { Flash::error('Pirep not found'); return redirect(route('admin.pireps.index')); } - $pirep = $this->pirepRepository->update($request->all(), $id); + $pirep = $this->pirepRepo->update($request->all(), $id); Flash::success('Pirep updated successfully.'); return redirect(route('admin.pireps.index')); @@ -135,14 +150,14 @@ class PirepController extends BaseController */ public function destroy($id) { - $pirep = $this->pirepRepository->findWithoutFail($id); + $pirep = $this->pirepRepo->findWithoutFail($id); if (empty($pirep)) { Flash::error('Pirep not found'); return redirect(route('admin.pireps.index')); } - $this->pirepRepository->delete($id); + $this->pirepRepo->delete($id); Flash::success('Pirep deleted successfully.'); return redirect(route('admin.pireps.index')); diff --git a/app/Models/PirepFieldValues.php b/app/Models/PirepFieldValues.php index e18a3b18..06313295 100644 --- a/app/Models/PirepFieldValues.php +++ b/app/Models/PirepFieldValues.php @@ -30,7 +30,7 @@ class PirepFieldValues extends Model = [ 'name' => 'string', 'value' => 'string', - 'source' => 'integer', + 'source' => 'string', ]; /** diff --git a/database/migrations/2017_06_28_195426_create_pireps_table.php b/database/migrations/2017_06_28_195426_create_pireps_table.php index 0515e021..419ef7be 100644 --- a/database/migrations/2017_06_28_195426_create_pireps_table.php +++ b/database/migrations/2017_06_28_195426_create_pireps_table.php @@ -77,7 +77,7 @@ class CreatePirepsTable extends Migration $table->uuid('pirep_id'); $table->string('name', 50); $table->text('value'); - $table->tinyInteger('source')->default(0); + $table->string('source')->nullable(); $table->timestamps(); $table->index('pirep_id'); diff --git a/database/seeds/dev.yml b/database/seeds/dev.yml index b8ebb262..121c1f88 100644 --- a/database/seeds/dev.yml +++ b/database/seeds/dev.yml @@ -160,7 +160,8 @@ flight_fields: value: B pireps: - - user_id: 1 + - id: pirepid_1 + user_id: 1 flight_id: flightid_1 aircraft_id: 1 dpt_airport_id: 1 @@ -169,3 +170,15 @@ pireps: level: 320 status: -1 notes: just a pilot report + +pirep_fields: + - id: 1 + name: arrival gate + required: 0 + +pirep_field_values: + - id: 1 + pirep_id: pirepid_1 + name: arrival gate + value: B14 + source: manual diff --git a/resources/views/admin/pireps/field_values.blade.php b/resources/views/admin/pireps/field_values.blade.php new file mode 100644 index 00000000..e73e2430 --- /dev/null +++ b/resources/views/admin/pireps/field_values.blade.php @@ -0,0 +1,35 @@ +
+ + + + + + + + + @foreach($pirep->fields as $field) + + + + + + + @endforeach + +
NameValueSourceActions
{!! $field->name !!} + {!! $field->value !!} + {!! $field->source !!} + {!! Form::open(['url' => '/admin/pireps/'.$pirep->id.'/fields', + 'method' => 'delete', + 'class' => 'pjax_form pirep_fields' + ]) !!} + {!! Form::hidden('field_id', $field->id) !!} +
+ {{--{!! Form::button('', + ['type' => 'submit', + 'class' => 'btn btn-danger btn-xs']) + !!}--}} +
+ {!! Form::close() !!} +
+
diff --git a/resources/views/admin/pireps/fields.blade.php b/resources/views/admin/pireps/fields.blade.php index f5e1d2f8..a39d3b32 100644 --- a/resources/views/admin/pireps/fields.blade.php +++ b/resources/views/admin/pireps/fields.blade.php @@ -1,13 +1,13 @@ -
+{{--
{!! Form::label('flight_id', 'Flight ID:') !!} {!! Form::text('flight_id', null, ['class' => 'form-control']) !!} -
+
--}}
{!! Form::label('aircraft_id', 'Aircraft ID:') !!} - {!! Form::text('aircraft_id', null, ['class' => 'form-control']) !!} + {!! Form::select('aircraft_id', $aircraft, null, ['class' => 'form-control']) !!}
diff --git a/resources/views/admin/pireps/show.blade.php b/resources/views/admin/pireps/show.blade.php index 2c197c5d..1c924412 100644 --- a/resources/views/admin/pireps/show.blade.php +++ b/resources/views/admin/pireps/show.blade.php @@ -1,17 +1,23 @@ @extends('admin.app') @section('content') -
-

PIREP

-
-
-
-
-
- @include('admin.pireps.show_fields') - Back +

PIREP

+
+
+
+ @include('admin.pireps.show_fields') +
+
+
+
+
+

fields

+
+ @include('admin.pireps.field_values') +
+
@endsection diff --git a/resources/views/admin/pireps/show_fields.blade.php b/resources/views/admin/pireps/show_fields.blade.php index 01878f16..fb28393a 100644 --- a/resources/views/admin/pireps/show_fields.blade.php +++ b/resources/views/admin/pireps/show_fields.blade.php @@ -1,66 +1,100 @@ - -
- {!! Form::label('id', 'Id:') !!} -

{!! $pirep->id !!}

+
+
+
+ {{----}} +

{!! Form::label('dpt_airport_id', 'Dep ICAO') !!}

+
+

+ {!! $pirep->dpt_airport->icao !!} - {!! $pirep->dpt_airport->name !!} +

+
- -
- {!! Form::label('user_id', 'User Id:') !!} -

{!! $pirep->user_id !!}

+
+
+
+ {{----}} +

{!! Form::label('arr_airport_id', 'Arrival ICAO') !!}

+
+

+ {!! $pirep->arr_airport->icao !!} - {!! $pirep->arr_airport->name !!} +

+
+
- -
- {!! Form::label('flight_id', 'Flight Id:') !!} -

{!! $pirep->flight_id !!}

-
- -
- {!! Form::label('aircraft_id', 'Aircraft Id:') !!} -

{!! $pirep->aircraft_id !!}

-
- -
- {!! Form::label('flight_time', 'Flight Time:') !!} -

{!! $pirep->flight_time !!}

-
- -
- {!! Form::label('level', 'Level:') !!} -

{!! $pirep->level !!}

-
+
+
+
- -
- {!! Form::label('route', 'Route:') !!} -

{!! $pirep->route !!}

-
+ +
+ {!! Form::label('user_id', 'Pilot:') !!} +

{!! $pirep->user->name !!}

+
- -
- {!! Form::label('notes', 'Notes:') !!} -

{!! $pirep->notes !!}

-
+ +
+ {!! Form::label('flight_id', 'Flight Id:') !!} +

+ + {!! $pirep->flight->airline->code !!}{!! $pirep->flight->flight_number !!} + +

+
- -
- {!! Form::label('raw_data', 'Raw Data:') !!} -

{!! $pirep->raw_data !!}

-
+ +
+ {!! Form::label('aircraft_id', 'Aircraft:') !!} +

{!! $pirep->aircraft->subfleet->name !!}, {!! $pirep->aircraft->name !!} + ({!! $pirep->aircraft->registration !!}) +

+
- -
- {!! Form::label('created_at', 'Created At:') !!} -

{!! $pirep->created_at !!}

-
+ +
+ {!! Form::label('flight_time', 'Flight Time:') !!} +

{!! Utils::secondsToTime($pirep->flight_time) !!}

+
- -
- {!! Form::label('updated_at', 'Updated At:') !!} -

{!! $pirep->updated_at !!}

-
+ +
+ {!! Form::label('level', 'Level:') !!} +

{!! $pirep->level !!}

+
+ +
+ {!! Form::label('route', 'Route:') !!} +

{!! $pirep->route !!}

+
+ + +
+ {!! Form::label('notes', 'Notes:') !!} +

{!! $pirep->notes !!}

+
+ + +
+ {!! Form::label('raw_data', 'Raw Data:') !!} +

{!! $pirep->raw_data !!}

+
+ + +
+ {!! Form::label('created_at', 'Created At:') !!} +

{!! $pirep->created_at !!}

+
+ + +
+ {!! Form::label('updated_at', 'Updated At:') !!} +

{!! $pirep->updated_at !!}

+
+
+
+
diff --git a/resources/views/admin/pireps/table.blade.php b/resources/views/admin/pireps/table.blade.php index a5d4de3b..1bd84f5b 100644 --- a/resources/views/admin/pireps/table.blade.php +++ b/resources/views/admin/pireps/table.blade.php @@ -5,8 +5,7 @@ Aircraft Flight Time Level - Route - Action + Action @foreach($pireps as $pirep) @@ -24,8 +23,7 @@ {!! $pirep->aircraft->registration !!} ({!! $pirep->aircraft->name !!}) {!! Utils::secondsToTime($pirep->flight_time) !!} {!! $pirep->level !!} - {!! $pirep->route !!} - + {!! Form::open(['route' => ['admin.pireps.destroy', $pirep->id], 'method' => 'delete']) !!}