diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 7ff9ce2ded..dde84fce6b 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -54,8 +54,8 @@ class AccessoriesController extends Controller public function create(Request $request) { $this->authorize('create', Accessory::class); - // Show the page - return view('accessories/edit') + $category_type = 'accessory'; + return view('accessories/edit')->with('category_type', $category_type) ->with('item', new Accessory); } @@ -125,14 +125,15 @@ class AccessoriesController extends Controller */ public function edit(Request $request, $accessoryId = null) { - // Check if the accessory exists - if (is_null($item = Accessory::find($accessoryId))) { - return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); + + if ($item = Accessory::find($accessoryId)) { + $this->authorize($item); + $category_type = 'accessory'; + return view('accessories/edit', compact('item'))->with('category_type', $category_type); } - $this->authorize($item); + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); - return view('accessories/edit', compact('item')); } diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.php index 9a5a33092e..f94e786f00 100644 --- a/app/Http/Controllers/Api/CategoriesController.php +++ b/app/Http/Controllers/Api/CategoriesController.php @@ -139,7 +139,7 @@ class CategoriesController extends Controller * @see \App\Http\Transformers\SelectlistTransformer * */ - public function selectlist(Request $request) + public function selectlist(Request $request, $category_type = 'asset') { $this->authorize('view', Categories::class); @@ -153,7 +153,7 @@ class CategoriesController extends Controller $categories = $categories->where('name', 'LIKE', '%'.$request->get('search').'%'); } - $categories = $categories->orderBy('name', 'ASC')->paginate(50); + $categories = $categories->where('category_type', $category_type)->orderBy('name', 'ASC')->paginate(50); // Loop through and set some custom properties for the transformer to use. // This lets us have more flexibility in special cases like assets, where diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index ece53b0a69..1d3c37dab8 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -138,16 +138,15 @@ class UsersController extends Controller $users = Company::scopeCompanyables($users); if ($request->has('search')) { - $users = $users->where('first_name', '=', '%'.$request->get('search').'%') + $users = $users->where('first_name', 'LIKE', '%'.$request->get('search').'%') ->orWhere('last_name', 'LIKE', '%'.$request->get('search').'%') ->orWhere('username', 'LIKE', '%'.$request->get('search').'%') - ->orWhere('employee_num', '=', '%'.$request->get('search').'%'); + ->orWhere('employee_num', 'LIKE', '%'.$request->get('search').'%'); } - $users = $users->orderBy('last_name', 'asc'); + $users = $users->orderBy('last_name', 'asc')->orderBy('first_name', 'asc'); $users = $users->paginate(50); - foreach ($users as $user) { $name_str = ''; if ($user->last_name!='') { diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index fe752fced3..cad33d7793 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -35,7 +35,6 @@ class AssetModelsController extends Controller * the content for the accessories listing, which is generated in getDatatable. * * @author [A. Gianotto] [] - * @see AssetModelsController::getDatatable() method that generates the JSON response * @since [v1.0] * @return View */ @@ -53,11 +52,9 @@ class AssetModelsController extends Controller */ public function create() { - // Show the page - return view('models/edit') - ->with('category_list', Helper::categoryList('asset')) + $category_type = 'asset'; + return view('models/edit')->with('category_type',$category_type) ->with('depreciation_list', Helper::depreciationList()) - ->with('manufacturer_list', Helper::manufacturerList()) ->with('item', new AssetModel); } @@ -165,17 +162,15 @@ class AssetModelsController extends Controller */ public function edit($modelId = null) { - // Check if the model exists - if (is_null($item = AssetModel::find($modelId))) { - // Redirect to the model management page - return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); + if ($item = AssetModel::find($modelId)) { + $category_type = 'asset'; + $view = View::make('models/edit', compact('item','category_type')); + $view->with('depreciation_list', Helper::depreciationList()); + return $view; } - $view = View::make('models/edit', compact('item')); - $view->with('category_list', Helper::categoryList('asset')); - $view->with('depreciation_list', Helper::depreciationList()); - $view->with('manufacturer_list', Helper::manufacturerList()); - return $view; + return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); + } diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index b87544f8ca..bf4f102027 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -255,14 +255,8 @@ class AssetsController extends Controller return view('hardware/edit', compact('item')) ->with('model_list', Helper::modelList()) - ->with('supplier_list', Helper::suppliersList()) - ->with('company_list', Helper::companyList()) - ->with('locations_list', Helper::locationsList()) ->with('statuslabel_list', Helper::statusLabelList()) - ->with('assigned_to', Helper::usersList()) - ->with('manufacturer', Helper::manufacturerList()) - ->with('statuslabel_types', Helper::statusTypeList()) - ->with('category', Helper::categoryList('asset')); + ->with('statuslabel_types', Helper::statusTypeList()); } @@ -720,18 +714,9 @@ class AssetsController extends Controller $asset->assigned_to = ''; return view('hardware/edit') - ->with('supplier_list', Helper::suppliersList()) - ->with('model_list', Helper::modelList()) ->with('statuslabel_list', Helper::statusLabelList()) ->with('statuslabel_types', Helper::statusTypeList()) - ->with('assigned_to', Helper::usersList()) - ->with('item', $asset) - ->with('locations_list', Helper::locationsList()) - ->with('manufacturer', Helper::manufacturerList()) - ->with('category', Helper::categoryList('asset')) - ->with('users_list', Helper::usersList()) - ->with('assets_list', Helper::assetsList()) - ->with('company_list', Helper::companyList()); + ->with('item', $asset); } /** @@ -1035,8 +1020,7 @@ class AssetsController extends Controller return view('hardware/labels') ->with('assets', Asset::find($asset_ids)) ->with('settings', Setting::getSettings()) - ->with('count', $count) - ->with('settings', Setting::getSettings()); + ->with('count', $count); } elseif ($request->input('bulk_actions')=='delete') { $assets = Asset::with('assignedTo', 'location')->find($asset_ids); $assets->each(function ($asset) { @@ -1047,10 +1031,7 @@ class AssetsController extends Controller } elseif ($request->input('bulk_actions')=='edit') { return view('hardware/bulk') ->with('assets', request('ids')) - ->with('supplier_list', Helper::suppliersList()) ->with('statuslabel_list', Helper::statusLabelList()) - ->with('location_list', Helper::locationsList()) - ->with('models_list', Helper::modelList()) ->with( 'companies_list', array('' => '') + array('clear' => trans('general.remove_company')) + Helper::companyList() @@ -1222,11 +1203,11 @@ class AssetsController extends Controller } - public function quickScan(Request $request) + public function quickScan() { $this->authorize('audit', Asset::class); $dt = Carbon::now()->addMonths(12)->toDateString(); - return view('hardware/quickscan')->with('next_audit_date', $dt)->with('locations_list', Helper::locationsList()); + return view('hardware/quickscan')->with('next_audit_date', $dt); } @@ -1236,7 +1217,7 @@ class AssetsController extends Controller $this->authorize('audit', Asset::class); $dt = Carbon::now()->addMonths(12)->toDateString(); $asset = Asset::findOrFail($id); - return view('hardware/audit')->with('asset', $asset)->with('next_audit_date', $dt)->with('locations_list', Helper::locationsList()); + return view('hardware/audit')->with('asset', $asset)->with('next_audit_date', $dt)->with('locations_list'); } public function auditStore(Request $request, $id) diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index ac5becd220..01574ea794 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -59,8 +59,8 @@ class ComponentsController extends Controller public function create() { $this->authorize('create', Component::class); - // Show the page - return view('components/edit') + $category_type = 'component'; + return view('components/edit')->with('category_type',$category_type) ->with('item', new Component); } @@ -118,14 +118,18 @@ class ComponentsController extends Controller */ public function edit($componentId = null) { - if (is_null($item = Component::find($componentId))) { - return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist')); + + + if ($item = Component::find($componentId)) { + $this->authorize('update', $item); + $category_type = 'component'; + return view('components/edit', compact('item'))->with('category_type', $category_type); } + return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist')); + + - $this->authorize('update', $item); - return view('components/edit', compact('item')) - ->with('category_list', Helper::categoryList('component')); } diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 098bb7ab90..b67f41f235 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -56,8 +56,8 @@ class ConsumablesController extends Controller public function create() { $this->authorize('create', Consumable::class); - // Show the page - return view('consumables/edit') + $category_type = 'consumable'; + return view('consumables/edit')->with('category_type', $category_type) ->with('item', new Consumable); } @@ -119,17 +119,14 @@ class ConsumablesController extends Controller */ public function edit($consumableId = null) { - if (is_null($item = Consumable::find($consumableId))) { - return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist')); + if ($item = Consumable::find($consumableId)) { + $this->authorize($item); + $category_type = 'consumable'; + return view('consumables/edit', compact('item'))->with('category_type', $category_type); } - $this->authorize($item); + return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist')); - return view('consumables/edit', compact('item')) - ->with('category_list', Helper::categoryList('consumable')) - ->with('company_list', Helper::companyList()) - ->with('location_list', Helper::locationsList()) - ->with('manufacturer_list', Helper::manufacturerList()); } diff --git a/app/Http/Controllers/DepartmentsController.php b/app/Http/Controllers/DepartmentsController.php index 51769614b4..5b3452793c 100644 --- a/app/Http/Controllers/DepartmentsController.php +++ b/app/Http/Controllers/DepartmentsController.php @@ -100,10 +100,7 @@ class DepartmentsController extends Controller */ public function create() { - return view('departments/edit')->with('item', new Department) - ->with('manager_list', Helper::managerList()) - ->with('location_list', Helper::locationsList()) - ->with('company_list', Helper::companyList()); + return view('departments/edit')->with('item', new Department); } @@ -144,10 +141,7 @@ class DepartmentsController extends Controller if (is_null($item = Department::find($id))) { return redirect()->back()->with('error', trans('admin/locations/message.does_not_exist')); } - return view('departments/edit', compact('item')) - ->with('manager_list', Helper::managerList()) - ->with('location_list', Helper::locationsList()) - ->with('company_list', Helper::companyList()); + return view('departments/edit', compact('item')); } public function update(Request $request, $id) { diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index dc0cb1fe11..340965866b 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -65,8 +65,7 @@ class LocationsController extends Controller return view('locations/edit') ->with('location_options', $location_options) - ->with('item', new Location) - ->with('manager_list', Helper::managerList()); + ->with('item', new Location); } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index e2a76bb803..97d605425f 100755 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -30,8 +30,7 @@ class ProfileController extends Controller public function getIndex() { $user = Auth::user(); - $location_list = Helper::locationsList(); - return view('account/profile', compact('user'))->with('location_list', $location_list); + return view('account/profile', compact('user')); } /** diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 47859e4bca..45794f6c45 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -228,9 +228,9 @@ class UsersController extends Controller public function edit($id) { - try { - $user = User::find($id); + if ($user = User::find($id)) { + $this->authorize('update', $user); $permissions = config('permissions'); @@ -240,19 +240,14 @@ class UsersController extends Controller $user->permissions = $user->decodePermissions(); $userPermissions = Helper::selectedPermissionsArray($permissions, $user->permissions); $permissions = $this->filterDisplayable($permissions); - - } catch (UserNotFoundException $e) { - $error = trans('admin/users/message.user_not_found', compact('id')); - return redirect()->route('users.index')->with('error', $error); + return view('users/edit', compact('user', 'groups', 'userGroups', 'permissions', 'userPermissions'))->with('item', $user); } - // Show the page - return view('users/edit', compact('user', 'groups', 'userGroups', 'permissions', 'userPermissions')) - ->with('location_list', Helper::locationsList()) - ->with('department_list', Helper::departmentList()) - ->with('company_list', Helper::companyList()) - ->with('manager_list', Helper::managerList()); + $error = trans('admin/users/message.user_not_found', compact('id')); + return redirect()->route('users.index')->with('error', $error); + + } /** @@ -431,11 +426,6 @@ class UsersController extends Controller if ($request->input('bulk_actions')=='edit') { return view('users/bulk-edit', compact('users')) - ->with('location_list', Helper::locationsList()) - ->with('company_list', Helper::companyList()) - ->with('manager_list', Helper::managerList()) - ->with('manager_list', Helper::managerList()) - ->with('department_list', Helper::departmentList()) ->with('groups', Group::pluck('name', 'id')); } @@ -721,7 +711,7 @@ class UsersController extends Controller $user->first_name = ''; $user->last_name = ''; $user->email = substr($user->email, ($pos = strpos($user->email, '@')) !== false ? $pos : 0); - ; + $user->id = null; // Get this user groups @@ -734,10 +724,6 @@ class UsersController extends Controller // Show the page return view('users/edit', compact('permissions', 'userPermissions')) - ->with('location_list', Helper::locationsList()) - ->with('company_list', Helper::companyList()) - ->with('manager_list', Helper::managerList()) - ->with('department_list', Helper::departmentList()) ->with('user', $user) ->with('groups', Group::pluck('name', 'id')) ->with('userGroups', $userGroups) diff --git a/app/Models/User.php b/app/Models/User.php index 3c3748bb31..a9c40a12ed 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -55,7 +55,8 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo 'username' => 'required|string|min:1|unique_undeleted', 'email' => 'email|nullable', 'password' => 'required|min:6', - 'locale' => 'max:10|nullable' + 'locale' => 'max:10|nullable', + 'manager_id' => 'nullable|different:id', ]; diff --git a/resources/views/account/profile.blade.php b/resources/views/account/profile.blade.php index b1e81d717e..3b8cddba0f 100755 --- a/resources/views/account/profile.blade.php +++ b/resources/views/account/profile.blade.php @@ -19,7 +19,7 @@
-
+
{!! $errors->first('first_name', ' :message') !!}
@@ -30,24 +30,15 @@ -
+
{!! $errors->first('last_name', ' :message') !!}
+ -
- -
-
- {{ Form::select('location_id', $location_list , Input::old('location_id', $user->location_id), array('class'=>'select2', 'style'=>'width:300px')) }} - {!! $errors->first('location_id', ' :message') !!} -
-
-
+ @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
@@ -62,7 +53,7 @@
-
+
{!! $errors->first('website', ' :message') !!}
@@ -73,7 +64,7 @@ -
+
{!! $errors->first('gravatar', ' :message') !!}

@@ -87,7 +78,7 @@ @if ($user->avatar)

-
+
{{ Form::checkbox('avatar_delete') }} {!! $errors->first('avatar_delete', ':message') !!} @@ -97,7 +88,7 @@
-
+
{{ Form::file('avatar') }} {!! $errors->first('avatar', ':message') !!}
diff --git a/resources/views/departments/edit.blade.php b/resources/views/departments/edit.blade.php index 7e3430044a..182e9bb9e9 100644 --- a/resources/views/departments/edit.blade.php +++ b/resources/views/departments/edit.blade.php @@ -11,26 +11,17 @@ @include ('partials.forms.edit.name', ['translated_name' => trans('admin/departments/table.name')]) - @include ('partials.forms.edit.company') + + @if (\App\Models\Company::canManageUsersCompanies()) + @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id']) + @endif + -
- -
- {{ Form::select('manager_id', $manager_list , Input::old('manager_id', $item->manager_id), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('manager_id', ':message') !!} -
-
+ @include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/users/table.manager'), 'fieldname' => 'manager_id']) -
- -
- {{ Form::select('location_id', $location_list , Input::old('location_id', $item->location_id), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('location_id', ':message') !!} -
-
+ @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) @if ($item->image) diff --git a/resources/views/hardware/audit.blade.php b/resources/views/hardware/audit.blade.php index 7fc9afdca0..63f4370b22 100644 --- a/resources/views/hardware/audit.blade.php +++ b/resources/views/hardware/audit.blade.php @@ -45,14 +45,7 @@
-
- {{ Form::label('location_id', trans('general.location'), array('class' => 'col-md-3 control-label')) }} -
- {{ Form::select('location_id', $locations_list , Input::old('location_id'), array('class'=>'select2', 'id'=>'location_id', 'style'=>'width:100%')) }} - - {!! $errors->first('location_id', ' :message') !!} -
-
+ @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 47c438a6b3..6cb84f6dfc 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -30,7 +30,7 @@
- +
@@ -40,7 +40,7 @@
-
- -
- -
- {{ Form::select('model_id', $models_list , Input::old('model_id'), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('model_id', ' :message') !!} -
-
+ @include ('partials.forms.edit.model-select', ['translated_name' => trans('admin/hardware/form.model'), 'fieldname' => 'model_id']) -
- -
- {{ Form::select('rtd_location_id', $location_list , Input::old('rtd_location_id'), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('status_id', ' :message') !!} -
-
+ @include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'fieldname' => 'location_id']) - + +
-