A free open source IT asset/license management system
Components routes
snipef832b15cf356
diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.phpindex d84a3d3dc7..897463f52f 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 = '<div style=" white-space: nowrap;"><a href="'.route('update/component', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/component', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';+ $actions = '<div style=" white-space: nowrap;"><a href="'.route('components.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('components.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';}diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.phpindex 314940d0e4..d6c26bda4b 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 Controllerif ($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 existsif (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 existsif (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 existsif (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 Controllerif (!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 errorreturn 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 errorreturn 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 existsif (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 .= '<a href="' . route('update/component',+ $actions .= '<a href="' . route('components.edit',$component->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';}if (Gate::allows('components.delete')) {- $actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/component',+ $actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('components.destroy',$component->id) . '" data-content="' . trans('admin/components/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($component->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';}@@ -471,10 +461,10 @@ class ComponentsController extends Controller$rows[] = array('checkbox' =>'<div class="text-center"><input type="checkbox" name="component['.$component->id.']" class="one_required"></div>','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 Controllerforeach ($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.phpindex 67f33272c9..de72206c77 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 = '<i class="fa fa-barcode"></i>';} elseif ($activity->itemType() == "accessory") {+ $routename = 'accessories';$activity_icons = '<i class="fa fa-keyboard-o"></i>';} elseif ($activity->itemType()=="consumable") {+ $routename = 'consumables';$activity_icons = '<i class="fa fa-tint"></i>';} elseif ($activity->itemType()=="license"){+ $routename = 'licenses';$activity_icons = '<i class="fa fa-floppy-o"></i>';} elseif ($activity->itemType()=="component") {+ $routename = 'components';$activity_icons = '<i class="fa fa-hdd-o"></i>';} else {$activity_icons = '<i class="fa fa-paperclip"></i>';}+if (($activity->item) && ($activity->itemType()=="asset")) {$activity_item = '<a href="'.route('hardware.show', $activity->item_id).'">'.e($activity->item->asset_tag).' - '. e($activity->item->showAssetName()).'</a>';$item_type = 'asset';} elseif ($activity->item) {- $activity_item = '<a href="' . route('view/' . $activity->itemType(),- $activity->item_id) . '">' . e($activity->item->name) . '</a>';+ $activity_item = '<a href="' . route($routename.'.show', $activity->item_id) . '">' . e($activity->item->name) . '</a>';$item_type = $activity->itemType();} else {$activity_item = "unkonwn";$item_type = "null";}-+if (($activity->user) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) {$activity_target = '<a href="'.route('view/user', $activity->target_id).'">'.$activity->user->fullName().'</a>';@@ -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'));}}-+/*** getImprovementsReportdiff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.phpindex 7f59c11b90..5da762382e 100644--- a/app/Providers/RouteServiceProvider.php+++ b/app/Providers/RouteServiceProvider.php@@ -61,6 +61,7 @@ class RouteServiceProvider extends ServiceProviderrequire 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.phpindex b2720d13c5..84b7bb3e2b 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.phpindex 71b031dd55..2421ab44f0 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')- <a href="{{ route('create/component') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>+ <a href="{{ route('components.create') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>@endcan@stopdiff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.phpindex 7463d407b5..ea995aca98 100644--- a/resources/views/components/view.blade.php+++ b/resources/views/components/view.blade.php@@ -26,7 +26,7 @@@endcan@endif@can('components.edit')- <li role="presentation"><a href="{{ route('update/component', $component->id) }}">{{ trans('admin/components/general.edit') }}</a></li>+ <li role="presentation"><a href="{{ route('components.edit', $component->id) }}">{{ trans('admin/components/general.edit') }}</a></li>@endcan</ul>diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.phpindex ead5569e68..c594b9ad1f 100755--- a/resources/views/hardware/view.blade.php+++ b/resources/views/hardware/view.blade.php@@ -471,7 +471,7 @@@foreach ($asset->components as $component)@if (is_null($component->deleted_at))<tr>- <td><a href="{{ route('view/component', $component->id) }}">{{ $component->name }}</a></td>+ <td><a href="{{ route('components.show', $component->id) }}">{{ $component->name }}</a></td></tr>@endif@endforeachdiff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.phpindex e8a8c92c5c..15b4883c66 100644--- a/resources/views/layouts/default.blade.php+++ b/resources/views/layouts/default.blade.php@@ -158,7 +158,7 @@@endcan@can('components.view')<li {!! (Request::is('components*') ? ' class="active"' : '') !!}>- <a href="{{ url('components') }}">+ <a href="{{ route('components.index') }}"><i class="fa fa-hdd-o"></i></a></li>@@ -223,7 +223,7 @@@endcan@can('components.create')<li {!! (Request::is('components/create') ? 'class="active"' : '') !!}>- <a href="{{ route('create/component') }}">+ <a href="{{ route('components.create') }}"><i class="fa fa-hdd-o"></i>@lang('general.component')</a></li>@@ -483,7 +483,7 @@@endcan@can('components.view')<li{!! (Request::is('components*') ? ' class="active"' : '') !!}>- <a href="{{ url('admin/components') }}">+ <a href="{{ route('components.index') }}"><i class="fa fa-hdd-o"></i><span>@lang('general.components')</span></a>diff --git a/routes/web.php b/routes/web.phpindex 4f77e1d9b7..ef7fc44c7b 100644--- a/routes/web.php+++ b/routes/web.php@@ -99,49 +99,9 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function ()]);----- # Components- Route::group([ 'prefix' => 'components', 'middleware'=>'authorize:components.view' ], function () {-- Route::get('create', [ 'as' => 'create/component', 'middleware'=>'authorize:components.create','uses' => 'ComponentsController@getCreate' ]);- Route::post('create', [ 'as' => 'create/component', 'middleware'=>'authorize:components.create','uses' => 'ComponentsController@postCreate' ]);- Route::get(- '{componentID}/edit',- [ 'as' => 'update/component', 'middleware'=>'authorize:components.edit','uses' => 'ComponentsController@getEdit' ]- );- Route::post(- '{componentID}/edit',- [ 'as' => 'update/component', 'middleware'=>'authorize:components.edit','uses' => 'ComponentsController@postEdit' ]- );- Route::get(- '{componentID}/delete',- [ 'as' => 'delete/component', 'middleware'=>'authorize:components.delete','uses' => 'ComponentsController@getDelete' ]- );- Route::get(- '{componentID}/view',- [ 'as' => 'view/component', 'middleware'=>'authorize:components.view','uses' => 'ComponentsController@getView' ]- );- Route::get(- '{componentID}/checkout',- [ 'as' => 'checkout/component', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@getCheckout' ]- );- Route::post(- '{componentID}/checkout',- [ 'as' => 'checkout/component', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@postCheckout' ]- );- Route::post('bulk', [ 'as' => 'component/bulk-form', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@postBulk' ]);- Route::post('bulksave', [ 'as' => 'component/bulk-save', 'middleware'=>'authorize:components.edit','uses' => 'ComponentsController@postBulkSave' ]);- Route::get('/', [ 'as' => 'components', 'middleware'=>'authorize:components.view','uses' => 'ComponentsController@getIndex' ]);- });-# Admin Settings Routes (for categories, maufactureres, etc)Route::group([ 'prefix' => 'settings', 'middleware'=>'authorize:superuser'], function () {--# SettingsRoute::group([ 'prefix' => 'app' ], function () {diff --git a/routes/web/components.php b/routes/web/components.phpnew file mode 100644index 0000000000..447fc6b604--- /dev/null+++ b/routes/web/components.php@@ -0,0 +1,21 @@+<?php++# Components+Route::group([ 'prefix' => 'components', 'middleware'=>'authorize:components.view' ], function () {++ Route::get(+ '{componentID}/checkout',+ [ 'as' => 'checkout/component', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@getCheckout' ]+ );+ Route::post(+ '{componentID}/checkout',+ [ 'as' => 'checkout/component', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@postCheckout' ]+ );+ Route::post('bulk', [ 'as' => 'component/bulk-form', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@postBulk' ]);+ Route::post('bulksave', [ 'as' => 'component/bulk-save', 'middleware'=>'authorize:components.edit','uses' => 'ComponentsController@postBulkSave' ]);++});++Route::resource('components', 'ComponentsController', [+ 'parameters' => ['component' => 'component_id']+]);diff --git a/tests/functional/ComponentsCest.php b/tests/functional/ComponentsCest.phpindex 038afa8643..1c3f347e25 100644--- a/tests/functional/ComponentsCest.php+++ b/tests/functional/ComponentsCest.php@@ -16,7 +16,7 @@ class ComponentsCest{$I->wantTo('ensure that the create components form loads without errors');$I->lookForwardTo('seeing it load without errors');- $I->amOnPage(route('create/component'));+ $I->amOnPage(route('components.create'));$I->dontSee('Create Component', '.page-header');$I->see('Create Component', 'h1.pull-left');}@@ -24,7 +24,7 @@ class ComponentsCestpublic function failsEmptyValidation(FunctionalTester $I){$I->wantTo("Test Validation Fails with blank elements");- $I->amOnPage(route('create/component'));+ $I->amOnPage(route('components.create'));$I->click('Save');$I->seeElement('.alert-danger');$I->see('The name field is required.', '.alert-msg');@@ -35,7 +35,7 @@ class ComponentsCestpublic function failsShortValidation(FunctionalTester $I){$I->wantTo("Test Validation Fails with short name");- $I->amOnPage(route('create/component'));+ $I->amOnPage(route('components.create'));$I->fillField('name', 't2');$I->fillField('qty', '-15');$I->fillField('min_amt', '-15');@@ -62,7 +62,7 @@ class ComponentsCest'purchase_cost' => $component->purchase_cost,];$I->wantTo("Test Validation Succeeds");- $I->amOnPage(route('create/component'));+ $I->amOnPage(route('components.create'));$I->submitForm('form#create-form', $values);$I->seeRecord('components', $values);$I->dontSee('<span class="');@@ -71,7 +71,7 @@ class ComponentsCestpublic function allowsDelete(FunctionalTester $I){$I->wantTo('Ensure I can delete a component');- $I->amOnPage(route('delete/component', $I->getComponentId()));+ $I->amOnPage(route('components.destroy', $I->getComponentId()));$I->seeElement('.alert-success');}}