Components routes

This commit is contained in:
snipe 2016-12-15 19:59:42 -08:00
parent e685e0f019
commit f832b15cf3
12 changed files with 77 additions and 97 deletions

View file

@ -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>';
}

View file

@ -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 .= '<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 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'),
);

View file

@ -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'));
}
}
/**
* getImprovementsReport

View file

@ -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');
});
}

View file

@ -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 --}}

View file

@ -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
@stop

View file

@ -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>

View file

@ -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
@endforeach

View file

@ -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>

View file

@ -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 () {
# Settings
Route::group([ 'prefix' => 'app' ], function () {

21
routes/web/components.php Normal file
View file

@ -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']
]);

View file

@ -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 ComponentsCest
public 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 ComponentsCest
public 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('&lt;span class=&quot;');
@ -71,7 +71,7 @@ class ComponentsCest
public 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');
}
}