Some route/transformer edits

This commit is contained in:
snipe 2017-01-13 00:13:57 -08:00
parent d2f84a2329
commit 58b1ac5f0f
9 changed files with 47 additions and 11 deletions

View file

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Helpers\Helper; use App\Helpers\Helper;
use App\Models\Location; use App\Models\Location;
use App\Http\Transformers\DatatablesTransformer;
class LocationsController extends Controller class LocationsController extends Controller
{ {
@ -20,7 +21,7 @@ class LocationsController extends Controller
{ {
$this->authorize('view', Location::class); $this->authorize('view', Location::class);
$locations = Location::all(); $locations = Location::all();
return $locations; return (new DatatablesTransformer)->transformDatatables($locations);
} }

View file

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Transformers\UsersTransformer; use App\Http\Transformers\UsersTransformer;
use App\Http\Transformers\DatatablesTransformer;
use App\Models\User; use App\Models\User;
class UsersController extends Controller class UsersController extends Controller

View file

@ -0,0 +1,16 @@
<?php
namespace App\Http\Transformers;
use App\Models\Location;
class DatatablesTransformer
{
public function transformDatatables($objects)
{
$objects_array['rows'] = $objects;
$objects_array['total'] = count($objects);
return $objects_array;
}
}

View file

@ -21,7 +21,11 @@ class LocationsTransformer
if ($location) { if ($location) {
$locations_array[] = [ $locations_array[] = [
'id' => e($location->id), 'id' => e($location->id),
'name' => e($location->name) 'name' => e($location->name),
'address' => e($location->address),
'city' => e($location->city),
'state' => e($location->state),
'country' => e($location->country),
]; ];
return $locations_array; return $locations_array;
} }

View file

@ -13,15 +13,19 @@ class UsersTransformer
foreach ($users as $user) { foreach ($users as $user) {
$users_array[] = self::transformUser($user); $users_array[] = self::transformUser($user);
} }
return $users_array; return (new DatatablesTransformer)->transformDatatables($users_array);
} }
public function transformUser(User $user) public function transformUser(User $user)
{ {
$user_array[] = [ $user_array[] = [
'id' => e($user->id), 'id' => e($user->id),
'first_name' => e($user->first_name), 'name' => e($user->first_name).' '.($user->last_name),
'last_name' => e($user->last_name), 'firstname' => e($user->first_name),
'lastname' => e($user->last_name),
'username' => e($user->username),
'jobtitle' => e($user->jobtitle),
'email' => e($user->email),
'location' => (new LocationsTransformer)->transformLocation($user->userloc), 'location' => (new LocationsTransformer)->transformLocation($user->userloc),
'permissions' => $user->decodePermissions(), 'permissions' => $user->decodePermissions(),
'created_at' => $user->created_at, 'created_at' => $user->created_at,
@ -31,6 +35,10 @@ class UsersTransformer
return $user_array; return $user_array;
} }
public function transformUsersDatatable($users) {
return (new DatatablesTransformer)->transformDatatables($users);
}
} }

View file

@ -21,7 +21,7 @@
name="locations" name="locations"
class="table table-striped snipe-table" class="table table-striped snipe-table"
id="table" id="table"
data-url="{{ route('api.locations.list') }}" data-url="{{ route('api.locations.index') }}"
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"
data-cookie-id-table="locationsTable-{{ config('version.hash_version') }}"> data-cookie-id-table="locationsTable-{{ config('version.hash_version') }}">

View file

@ -61,7 +61,7 @@
class="table table-striped snipe-table" class="table table-striped snipe-table"
id="table" id="table"
data-toggle="table" data-toggle="table"
data-url="{{ route('api.users.list', array(''=>e(Input::get('status')))) }}" data-url="{{ route('api.users.index', array(''=>e(Input::get('status')))) }}"
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"
data-cookie-id-table="userTableDisplay-{{ config('version.hash_version') }}"> data-cookie-id-table="userTableDisplay-{{ config('version.hash_version') }}">

View file

@ -47,7 +47,7 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
] ]
); );
Route::resource('location', 'LocationsController', Route::resource('locations', 'LocationsController',
['names' => ['names' =>
[ [
'index' => 'api.locations.index', 'index' => 'api.locations.index',

View file

@ -1,7 +1,5 @@
<?php <?php
use App\Models\CheckoutRequest;
use App\Models\Location;
use App\Models\Statuslabel;
/* /*
@ -54,6 +52,14 @@ Route::resource('suppliers', 'SuppliersController', [
]); ]);
/*
* Status Labels
*/
Route::resource('components', 'ComponentsController', [
'parameters' => ['component' => 'component_id']
]);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Log Routes | Log Routes