#21 adjust the pirep view/edit form

This commit is contained in:
Nabeel Shahzad 2017-07-13 22:09:38 -05:00
parent b531fb4d15
commit fc6253b46f
9 changed files with 185 additions and 84 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Requests\CreatePirepRequest; use App\Http\Requests\CreatePirepRequest;
use App\Http\Requests\UpdatePirepRequest; use App\Http\Requests\UpdatePirepRequest;
use App\Repositories\AircraftRepository;
use App\Repositories\PirepRepository; use App\Repositories\PirepRepository;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Flash; use Flash;
@ -12,11 +13,24 @@ use Response;
class PirepController extends BaseController 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) public function index(Request $request)
{ {
$this->pirepRepository->pushCriteria(new RequestCriteria($request)); $this->pirepRepo->pushCriteria(new RequestCriteria($request));
$pireps = $this->pirepRepository->all(); $pireps = $this->pirepRepo->all();
return view('admin.pireps.index', [ return view('admin.pireps.index', [
'pireps' => $pireps 'pireps' => $pireps
@ -55,7 +69,7 @@ class PirepController extends BaseController
public function store(CreatePirepRequest $request) public function store(CreatePirepRequest $request)
{ {
$input = $request->all(); $input = $request->all();
$pirep = $this->pirepRepository->create($input); $pirep = $this->pirepRepo->create($input);
Flash::success('Pirep saved successfully.'); Flash::success('Pirep saved successfully.');
return redirect(route('admin.pireps.index')); return redirect(route('admin.pireps.index'));
@ -70,7 +84,7 @@ class PirepController extends BaseController
*/ */
public function show($id) public function show($id)
{ {
$pirep = $this->pirepRepository->findWithoutFail($id); $pirep = $this->pirepRepo->findWithoutFail($id);
if (empty($pirep)) { if (empty($pirep)) {
Flash::error('Pirep not found'); Flash::error('Pirep not found');
@ -91,7 +105,7 @@ class PirepController extends BaseController
*/ */
public function edit($id) public function edit($id)
{ {
$pirep = $this->pirepRepository->findWithoutFail($id); $pirep = $this->pirepRepo->findWithoutFail($id);
if (empty($pirep)) { if (empty($pirep)) {
Flash::error('Pirep not found'); Flash::error('Pirep not found');
@ -100,6 +114,7 @@ class PirepController extends BaseController
return view('admin.pireps.edit', [ return view('admin.pireps.edit', [
'pirep' => $pirep, 'pirep' => $pirep,
'aircraft' => $this->aircraftList(),
]); ]);
} }
@ -113,14 +128,14 @@ class PirepController extends BaseController
*/ */
public function update($id, UpdatePirepRequest $request) public function update($id, UpdatePirepRequest $request)
{ {
$pirep = $this->pirepRepository->findWithoutFail($id); $pirep = $this->pirepRepo->findWithoutFail($id);
if (empty($pirep)) { if (empty($pirep)) {
Flash::error('Pirep not found'); Flash::error('Pirep not found');
return redirect(route('admin.pireps.index')); 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.'); Flash::success('Pirep updated successfully.');
return redirect(route('admin.pireps.index')); return redirect(route('admin.pireps.index'));
@ -135,14 +150,14 @@ class PirepController extends BaseController
*/ */
public function destroy($id) public function destroy($id)
{ {
$pirep = $this->pirepRepository->findWithoutFail($id); $pirep = $this->pirepRepo->findWithoutFail($id);
if (empty($pirep)) { if (empty($pirep)) {
Flash::error('Pirep not found'); Flash::error('Pirep not found');
return redirect(route('admin.pireps.index')); return redirect(route('admin.pireps.index'));
} }
$this->pirepRepository->delete($id); $this->pirepRepo->delete($id);
Flash::success('Pirep deleted successfully.'); Flash::success('Pirep deleted successfully.');
return redirect(route('admin.pireps.index')); return redirect(route('admin.pireps.index'));

View File

@ -30,7 +30,7 @@ class PirepFieldValues extends Model
= [ = [
'name' => 'string', 'name' => 'string',
'value' => 'string', 'value' => 'string',
'source' => 'integer', 'source' => 'string',
]; ];
/** /**

View File

@ -77,7 +77,7 @@ class CreatePirepsTable extends Migration
$table->uuid('pirep_id'); $table->uuid('pirep_id');
$table->string('name', 50); $table->string('name', 50);
$table->text('value'); $table->text('value');
$table->tinyInteger('source')->default(0); $table->string('source')->nullable();
$table->timestamps(); $table->timestamps();
$table->index('pirep_id'); $table->index('pirep_id');

View File

@ -160,7 +160,8 @@ flight_fields:
value: B value: B
pireps: pireps:
- user_id: 1 - id: pirepid_1
user_id: 1
flight_id: flightid_1 flight_id: flightid_1
aircraft_id: 1 aircraft_id: 1
dpt_airport_id: 1 dpt_airport_id: 1
@ -169,3 +170,15 @@ pireps:
level: 320 level: 320
status: -1 status: -1
notes: just a pilot report 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

View File

@ -0,0 +1,35 @@
<div id="pirep_field_values_wrapper">
<table class="table table-responsive" id="flight-fields-table">
<thead>
<th>Name</th>
<th>Value</th>
<th>Source</th>
<th style="text-align: right;">Actions</th>
</thead>
<tbody>
@foreach($pirep->fields as $field)
<tr>
<td>{!! $field->name !!}</td>
<td>
<a class="inline" href="#" data-pk="{!! $field->id !!}" data-name="{!! $field->name !!}">{!! $field->value !!}</a>
</td>
<td>{!! $field->source !!}</td>
<td style="width: 10%; text-align: right;" class="form-inline">
{!! Form::open(['url' => '/admin/pireps/'.$pirep->id.'/fields',
'method' => 'delete',
'class' => 'pjax_form pirep_fields'
]) !!}
{!! Form::hidden('field_id', $field->id) !!}
<div class='btn-group'>
{{--{!! Form::button('<i class="glyphicon glyphicon-trash"></i>',
['type' => 'submit',
'class' => 'btn btn-danger btn-xs'])
!!}--}}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>

View File

@ -1,13 +1,13 @@
<!-- Flight Id Field --> <!-- Flight Id Field -->
<div class="form-group col-sm-6"> {{--<div class="form-group col-sm-6">
{!! Form::label('flight_id', 'Flight ID:') !!} {!! Form::label('flight_id', 'Flight ID:') !!}
{!! Form::text('flight_id', null, ['class' => 'form-control']) !!} {!! Form::text('flight_id', null, ['class' => 'form-control']) !!}
</div> </div>--}}
<!-- Aircraft Id Field --> <!-- Aircraft Id Field -->
<div class="form-group col-sm-6"> <div class="form-group col-sm-6">
{!! Form::label('aircraft_id', 'Aircraft ID:') !!} {!! Form::label('aircraft_id', 'Aircraft ID:') !!}
{!! Form::text('aircraft_id', null, ['class' => 'form-control']) !!} {!! Form::select('aircraft_id', $aircraft, null, ['class' => 'form-control']) !!}
</div> </div>
<!-- Flight Time Field --> <!-- Flight Time Field -->

View File

@ -1,17 +1,23 @@
@extends('admin.app') @extends('admin.app')
@section('content') @section('content')
<section class="content-header"> <section class="content-header"><h1>PIREP</h1></section>
<h1>PIREP</h1> <section class="content">
</section> <div class="clearfix"></div>
<div class="content"> <div class="row">
<div class="box box-primary"> @include('admin.pireps.show_fields')
<div class="box-body"> </div>
<div class="row" style="padding-left: 20px"> <div class="box box-primary">
@include('admin.pireps.show_fields') <div class="box-body">
<a href="{!! route('admin.pireps.index') !!}" class="btn btn-default">Back</a> <div class="row">
<div class="col-xs-12">
<h3>fields</h3>
<div class="box-body">
@include('admin.pireps.field_values')
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</section>
@endsection @endsection

View File

@ -1,66 +1,100 @@
<!-- Id Field --> <div class="form-group col-sm-6">
<div class="form-group"> <div class="box box-solid">
{!! Form::label('id', 'Id:') !!} <div class="box-header with-border">
<p>{!! $pirep->id !!}</p> {{--<i class="fa fa-text-width"></i>--}}
<h3 class="box-title">{!! Form::label('dpt_airport_id', 'Dep ICAO') !!}</h3>
</div>
<div class="box-body"><p class="lead">
{!! $pirep->dpt_airport->icao !!} - {!! $pirep->dpt_airport->name !!}
</p></div>
</div>
</div> </div>
<!-- User Id Field --> <div class="form-group col-sm-6">
<div class="form-group"> <div class="box box-solid">
{!! Form::label('user_id', 'User Id:') !!} <div class="box-header with-border">
<p>{!! $pirep->user_id !!}</p> {{--<i class="fa fa-text-width"></i>--}}
<h3 class="box-title">{!! Form::label('arr_airport_id', 'Arrival ICAO') !!}</h3>
</div>
<div class="box-body"><p class="lead">
{!! $pirep->arr_airport->icao !!} - {!! $pirep->arr_airport->name !!}
</p>
</div>
</div>
</div> </div>
<!-- Flight Id Field -->
<div class="form-group">
{!! Form::label('flight_id', 'Flight Id:') !!}
<p>{!! $pirep->flight_id !!}</p>
</div>
<!-- Aircraft Id Field -->
<div class="form-group">
{!! Form::label('aircraft_id', 'Aircraft Id:') !!}
<p>{!! $pirep->aircraft_id !!}</p>
</div>
<!-- Flight Time Field -->
<div class="form-group">
{!! Form::label('flight_time', 'Flight Time:') !!}
<p>{!! $pirep->flight_time !!}</p>
</div>
<!-- Level Field --> <div class="form-group col-sm-12">
<div class="form-group"> <div class="box box-primary">
{!! Form::label('level', 'Level:') !!} <div class="box-body">
<p>{!! $pirep->level !!}</p>
</div>
<!-- Route Field --> <!-- User Id Field -->
<div class="form-group"> <div class="form-group">
{!! Form::label('route', 'Route:') !!} {!! Form::label('user_id', 'Pilot:') !!}
<p>{!! $pirep->route !!}</p> <p>{!! $pirep->user->name !!}</p>
</div> </div>
<!-- Notes Field --> <!-- Flight Id Field -->
<div class="form-group"> <div class="form-group">
{!! Form::label('notes', 'Notes:') !!} {!! Form::label('flight_id', 'Flight Id:') !!}
<p>{!! $pirep->notes !!}</p> <p>
</div> <a href="{!! route('admin.flights.show', [$pirep->flight_id]) !!}" target="_blank">
{!! $pirep->flight->airline->code !!}{!! $pirep->flight->flight_number !!}
</a>
</p>
</div>
<!-- Raw Data Field --> <!-- Aircraft Id Field -->
<div class="form-group"> <div class="form-group">
{!! Form::label('raw_data', 'Raw Data:') !!} {!! Form::label('aircraft_id', 'Aircraft:') !!}
<p>{!! $pirep->raw_data !!}</p> <p>{!! $pirep->aircraft->subfleet->name !!}, {!! $pirep->aircraft->name !!}
</div> ({!! $pirep->aircraft->registration !!})
</p>
</div>
<!-- Created At Field --> <!-- Flight Time Field -->
<div class="form-group"> <div class="form-group">
{!! Form::label('created_at', 'Created At:') !!} {!! Form::label('flight_time', 'Flight Time:') !!}
<p>{!! $pirep->created_at !!}</p> <p>{!! Utils::secondsToTime($pirep->flight_time) !!}</p>
</div> </div>
<!-- Updated At Field --> <!-- Level Field -->
<div class="form-group"> <div class="form-group">
{!! Form::label('updated_at', 'Updated At:') !!} {!! Form::label('level', 'Level:') !!}
<p>{!! $pirep->updated_at !!}</p> <p>{!! $pirep->level !!}</p>
</div> </div>
<!-- Route Field -->
<div class="form-group">
{!! Form::label('route', 'Route:') !!}
<p>{!! $pirep->route !!}</p>
</div>
<!-- Notes Field -->
<div class="form-group">
{!! Form::label('notes', 'Notes:') !!}
<p>{!! $pirep->notes !!}</p>
</div>
<!-- Raw Data Field -->
<div class="form-group">
{!! Form::label('raw_data', 'Raw Data:') !!}
<p>{!! $pirep->raw_data !!}</p>
</div>
<!-- Created At Field -->
<div class="form-group">
{!! Form::label('created_at', 'Created At:') !!}
<p>{!! $pirep->created_at !!}</p>
</div>
<!-- Updated At Field -->
<div class="form-group">
{!! Form::label('updated_at', 'Updated At:') !!}
<p>{!! $pirep->updated_at !!}</p>
</div>
</div>
</div>
</div>

View File

@ -5,8 +5,7 @@
<th>Aircraft</th> <th>Aircraft</th>
<th>Flight Time</th> <th>Flight Time</th>
<th>Level</th> <th>Level</th>
<th>Route</th> <th colspan="3" style="text-align: right">Action</th>
<th colspan="3">Action</th>
</thead> </thead>
<tbody> <tbody>
@foreach($pireps as $pirep) @foreach($pireps as $pirep)
@ -24,8 +23,7 @@
<td>{!! $pirep->aircraft->registration !!} ({!! $pirep->aircraft->name !!})</td> <td>{!! $pirep->aircraft->registration !!} ({!! $pirep->aircraft->name !!})</td>
<td>{!! Utils::secondsToTime($pirep->flight_time) !!}</td> <td>{!! Utils::secondsToTime($pirep->flight_time) !!}</td>
<td>{!! $pirep->level !!}</td> <td>{!! $pirep->level !!}</td>
<td>{!! $pirep->route !!}</td> <td style="text-align: right;">
<td>
{!! Form::open(['route' => ['admin.pireps.destroy', $pirep->id], 'method' => 'delete']) !!} {!! Form::open(['route' => ['admin.pireps.destroy', $pirep->id], 'method' => 'delete']) !!}
<div class='btn-group'> <div class='btn-group'>
<a href="{!! route('admin.pireps.show', [$pirep->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a> <a href="{!! route('admin.pireps.show', [$pirep->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>