Skip to content

Commit

Permalink
Components routes
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Dec 16, 2016
1 parent e685e0f commit f832b15
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 97 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public function getDataViewComponent($categoryID)
$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>';
}


Expand Down
68 changes: 29 additions & 39 deletions app/Http/Controllers/ComponentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ComponentsController extends Controller
* @since [v3.0]
* @return View
*/
public function getIndex()
public function index()
{
return View::make('components/index');
}
Expand All @@ -53,7 +53,7 @@ public function getIndex()
* @since [v3.0]
* @return View
*/
public function getCreate()
public function create()
{
// Show the page
$category_list = Helper::categoryList('component');
Expand All @@ -76,7 +76,7 @@ public function getCreate()
* @since [v3.0]
* @return Redirect
*/
public function postCreate()
public function store()
{

// create a new model instance
Expand Down Expand Up @@ -110,7 +110,7 @@ public function postCreate()
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());
Expand All @@ -127,14 +127,14 @@ public function postCreate()
* @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');
Expand All @@ -157,14 +157,14 @@ public function getEdit($componentId = null)
* @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'));
}


Expand All @@ -191,17 +191,12 @@ public function postEdit($componentId = null)

$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());




}

/**
Expand All @@ -212,20 +207,16 @@ public function postEdit($componentId = null)
* @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'));

}

Expand All @@ -249,15 +240,15 @@ public function postBulkSave($componentId = null)
* @param int $componentId
* @return View
*/
public function getView($componentId = null)
public function show($componentId = null)
{
$component = Component::find($componentId);

if (isset($component->id)) {


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'));
}
Expand Down Expand Up @@ -288,7 +279,7 @@ public function getCheckout($componentId)
// 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
Expand Down Expand Up @@ -317,7 +308,7 @@ public function postCheckout(Request $request, $componentId)
// 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'));
}


Expand All @@ -339,9 +330,9 @@ public function postCheckout(Request $request, $componentId)
// 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;

Expand Down Expand Up @@ -372,7 +363,7 @@ public function postCheckout(Request $request, $componentId)
'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:',
Expand All @@ -386,8 +377,7 @@ public function postCheckout(Request $request, $componentId)
}
}

// 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'));



Expand Down Expand Up @@ -456,12 +446,12 @@ public function getDatatable()
}

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

Expand All @@ -471,10 +461,10 @@ public function getDatatable()
$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),
Expand Down Expand Up @@ -515,7 +505,7 @@ public function getDataView($componentId)

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'),
);
Expand Down
16 changes: 11 additions & 5 deletions app/Http/Controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,33 +338,39 @@ public function getActivityReportDataTable()
$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>';
Expand Down Expand Up @@ -397,7 +403,7 @@ public function getActivityReportDataTable()
}
}


$rows[] = array(
'icon' => $activity_icons,
'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)),
Expand Down Expand Up @@ -748,7 +754,7 @@ public function postCustom()
->with('error', trans('admin/reports/message.error'));
}
}


/**
* getImprovementsReport
Expand Down
1 change: 1 addition & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected function mapWebRoutes()
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');
});
}
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 --}}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Loading

0 comments on commit f832b15

Please sign in to comment.