Skip to content

A free open source IT asset/license management system

Small tweaks to locations API

snipea4ad7a0baf44
diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php
index 7137362bcf..8802ca7be5 100644
--- a/app/Http/Transformers/LocationsTransformer.php
+++ b/app/Http/Transformers/LocationsTransformer.php
@@ -113,7 +113,11 @@ class LocationsTransformer
$array = [
'id' => $accessory_checkout->id,
- 'assigned_to' => $accessory_checkout->assigned_to,
+ 'assigned_to' => $accessory_checkout->assignedTo ? [
+ 'id' => $accessory_checkout->assignedTo?->id,
+ 'name' => $accessory_checkout->assignedTo?->display_name,
+ 'type' => strtolower($accessory_checkout->assignedType()),
+ ] : null,
'accessory' => $this->transformAccessory($accessory_checkout->accessory),
'image' => ($accessory_checkout?->accessory?->image) ? Storage::disk('public')->url('accessories/'.e($accessory_checkout->accessory->image)) : null,
'note' => $accessory_checkout->note ? e($accessory_checkout->note) : null,
diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php
index 02823e91ad..2ce5d1beec 100644
--- a/app/Presenters/AccessoryPresenter.php
+++ b/app/Presenters/AccessoryPresenter.php
@@ -210,22 +210,83 @@ class AccessoryPresenter extends Presenter
'visible' => false,
],
[
- 'field' => 'assigned_to.image',
+ 'field' => 'assigned_to',
'searchable' => false,
'sortable' => false,
'switchable' => true,
- 'title' => trans('general.image'),
+ 'title' => trans('general.checked_out_to'),
'visible' => true,
- 'formatter' => 'imageFormatter',
+ 'formatter' => 'polymorphicItemFormatter',
],
[
- 'field' => 'assigned_to',
+ 'field' => 'note',
'searchable' => false,
'sortable' => false,
'switchable' => true,
- 'title' => trans('general.checked_out_to'),
+ 'title' => trans('general.notes'),
'visible' => true,
- 'formatter' => 'polymorphicItemFormatter',
+ ],
+ [
+ 'field' => 'created_at',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('admin/hardware/table.checkout_date'),
+ 'visible' => true,
+ 'formatter' => 'dateDisplayFormatter',
+ ],
+ [
+ 'field' => 'created_by',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'title' => trans('general.created_by'),
+ 'visible' => false,
+ 'formatter' => 'usersLinkObjFormatter',
+ ],
+ [
+ 'field' => 'available_actions',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => false,
+ 'title' => trans('table.actions'),
+ 'formatter' => 'accessoriesInOutFormatter',
+ 'printIgnore' => true,
+ 'class' => 'hidden-print',
+ ],
+ ];
+
+ return json_encode($layout);
+ }
+
+ public static function assignedDataTableLayoutForObject()
+ {
+ $layout = [
+ [
+ 'field' => 'id',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('general.id'),
+ 'visible' => false,
+ ],
+
+ [
+ 'field' => 'accessory',
+ 'searchable' => true,
+ 'sortable' => false,
+ 'switchable' => false,
+ 'title' => trans('general.name'),
+ 'visible' => true,
+ 'formatter' => 'accessoriesLinkObjFormatter',
+ ],
+ [
+ 'field' => 'image',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('general.image'),
+ 'visible' => true,
+ 'formatter' => 'imageFormatter',
],
[
'field' => 'note',
diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php
index 27745aceb5..dab2adea36 100644
--- a/resources/views/locations/view.blade.php
+++ b/resources/views/locations/view.blade.php
@@ -150,7 +150,12 @@
<!-- start assigned accessories tab pane -->
<x-tabs.pane name="accessories_assigned">
- <x-table.accessories :table_header="trans('general.accessories_assigned')" :route="route('api.locations.assigned_accessories', ['location' => $location]) "/>
+
+ <x-table.accessories
+ :table_header="trans('general.accessories_assigned')"
+ :presenter="\App\Presenters\AccessoryPresenter::assignedDataTableLayoutForObject()"
+ :route="route('api.locations.assigned_accessories', ['location' => $location]) "/>
+
</x-tabs.pane>
@endcan
<!-- end assigned accessories tab pane -->