A free open source IT asset/license management system
Fixes #4059 - accessories view
snipe4d32f2b337d9
diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.phpindex b1ca7041c1..07fbc21971 100644--- a/app/Http/Controllers/Api/AccessoriesController.php+++ b/app/Http/Controllers/Api/AccessoriesController.php@@ -129,9 +129,8 @@ class AccessoriesController extends Controller{$this->authorize('view', Accessory::class);$accessory = Accessory::findOrFail($id)->with('users')->first();- $accessories_users = $accessory->users;- $total = $accessories_users->count();- return (new AccessoriesTransformer)->transformCheckedoutAccessories($accessories_users, $total);+ $total = $accessory->users->count();+ return (new AccessoriesTransformer)->transformCheckedoutAccessory($accessory, $total);}diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.phpindex 575e8be943..ffab0d7cf5 100644--- a/app/Http/Transformers/AccessoriesTransformer.php+++ b/app/Http/Transformers/AccessoriesTransformer.php@@ -59,13 +59,30 @@ class AccessoriesTransformer}- public function transformCheckedoutAccessories (Collection $accessories_users, $total)+ public function transformCheckedoutAccessory (Accessory $accessory, $total){+++$array = array();- foreach ($accessories_users as $user) {- $array[] = (new UsersTransformer)->transformUser($user);+ foreach ($accessory->users as $user) {+ $array[] = [+ 'assigned_pivot_id' => $user->pivot->id,+ 'id' => (int) $user->id,+ 'username' => e($user->username),+ 'name' => e($user->getFullNameAttribute()),+ 'first_name'=> e($user->first_name),+ 'last_name'=> e($user->last_name),+ 'employee_number' => e($user->employee_num),+ 'type' => 'user',+ 'available_actions' => ['checkin' => true]+ ];+}+++return (new DatatablesTransformer)->transformDatatables($array, $total);}diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.phpindex c8c054c9be..adcbfafe9a 100644--- a/app/Http/Transformers/AssetsTransformer.php+++ b/app/Http/Transformers/AssetsTransformer.php@@ -33,7 +33,8 @@ class AssetsTransformer'model_number' => ($asset->model) ? e($asset->model->model_number) : null,'status_label' => ($asset->assetstatus) ? ['id' => (int) $asset->assetstatus->id,- 'name'=> e($asset->assetstatus->name)+ 'name'=> e($asset->assetstatus->name),+ 'status_type' => e($asset->assetstatus->getStatuslabelType()),] : null,'category' => ($asset->model->category) ? ['id' => (int) $asset->model->category->id,diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.phpindex 4ce9fb843d..b44e584e01 100644--- a/resources/views/accessories/view.blade.php+++ b/resources/views/accessories/view.blade.php@@ -57,15 +57,15 @@name="accessory_users"class="table table-striped snipe-table"id="table"- data-url="{{ route('api.accessories.show', $accessory->id) }}"+ data-url="{{ route('api.accessories.checkedout', $accessory->id) }}"data-cookie="true"data-click-to-select="true"data-cookie-id-table="accessoryUsersTable"><thead><tr>- <th data-switchable="false" data-searchable="false" data-formatter="userLinkObjFormatter" data-sortable="false" data-field="name">{{ trans('general.user') }}</th>- <th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>+ <th data-switchable="false" data-searchable="false" data-formatter="usersLinkFormatter" data-sortable="false" data-field="name">{{ trans('general.user') }}</th>+ <th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions" data-formatter="accessoriesInOutFormatter">{{ trans('table.actions') }}</th></tr></thead></table>diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.phpindex 91b8836283..d02d376aa8 100644--- a/resources/views/partials/bootstrap-table.blade.php+++ b/resources/views/partials/bootstrap-table.blade.php@@ -139,7 +139,9 @@ $('.snipe-table').bootstrapTable({// Use this when we're introspecting into a column object and need to linkfunction genericColumnObjLinkFormatter(destination) {return function (value,row) {- if ((value) && (value.name)) {+ if (value.status_type) {+ return '<a href="{{ url('/') }}/' + destination + '/' + value.id + '"> ' + value.name + '</a> ' + '<label class="label label-default">'+ value.status_type + '</label>';+ } else if ((value) && (value.name)) {return '<a href="{{ url('/') }}/' + destination + '/' + value.id + '"> ' + value.name + '</a>';}};@@ -228,8 +230,14 @@ $('.snipe-table').bootstrapTable({return '<div data-tooltip="true" title="This item has a status label that is undeployable and cannot be checked out at this time."><a class="btn btn-sm btn-primary disabled">{{ trans('general.checkout') }}</a></div>';// The user is allowed to check items in- } else if ((row.available_actions.checkin == true) && (row.assigned_to)) {- return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.id + '/checkin" class="btn btn-sm btn-primary" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans('general.checkin') }}</a>';+ } else if (row.available_actions.checkin == true) {+ if (row.assigned_to) {+ return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.id + '/checkin" class="btn btn-sm btn-primary" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans('general.checkin') }}</a>';+ } else if (row.assigned_pivot_id) {+ return '<nobr><a href="{{ url('/') }}/' + destination + '/' + row.assigned_pivot_id + '/checkin" class="btn btn-sm btn-primary" data-tooltip="true" title="Check this item in so it is available for re-imaging, re-issue, etc.">{{ trans('general.checkin') }}</a>';+ }++ } else {}