mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
Removed old getDataTable methods
These are no longer used because of the API
This commit is contained in:
parent
f51dc9a1c4
commit
b3186ba5ea
|
@ -369,143 +369,5 @@ class AccessoriesController extends Controller
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error'));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates the JSON response for accessories listing view.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* {
|
|
||||||
* "actions": "(links to available actions)",
|
|
||||||
* "category": "(link to category)",
|
|
||||||
* "company": "My Company",
|
|
||||||
* "location": "My Location",
|
|
||||||
* "min_amt": 2,
|
|
||||||
* "name": "(link to accessory),
|
|
||||||
* "numRemaining": 6,
|
|
||||||
* "order_number": null,
|
|
||||||
* "purchase_cost": "0.00",
|
|
||||||
* "purchase_date": null,
|
|
||||||
* "qty": 7
|
|
||||||
* },
|
|
||||||
*
|
|
||||||
* The names of the fields in the returns JSON correspond directly to the the
|
|
||||||
* names of the fields in the bootstrap-tables in the view.
|
|
||||||
*
|
|
||||||
* For debugging, see at /api/accessories/list
|
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @param Request $request
|
|
||||||
* @return string JSON containing accessories and their associated atrributes.
|
|
||||||
* @internal param int $accessoryId
|
|
||||||
*/
|
|
||||||
public function getDatatable(Request $request)
|
|
||||||
{
|
|
||||||
$this->authorize('index', Accessory::class);
|
|
||||||
$accessories = Company::scopeCompanyables(
|
|
||||||
Accessory::select('accessories.*')
|
|
||||||
->whereNull('accessories.deleted_at')
|
|
||||||
->with('category', 'company', 'manufacturer', 'users', 'location')
|
|
||||||
);
|
|
||||||
if (Input::has('search')) {
|
|
||||||
$accessories = $accessories->TextSearch(e(Input::get('search')));
|
|
||||||
}
|
|
||||||
$offset = request('offset', 0);
|
|
||||||
$limit = request('limit', 50);
|
|
||||||
|
|
||||||
$allowed_columns = ['name','min_amt','order_number','purchase_date','purchase_cost','company','category','model_number', 'manufacturer', 'location'];
|
|
||||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
|
||||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at';
|
|
||||||
|
|
||||||
switch ($sort) {
|
|
||||||
case 'category':
|
|
||||||
$accessories = $accessories->OrderCategory($order);
|
|
||||||
break;
|
|
||||||
case 'company':
|
|
||||||
$accessories = $accessories->OrderCompany($order);
|
|
||||||
break;
|
|
||||||
case 'location':
|
|
||||||
$accessories = $accessories->OrderLocation($order);
|
|
||||||
break;
|
|
||||||
case 'manufacturer':
|
|
||||||
$accessories = $accessories->OrderManufacturer($order);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$accessories = $accessories->orderBy($sort, $order);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$accessCount = $accessories->count();
|
|
||||||
$accessories = $accessories->skip($offset)->take($limit)->get();
|
|
||||||
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
foreach ($accessories as $accessory) {
|
|
||||||
$rows[] = $accessory->present()->forDataTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total'=>$accessCount, 'rows'=>$rows);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates the JSON response for accessory detail view.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* <code>
|
|
||||||
* {
|
|
||||||
* "rows": [
|
|
||||||
* {
|
|
||||||
* "actions": "(link to available actions)",
|
|
||||||
* "name": "(link to user)"
|
|
||||||
* }
|
|
||||||
* ],
|
|
||||||
* "total": 1
|
|
||||||
* }
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* The names of the fields in the returns JSON correspond directly to the the
|
|
||||||
* names of the fields in the bootstrap-tables in the view.
|
|
||||||
*
|
|
||||||
* For debugging, see at /api/accessories/$accessoryID/view
|
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @param int $accessoryId
|
|
||||||
* @return string JSON containing accessories and their associated atrributes.
|
|
||||||
**/
|
|
||||||
public function getDataView(Request $request, $accessoryID)
|
|
||||||
{
|
|
||||||
$accessory = Accessory::find($accessoryID);
|
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($accessory)) {
|
|
||||||
return ['total' => 0, 'rows' => []];
|
|
||||||
}
|
|
||||||
|
|
||||||
$accessory_users = $accessory->users;
|
|
||||||
$count = $accessory_users->count();
|
|
||||||
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
foreach ($accessory_users as $user) {
|
|
||||||
$actions = '';
|
|
||||||
if (Gate::allows('checkin', $accessory)) {
|
|
||||||
$actions .= Helper::generateDatatableButton('checkin', route('checkin/accessory', $user->pivot->id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Gate::allows('view', $user)) {
|
|
||||||
$name = (string) link_to_route('users.show', e($user->present()->fullName()), [$user->id]);
|
|
||||||
} else {
|
|
||||||
$name = e($user->present()->fullName());
|
|
||||||
}
|
|
||||||
|
|
||||||
$rows[] = array(
|
|
||||||
'name' => $name,
|
|
||||||
'actions' => $actions
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total'=>$count, 'rows'=>$rows);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,49 +366,6 @@ class AssetModelsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the asset information to present to the model view detail page
|
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @since [v2.0]
|
|
||||||
* @param Request $request
|
|
||||||
* @param $modelID
|
|
||||||
* @return String JSON
|
|
||||||
* @internal param int $modelId
|
|
||||||
*/
|
|
||||||
public function getDataView(Request $request, $modelID)
|
|
||||||
{
|
|
||||||
$assets = Asset::where('model_id', '=', $modelID)->with('company', 'assetstatus');
|
|
||||||
|
|
||||||
if (Input::has('search')) {
|
|
||||||
$assets = $assets->TextSearch(e($request->input('search')));
|
|
||||||
}
|
|
||||||
$offset = request('offset', 0);
|
|
||||||
$limit = request('limit', 50);
|
|
||||||
|
|
||||||
|
|
||||||
$allowed_columns = ['name', 'serial','asset_tag'];
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
|
||||||
|
|
||||||
$assets = $assets->orderBy($sort, $order);
|
|
||||||
|
|
||||||
$assetsCount = $assets->count();
|
|
||||||
$assets = $assets->skip($offset)->take($limit)->get();
|
|
||||||
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
$all_custom_fields = CustomField::all();
|
|
||||||
foreach ($assets as $asset) {
|
|
||||||
|
|
||||||
$rows[] = $asset->present()->forDataTable($all_custom_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total' => $assetsCount, 'rows' => $rows);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that allows the user to bulk edit model attrbutes
|
* Returns a view that allows the user to bulk edit model attrbutes
|
||||||
|
|
|
@ -288,35 +288,4 @@ class ComponentsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return JSON data to populate the components view,
|
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @see ComponentsController::getView() method that returns the view.
|
|
||||||
* @since [v3.0]
|
|
||||||
* @param int $componentId
|
|
||||||
* @return string JSON
|
|
||||||
*/
|
|
||||||
public function getDataView($componentId)
|
|
||||||
{
|
|
||||||
if (is_null($component = Component::with('assets')->find($componentId))) {
|
|
||||||
// Redirect to the component management page with error
|
|
||||||
return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($component)) {
|
|
||||||
return ['total' => 0, 'rows' => []];
|
|
||||||
}
|
|
||||||
$this->authorize('view', $component);
|
|
||||||
|
|
||||||
$rows = array();
|
|
||||||
$all_custom_fields = CustomField::all(); // Cached for table;
|
|
||||||
foreach ($component->assets as $component_assignment) {
|
|
||||||
$rows[] = $component_assignment->present()->forDataTable($all_custom_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
$componentCount = $component->assets->count();
|
|
||||||
$data = array('total' => $componentCount, 'rows' => $rows);
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -591,61 +591,10 @@ class LicensesController extends Controller
|
||||||
$file = $log->get_src('licenses');
|
$file = $log->get_src('licenses');
|
||||||
return Response::download($file);
|
return Response::download($file);
|
||||||
}
|
}
|
||||||
// Prepare the error message
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist', compact('id')));
|
||||||
$error = trans('admin/licenses/message.does_not_exist', compact('id'));
|
|
||||||
// Redirect to the licence management page
|
|
||||||
return redirect()->route('licenses.index')->with('error', $error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a JSON response to populate the licence index datatables.
|
|
||||||
*
|
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
||||||
* @see LicensesController::getIndex() method that provides the view
|
|
||||||
* @since [v1.0]
|
|
||||||
* @return String JSON
|
|
||||||
*/
|
|
||||||
public function getDatatable(Request $request)
|
|
||||||
{
|
|
||||||
$this->authorize('view', License::class);
|
|
||||||
$licenses = Company::scopeCompanyables(License::with('company', 'licenseSeatsRelation', 'manufacturer'));
|
|
||||||
|
|
||||||
if (Input::has('search')) {
|
|
||||||
$licenses = $licenses->TextSearch($request->input('search'));
|
|
||||||
}
|
|
||||||
$offset = request('offset', 0);
|
|
||||||
$limit = request('limit', 50);
|
|
||||||
|
|
||||||
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company'];
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
|
||||||
|
|
||||||
switch ($sort) {
|
|
||||||
case 'manufacturer':
|
|
||||||
$licenses = $licenses->OrderManufacturer($order);
|
|
||||||
break;
|
|
||||||
case 'company':
|
|
||||||
$licenses = $licenses->OrderCompany($order);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$licenses = $licenses->orderBy($sort, $order);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$licenseCount = $licenses->count();
|
|
||||||
$licenses = $licenses->skip($offset)->take($limit)->get();
|
|
||||||
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
foreach ($licenses as $license) {
|
|
||||||
$rows[] = $license->present()->forDataTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total' => $licenseCount, 'rows' => $rows);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the next free seat ID for checkout.
|
* Generates the next free seat ID for checkout.
|
||||||
|
|
|
@ -212,116 +212,5 @@ class ManufacturersController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getDataAssetsView(Manufacturer $manufacturer, Request $request)
|
|
||||||
{
|
|
||||||
$manufacturer = $manufacturer->load('assets.model', 'assets.assignedTo', 'assets.assetstatus', 'assets.company');
|
|
||||||
$manufacturer_assets = $manufacturer->assets();
|
|
||||||
|
|
||||||
if ($request->has('search')) {
|
|
||||||
$manufacturer_assets = $manufacturer_assets->TextSearch(e($request->input('search')));
|
|
||||||
}
|
|
||||||
|
|
||||||
$offset = request('offset', 0);
|
|
||||||
$limit = request('limit', 50);
|
|
||||||
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
|
||||||
|
|
||||||
$allowed_columns = ['id','name','serial','asset_tag'];
|
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
|
|
||||||
$count = $manufacturer_assets->count();
|
|
||||||
$manufacturer_assets = $manufacturer_assets->skip($offset)->take($limit)->get();
|
|
||||||
$rows = array();
|
|
||||||
$all_custom_fields = CustomField::all(); // cached;
|
|
||||||
foreach ($manufacturer_assets as $asset) {
|
|
||||||
$rows[] = $asset->present()->forDataTable($all_custom_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total' => $count, 'rows' => $rows);
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getDataLicensesView(Manufacturer $manufacturer, Request $request)
|
|
||||||
{
|
|
||||||
$manufacturer = $manufacturer->load('licenses.company', 'licenses.manufacturer', 'licenses.licenseSeatsRelation');
|
|
||||||
$licenses = $manufacturer->licenses;
|
|
||||||
|
|
||||||
if ($request->has('search')) {
|
|
||||||
$licenses = $licenses->TextSearch($request->input('search'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$licenseCount = $licenses->count();
|
|
||||||
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
foreach ($licenses as $license) {
|
|
||||||
$rows[] = $license->present()->forDataTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total' => $licenseCount, 'rows' => $rows);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDataAccessoriesView(Manufacturer $manufacturer, Request $request)
|
|
||||||
{
|
|
||||||
$manufacturer = $manufacturer->load(
|
|
||||||
'accessories.location',
|
|
||||||
'accessories.company',
|
|
||||||
'accessories.category',
|
|
||||||
'accessories.manufacturer',
|
|
||||||
'accessories.users'
|
|
||||||
);
|
|
||||||
$accessories = $manufacturer->accessories();
|
|
||||||
|
|
||||||
if ($request->has('search')) {
|
|
||||||
$accessories = $accessories->TextSearch(e($request->input('search')));
|
|
||||||
}
|
|
||||||
|
|
||||||
$offset = request('offset', 0);
|
|
||||||
$limit = request('limit', 50);
|
|
||||||
|
|
||||||
$accessCount = $accessories->count();
|
|
||||||
$accessories = $accessories->skip($offset)->take($limit)->get();
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
foreach ($accessories as $accessory) {
|
|
||||||
$rows[] = $accessory->present()->forDataTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total'=>$accessCount, 'rows'=>$rows);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDataConsumablesView($manufacturer, Request $request)
|
|
||||||
{
|
|
||||||
$manufacturer = $manufacturer->load(
|
|
||||||
'consumables.location',
|
|
||||||
'consumables.company',
|
|
||||||
'consumables.category',
|
|
||||||
'consumables.manufacturer',
|
|
||||||
'consumables.users'
|
|
||||||
);
|
|
||||||
$consumables = $manufacturer->consumables();
|
|
||||||
|
|
||||||
if ($request->has('search')) {
|
|
||||||
$consumables = $consumables->TextSearch(e($request->input('search')));
|
|
||||||
}
|
|
||||||
|
|
||||||
$offset = request('offset', 0);
|
|
||||||
$limit = request('limit', 50);
|
|
||||||
|
|
||||||
|
|
||||||
$consumCount = $consumables->count();
|
|
||||||
$consumables = $consumables->skip($offset)->take($limit)->get();
|
|
||||||
$rows = array();
|
|
||||||
|
|
||||||
foreach ($consumables as $consumable) {
|
|
||||||
$rows[] = $consumable->present()->forDataTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('total' => $consumCount, 'rows' => $rows);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,55 +122,6 @@ class AccessoryPresenter extends Presenter
|
||||||
return json_encode($layout);
|
return json_encode($layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON representation of Accessory for datatable.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function forDataTable()
|
|
||||||
{
|
|
||||||
|
|
||||||
$actions = '<nobr>';
|
|
||||||
if (Gate::allows('checkout', $this->model)) {
|
|
||||||
$actions .= Helper::generateDatatableButton(
|
|
||||||
'checkout',
|
|
||||||
route('checkout/accessory', $this->id),
|
|
||||||
$this->numRemaining() > 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (Gate::allows('update', $this->model)) {
|
|
||||||
$actions .= Helper::generateDatatableButton('edit', route('accessories.edit', $this->id));
|
|
||||||
}
|
|
||||||
if (Gate::allows('delete', $this->model)) {
|
|
||||||
$actions .= Helper::generateDatatableButton(
|
|
||||||
'delete',
|
|
||||||
route('accessories.destroy', $this->id),
|
|
||||||
true, /*enabled*/
|
|
||||||
trans('admin/accessories/message.delete.confirm'),
|
|
||||||
$this->name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$actions .= '</nobr>';
|
|
||||||
|
|
||||||
$results = [];
|
|
||||||
$results['name'] = $this->nameUrl();
|
|
||||||
$results['category'] = '';
|
|
||||||
if ($this->model->category) {
|
|
||||||
$results['category'] = $this->model->category->present()->nameUrl();
|
|
||||||
}
|
|
||||||
$results['model_number'] = $this->model_number;
|
|
||||||
$results['qty'] = $this->qty;
|
|
||||||
$results['order_number'] = $this->order_number;
|
|
||||||
$results['min_amt'] = $this->min_amt;
|
|
||||||
$results['location'] = $this->model->location ? $this->model->location->present()->nameUrl() : '';
|
|
||||||
$results['purchase_date'] = $this->purchase_date;
|
|
||||||
$results['purchase_cost'] = Helper::formatCurrencyOutput($this->purchase_cost);
|
|
||||||
$results['numRemaining'] = $this->numRemaining();
|
|
||||||
$results['companyName'] = $this->model->company ? $this->model->company->present()->nameUrl() : '';
|
|
||||||
$results['manufacturer'] = $this->model->manufacturer ? $this->model->manufacturer->present()->nameUrl() : '';
|
|
||||||
$results['actions'] = $actions;
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pregenerated link to this accessories view page.
|
* Pregenerated link to this accessories view page.
|
||||||
|
|
Loading…
Reference in a new issue