From cd9cca9c6bdfbd01ed5de40ae58877de38d21865 Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Sun, 5 Jun 2016 09:47:44 -0500 Subject: [PATCH] Modify Helper::categoryList() to take a category type parameter. This allows for centralizing the category fetching code more and fixes an error in asset model viewing (#2118). Also add a few translated strings and standardize on a base of 'Select a *' for the default value in our lists. --- app/Helpers/Helper.php | 14 ++++++++------ app/Http/Controllers/AccessoriesController.php | 4 ++-- app/Http/Controllers/AssetModelsController.php | 18 +++++++++--------- app/Http/Controllers/AssetsController.php | 8 ++++---- app/Http/Controllers/ComponentsController.php | 4 ++-- app/Http/Controllers/ConsumablesController.php | 4 ++-- resources/lang/en/general.php | 7 ++++--- 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 827f482b3f..a16c017690 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -117,12 +117,14 @@ class Helper } - public static function categoryList() + public static function categoryList($category_type = null) { - $category_list = array('' => '') + Category::orderBy('name', 'asc') + $categories = Category::orderBy('name', 'asc') ->whereNull('deleted_at') - ->orderBy('name', 'asc') - ->pluck('name', 'id')->toArray(); + ->orderBy('name', 'asc'); + if(!empty($category_type)) + $categories = $categories->where('category_type', '=', $category_type); + $category_list = array('' => trans('general.select_category')) + $categories->pluck('name', 'id')->toArray(); return $category_list; } @@ -150,7 +152,7 @@ class Helper public static function manufacturerList() { - $manufacturer_list = array('' => 'Select One') + + $manufacturer_list = array('' => trans('general.select_manufacturer')) + Manufacturer::orderBy('name', 'asc') ->pluck('name', 'id')->toArray(); return $manufacturer_list; @@ -164,7 +166,7 @@ class Helper public static function managerList() { - $manager_list = array('' => '') + + $manager_list = array('' => trans('general.select_user')) + User::where('deleted_at', '=', null) ->orderBy('last_name', 'asc') ->orderBy('first_name', 'asc')->get() diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index 736a0db964..87e301007d 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -52,7 +52,7 @@ class AccessoriesController extends Controller public function getCreate(Request $request) { // Show the page - $category_list = array('' => '') + DB::table('categories')->where('category_type', '=', 'accessory')->whereNull('deleted_at')->orderBy('name', 'ASC')->lists('name', 'id'); + $category_list = Helper::categoryList('accessory'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); return View::make('accessories/edit') @@ -125,7 +125,7 @@ class AccessoriesController extends Controller return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions')); } - $category_list = array('' => '') + DB::table('categories')->where('category_type', '=', 'accessory')->whereNull('deleted_at')->orderBy('name', 'ASC')->lists('name', 'id'); + $category_list = Helper::categoryList('accessory'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 6eaef55f8e..5fa7302c61 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -55,9 +55,9 @@ class AssetModelsController extends Controller public function getCreate() { // Show the page - $depreciation_list = \App\Helpers\Helper::depreciationList(); - $manufacturer_list = \App\Helpers\Helper::manufacturerList(); - $category_list = \App\Helpers\Helper::categoryList(); + $depreciation_list = Helper::depreciationList(); + $manufacturer_list = Helper::manufacturerList(); + $category_list = Helper::categoryList('asset'); return View::make('models/edit') ->with('category_list', $category_list) ->with('depreciation_list', $depreciation_list) @@ -181,9 +181,9 @@ class AssetModelsController extends Controller return redirect()->to('assets/models')->with('error', trans('admin/models/message.does_not_exist')); } - $depreciation_list = \App\Helpers\Helper::depreciationList(); - $manufacturer_list = \App\Helpers\Helper::manufacturerList(); - $category_list = \App\Helpers\Helper::categoryList(); + $depreciation_list = Helper::depreciationList(); + $manufacturer_list = Helper::manufacturerList(); + $category_list = Helper::categoryList('asset'); $view = View::make('models/edit', compact('model')); $view->with('category_list', $category_list); $view->with('depreciation_list', $depreciation_list); @@ -371,9 +371,9 @@ class AssetModelsController extends Controller $model->id = null; // Show the page - $depreciation_list = array('' => 'Do Not Depreciate') + Depreciation::lists('name', 'id'); - $manufacturer_list = array('' => 'Select One') + Manufacturer::lists('name', 'id'); - $category_list = array('' => '') + DB::table('categories')->whereNull('deleted_at')->lists('name', 'id'); + $depreciation_list = Helper::depreciationList(); + $manufacturer_list = Helper::manufacturerList(); + $category_list = Helper::categoryList('asset'); $view = View::make('models/edit'); $view->with('category_list', $category_list); $view->with('depreciation_list', $depreciation_list); diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 510e7aeed1..fca715f694 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -107,7 +107,7 @@ class AssetsController extends Controller $statuslabel_list = Helper::statusLabelList(); $location_list = Helper::locationsList(); $manufacturer_list = Helper::manufacturerList(); - $category_list = Helper::categoryList(); + $category_list = Helper::categoryList('asset'); $supplier_list = Helper::suppliersList(); $company_list = Helper::companyList(); $assigned_to = Helper::usersList(); @@ -269,11 +269,11 @@ class AssetsController extends Controller $statuslabel_list = Helper::statusLabelList(); $location_list = Helper::locationsList(); $manufacturer_list = Helper::manufacturerList(); - $category_list = Helper::categoryList(); + $category_list = Helper::categoryList('asset'); $supplier_list = Helper::suppliersList(); $company_list = Helper::companyList(); $assigned_to = Helper::usersList(); - $statuslabel_types =Helper:: statusTypeList(); + $statuslabel_types =Helper::statusTypeList(); return View::make('hardware/edit', compact('asset')) ->with('model_list', $model_list) @@ -895,7 +895,7 @@ class AssetsController extends Controller $statuslabel_list = Helper::statusLabelList(); $location_list = Helper::locationsList(); $manufacturer_list = Helper::manufacturerList(); - $category_list = Helper::categoryList(); + $category_list = Helper::categoryList('asset'); $supplier_list = Helper::suppliersList(); $assigned_to =Helper::usersList(); $statuslabel_types = Helper::statusTypeList(); diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index 1e74511601..2e35d1013a 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -54,7 +54,7 @@ class ComponentsController extends Controller public function getCreate() { // Show the page - $category_list = array('' => '') + DB::table('categories')->where('category_type', '=', 'component')->whereNull('deleted_at')->orderBy('name', 'ASC')->lists('name', 'id'); + $category_list = Helper::categoryList('component'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); @@ -133,7 +133,7 @@ class ComponentsController extends Controller return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); } - $category_list = Helper::categoryList(); + $category_list = Helper::categoryList('component'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 7a6f01c72d..f75d28a560 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -52,7 +52,7 @@ class ConsumablesController extends Controller public function getCreate() { // Show the page - $category_list = array('' => '') + DB::table('categories')->where('category_type', '=', 'consumable')->whereNull('deleted_at')->orderBy('name', 'ASC')->lists('name', 'id'); + $category_list = Helper::categoryList('consumable'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); $manufacturer_list = Helper::manufacturerList(); @@ -132,7 +132,7 @@ class ConsumablesController extends Controller return redirect()->to('admin/consumables')->with('error', trans('general.insufficient_permissions')); } - $category_list = Helper::categoryList(); + $category_list = Helper::categoryList('consumable'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); $manufacturer_list = Helper::manufacturerList(); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index b36221d618..b7c9acbae0 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -121,12 +121,13 @@ 'quantity' => 'Quantity', 'ready_to_deploy' => 'Ready to Deploy', 'recent_activity' => 'Recent Activity', - 'remove_company' => 'Remove Company Association', + 'remove_company' => 'Remove Company Association', 'reports' => 'Reports', 'requested' => 'Requested', 'save' => 'Save', 'select' => 'Select', 'search' => 'Search', + 'select_category' => 'Select a Category', 'select_depreciation' => 'Select a Depreciation Type', 'select_location' => 'Select a Location', 'select_manufacturer' => 'Select a Manufacturer', @@ -135,8 +136,8 @@ 'select_user' => 'Select a User', 'select_date' => 'Select Date', 'select_statuslabel' => 'Select Status', - 'select_company' => 'Select Company', - 'select_asset' => 'Select Asset', + 'select_company' => 'Select Company', + 'select_asset' => 'Select Asset', 'settings' => 'Settings', 'sign_in' => 'Sign in', 'site_name' => 'Site Name',