diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 2466fe15b8..f44a8b5735 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -151,8 +151,10 @@ class AssetsController extends Controller if ($asset = Asset::withTrashed()->find($id)) { $this->authorize('view', $asset); + $asset = $asset->present()->detail(); - return $asset; + return (new AssetsTransformer)->transformAsset($asset); + } return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 404); diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index bcc95b3a7f..df9da9677a 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -3,6 +3,7 @@ namespace App\Http\Transformers; use App\Models\Asset; use Illuminate\Database\Eloquent\Collection; +use App\Http\Transformers\UsersTransformer; class AssetsTransformer { @@ -33,9 +34,9 @@ class AssetsTransformer 'expected_checkin' => $asset->expected_checkin, 'order_number' => $asset->order_number, 'companyName' => $asset->companyName, - 'location' => ($asset->assetLoc) ? $asset->assetLoc->name : '', + 'location' => ($asset->assetLoc) ? $asset->assetLoc : '', 'image' => $asset->image, - 'assigned_to' => ($asset->assigneduser) ? $asset->assigneduser->present()->fullName() : '', + 'assigned_to' => ($asset->assigneduser) ? (new UsersTransformer)->transformUser($asset->assigneduser) : null, 'created_at' => $asset->created_at, 'purchase_date' => $asset->purchase_date, 'purchase_cost' => $asset->purchase_cost, diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index 874ac64e3e..a4711b0d39 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -17,7 +17,7 @@ class LocationsTransformer public function transformLocation (Location $location = null) { if ($location) { - $locations_array[] = [ + $transformed = [ 'id' => e($location->id), 'name' => e($location->name), 'address' => e($location->address), @@ -25,7 +25,7 @@ class LocationsTransformer 'state' => e($location->state), 'country' => e($location->country), ]; - return $locations_array; + return $transformed; } diff --git a/resources/views/categories/index.blade.php b/resources/views/categories/index.blade.php index 4244a6c5f8..6c6bbff2f0 100755 --- a/resources/views/categories/index.blade.php +++ b/resources/views/categories/index.blade.php @@ -37,7 +37,7 @@ {{ trans('general.assets') }} {{ trans('admin/categories/table.require_acceptance') }} {{ trans('admin/categories/table.eula_text') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} diff --git a/resources/views/components/index.blade.php b/resources/views/components/index.blade.php index b1cdc77262..d773302c99 100644 --- a/resources/views/components/index.blade.php +++ b/resources/views/components/index.blade.php @@ -37,7 +37,7 @@ name="components" class="table table-striped snipe-table" id="table" - data-url="{{route('api.components.list') }}" + data-url="{{route('api.components.index') }}" data-cookie="true" data-click-to-select="true" data-cookie-id-table="componentsTable-{{ config('version.hash_version') }}-{{ config('version.hash_version') }}" diff --git a/resources/views/depreciations/index.blade.php b/resources/views/depreciations/index.blade.php index 1f7eadbb24..09272797a8 100755 --- a/resources/views/depreciations/index.blade.php +++ b/resources/views/depreciations/index.blade.php @@ -24,7 +24,7 @@ Asset Depreciations name="depreciations" class="table table-striped snipe-table" id="table" - data-url="{{ route('api.depreciations.list') }}" + data-url="{{ route('api.depreciations.index') }}" data-cookie="true" data-cookie-id-table="depreciationsTable-{{ config('version.hash_version') }}"> diff --git a/resources/views/groups/index.blade.php b/resources/views/groups/index.blade.php index c3e8ffabef..b6e03519d4 100755 --- a/resources/views/groups/index.blade.php +++ b/resources/views/groups/index.blade.php @@ -23,7 +23,7 @@ class="table table-striped snipe-table" id="table" data-toggle="table" - data-url="{{ route('api.groups.list') }}" + data-url="{{ route('api.groups.index') }}" data-cookie="true" data-click-to-select="true" data-cookie-id-table="userGroupDisplay-{{ config('version.hash_version') }}"> diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index 32460f222b..07f887a3df 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -74,18 +74,18 @@ @endif {{ trans('general.id') }} - {{ trans('general.company') }} + {{ trans('general.company') }} {{ trans('admin/hardware/table.image') }} - {{ trans('admin/hardware/form.name') }} - {{ trans('admin/hardware/table.asset_tag') }} - {{ trans('admin/hardware/table.serial') }} - {{ trans('admin/hardware/form.model') }} + {{ trans('admin/hardware/form.name') }} + {{ trans('admin/hardware/table.asset_tag') }} + {{ trans('admin/hardware/table.serial') }} + {{ trans('admin/hardware/form.model') }} {{ trans('admin/models/table.modelnumber') }} - {{ trans('admin/hardware/table.status') }} - {{ trans('admin/hardware/form.checkedout_to') }} - {{ trans('admin/hardware/table.location') }} - {{ trans('general.category') }} - {{ trans('general.manufacturer') }} + {{ trans('admin/hardware/table.status') }} + {{ trans('admin/hardware/form.checkedout_to') }} + {{ trans('admin/hardware/table.location') }} + {{ trans('general.category') }} + {{ trans('general.manufacturer') }} {{ trans('admin/hardware/form.cost') }} {{ trans('admin/hardware/form.date') }} {{ trans('general.eol') }} @@ -108,7 +108,7 @@ {{ trans('general.created_at') }} {{ trans('admin/hardware/table.change') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} @@ -128,18 +128,4 @@ 'multiSort' => true ]) - @stop diff --git a/resources/views/licenses/index.blade.php b/resources/views/licenses/index.blade.php index df7405949a..953ea02e84 100755 --- a/resources/views/licenses/index.blade.php +++ b/resources/views/licenses/index.blade.php @@ -35,9 +35,9 @@ {{ trans('general.id') }} - {{ trans('general.company') }} - {{ trans('admin/licenses/table.title') }} - {{ trans('general.manufacturer') }} + {{ trans('general.company') }} + {{ trans('admin/licenses/table.title') }} + {{ trans('general.manufacturer') }} {{ trans('admin/licenses/form.license_key') }} {{ trans('admin/licenses/form.to_name') }} {{ trans('admin/licenses/form.to_email') }} @@ -50,7 +50,7 @@ {{ trans('general.created_at') }} {{ trans('admin/hardware/form.notes') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} @@ -66,16 +66,4 @@ @section('moar_scripts') @include ('partials.bootstrap-table', ['exportFile' => 'licenses-export', 'search' => true]) - @stop diff --git a/resources/views/locations/index.blade.php b/resources/views/locations/index.blade.php index 41b175ae69..72a2946377 100755 --- a/resources/views/locations/index.blade.php +++ b/resources/views/locations/index.blade.php @@ -28,7 +28,7 @@ {{ trans('general.id') }} - {{ trans('admin/locations/table.name') }} + {{ trans('admin/locations/table.name') }} {{ trans('admin/locations/table.parent') }} {{ trans('admin/locations/table.assets_rtd') }} {{ trans('admin/locations/table.assets_checkedout') }} @@ -44,7 +44,7 @@ {{ trans('admin/locations/table.country') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} @@ -59,14 +59,4 @@ @section('moar_scripts') @include ('partials.bootstrap-table', ['exportFile' => 'locations-export', 'search' => true]) - @stop diff --git a/resources/views/manufacturers/index.blade.php b/resources/views/manufacturers/index.blade.php index f4e75344f7..86d41743d2 100755 --- a/resources/views/manufacturers/index.blade.php +++ b/resources/views/manufacturers/index.blade.php @@ -36,7 +36,7 @@ {{ trans('general.licenses') }} {{ trans('general.accessories') }} {{ trans('general.consumables') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} diff --git a/resources/views/models/index.blade.php b/resources/views/models/index.blade.php index 1cab62bb6a..172d1024ec 100755 --- a/resources/views/models/index.blade.php +++ b/resources/views/models/index.blade.php @@ -39,7 +39,7 @@ {{ trans('general.id') }} {{ trans('admin/hardware/table.image') }} {{ trans('general.manufacturer') }} - {{ trans('admin/models/table.title') }} + {{ trans('admin/models/table.title') }} {{ trans('admin/models/table.modelnumber') }} {{ trans('admin/models/table.numassets') }} {{ trans('general.depreciation') }} @@ -47,7 +47,7 @@ {{ trans('general.eol') }} {{ trans('admin/models/general.fieldset') }} {{ trans('general.notes') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.php index c48f0959a0..e4561cbf70 100755 --- a/resources/views/models/view.blade.php +++ b/resources/views/models/view.blade.php @@ -44,7 +44,7 @@ name="modelassets" id="table" class="snipe-table" - data-url="{{route('api.models.view', $model->id)}}" + data-url="{{route('api.models.show', $model->id)}}" data-cookie="true" data-click-to-select="true" data-cookie-id-table="modeldetailsViewTable"> diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index ea582615f8..1eb7cd9f82 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -78,6 +78,53 @@ $('.snipe-table').bootstrapTable({ }); + // This only works for model index pages because it uses the row's model ID + function genericRowLinkFormatter(destination) { + return function (value,row) { + if (value) { + return ' ' + value + ''; + } + }; + } + + // Use this when we're introspecting into a column object and need to link + function genericColumnObjLinkFormatter(destination) { + return function (value,row) { + if ((value) && (value.name)) { + return ' ' + value.name + ''; + } + }; + } + + function genericActionsFormatter(destination) { + return function (value,row) { + return ' ' + + '' + + ''; + }; + } + + // Use this when we're introspecting into a column object with more than one item + function genericColumnArrayLinkFormatter(destination) { + return function (value,row) { + if ((value) && (value.name)) { + return ' ' + value.name + ''; + } + }; + } + + var formatters = ['hardware','locations','users','manufacturers','statuslabels','models','licenses','categories','suppliers','companies']; + + for (var i in formatters) { + window[formatters[i] + 'LinkFormatter'] = genericRowLinkFormatter(formatters[i]); + window[formatters[i] + 'LinkObjFormatter'] = genericColumnObjLinkFormatter(formatters[i]); + window[formatters[i] + 'ActionsFormatter'] = genericActionsFormatter(formatters[i]); + } + + + function createdAtFormatter(value, row) { if ((value) && (value.date)) { return value.date; @@ -92,61 +139,6 @@ $('.snipe-table').bootstrapTable({ } } - function userFormatter(value, row) { - if (value.name) { - return ' ' + value.name + ''; - } else if (value) { - return ' ' + value + ''; - } - } - - function assetFormatter(value, row) { - if (value) { - return ' ' + value + ''; - } - } - - function manufacturerFormatter(value, row) { - if (value) { - return ' ' + value.name + ''; - } - } - - function statusFormatter(value, row) { - if (value) { - return ' ' + value.name + ''; - } - } - - function modelFormatter(value, row) { - if (value) { - return ' ' + value.name + ''; - } - } - - function licenseFormatter(value, row) { - if (value) { - return ' ' + row.name + ''; - } - } - - function categoryFormatter(value, row) { - if (value) { - return ' ' + value.name + ''; - } - } - - function companyFormatter(value, row) { - if ((value) && (value[0].name)) { - return ' ' + value[0].name + ''; - } - } - - function locationFormatter(value, row) { - if ((value) && (value[0].name)) { - return ' ' + value[0].name + ''; - } - } function emailFormatter(value, row) { if (value) { diff --git a/resources/views/statuslabels/index.blade.php b/resources/views/statuslabels/index.blade.php index f010c8a646..a721dfd066 100755 --- a/resources/views/statuslabels/index.blade.php +++ b/resources/views/statuslabels/index.blade.php @@ -34,7 +34,7 @@ {{ trans('admin/statuslabels/table.status_type') }} {{ trans('admin/statuslabels/table.color') }} {{ trans('admin/statuslabels/table.show_in_nav') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} diff --git a/resources/views/statuslabels/view.blade.php b/resources/views/statuslabels/view.blade.php index cdeef1cca9..1a8dbf98aa 100644 --- a/resources/views/statuslabels/view.blade.php +++ b/resources/views/statuslabels/view.blade.php @@ -53,13 +53,13 @@ {{ trans('general.company') }} {{ trans('admin/hardware/table.image') }} {{ trans('admin/hardware/form.name') }} - {{ trans('admin/hardware/table.asset_tag') }} - {{ trans('admin/hardware/table.serial') }} + {{ trans('admin/hardware/table.asset_tag') }} + {{ trans('admin/hardware/table.serial') }} {{ trans('admin/hardware/form.model') }} {{ trans('admin/models/table.modelnumber') }} {{ trans('admin/hardware/form.checkedout_to') }} - {{ trans('admin/hardware/table.location') }} + {{ trans('admin/hardware/table.location') }} {{ trans('general.category') }} {{ trans('general.manufacturer') }} {{ trans('admin/hardware/form.cost') }} diff --git a/resources/views/suppliers/index.blade.php b/resources/views/suppliers/index.blade.php index ee3ea51eed..5d8f8cf42e 100755 --- a/resources/views/suppliers/index.blade.php +++ b/resources/views/suppliers/index.blade.php @@ -38,7 +38,7 @@ {{ trans('admin/suppliers/table.fax') }} {{ trans('admin/suppliers/table.assets') }} {{ trans('admin/suppliers/table.licenses') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} diff --git a/resources/views/users/index.blade.php b/resources/views/users/index.blade.php index e3a4abd40a..fb91017345 100755 --- a/resources/views/users/index.blade.php +++ b/resources/views/users/index.blade.php @@ -75,15 +75,15 @@ {{ trans('general.id') }} {{ trans('admin/companies/table.title') }} {{ trans('admin/users/table.employee_num') }} - {{ trans('admin/users/table.name') }} + {{ trans('admin/users/table.name') }} {{ trans('admin/users/table.title') }} {{ trans('admin/users/table.username') }} - {{ trans('admin/users/table.manager') }} - {{ trans('admin/users/table.location') }} + {{ trans('admin/users/table.manager') }} + {{ trans('admin/users/table.location') }} @@ -109,7 +109,7 @@ {{ trans('general.activated') }} {{ trans('general.created_at') }} - {{ trans('table.actions') }} + {{ trans('table.actions') }} @@ -136,15 +136,5 @@ } - function actionsFormatter(value, row) { - return ' ' - + '' - + ''; - - } - - @stop