mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add ability to view assets by status label
This should be refactored. Lots of copypaste from the assets views here
This commit is contained in:
parent
19cb428fb0
commit
ad4bf83aaa
|
@ -8,6 +8,7 @@ use App\Helpers\Helper;
|
|||
use App\Models\Statuslabel;
|
||||
use App\Models\Asset;
|
||||
use App\Http\Transformers\DatatablesTransformer;
|
||||
use App\Http\Transformers\AssetsTransformer;
|
||||
|
||||
class StatuslabelsController extends Controller
|
||||
{
|
||||
|
@ -161,4 +162,36 @@ class StatuslabelsController extends Controller
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function assets(Request $request, $id)
|
||||
{
|
||||
$this->authorize('view', Statuslabel::class);
|
||||
$this->authorize('index', Asset::class);
|
||||
$assets = Asset::where('status_id','=',$id);
|
||||
|
||||
$allowed_columns = [
|
||||
'id',
|
||||
'name'
|
||||
];
|
||||
|
||||
$offset = request('offset', 0);
|
||||
$limit = $request->input('limit', 50);
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
|
||||
$assets->orderBy($sort, $order);
|
||||
|
||||
$total = $assets->count();
|
||||
$assets = $assets->skip($offset)->take($limit)->get();
|
||||
|
||||
|
||||
return (new AssetsTransformer)->transformAssets($assets, $total);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,10 +32,19 @@ class StatuslabelsController extends Controller
|
|||
|
||||
public function index()
|
||||
{
|
||||
// Show the page
|
||||
return View::make('statuslabels/index', compact('statuslabels'));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$statuslabel = Statuslabel::find($id);
|
||||
|
||||
if (isset($statuslabel->id)) {
|
||||
return View::make('statuslabels/view', compact('statuslabel'));
|
||||
}
|
||||
|
||||
return redirect()->route('statuslabels.index')->with('error', trans('admin/locations/message.does_not_exist', compact('id')));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class AssetsTransformer
|
|||
'serial' => $asset->serial,
|
||||
'model' => ($asset->model) ? $asset->model->name : '',
|
||||
'model_number' => $asset->model_number,
|
||||
'status_label' => ($asset->assetstatus) ? $asset->assetstatus->name : '',
|
||||
'status_label' => ($asset->assetstatus) ? $asset->assetstatus : '',
|
||||
'last_checkout' => $asset->last_checkout,
|
||||
'category' => ($asset->model->category) ? $asset->model->category->name : '',
|
||||
'manufacturer' => $asset->manufacturer,
|
||||
|
|
|
@ -26,7 +26,8 @@ class UsersTransformer
|
|||
'lastname' => e($user->last_name),
|
||||
'username' => e($user->username),
|
||||
'employee_num' => e($user->employee_num),
|
||||
'manager' => ($user->manager) ? $user->manager->name : false,
|
||||
'manager' => ($user->manager) ? (new UsersTransformer)->transformUser($user->manager) : '',
|
||||
'groups' => $user->groups,
|
||||
'jobtitle' => e($user->jobtitle),
|
||||
'email' => e($user->email),
|
||||
'location' => (new LocationsTransformer)->transformLocation($user->userloc),
|
||||
|
@ -46,4 +47,6 @@ class UsersTransformer
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
102
resources/views/statuslabels/view.blade.php
Normal file
102
resources/views/statuslabels/view.blade.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
@extends('layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
{{ $statuslabel->name }} Assets ({{ $statuslabel->getStatuslabelType() }})
|
||||
@parent
|
||||
@stop
|
||||
|
||||
@section('header_right')
|
||||
<a href="{{ route('statuslabels.create') }}" class="btn btn-primary pull-right">
|
||||
{{ trans('general.create') }}</a>
|
||||
@stop
|
||||
{{-- Page content --}}
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box">
|
||||
<div class="box-body">
|
||||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['hardware/bulkedit'],
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkForm']) }}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@if (Input::get('status')!='Deleted')
|
||||
<div id="toolbar">
|
||||
<select name="bulk_actions" class="form-control select2">
|
||||
<option value="edit">Edit</option>
|
||||
<option value="delete">Delete</option>
|
||||
<option value="labels">Generate Labels</option>
|
||||
</select>
|
||||
<button class="btn btn-default" id="bulkEdit" disabled>Go</button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<table
|
||||
name="assets"
|
||||
{{-- data-row-style="rowStyle" --}}
|
||||
data-toolbar="#toolbar"
|
||||
class="table table-striped snipe-table"
|
||||
id="table"
|
||||
data-url="{{route('api.assets.index', array(''=>e(Input::get('status')),'order_number'=>e(Input::get('order_number')), 'status_id'=>e(Input::get('status_id'))))}}"
|
||||
data-cookie="true"
|
||||
data-click-to-select="true"
|
||||
data-cookie-id-table="{{ e(Input::get('status')) }}assetTable-{{ config('version.hash_version') }}">
|
||||
<thead>
|
||||
<tr>
|
||||
@if (Input::get('status')!='Deleted')
|
||||
<th data-checkbox="true" data-field="checkbox"></th>
|
||||
@endif
|
||||
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||
<th data-field="companyName" data-searchable="true" data-sortable="true" data-switchable="true" data-visible="false">{{ trans('general.company') }}</th>
|
||||
<th data-sortable="true" data-field="image" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
|
||||
<th data-sortable="true" data-field="name" data-visible="false">{{ trans('admin/hardware/form.name') }}</th>
|
||||
<th data-sortable="true" data-field="asset_tag" data-formatter="assetFormatter">{{ trans('admin/hardware/table.asset_tag') }}</th>
|
||||
<th data-sortable="true" data-field="serial" data-formatter="assetFormatter">{{ trans('admin/hardware/table.serial') }}</th>
|
||||
<th data-sortable="true" data-field="model">{{ trans('admin/hardware/form.model') }}</th>
|
||||
<th data-sortable="true" data-field="model_number" data-visible="false">{{ trans('admin/models/table.modelnumber') }}</th>
|
||||
|
||||
<th data-sortable="true" data-field="assigned_to">{{ trans('admin/hardware/form.checkedout_to') }}</th>
|
||||
<th data-sortable="true" data-formatter="locationFormatter" data-field="location" data-searchable="true">{{ trans('admin/hardware/table.location') }}</th>
|
||||
<th data-sortable="true" data-field="category" data-searchable="true">{{ trans('general.category') }}</th>
|
||||
<th data-sortable="true" data-field="manufacturer" data-searchable="true" data-visible="false">{{ trans('general.manufacturer') }}</th>
|
||||
<th data-sortable="true" data-field="purchase_cost" data-searchable="true" data-visible="false">{{ trans('admin/hardware/form.cost') }}</th>
|
||||
<th data-sortable="true" data-field="purchase_date" data-searchable="true" data-visible="false">{{ trans('admin/hardware/form.date') }}</th>
|
||||
<th data-sortable="false" data-field="eol" data-searchable="true">{{ trans('general.eol') }}</th>
|
||||
<th data-sortable="true" data-searchable="true" data-field="notes">{{ trans('general.notes') }}</th>
|
||||
<th data-sortable="true" data-searchable="true" data-field="order_number">{{ trans('admin/hardware/form.order') }}</th>
|
||||
<th data-sortable="true" data-searchable="true" data-field="last_checkout">{{ trans('admin/hardware/table.checkout_date') }}</th>
|
||||
<th data-sortable="true" data-field="expected_checkin" data-searchable="true">{{ trans('admin/hardware/form.expected_checkin') }}</th>
|
||||
@foreach(\App\Models\CustomField::all() AS $field)
|
||||
|
||||
|
||||
<th data-sortable="{{ ($field->field_encrypted=='1' ? 'false' : 'true') }}" data-visible="false" data-field="{{$field->db_column_name()}}">
|
||||
@if ($field->field_encrypted=='1')
|
||||
<i class="fa fa-lock"></i>
|
||||
@endif
|
||||
|
||||
{{$field->name}}
|
||||
</th>
|
||||
|
||||
@endforeach
|
||||
<th data-sortable="true" data-field="created_at" data-formatter="createdAtFormatter" data-searchable="true" data-visible="false">{{ trans('general.created_at') }}</th>
|
||||
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="change">{{ trans('admin/hardware/table.change') }}</th>
|
||||
|
||||
<th data-switchable="false" data-searchable="false" data-formatter="actionsFormatter" data-sortable="false" data-field="actions" >{{ trans('table.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div><!-- /.col -->
|
||||
</div><!-- /.row -->
|
||||
{{ Form::close() }}
|
||||
</div><!-- ./box-body -->
|
||||
</div><!-- /.box -->
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
|
||||
@section('moar_scripts')
|
||||
@include ('partials.bootstrap-table', ['exportFile' => 'statuslabels-export', 'search' => true])
|
||||
@stop
|
|
@ -147,6 +147,9 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
Route::group([ 'prefix' => 'statuslabels'], function () {
|
||||
|
||||
|
||||
Route::get('{id}/assetlist',
|
||||
[ 'as' => 'api.statuslabels.assets', 'uses' => 'StatuslabelsController@assets' ]);
|
||||
|
||||
Route::get('{id}/deployable', function ($statuslabelId) {
|
||||
|
||||
$statuslabel = Statuslabel::find($statuslabelId);
|
||||
|
|
Loading…
Reference in a new issue