Skip to content

Commit

Permalink
Fixes #387 - sortable asset view by manufacturer
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Feb 11, 2015
1 parent 35a133b commit 80e10c4
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 51 deletions.
14 changes: 7 additions & 7 deletions app/controllers/admin/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function postCreate()

// create a new model instance
$category = new Category();

$validator = Validator::make(Input::all(), $category->rules);

if ($validator->fails())
{
// The given data did not pass validation
// The given data did not pass validation
return Redirect::back()->withInput()->withErrors($validator->messages());
}
else{
Expand All @@ -71,7 +71,7 @@ public function postCreate()
// Redirect to the new category page
return Redirect::to("admin/settings/categories")->with('success', Lang::get('admin/categories/message.create.success'));
}
}
}

// Redirect to the category create page
return Redirect::to('admin/settings/categories/create')->with('error', Lang::get('admin/categories/message.create.error'));
Expand Down Expand Up @@ -119,9 +119,9 @@ public function postEdit($categoryId = null)
// get the POST data
$new = Input::all();

// attempt validation
// attempt validation
$validator = Validator::make(Input::all(), $category->validationRules($categoryId));


if ($validator->fails())
{
Expand All @@ -139,7 +139,7 @@ public function postEdit($categoryId = null)
// Redirect to the new category page
return Redirect::to("admin/settings/categories")->with('success', Lang::get('admin/categories/message.update.success'));
}
}
}

// Redirect to the category management page
return Redirect::to("admin/settings/categories/$categoryID/edit")->with('error', Lang::get('admin/categories/message.update.error'));
Expand Down Expand Up @@ -179,7 +179,7 @@ public function getDelete($categoryId)


/**
* Get the asset information to present to the model view page
* Get the asset information to present to the category view page
*
* @param int $assetId
* @return View
Expand Down
29 changes: 27 additions & 2 deletions app/controllers/admin/ManufacturersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function postEdit($manufacturerId = null)

if ($validator->fails())
{
// The given data did not pass validation
// The given data did not pass validation
return Redirect::back()->withInput()->withErrors($validator->messages());
}
// attempt validation
Expand All @@ -126,7 +126,7 @@ public function postEdit($manufacturerId = null)
// Redirect to the new manufacturer page
return Redirect::to("admin/settings/manufacturers")->with('success', Lang::get('admin/manufacturers/message.update.success'));
}
}
}

// Redirect to the manufacturer management page
return Redirect::to("admin/settings/manufacturers/$manufacturerId/edit")->with('error', Lang::get('admin/manufacturers/message.update.error'));
Expand Down Expand Up @@ -169,5 +169,30 @@ public function getDelete($manufacturerId)



/**
* Get the asset information to present to the category view page
*
* @param int $assetId
* @return View
**/
public function getView($manufacturerID = null)
{
$manufacturer = Manufacturer::find($manufacturerID);

if (isset($manufacturer->id)) {
return View::make('backend/manufacturers/view', compact('manufacturer'));
} else {
// Prepare the error message
$error = Lang::get('admin/manufacturers/message.does_not_exist', compact('id'));

// Redirect to the user management page
return Redirect::route('manufacturers')->with('error', $error);
}


}




}
11 changes: 11 additions & 0 deletions app/models/Manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ public function has_models()
{
return $this->hasMany('Model', 'manufacturer_id')->count();
}

public function assetscount()
{
return $this->hasManyThrough('Asset', 'Model')->count();
}

public function assets()
{
return $this->hasManyThrough('Asset', 'Model');
}

}
1 change: 1 addition & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
Route::get('{manufacturerId}/edit', array('as' => 'update/manufacturer', 'uses' => 'ManufacturersController@getEdit'));
Route::post('{manufacturerId}/edit', 'ManufacturersController@postEdit');
Route::get('{manufacturerId}/delete', array('as' => 'delete/manufacturer', 'uses' => 'ManufacturersController@getDelete'));
Route::get('{manufacturerId}/view', array('as' => 'view/manufacturer', 'uses' => 'ManufacturersController@getView'));
});

# Suppliers
Expand Down
10 changes: 6 additions & 4 deletions app/views/backend/categories/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
<div class="row profile">
<div class="col-md-9 bio">

<table id="example">
<div class="table-responsive">
<table id="example">
<thead>
<tr role="row">
<th class="col-md-5">@lang('admin/categories/table.title')</th>
<th class="col-md-5 actions">@lang('general.assets')</th>
<th class="col-md-2 actions">@lang('table.actions')</th>
<th class="col-md-5" bSortable="true">@lang('admin/categories/table.title')</th>
<th class="col-md-5" bSortable="true">@lang('general.assets')</th>
<th class="col-md-2 actions" bSortable="true">@lang('table.actions')</th>
</tr>
</thead>
<tbody>
Expand All @@ -47,6 +48,7 @@


