Skip to content

A free open source IT asset/license management system

Merge branch 'checkout-to-location-v2' of https://github.com/dmeltzer/snipe-it into dmeltzer-checkout-to-location-v2

snipe08f3e78d26cf
diff --cc app/Http/Controllers/Api/___UsersController_BASE_5796___php___6R2jXl
index 0000000000,0000000000..e69de29bb2
new file mode 100644
--- /dev/null
+++ b/app/Http/Controllers/Api/___UsersController_BASE_5796___php___6R2jXl
diff --cc app/Http/Transformers/LocationsTransformer.php
index 6c596c74f4,bd69834319..1366391d3c
--- a/app/Http/Transformers/LocationsTransformer.php
+++ b/app/Http/Transformers/LocationsTransformer.php
@@@ -18,16 -18,17 +18,16 @@@ class LocationsTransforme
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
- public function transformLocation (Location $location = null)
+ public function transformLocation(Location $location = null)
{
if ($location) {
- $assets_arr = [];
- foreach ($location->assets() as $asset) {
- $assets_arr = ['id' => $asset->id];
- }
$children_arr = [];
- foreach ($location->childLocations() as $child) {
- $children_arr = ['id' => $child->id];
+ foreach($location->childLocations as $child) {
+ $children_arr[] = [
+ 'id' => (int) $child->id,
+ 'name' => $child->name
+ ];
}
$array = [
@@@ -39,12 -40,11 +39,15 @@@
'assets_checkedout' => $location->assets()->count(),
'assets_default' => $location->assignedassets()->count(),
'country' => e($location->country),
- 'assets' => $assets_arr,
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
- 'parent_id' => e($location->parent_id),
- 'manager' => ($location->manager) ? (new UsersTransformer)->transformUser($location->manager) : '',
+ 'parent' => ($location->parent) ? [
+ 'id' => (int) $location->parent->id,
+ 'name'=> e($location->parent->name)
+ ] : null,
++ 'manager' => ($location->manager) ? (new UsersTransformer)->transformUser($location->manager) : null,
++
++
'children' => $children_arr,
];
diff --cc app/Models/Asset.php
index 5835ac4d8d,d64ce611e9..738a8a3a53
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@@ -276,13 -275,13 +276,17 @@@ class Asset extends Depreciabl
if (!empty($this->assignedType())) {
if ($this->assignedType() == self::ASSET) {
return $this->assignedTo->assetloc(); // Recurse until we have a final location
- } elseif ($this->assignedType() == self::LOCATION) {
+ }
+ if ($this->assignedType() == self::LOCATION) {
return $this->assignedTo();
+ } elseif (!$this->assignedTo) {
+ return $this->defaultLoc();
+ } elseif ($this->assignedType() == self::USER) {
+ return $this->assignedTo->userLoc();
}
+ if ($this->assignedType() == self::USER) {
+ return $this->assignedTo->userLoc();
+ }
}
return $this->defaultLoc();
}
diff --cc app/Models/Location.php
index 94e415f0a2,2327d137da..bb0e80e53a
--- a/app/Models/Location.php
+++ b/app/Models/Location.php
@@@ -63,9 -64,14 +64,14 @@@ class Location extends SnipeMode
public function parent()
{
- return $this->belongsTo('\App\Models\Location', 'parent_id');
+ return $this->belongsTo('\App\Models\Location', 'parent_id','id');
}
+ public function manager()
+ {
+ return $this->belongsTo('\App\Models\User', 'manager_id');
+ }
+
public function childLocations()
{
return $this->hasMany('\App\Models\Location', 'parent_id');
diff --cc resources/views/locations/view.blade.php
index 603957833e,a98523728f..4321fb70cb
--- a/resources/views/locations/view.blade.php
+++ b/resources/views/locations/view.blade.php
@@@ -26,7 -29,7 +29,7 @@@
name="location_users"
id="table-users"
class="table table-striped snipe-table"
- data-url="{{route('api.users.index', ['location_id' => $location->id]) }}"
- data-url="{{route('api.users.index', ['location_id' => $location->id])}}"
++ data-url="{{route('api.locations.viewusers', $location->id)}}"
data-cookie="true"
data-click-to-select="true"
data-cookie-id-table="location_usersDetailTable">
diff --cc routes/api.php
index d9051f8851,45264e4df0..8e9b3e405f
--- a/routes/api.php
+++ b/routes/api.php
@@@ -329,7 -294,6 +329,21 @@@ Route::group(['prefix' => 'v1','namespa
); // Locations resource
Route::group(['prefix' => 'locations'], function () {
+
++ Route::get('{location}/users',
++ [
++ 'as'=>'api.locations.viewusers',
++ 'uses'=>'LocationsController@getDataViewUsers'
++ ]
++ );
++
++ Route::get('{location}/assets',
++ [
++ 'as'=>'api.locations.viewassets',
++ 'uses'=>'LocationsController@getDataViewAssets'
++ ]
++ );
++
// Do we actually still need this, now that we have an API?
Route::get('{location}/check',
[