#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\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'));

View File

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

View File

@ -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');

View File

@ -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

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

View File

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

View File

@ -1,66 +1,100 @@
<!-- Id Field -->
<div class="form-group">
{!! Form::label('id', 'Id:') !!}
<p>{!! $pirep->id !!}</p>
<div class="form-group col-sm-6">
<div class="box box-solid">
<div class="box-header with-border">
{{--<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>
<!-- User Id Field -->
<div class="form-group">
{!! Form::label('user_id', 'User Id:') !!}
<p>{!! $pirep->user_id !!}</p>
<div class="form-group col-sm-6">
<div class="box box-solid">
<div class="box-header with-border">
{{--<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>
<!-- 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">
{!! Form::label('level', 'Level:') !!}
<p>{!! $pirep->level !!}</p>
</div>
<div class="form-group col-sm-12">
<div class="box box-primary">
<div class="box-body">
<!-- Route Field -->
<div class="form-group">
{!! Form::label('route', 'Route:') !!}
<p>{!! $pirep->route !!}</p>
</div>
<!-- User Id Field -->
<div class="form-group">
{!! Form::label('user_id', 'Pilot:') !!}
<p>{!! $pirep->user->name !!}</p>
</div>
<!-- Notes Field -->
<div class="form-group">
{!! Form::label('notes', 'Notes:') !!}
<p>{!! $pirep->notes !!}</p>
</div>
<!-- Flight Id Field -->
<div class="form-group">
{!! Form::label('flight_id', 'Flight Id:') !!}
<p>
<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 -->
<div class="form-group">
{!! Form::label('raw_data', 'Raw Data:') !!}
<p>{!! $pirep->raw_data !!}</p>
</div>
<!-- Aircraft Id Field -->
<div class="form-group">
{!! Form::label('aircraft_id', 'Aircraft:') !!}
<p>{!! $pirep->aircraft->subfleet->name !!}, {!! $pirep->aircraft->name !!}
({!! $pirep->aircraft->registration !!})
</p>
</div>
<!-- Created At Field -->
<div class="form-group">
{!! Form::label('created_at', 'Created At:') !!}
<p>{!! $pirep->created_at !!}</p>
</div>
<!-- Flight Time Field -->
<div class="form-group">
{!! Form::label('flight_time', 'Flight Time:') !!}
<p>{!! Utils::secondsToTime($pirep->flight_time) !!}</p>
</div>
<!-- Updated At Field -->
<div class="form-group">
{!! Form::label('updated_at', 'Updated At:') !!}
<p>{!! $pirep->updated_at !!}</p>
</div>
<!-- Level Field -->
<div class="form-group">
{!! Form::label('level', 'Level:') !!}
<p>{!! $pirep->level !!}</p>
</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>Flight Time</th>
<th>Level</th>
<th>Route</th>
<th colspan="3">Action</th>
<th colspan="3" style="text-align: right">Action</th>
</thead>
<tbody>
@foreach($pireps as $pirep)
@ -24,8 +23,7 @@
<td>{!! $pirep->aircraft->registration !!} ({!! $pirep->aircraft->name !!})</td>
<td>{!! Utils::secondsToTime($pirep->flight_time) !!}</td>
<td>{!! $pirep->level !!}</td>
<td>{!! $pirep->route !!}</td>
<td>
<td style="text-align: right;">
{!! Form::open(['route' => ['admin.pireps.destroy', $pirep->id], 'method' => 'delete']) !!}
<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>