Fix Admin: UserController and Flight Edit (#1204)

* Fix Admin / UserController

Use Role Repository and `selectBoxList` method instead of the model itself.

* Fix Flight Fields

Added empty/blank option for clearing out the days when needed

* StyleFix
This commit is contained in:
B.Fatih KOZ 2021-05-25 02:13:44 +03:00 committed by GitHub
parent 68a6ed24cb
commit 728b033675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -6,12 +6,12 @@ use App\Contracts\Controller;
use App\Http\Requests\CreateUserRequest; use App\Http\Requests\CreateUserRequest;
use App\Http\Requests\UpdateUserRequest; use App\Http\Requests\UpdateUserRequest;
use App\Models\Rank; use App\Models\Rank;
use App\Models\Role;
use App\Models\User; use App\Models\User;
use App\Models\UserAward; use App\Models\UserAward;
use App\Repositories\AirlineRepository; use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository; use App\Repositories\AirportRepository;
use App\Repositories\PirepRepository; use App\Repositories\PirepRepository;
use App\Repositories\RoleRepository;
use App\Repositories\UserRepository; use App\Repositories\UserRepository;
use App\Services\UserService; use App\Services\UserService;
use App\Support\Timezonelist; use App\Support\Timezonelist;
@ -29,6 +29,7 @@ class UserController extends Controller
private $airlineRepo; private $airlineRepo;
private $airportRepo; private $airportRepo;
private $pirepRepo; private $pirepRepo;
private $roleRepo;
private $userRepo; private $userRepo;
private $userSvc; private $userSvc;
@ -38,6 +39,7 @@ class UserController extends Controller
* @param AirlineRepository $airlineRepo * @param AirlineRepository $airlineRepo
* @param AirportRepository $airportRepo * @param AirportRepository $airportRepo
* @param PirepRepository $pirepRepo * @param PirepRepository $pirepRepo
* @param RoleRepository $roleRepo
* @param UserRepository $userRepo * @param UserRepository $userRepo
* @param UserService $userSvc * @param UserService $userSvc
*/ */
@ -45,12 +47,14 @@ class UserController extends Controller
AirlineRepository $airlineRepo, AirlineRepository $airlineRepo,
AirportRepository $airportRepo, AirportRepository $airportRepo,
PirepRepository $pirepRepo, PirepRepository $pirepRepo,
RoleRepository $roleRepo,
UserRepository $userRepo, UserRepository $userRepo,
UserService $userSvc UserService $userSvc
) { ) {
$this->airlineRepo = $airlineRepo; $this->airlineRepo = $airlineRepo;
$this->airportRepo = $airportRepo; $this->airportRepo = $airportRepo;
$this->pirepRepo = $pirepRepo; $this->pirepRepo = $pirepRepo;
$this->roleRepo = $roleRepo;
$this->userSvc = $userSvc; $this->userSvc = $userSvc;
$this->userRepo = $userRepo; $this->userRepo = $userRepo;
} }
@ -88,6 +92,7 @@ class UserController extends Controller
->mapWithKeys(function ($item, $key) { ->mapWithKeys(function ($item, $key) {
return [strtolower($item['alpha2']) => $item['name']]; return [strtolower($item['alpha2']) => $item['name']];
}); });
$roles = $this->roleRepo->selectBoxList(false, true);
return view('admin.users.create', [ return view('admin.users.create', [
'user' => null, 'user' => null,
@ -98,7 +103,7 @@ class UserController extends Controller
'countries' => $countries, 'countries' => $countries,
'airports' => $airports, 'airports' => $airports,
'ranks' => Rank::all()->pluck('name', 'id'), 'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => Role::all()->pluck('name', 'id'), 'roles' => $roles,
]); ]);
} }
@ -163,6 +168,7 @@ class UserController extends Controller
$airlines = $this->airlineRepo->selectBoxList(); $airlines = $this->airlineRepo->selectBoxList();
$airports = $this->airportRepo->selectBoxList(false); $airports = $this->airportRepo->selectBoxList(false);
$roles = $this->roleRepo->selectBoxList(false, true);
return view('admin.users.edit', [ return view('admin.users.edit', [
'user' => $user, 'user' => $user,
@ -173,7 +179,7 @@ class UserController extends Controller
'airports' => $airports, 'airports' => $airports,
'airlines' => $airlines, 'airlines' => $airlines,
'ranks' => Rank::all()->pluck('name', 'id'), 'ranks' => Rank::all()->pluck('name', 'id'),
'roles' => Role::all()->pluck('name', 'id'), 'roles' => $roles,
]); ]);
} }

View File

@ -199,6 +199,7 @@
{{ Form::label('days', 'Days of Week') }} {{ Form::label('days', 'Days of Week') }}
<span class="description small">optional</span> <span class="description small">optional</span>
<select id="days_of_week" name="days[]" multiple="multiple" size="7" style="width: 100%;"> <select id="days_of_week" name="days[]" multiple="multiple" size="7" style="width: 100%;">
<option value="">Select Days</option>
<option value="{{\App\Models\Enums\Days::MONDAY}}" <option value="{{\App\Models\Enums\Days::MONDAY}}"
{{in_mask($days, \App\Models\Enums\Days::MONDAY) ? 'selected':'' }}> {{in_mask($days, \App\Models\Enums\Days::MONDAY) ? 'selected':'' }}>
@lang('common.days.mon') @lang('common.days.mon')