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

View File

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

View File

@ -37,6 +37,18 @@
</td> </td>
</tr> </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> <tr>
<td>Country</td> <td>Country</td>
<td> <td>