</div>
</div>


<!-- side address column -->
Expand Down
38 changes: 1 addition & 37 deletions app/views/backend/categories/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<div class="user-profile">
<div class="row profile">
<div class="col-md-9 bio">
<div class="col-md-12 bio">


<!-- checked out categories table -->
Expand Down Expand Up @@ -88,40 +88,4 @@
</div>


<!-- side address column -->
<div class="col-md-3 col-xs-12 address pull-right">
<h6>More Info:</h6>
<ul>


@if ($category->manufacturer)
<li>@lang('general.manufacturer'):
{{ $category->manufacturer->name }}</li>
@endif

@if ($category->modelno)
<li>@lang('general.model_no'):
{{ $category->modelno }}</li>
@endif

@if ($category->depreciation)
<li>@lang('general.depreciation'):
{{ $category->depreciation->name }} ({{ $category->depreciation->months }}
@lang('general.months')
)</li>
@endif

@if ($category->eol)
<li>@lang('general.eol'):
{{ $category->eol }}
@lang('general.months')</li>
@endif

@if ($category->image)
<li><br /><img src="/uploads/models/{{{ $category->image }}}" /></li>
@endif

</ul>

</div>
@stop
6 changes: 5 additions & 1 deletion app/views/backend/manufacturers/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@
<div class="col-md-9 bio">


<div class="table-responsive">
<table id="example">
<thead>
<tr role="row">
<th class="col-md-7">@lang('admin/manufacturers/table.name')</th>
<th class="col-md-7" bSortable="true">@lang('admin/manufacturers/table.name')</th>
<th bSortable="true">@lang('general.assets')</th>
<th class="col-md-2 actions">@lang('table.actions')</th>
</tr>
</thead>
<tbody>
@foreach ($manufacturers as $manufacturer)
<tr>
<td>{{{ $manufacturer->name }}}</td>
<td><a href="{{ route('view/manufacturer',$manufacturer->id) }}">{{ $manufacturer->assetscount() }}</a></td>
<td>

<a href="{{ route('update/manufacturer', $manufacturer->id) }}" class="btn btn-warning"><i class="icon-pencil icon-white"></i></a>
Expand All @@ -45,6 +48,7 @@
@endforeach
</tbody>
</table>
</div>
</div>

<!-- side address column -->
Expand Down
92 changes: 92 additions & 0 deletions app/views/backend/manufacturers/view.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@extends('backend/layouts/default')

{{-- Page title --}}
@section('title')

{{{ $manufacturer->name }}}
@lang('general.manufacturer') ::
@parent
@stop

{{-- Page content --}}
@section('content')


<div class="row header">
<div class="col-md-12">
<div class="btn-group pull-right">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">@lang('button.actions')
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="{{ route('update/model', $manufacturer->id) }}">@lang('admin/categories/table.edit')</a></li>
<li><a href="{{ route('clone/model', $manufacturer->id) }}">@lang('admin/categories/table.clone')</a></li>
<li><a href="{{ route('create/hardware', $manufacturer->id) }}">@lang('admin/hardware/form.create')</a></li>
</ul>
</div>
<h3>
{{{ $manufacturer->name }}}
@lang('general.manufacturer')

</h3>
</div>
</div>

<div class="user-profile">
<div class="row profile">
<div class="col-md-12 bio">


<!-- checked out categories table -->
@if (count($manufacturer->assets) > 0)
<table id="example">
<thead>
<tr role="row">
<th class="col-md-3">@lang('general.name')</th>
<th class="col-md-3">@lang('general.asset_tag')</th>
<th class="col-md-3">@lang('general.user')</th>
<th class="col-md-2">@lang('table.actions')</th>
</tr>
</thead>
<tbody>

@foreach ($manufacturer->assets as $modelassets)
<tr>
<td><a href="{{ route('view/hardware', $modelassets->id) }}">{{{ $modelassets->name }}}</a></td>
<td><a href="{{ route('view/hardware', $modelassets->id) }}">{{{ $modelassets->asset_tag }}}</a></td>
<td>
@if ($modelassets->assigneduser)
<a href="{{ route('view/user', $modelassets->assigned_to) }}">
{{{ $modelassets->assigneduser->fullName() }}}
</a>
@endif
</td>
<td>
@if ($modelassets->assigned_to != 0)
<a href="{{ route('checkin/hardware', $modelassets->id) }}" class="btn-flat info">Checkin</a>
@else
<a href="{{ route('checkout/hardware', $modelassets->id) }}" class="btn-flat success">Checkout</a>
@endif
</td>

</tr>
@endforeach


</tbody>
</table>

@else
<div class="col-md-9">
<div class="alert alert-info alert-block">
<i class="icon-info-sign"></i>
@lang('general.no_results')
</div>
</div>
@endif

</div>



@stop

0 comments on commit 80e10c4

Please sign in to comment.