Implement airport hub restriction closes #104

This commit is contained in:
Nabeel Shahzad 2018-02-28 15:37:24 -06:00
parent 3188f356eb
commit 448a9846c9
3 changed files with 53 additions and 10 deletions

View File

@ -6,10 +6,11 @@ use App\Facades\Utils;
use App\Http\Requests\CreateUserRequest;
use App\Http\Requests\UpdateUserRequest;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Rank;
use App\Models\Role;
use App\Models\User;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\PirepRepository;
use App\Repositories\UserRepository;
use App\Services\UserService;
@ -24,19 +25,29 @@ use Response;
class UserController extends BaseController
{
private $pirepRepo,
private $airlineRepo,
$airportRepo,
$pirepRepo,
$userRepo,
$userSvc;
/**
* UserController constructor.
* @param AirlineRepository $airlineRepo
* @param AirportRepository $airportRepo
* @param PirepRepository $pirepRepo
* @param UserRepository $userRepo
* @param UserService $userSvc
*/
public function __construct(
AirlineRepository $airlineRepo,
AirportRepository $airportRepo,
PirepRepository $pirepRepo,
UserRepository $userRepo,
UserService $userSvc
) {
$this->airlineRepo = $airlineRepo;
$this->airportRepo = $airportRepo;
$this->pirepRepo = $pirepRepo;
$this->userSvc = $userSvc;
$this->userRepo = $userRepo;
@ -67,8 +78,18 @@ class UserController extends BaseController
*/
public function create()
{
return view('admin.user.create', [
'airlines' => Airline::all()->pluck('name', 'id'),
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only'));
return view('admin.users.create', [
'user' => null,
'pireps' => null,
'airlines' => $airlines,
'timezones' => Timezonelist::toArray(),
'country' => new \League\ISO3166\ISO3166(),
'airports' => $airports,
'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => Role::all()->pluck('name', 'id'),
]);
}
@ -105,13 +126,16 @@ class UserController extends BaseController
->whereOrder(['user_id' => $id], 'created_at', 'desc')
->paginate();
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only'));
return view('admin.users.show', [
'user' => $user,
'pireps' => $pireps,
'airlines' => Airline::all(),
'airlines' => $airlines,
'timezones' => Timezonelist::toArray(),
'country' => new \League\ISO3166\ISO3166(),
'airports' => Airport::all()->pluck('icao', 'id'),
'airports' => $airports,
'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => Role::all()->pluck('name', 'id'),
]);
@ -140,13 +164,16 @@ class UserController extends BaseController
return [strtolower($item['alpha2']) => $item['name']];
});
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only'));
return view('admin.users.edit', [
'user' => $user,
'pireps' => $pireps,
'countries' => $countries,
'timezones' => Timezonelist::toArray(),
'airports' => Airport::all()->pluck('icao', 'id'),
'airlines' => Airline::all()->pluck('name', 'id'),
'airports' => $airports,
'airlines' => $airlines,
'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => Role::all()->pluck('name', 'id'),
]);

View File

@ -44,7 +44,11 @@ class ProfileController extends Controller
*/
public function index()
{
$airports = $this->airportRepo->all();
if(setting('pilots.home_hubs_only')) {
$airports = $this->airportRepo->findWhere(['hub' => true]);
} else {
$airports = $this->airportRepo->all();
}
return $this->view('profile.index', [
'user' => Auth::user(),
@ -86,7 +90,7 @@ class ProfileController extends Controller
}
$airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only'));
return $this->view('profile.edit', [
'user' => $user,

View File

@ -37,6 +37,18 @@
</td>
</tr>
<tr>
<td>Home Airport</td>
<td>
<div class="input-group form-group-no-border{{ $errors->has('home_airport_id') ? ' has-danger' : '' }}">
{!! Form::select('home_airport_id', $airports, null , ['class' => 'form-control select2']) !!}
</div>
@if ($errors->has('home_airport_id'))
<p class="text-danger">{{ $errors->first('home_airport_id') }}</p>
@endif
</td>
</tr>
<tr>
<td>Country</td>
<td>