Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/better table options #5018

Merged
merged 18 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/Http/Controllers/Api/AssetMaintenancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,24 @@ public function index(Request $request)
$maintenances = $maintenances->TextSearch(e($request->input('search')));
}

if ($request->has('asset_id')) {
$maintenances->where('asset_id', '=', $request->input('asset_id'));
}

$offset = request('offset', 0);
$limit = request('limit', 50);

$allowed_columns = ['id','title','asset_maintenance_time','asset_maintenance_type','cost','start_date','completion_date','notes','user_id'];
$allowed_columns = [
'id',
'title',
'asset_maintenance_time',
'asset_maintenance_type',
'cost',
'start_date',
'completion_date',
'notes',
'user_id'
];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array(Input::get('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GroupsController extends Controller
public function index(Request $request)
{
$this->authorize('view', Group::class);
$allowed_columns = ['id','name','created_at'];
$allowed_columns = ['id','name','created_at', 'users_count'];

$groups = Group::select('id','name','permissions','created_at','updated_at')->withCount('users');

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/LocationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index(Request $request)
$allowed_columns = [
'id','name','address','address2','city','state','country','zip','created_at',
'updated_at','parent_id', 'manager_id','image',
'assigned_assets_count','users_count','assets_count'];
'assigned_assets_count','users_count','assets_count','currency'];

$locations = Location::with('parent', 'manager', 'childLocations')->select([
'locations.id',
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Api/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public function index(Request $request)

$allowed_columns = [
'id',
'created_at'
'created_at',
'target_id',
'user_id',
'action_type',
'note'
];

$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
Expand Down
81 changes: 0 additions & 81 deletions app/Http/Controllers/AssetMaintenancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,85 +63,6 @@ public function index()
}


/**
* Generates the JSON response for asset maintenances listing view.
*
* @see AssetMaintenancesController::getIndex() method that generates view
* @author Vincent Sposato <vincent.sposato@gmail.com>
* @version v1.0
* @since [v1.8]
* @return String JSON
*/
public function getDatatable(Request $request)
{
$maintenances = AssetMaintenance::with('asset', 'supplier', 'asset.company', 'admin');

if (Input::has('search')) {
$maintenances = $maintenances->TextSearch(e($request->input('search')));
}

$offset = request('offset', 0);
$limit = request('limit', 50);

$allowed_columns = ['id','title','asset_maintenance_time','asset_maintenance_type','cost','start_date','completion_date','notes','user_id'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array(Input::get('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';

switch ($sort) {
case 'user_id':
$maintenances = $maintenances->OrderAdmin($order);
break;
default:
$maintenances = $maintenances->orderBy($sort, $order);
break;
}

$maintenancesCount = $maintenances->count();
$maintenances = $maintenances->skip($offset)->take($limit)->get();

$rows = array();
$settings = Setting::getSettings();

foreach ($maintenances as $maintenance) {
$actions = '';
if (Gate::allows('update', Asset::class)) {
$actions .= Helper::generateDatatableButton('edit', route('maintenances.edit', $maintenance->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('maintenances.destroy', $maintenance->id),
$enabled = true,
trans('admin/asset_maintenances/message.delete.confirm'),
$maintenance->title
);
}

if (($maintenance->cost) && (isset($maintenance->asset)) && ($maintenance->asset->location) && ($maintenance->asset->location->currency!='')) {
$maintenance_cost = $maintenance->asset->location->currency.$maintenance->cost;
} else {
$maintenance_cost = $settings->default_currency.$maintenance->cost;
}

$rows[] = array(
'id' => $maintenance->id,
'asset_name' => ($maintenance->asset) ? (string)link_to_route('maintenances.show', $maintenance->asset->present()->Name(), ['maintenance' => $maintenance->asset->id]) : 'Deleted Asset' ,
'title' => $maintenance->title,
'notes' => $maintenance->notes,
'supplier' => ($maintenance->supplier) ? (string)link_to_route('suppliers.show', $maintenance->supplier->name, ['maintenance'=>$maintenance->supplier->id]) : 'Deleted Supplier',
'cost' => $maintenance_cost,
'asset_maintenance_type' => e($maintenance->asset_maintenance_type),
'start_date' => $maintenance->start_date,
'asset_maintenance_time' => $maintenance->asset_maintenance_time,
'completion_date' => $maintenance->completion_date,
'user_id' => ($maintenance->admin) ? (string)link_to_route('users.show', $maintenance->admin->present()->fullName(), ['user'=>$maintenance->admin->id]) : '',
'actions' => $actions,
'company' => ($maintenance->asset->company) ? $maintenance->asset->company->name : ''
);
}

$data = array('total' => $maintenancesCount, 'rows' => $rows);
return $data;

}

/**
* Returns a form view to create a new asset maintenance.
Expand Down Expand Up @@ -265,9 +186,7 @@ public function edit($assetMaintenanceId = null)
// Get Supplier List
// Render the view
return view('asset_maintenances/edit')
->with('asset_list', Helper::detailedAssetList())
->with('selectedAsset', null)
->with('supplier_list', Helper::suppliersList())
->with('assetMaintenanceType', $assetMaintenanceType)
->with('item', $assetMaintenance);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function postSettings(Request $request)

$setting->modellist_displays = '';

if (($request->has('show_in_model_list')) && (count($request->has('show_in_model_list')) > 0))
if (($request->has('show_in_model_list')) && (count($request->input('show_in_model_list')) > 0))
{
$setting->modellist_displays = implode(',', $request->input('show_in_model_list'));
}
Expand Down
13 changes: 7 additions & 6 deletions app/Http/Transformers/LocationsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ public function transformLocation(Location $location = null)
'id' => (int) $location->id,
'name' => e($location->name),
'image' => ($location->image) ? app('locations_upload_url').e($location->image) : null,
'address' => e($location->address),
'city' => e($location->city),
'state' => e($location->state),
'country' => e($location->country),
'zip' => e($location->zip),
'address' => ($location->address) ? e($location->address) : null,
'address2' => ($location->address2) ? e($location->address2) : null,
'city' => ($location->city) ? e($location->city) : null,
'state' => ($location->state) ? e($location->state) : null,
'country' => ($location->country) ? e($location->country) : null,
'zip' => ($location->zip) ? e($location->zip) : null,
'assigned_assets_count' => (int) $location->assigned_assets_count,
'assets_count' => (int) $location->assets_count,
'users_count' => (int) $location->users_count,

'currency' => ($location->currency) ? e($location->currency) : null,
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
'parent' => ($location->parent) ? [
Expand Down
53 changes: 53 additions & 0 deletions app/Presenters/LicensePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,59 @@ public static function dataTableLayout()
}


/**
* Json Column Layout for bootstrap table
* @return string
*/
public static function dataTableLayoutSeats()
{
$layout = [
[
"field" => "name",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => trans('admin/licenses/general.seat'),
"visible" => true,
], [
"field" => "assigned_user",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => trans('admin/licenses/general.user'),
"visible" => true,
"formatter" => "usersLinkObjFormatter"
], [
"field" => "assigned_asset",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => trans('admin/licenses/form.asset'),
"visible" => true,
"formatter" => "hardwareLinkObjFormatter"
], [
"field" => "location",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => trans('general.location'),
"visible" => true,
"formatter" => "locationsLinkObjFormatter"
], [
"field" => "checkincheckout",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => trans('general.checkin').'/'.trans('general.checkout'),
"visible" => true,
"formatter" => "licenseSeatInOutFormatter"
]
];

return json_encode($layout);
}


/**
* Link to this licenses Name
* @return string
Expand Down
Loading