admin can add comments to PIREPs #70
This commit is contained in:
@@ -380,3 +380,17 @@ pirep_field_values:
|
||||
name: arrival gate
|
||||
value: B14
|
||||
source: manual
|
||||
|
||||
pirep_comments:
|
||||
- id: 1
|
||||
pirep_id: pirepid_1
|
||||
user_id: 1
|
||||
comment: A comment
|
||||
created_at: now
|
||||
updated_at: now
|
||||
- id: 2
|
||||
pirep_id: pirepid_1
|
||||
user_id: 2
|
||||
comment: Another comment
|
||||
created_at: now
|
||||
updated_at: now
|
||||
|
||||
@@ -2,19 +2,24 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Log;
|
||||
use Flash;
|
||||
use Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
|
||||
use App\Services\PIREPService;
|
||||
|
||||
use App\Models\PirepComment;
|
||||
use App\Models\Enums\PirepState;
|
||||
|
||||
use App\Http\Requests\CreatePirepRequest;
|
||||
use App\Http\Requests\UpdatePirepRequest;
|
||||
use App\Models\Enums\PirepState;
|
||||
use App\Repositories\AircraftRepository;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Repositories\PirepRepository;
|
||||
use App\Services\PIREPService;
|
||||
use Illuminate\Http\Request;
|
||||
use Flash;
|
||||
use Log;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
use Response;
|
||||
use App\Facades\Utils;
|
||||
|
||||
|
||||
@@ -230,4 +235,36 @@ class PirepController extends BaseController
|
||||
$pirep->refresh();
|
||||
return view('admin.pireps.pirep_card', ['pirep' => $pirep]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a comment to the Pirep
|
||||
* @param $id
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function comments($id, Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$pirep = $this->pirepRepo->findWithoutFail($request->id);
|
||||
if ($request->isMethod('post')) {
|
||||
$comment = new PirepComment([
|
||||
'user_id' => $user->id,
|
||||
'pirep_id' => $pirep->id,
|
||||
'comment' => $request->get('comment'),
|
||||
]);
|
||||
|
||||
$comment->save();
|
||||
$pirep->refresh();
|
||||
}
|
||||
|
||||
if($request->isMethod('delete')) {
|
||||
$comment = PirepComment::find($request->get('comment_id'));
|
||||
$comment->delete();
|
||||
$pirep->refresh();
|
||||
}
|
||||
|
||||
return view('admin.pireps.comments', [
|
||||
'pirep' => $pirep,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,15 +87,20 @@ class UserController extends BaseController
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$users = $this->userRepo->findWithoutFail($id);
|
||||
$user = $this->userRepo->findWithoutFail($id);
|
||||
|
||||
if (empty($users)) {
|
||||
if (empty($user)) {
|
||||
Flash::error('User not found');
|
||||
return redirect(route('admin.users.index'));
|
||||
}
|
||||
|
||||
return view('admin.users.show', [
|
||||
'users' => $users,
|
||||
'user' => $user,
|
||||
'airlines' => Airline::all(),
|
||||
'timezones' => Timezonelist::toArray(),
|
||||
'airports' => Airport::all()->pluck('icao', 'id'),
|
||||
'ranks' => Rank::all()->pluck('name', 'id'),
|
||||
'roles' => Role::all()->pluck('name', 'id'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,23 +11,28 @@ class PirepComment extends BaseModel
|
||||
{
|
||||
public $table = 'pirep_comments';
|
||||
|
||||
public $fillable
|
||||
= [
|
||||
'comment',
|
||||
];
|
||||
public $fillable = [
|
||||
'pirep_id',
|
||||
'user_id',
|
||||
'comment',
|
||||
];
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $rules
|
||||
= [
|
||||
'comment' => 'required',
|
||||
];
|
||||
public static $rules = [
|
||||
'comment' => 'required',
|
||||
];
|
||||
|
||||
public function pirep()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Pirep', 'pirep_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\User', 'user_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ Route::group([
|
||||
# pirep related routes
|
||||
Route::resource('pireps', 'PirepController');
|
||||
Route::match(['get'], 'pireps/pending', 'PirepController@pending');
|
||||
Route::match(['get', 'post', 'delete'], 'pireps/{id}/comments', 'PirepController@comments');
|
||||
Route::match(['post', 'put'], 'pireps/{id}/status', 'PirepController@status')->name('pirep.status');
|
||||
|
||||
Route::resource('pirepfields', 'PirepFieldController');
|
||||
|
||||
45
resources/views/admin/pireps/comments.blade.php
Normal file
45
resources/views/admin/pireps/comments.blade.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<div id="pirep_comments_wrapper" class="col-12">
|
||||
<table class="table table-responsive" id="pireps-comments-table">
|
||||
<thead>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($pirep->comments as $comment)
|
||||
<tr>
|
||||
<td width="1%" nowrap="" style="vertical-align: text-top">
|
||||
<a href="{!! route('admin.users.show', [$comment->user_id]) !!}">
|
||||
{!! $comment->user->name !!}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<p>{!! $comment->comment !!}</p>
|
||||
<p class="small">{!! show_datetime($comment->created_at) !!}</p>
|
||||
</td>
|
||||
<td align="right">
|
||||
{!! Form::open(['url' => url('/admin/pireps/'.$pirep->id.'/comments'),
|
||||
'method' => 'delete', 'class' => 'pjax_form form-inline']) !!}
|
||||
{!! Form::hidden('comment_id', $comment->id) !!}
|
||||
{!! Form::button('<i class="fa fa-times"></i>', ['type' => 'submit',
|
||||
'class' => 'btn btn-danger btn-small']) !!}
|
||||
{!! Form::close() !!}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="input-group input-group-lg pull-right">
|
||||
{!! Form::open(['url' => url('/admin/pireps/'.$pirep->id.'/comments'),
|
||||
'method' => 'post', 'class' => 'pjax_form form-inline']) !!}
|
||||
{!! Form::input('text', 'comment', null, ['class' => 'form-control input-sm']) !!}
|
||||
{!! Form::button('<i class="fa fa-plus"></i> Add', ['type' => 'submit',
|
||||
'class' => 'btn btn-success btn-small']) !!}
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -22,3 +22,4 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@include('admin.pireps.scripts')
|
||||
|
||||
@@ -19,4 +19,4 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@include('admin.pireps.script')
|
||||
@include('admin.pireps.scripts')
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@include('admin.pireps.script')
|
||||
@include('admin.pireps.scripts')
|
||||
|
||||
@@ -17,6 +17,16 @@ function changeStatus(values) {
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$(document).on('submit', 'form.pjax_form', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#pirep_comments_wrapper', {push: false});
|
||||
});
|
||||
|
||||
$(document).on('pjax:complete', function () {
|
||||
$(".select2").select2();
|
||||
});
|
||||
|
||||
$(document).on('submit', 'form.pirep_submit_status', function (event) {
|
||||
console.log(event);
|
||||
|
||||
@@ -29,9 +39,6 @@ $(document).ready(function() {
|
||||
console.log(values);
|
||||
console.log('Changing PIREP ' + values.pirep_id + ' to state ' + values.new_status);
|
||||
|
||||
//var destContainer = '#pirep_' + pirep_id + '_container';
|
||||
//$.pjax.submit(event, destContainer, { push: false, maxCacheLength: 0 });
|
||||
|
||||
changeStatus(values);
|
||||
});
|
||||
});
|
||||
@@ -14,13 +14,22 @@
|
||||
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
<h4>custom fields</h4>
|
||||
@include('admin.pireps.field_values')
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
<h4>comments</h4>
|
||||
@include('admin.pireps.comments')
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
@include('admin.pireps.map')
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@include('admin.pireps.scripts');
|
||||
|
||||
@@ -10,3 +10,4 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@include('admin.ranks.scripts')
|
||||
|
||||
@@ -21,19 +21,4 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@section('scripts')
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(".select2_dropdown").select2();
|
||||
|
||||
$(document).on('submit', 'form.pjax_form', function(event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#rank_subfleet_wrapper', {push: false});
|
||||
});
|
||||
|
||||
$(document).on('pjax:complete', function() {
|
||||
$(".select2_dropdown").select2();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
@include('admin.ranks.scripts')
|
||||
|
||||
@@ -13,13 +13,4 @@
|
||||
@include('admin.ranks.table')
|
||||
</div>
|
||||
@endsection
|
||||
@section('scripts')
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$(document).on('submit', 'form.add_rank', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#ranks_table_wrapper', {push: false});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
@include('admin.ranks.scripts')
|
||||
|
||||
21
resources/views/admin/ranks/scripts.blade.php
Normal file
21
resources/views/admin/ranks/scripts.blade.php
Normal file
@@ -0,0 +1,21 @@
|
||||
@section('scripts')
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$(".select2").select2();
|
||||
|
||||
$(document).on('submit', 'form.add_rank', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#ranks_table_wrapper', {push: false});
|
||||
});
|
||||
|
||||
$(document).on('submit', 'form.pjax_form', function (event) {
|
||||
event.preventDefault();
|
||||
$.pjax.submit(event, '#rank_subfleet_wrapper', {push: false});
|
||||
});
|
||||
|
||||
$(document).on('pjax:complete', function () {
|
||||
$(".select2").select2();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
@@ -14,3 +14,4 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@include('admin.ranks.scripts')
|
||||
|
||||
@@ -31,14 +31,14 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="input-group input-group-lg pull-right">
|
||||
{!! Form::open(['url' => '/admin/ranks/'.$rank->id.'/subfleets',
|
||||
{!! Form::open(['url' => url('/admin/ranks/'.$rank->id.'/subfleets'),
|
||||
'method' => 'post',
|
||||
'class' => 'pjax_form form-inline'
|
||||
])
|
||||
!!}
|
||||
{!! Form::select('subfleet_id', $avail_subfleets, null, [
|
||||
'placeholder' => 'Select Subfleet',
|
||||
'class' => 'select2_dropdown form-control input-lg'])
|
||||
'class' => 'select2 form-control input-lg'])
|
||||
!!}
|
||||
{!! Form::button('<i class="fa fa-plus"></i> Add',
|
||||
['type' => 'submit',
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>
|
||||
Airlines
|
||||
</h1>
|
||||
</section>
|
||||
<div class="card">
|
||||
<div class="content">
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
<div class="row" style="padding-left: 20px">
|
||||
@include('admin.airlines.show_fields')
|
||||
<a href="{!! route('admin.airlines.index') !!}" class="btn btn-default">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('admin.users.fields')
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<!-- Code Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('icao', 'ICAO:') !!}
|
||||
<p>{!! $airlines->icao !!}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{!! Form::label('iata', 'IATA:') !!}
|
||||
<p>{!! $airlines->iata !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Name Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('name', 'Name:') !!}
|
||||
<p>{!! $airlines->name !!}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{!! Form::label('logo', 'Logo URL:') !!}
|
||||
<p>{!! $airlines->logo !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Active Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('active', 'Active:') !!}
|
||||
<p>{!! $airlines->active !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Created At Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('created_at', 'Created At:') !!}
|
||||
<p>{!! $airlines->created_at !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Updated At Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('updated_at', 'Updated At:') !!}
|
||||
<p>{!! $airlines->updated_at !!}</p>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<tbody>
|
||||
@foreach($users as $user)
|
||||
<tr>
|
||||
<td>{!! $user->name !!}</td>
|
||||
<td><a href="{!! route('admin.users.show', [$user->id]) !!}">{!! $user->name !!}</a></td>
|
||||
<td>{!! $user->email !!}</td>
|
||||
<td>{!! show_date($user->created_at) !!}</td>
|
||||
<td class="text-center">
|
||||
|
||||
Reference in New Issue
Block a user