diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php index d84a3d3dc..897463f52 100755 --- a/app/Http/Controllers/CategoriesController.php +++ b/app/Http/Controllers/CategoriesController.php @@ -509,7 +509,7 @@ class CategoriesController extends Controller $inout=''; if ($asset->deleted_at=='') { - $actions = '
'; + $actions = ''; } diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index 314940d0e..d6c26bda4 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -39,7 +39,7 @@ class ComponentsController extends Controller * @since [v3.0] * @return View */ - public function getIndex() + public function index() { return View::make('components/index'); } @@ -53,7 +53,7 @@ class ComponentsController extends Controller * @since [v3.0] * @return View */ - public function getCreate() + public function create() { // Show the page $category_list = Helper::categoryList('component'); @@ -76,7 +76,7 @@ class ComponentsController extends Controller * @since [v3.0] * @return Redirect */ - public function postCreate() + public function store() { // create a new model instance @@ -110,7 +110,7 @@ class ComponentsController extends Controller if ($component->save()) { $component->logCreate(); // Redirect to the new component page - return redirect()->to("admin/components")->with('success', trans('admin/components/message.create.success')); + return redirect()->route('components.index')->with('success', trans('admin/components/message.create.success')); } return redirect()->back()->withInput()->withErrors($component->getErrors()); @@ -127,14 +127,14 @@ class ComponentsController extends Controller * @param int $componentId * @return View */ - public function getEdit($componentId = null) + public function edit($componentId = null) { // Check if the component exists if (is_null($item = Component::find($componentId))) { // Redirect to the blogs management page - return redirect()->to('admin/components')->with('error', trans('admin/components/message.does_not_exist')); + return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist')); } elseif (!Company::isCurrentUserHasAccess($item)) { - return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } $category_list = Helper::categoryList('component'); @@ -157,14 +157,14 @@ class ComponentsController extends Controller * @since [v3.0] * @return Redirect */ - public function postEdit($componentId = null) + public function update($componentId = null) { // Check if the blog post exists if (is_null($component = Component::find($componentId))) { // Redirect to the blogs management page - return redirect()->to('admin/components')->with('error', trans('admin/components/message.does_not_exist')); + return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist')); } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } @@ -191,17 +191,12 @@ class ComponentsController extends Controller $component->qty = e(Input::get('qty')); - // Was the component created? if ($component->save()) { - // Redirect to the new component page - return redirect()->to("admin/components")->with('success', trans('admin/components/message.update.success')); + return redirect()->route('components.index')->with('success', trans('admin/components/message.update.success')); } return redirect()->back()->withInput()->withErrors($component->getErrors()); - - - } /** @@ -212,20 +207,16 @@ class ComponentsController extends Controller * @param int $componentId * @return Redirect */ - public function getDelete($componentId) + public function destroy($componentId) { - // Check if the blog post exists if (is_null($component = Component::find($componentId))) { - // Redirect to the blogs management page - return redirect()->to('admin/components')->with('error', trans('admin/components/message.not_found')); + return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found')); } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } - $component->delete(); - - // Redirect to the locations management page - return redirect()->to('admin/components')->with('success', trans('admin/components/message.delete.success')); + $component->delete(); + return redirect()->route('components.index')->with('success', trans('admin/components/message.delete.success')); } @@ -249,7 +240,7 @@ class ComponentsController extends Controller * @param int $componentId * @return View */ - public function getView($componentId = null) + public function show($componentId = null) { $component = Component::find($componentId); @@ -257,7 +248,7 @@ class ComponentsController extends Controller if (!Company::isCurrentUserHasAccess($component)) { - return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } else { return View::make('components/view', compact('component')); } @@ -288,7 +279,7 @@ class ComponentsController extends Controller // Redirect to the component management page with error return redirect()->to('components')->with('error', trans('admin/components/message.not_found')); } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } // Get the dropdown of assets and then pass it to the checkout view @@ -317,7 +308,7 @@ class ComponentsController extends Controller // Redirect to the component management page with error return redirect()->to('components')->with('error', trans('admin/components/message.not_found')); } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } @@ -339,9 +330,9 @@ class ComponentsController extends Controller // Check if the user exists if (is_null($asset = Asset::find($asset_id))) { // Redirect to the component management page with error - return redirect()->to('admin/components')->with('error', trans('admin/components/message.asset_does_not_exist')); + return redirect()->route('components.index')->with('error', trans('admin/components/message.asset_does_not_exist')); } - + // Update the component data $component->asset_id = $asset_id; @@ -372,7 +363,7 @@ class ComponentsController extends Controller 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => class_basename(strtoupper($logaction->item_type)).' <'.url('/').'/admin/components/'.$component->id.'/view'.'|'.$component->name.'> checked out to <'.url('/').'/hardware/'.$asset->id.'/view|'.$asset->showAssetName().'> by <'.url('/').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' <'.route('components.show', ['component' => $component->id]).'|'.$component->name.'> checked out to <'.url('/').'/hardware/'.$asset->id.'|'.$asset->showAssetName().'> by <'.url('/').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' ], [ 'title' => 'Note:', @@ -386,8 +377,7 @@ class ComponentsController extends Controller } } - // Redirect to the new component page - return redirect()->to("admin/components")->with('success', trans('admin/components/message.checkout.success')); + return redirect()->route('components.index')->with('success', trans('admin/components/message.checkout.success')); @@ -456,12 +446,12 @@ class ComponentsController extends Controller } if (Gate::allows('components.edit')) { - $actions .= 'id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;">'; } if (Gate::allows('components.delete')) { - $actions .= ''; } @@ -471,10 +461,10 @@ class ComponentsController extends Controller $rows[] = array( 'checkbox' =>'', 'id' => $component->id, - 'name' => (string)link_to('admin/components/'.$component->id.'/view', e($component->name)), + 'name' => (string)link_to_route('components.show', e($component->name), ['component' => $component->id]), 'serial_number' => $component->serial, 'location' => ($component->location) ? e($component->location->name) : '', - 'qty' => e($component->qty), + 'qty' => number_format($component->qty), 'min_amt' => e($component->min_amt), 'category' => ($component->category) ? e($component->category->name) : 'Missing category', 'order_number' => e($component->order_number), @@ -515,7 +505,7 @@ class ComponentsController extends Controller foreach ($component->assets as $component_assignment) { $rows[] = array( - 'name' => (string)link_to('/hardware/'.$component_assignment->id.'/view', e($component_assignment->showAssetName())), + 'name' => (string)link_to_route('hardware.show', e($component_assignment->showAssetName()), ['hardware' => $component_assignment->id]), 'qty' => e($component_assignment->pivot->assigned_qty), 'created_at' => ($component_assignment->created_at->format('Y-m-d H:i:s')=='-0001-11-30 00:00:00') ? '' : $component_assignment->created_at->format('Y-m-d H:i:s'), ); diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 67f33272c..de72206c7 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -338,33 +338,39 @@ class ReportsController extends Controller $rows = array(); foreach ($activitylogs as $activity) { + // This is janky AF and should be handled better. if ($activity->itemType() == "asset") { + $routename = 'assets'; $activity_icons = ''; } elseif ($activity->itemType() == "accessory") { + $routename = 'accessories'; $activity_icons = ''; } elseif ($activity->itemType()=="consumable") { + $routename = 'consumables'; $activity_icons = ''; } elseif ($activity->itemType()=="license"){ + $routename = 'licenses'; $activity_icons = ''; } elseif ($activity->itemType()=="component") { + $routename = 'components'; $activity_icons = ''; } else { $activity_icons = ''; } + if (($activity->item) && ($activity->itemType()=="asset")) { $activity_item = ''.e($activity->item->asset_tag).' - '. e($activity->item->showAssetName()).''; $item_type = 'asset'; } elseif ($activity->item) { - $activity_item = '' . e($activity->item->name) . ''; + $activity_item = '' . e($activity->item->name) . ''; $item_type = $activity->itemType(); } else { $activity_item = "unkonwn"; $item_type = "null"; } - + if (($activity->user) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) { $activity_target = ''.$activity->user->fullName().''; @@ -397,7 +403,7 @@ class ReportsController extends Controller } } - + $rows[] = array( 'icon' => $activity_icons, 'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)), @@ -748,7 +754,7 @@ class ReportsController extends Controller ->with('error', trans('admin/reports/message.error')); } } - + /** * getImprovementsReport diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 7f59c11b9..5da762382 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -61,6 +61,7 @@ class RouteServiceProvider extends ServiceProvider require base_path('routes/web/licenses.php'); require base_path('routes/web/consumables.php'); require base_path('routes/web/fields.php'); + require base_path('routes/web/components.php'); require base_path('routes/web.php'); }); } diff --git a/resources/views/components/edit.blade.php b/resources/views/components/edit.blade.php index b2720d13c..84b7bb3e2 100644 --- a/resources/views/components/edit.blade.php +++ b/resources/views/components/edit.blade.php @@ -2,7 +2,9 @@ 'createText' => trans('admin/components/general.create') , 'updateText' => trans('admin/components/general.update'), 'helpTitle' => trans('admin/components/general.about_components_title'), - 'helpText' => trans('admin/components/general.about_components_text') + 'helpText' => trans('admin/components/general.about_components_text'), + 'formAction' => ($item) ? route('components.update', ['component' => $item->id]) : route('components.store'), + ]) {{-- Page content --}} diff --git a/resources/views/components/index.blade.php b/resources/views/components/index.blade.php index 71b031dd5..2421ab44f 100644 --- a/resources/views/components/index.blade.php +++ b/resources/views/components/index.blade.php @@ -8,7 +8,7 @@ @section('header_right') @can('components.create') - {{ trans('general.create') }} + {{ trans('general.create') }} @endcan @stop diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php index 7463d407b..ea995aca9 100644 --- a/resources/views/components/view.blade.php +++ b/resources/views/components/view.blade.php @@ -26,7 +26,7 @@ @endcan @endif @can('components.edit') -