snipe-it/app/Http/Controllers/CategoriesController.php

529 lines
20 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
2016-03-25 01:18:05 -07:00
use App\Helpers\Helper;
use App\Models\Category as Category;
use App\Models\Company;
use App\Models\Setting;
use Auth;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
2016-03-25 01:18:05 -07:00
use Input;
use Lang;
use Redirect;
use Str;
use View;
2016-04-07 13:21:09 -07:00
/**
* This class controls all actions related to Categories for
* the Snipe-IT Asset Management application.
*
* @version v1.0
* @author [A. Gianotto] [<snipe@snipe.net>]
*/
2016-03-25 01:18:05 -07:00
class CategoriesController extends Controller
{
2016-03-25 18:07:12 -07:00
/**
* Returns a view that invokes the ajax tables which actually contains
* the content for the categories listing, which is generated in getDatatable.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::getDatatable() method that generates the JSON response
* @since [v1.0]
* @return View
*/
2016-12-15 16:42:47 -08:00
public function index()
2016-03-25 01:18:05 -07:00
{
// Show the page
return View::make('categories/index');
}
/**
2016-03-25 18:07:12 -07:00
* Returns a form view to create a new category.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
2016-12-15 16:42:47 -08:00
* @see CategoriesController::store() method that stores the data
2016-03-25 18:07:12 -07:00
* @since [v1.0]
* @return View
*/
2016-12-15 16:42:47 -08:00
public function create()
2016-03-25 01:18:05 -07:00
{
// Show the page
$category_types= Helper::categoryTypeList();
Partialize forms (#2884) * Consolidate edit form elements into reusable partials. This is a large code change that doesn't do much immediately. It refactors all of the various edit.blade.php files to reference standardized partials, so that they all reference the same base html layout. This has the side effect of moving everything to the new fancy "required" indicators, and making things look consistent. In addition, I've gone ahead and renamed a few database fields. We had Assetmodel::modelno and Consumable::model_no, I've renamed both to model_number. We had items using ::note and ::notes, I've standardized on ::notes. Component used total_qty where consumables and accessories used qty, so I've moved everything to qty (And fixed a few bugs in the helper file in the process. TODO includes looking at how/where to place the modal javascripts to allow for on the fly creation from all places, rather than just the asset page. Rename assetmodel::modelno to model_number for clarity and consistency Rename consumable::model_no to model_number for clarity and consistency Rename assetmodel::note to notes for clarity and consistency Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying. * Share a settings variable with all views. * Allow editing the per_page setting. We showed the value, but we never showed it on the edit page.. * use snipeSettings in all views instead of the long ugly path. * War on partials. Centralize all bootstrap table javascript * Use model_number instead of modelno in importer * Codacy fix. * More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read. * Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs * Fix DB seeder. * Base sql dump and csv's to import data from for tests. * Start some functional tests for creating items. * Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things * Improvements to functional tests. Use the built in DB seeding mechanism instead of doing it ourselves. Break the tests into multiple units, rather than testing everything in each function. * Some improvements to acceptance tests. Make sure we're only looking at the "trs" within the bootstrap table. Creation of assets is now tested at the functional level (and is faster) so ignore it here. I'm testing acceptance tests with the IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder imported. * A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name * Use a .env.tests file for testing functional and unit to allow a separate database. * Add functional tests for compoents, groups, and licenses. * Now that the config is in the functional.yml, this just confuses things. * Start some functional tests for creating items. * Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things * Improvements to functional tests. Use the built in DB seeding mechanism instead of doing it ourselves. Break the tests into multiple units, rather than testing everything in each function. * Some improvements to acceptance tests. Make sure we're only looking at the "trs" within the bootstrap table. Creation of assets is now tested at the functional level (and is faster) so ignore it here. I'm testing acceptance tests with the IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder imported. * update db dump * Update tests to new reality * env for the test setup * only load the database at beginning of tests, not between each Functional test. * Fix a miss from renaming note to notes. * Set Termination date when creating an asset. It was only set on edit. * Rename serial_number to serial in components for consistency. * Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB. * Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
return View::make('categories/edit')->with('item', new Category)
2016-03-25 01:18:05 -07:00
->with('category_types', $category_types);
}
/**
2016-03-25 18:07:12 -07:00
* Validates and stores the new category data.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
2016-12-15 16:42:47 -08:00
* @see CategoriesController::create() method that makes the form.
2016-03-25 18:07:12 -07:00
* @since [v1.0]
* @return Redirect
*/
2016-12-15 16:42:47 -08:00
public function store(Request $request)
2016-03-25 01:18:05 -07:00
{
// create a new model instance
$category = new Category();
// Update the category data
2016-12-15 16:42:47 -08:00
$category->name = e($request->input('name'));
$category->category_type = e($request->input('category_type'));
$category->eula_text = e($request->input('eula_text'));
$category->use_default_eula = e($request->input('use_default_eula', '0'));
$category->require_acceptance = e($request->input('require_acceptance', '0'));
$category->checkin_email = e($request->input('checkin_email', '0'));
2016-03-25 01:18:05 -07:00
$category->user_id = Auth::user()->id;
if ($category->save()) {
2016-12-15 16:42:47 -08:00
return redirect()->route('categories.index')->with('success', trans('admin/categories/message.create.success'));
2016-03-25 01:18:05 -07:00
} else {
2016-04-28 21:06:41 -07:00
return redirect()->back()->withInput()->withErrors($category->getErrors());
2016-03-25 01:18:05 -07:00
}
2016-12-15 16:42:47 -08:00
return redirect()->route('categories.create')->with('error', trans('admin/categories/message.create.error'));
2016-03-25 01:18:05 -07:00
}
/**
2016-03-25 18:07:12 -07:00
* Returns a view that makes a form to update a category.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::postEdit() method saves the data
* @param int $categoryId
* @since [v1.0]
* @return View
*/
2016-12-15 16:42:47 -08:00
public function edit($categoryId = null)
2016-03-25 01:18:05 -07:00
{
// Check if the category exists
Partialize forms (#2884) * Consolidate edit form elements into reusable partials. This is a large code change that doesn't do much immediately. It refactors all of the various edit.blade.php files to reference standardized partials, so that they all reference the same base html layout. This has the side effect of moving everything to the new fancy "required" indicators, and making things look consistent. In addition, I've gone ahead and renamed a few database fields. We had Assetmodel::modelno and Consumable::model_no, I've renamed both to model_number. We had items using ::note and ::notes, I've standardized on ::notes. Component used total_qty where consumables and accessories used qty, so I've moved everything to qty (And fixed a few bugs in the helper file in the process. TODO includes looking at how/where to place the modal javascripts to allow for on the fly creation from all places, rather than just the asset page. Rename assetmodel::modelno to model_number for clarity and consistency Rename consumable::model_no to model_number for clarity and consistency Rename assetmodel::note to notes for clarity and consistency Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying. * Share a settings variable with all views. * Allow editing the per_page setting. We showed the value, but we never showed it on the edit page.. * use snipeSettings in all views instead of the long ugly path. * War on partials. Centralize all bootstrap table javascript * Use model_number instead of modelno in importer * Codacy fix. * More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read. * Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs * Fix DB seeder. * Base sql dump and csv's to import data from for tests. * Start some functional tests for creating items. * Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things * Improvements to functional tests. Use the built in DB seeding mechanism instead of doing it ourselves. Break the tests into multiple units, rather than testing everything in each function. * Some improvements to acceptance tests. Make sure we're only looking at the "trs" within the bootstrap table. Creation of assets is now tested at the functional level (and is faster) so ignore it here. I'm testing acceptance tests with the IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder imported. * A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name * Use a .env.tests file for testing functional and unit to allow a separate database. * Add functional tests for compoents, groups, and licenses. * Now that the config is in the functional.yml, this just confuses things. * Start some functional tests for creating items. * Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things * Improvements to functional tests. Use the built in DB seeding mechanism instead of doing it ourselves. Break the tests into multiple units, rather than testing everything in each function. * Some improvements to acceptance tests. Make sure we're only looking at the "trs" within the bootstrap table. Creation of assets is now tested at the functional level (and is faster) so ignore it here. I'm testing acceptance tests with the IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder imported. * update db dump * Update tests to new reality * env for the test setup * only load the database at beginning of tests, not between each Functional test. * Fix a miss from renaming note to notes. * Set Termination date when creating an asset. It was only set on edit. * Rename serial_number to serial in components for consistency. * Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB. * Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
if (is_null($item = Category::find($categoryId))) {
2016-03-25 01:18:05 -07:00
// Redirect to the blogs management page
2016-04-28 21:06:41 -07:00
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.does_not_exist'));
2016-03-25 01:18:05 -07:00
}
$category_options = array('' => 'Top Level') + DB::table('categories')->where('id', '!=', $categoryId)->lists('name', 'id');
$category_types= Helper::categoryTypeList();
Partialize forms (#2884) * Consolidate edit form elements into reusable partials. This is a large code change that doesn't do much immediately. It refactors all of the various edit.blade.php files to reference standardized partials, so that they all reference the same base html layout. This has the side effect of moving everything to the new fancy "required" indicators, and making things look consistent. In addition, I've gone ahead and renamed a few database fields. We had Assetmodel::modelno and Consumable::model_no, I've renamed both to model_number. We had items using ::note and ::notes, I've standardized on ::notes. Component used total_qty where consumables and accessories used qty, so I've moved everything to qty (And fixed a few bugs in the helper file in the process. TODO includes looking at how/where to place the modal javascripts to allow for on the fly creation from all places, rather than just the asset page. Rename assetmodel::modelno to model_number for clarity and consistency Rename consumable::model_no to model_number for clarity and consistency Rename assetmodel::note to notes for clarity and consistency Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying. * Share a settings variable with all views. * Allow editing the per_page setting. We showed the value, but we never showed it on the edit page.. * use snipeSettings in all views instead of the long ugly path. * War on partials. Centralize all bootstrap table javascript * Use model_number instead of modelno in importer * Codacy fix. * More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read. * Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs * Fix DB seeder. * Base sql dump and csv's to import data from for tests. * Start some functional tests for creating items. * Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things * Improvements to functional tests. Use the built in DB seeding mechanism instead of doing it ourselves. Break the tests into multiple units, rather than testing everything in each function. * Some improvements to acceptance tests. Make sure we're only looking at the "trs" within the bootstrap table. Creation of assets is now tested at the functional level (and is faster) so ignore it here. I'm testing acceptance tests with the IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder imported. * A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name * Use a .env.tests file for testing functional and unit to allow a separate database. * Add functional tests for compoents, groups, and licenses. * Now that the config is in the functional.yml, this just confuses things. * Start some functional tests for creating items. * Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things * Improvements to functional tests. Use the built in DB seeding mechanism instead of doing it ourselves. Break the tests into multiple units, rather than testing everything in each function. * Some improvements to acceptance tests. Make sure we're only looking at the "trs" within the bootstrap table. Creation of assets is now tested at the functional level (and is faster) so ignore it here. I'm testing acceptance tests with the IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder imported. * update db dump * Update tests to new reality * env for the test setup * only load the database at beginning of tests, not between each Functional test. * Fix a miss from renaming note to notes. * Set Termination date when creating an asset. It was only set on edit. * Rename serial_number to serial in components for consistency. * Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB. * Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
return View::make('categories/edit', compact('item'))
2016-03-25 01:18:05 -07:00
->with('category_options', $category_options)
->with('category_types', $category_types);
}
/**
2016-03-25 18:07:12 -07:00
* Validates and stores the updated category data.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::getEdit() method that makes the form.
* @param int $categoryId
* @since [v1.0]
* @return Redirect
*/
2016-12-15 16:42:47 -08:00
public function update(Request $request, $categoryId = null)
2016-03-25 01:18:05 -07:00
{
// Check if the blog post exists
if (is_null($category = Category::find($categoryId))) {
// Redirect to the blogs management page
2016-04-28 21:06:41 -07:00
return redirect()->to('admin/categories')->with('error', trans('admin/categories/message.does_not_exist'));
2016-03-25 01:18:05 -07:00
}
// Update the category data
$category->name = e($request->input('name'));
// If the item count is > 0, we disable the category type in the edit. Disabled items
// don't POST, so if the category_type is blank we just set it to the default.
$category->category_type = e($request->input('category_type', $category->category_type));
$category->eula_text = e($request->input('eula_text'));
$category->use_default_eula = e($request->input('use_default_eula', '0'));
$category->require_acceptance = e($request->input('require_acceptance', '0'));
$category->checkin_email = e($request->input('checkin_email', '0'));
2016-03-25 01:18:05 -07:00
if ($category->save()) {
// Redirect to the new category page
2016-12-15 16:42:47 -08:00
return redirect()->route('categories.index')->with('success', trans('admin/categories/message.update.success'));
2016-03-25 01:18:05 -07:00
} // attempt validation
else {
// The given data did not pass validation
2016-04-28 21:06:41 -07:00
return redirect()->back()->withInput()->withErrors($category->getErrors());
2016-03-25 01:18:05 -07:00
}
// Redirect to the category management page
2016-04-28 21:06:41 -07:00
return redirect()->back()->with('error', trans('admin/categories/message.update.error'));
2016-03-25 01:18:05 -07:00
}
/**
2016-03-25 18:07:12 -07:00
* Validates and marks a category as deleted.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0]
* @param int $categoryId
* @return Redirect
*/
2016-12-15 16:42:47 -08:00
public function destroy($categoryId)
2016-03-25 01:18:05 -07:00
{
// Check if the category exists
if (is_null($category = Category::find($categoryId))) {
// Redirect to the blogs management page
2016-04-28 21:06:41 -07:00
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.not_found'));
2016-03-25 01:18:05 -07:00
}
if ($category->has_models() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'model']));
2016-03-25 01:18:05 -07:00
} elseif ($category->accessories()->count() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'accessory']));
} elseif ($category->consumables()->count() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'consumable']));
} elseif ($category->components()->count() > 0) {
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=>'component']));
2016-03-25 01:18:05 -07:00
} else {
$category->delete();
// Redirect to the locations management page
2016-04-28 21:06:41 -07:00
return redirect()->to('admin/settings/categories')->with('success', trans('admin/categories/message.delete.success'));
2016-03-25 01:18:05 -07:00
}
}
/**
2016-03-25 18:07:12 -07:00
* Returns a view that invokes the ajax tables which actually contains
* the content for the categories detail view, which is generated in getDataView.
2016-03-25 01:18:05 -07:00
*
2016-03-25 18:07:12 -07:00
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::getDataView() method that generates the JSON response
* @param int $categoryId
* @since [v1.8]
2016-03-25 01:18:05 -07:00
* @return View
2016-03-25 18:07:12 -07:00
*/
2016-12-15 16:42:47 -08:00
public function show($categoryId = null)
2016-03-25 01:18:05 -07:00
{
2016-03-25 18:07:12 -07:00
$category = Category::find($categoryId);
2016-03-25 01:18:05 -07:00
if (isset($category->id)) {
return View::make('categories/view', compact('category'));
} else {
// Prepare the error message
$error = trans('admin/categories/message.does_not_exist', compact('id'));
2016-03-25 01:18:05 -07:00
// Redirect to the user management page
2016-12-15 16:42:47 -08:00
return redirect()->route('categories.index')->with('error', $error);
2016-03-25 01:18:05 -07:00
}
}
2016-03-25 18:07:12 -07:00
/**
* Returns a JSON response with the data to populate the bootstrap table on the
* cateory listing page.
*
2016-04-07 17:23:52 -07:00
* @todo Refactor this nastiness. Assets do not behave the same as accessories, etc.
2016-03-25 18:07:12 -07:00
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see CategoriesController::getIndex() method that generates the view
* @since [v1.8]
* @return String JSON
*/
2016-12-15 16:42:47 -08:00
public function getDatatable(Request $request)
2016-03-25 01:18:05 -07:00
{
// Grab all the categories
2016-06-22 12:27:41 -07:00
$categories = Category::with('assets', 'accessories', 'consumables', 'components');
2016-03-25 01:18:05 -07:00
if (Input::has('search')) {
2016-12-15 16:42:47 -08:00
$categories = $categories->TextSearch(e($request->input('search')));
2016-03-25 01:18:05 -07:00
}
if (Input::has('offset')) {
2016-12-15 16:42:47 -08:00
$offset = e($request->input('offset'));
2016-03-25 01:18:05 -07:00
} else {
$offset = 0;
}
if (Input::has('limit')) {
2016-12-15 16:42:47 -08:00
$limit = e($request->input('limit'));
2016-03-25 01:18:05 -07:00
} else {
$limit = 50;
}
$allowed_columns = ['id','name','category_type'];
2016-12-15 16:42:47 -08:00
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
2016-03-25 01:18:05 -07:00
$categories = $categories->orderBy($sort, $order);
$catCount = $categories->count();
$categories = $categories->skip($offset)->take($limit)->get();
$rows = array();
foreach ($categories as $category) {
2016-12-15 16:42:47 -08:00
$actions = '<a href="'.route('categories.edit', ['category' => $category->id]).'" class="btn btn-warning btn-sm" style="margin-right:5px;">';
$actions .='<i class="fa fa-pencil icon-white"></i></a>';
$actions .='<a data-html="false" class="btn delete-asset btn-danger btn-sm';
if ($category->itemCount() > 0) {
$actions .=' disabled';
}
2016-12-15 16:42:47 -08:00
$actions .=' data-toggle="modal" href="'.route('categories.destroy', ['category' => $category->id]).'" data-content="'.trans('admin/categories/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($category->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
2016-03-25 01:18:05 -07:00
$rows[] = array(
'id' => $category->id,
2016-12-15 16:42:47 -08:00
'name' => (string)link_to_route('categories.show', $category->name, ['category' => $category->id]) ,
2016-03-25 01:18:05 -07:00
'category_type' => ucwords($category->category_type),
'count' => $category->itemCount(),
2016-03-25 01:18:05 -07:00
'acceptance' => ($category->require_acceptance=='1') ? '<i class="fa fa-check"></i>' : '',
'eula' => ($category->getEula()) ? '<i class="fa fa-check"></i>' : '',
'actions' => $actions
);
}
$data = array('total' => $catCount, 'rows' => $rows);
return $data;
}
2016-12-15 16:42:47 -08:00
public function getDataViewAssets(Request $request, $categoryID)
2016-06-22 12:27:41 -07:00
{
2016-03-25 01:18:05 -07:00
$category = Category::find($categoryID);
$category = $category->load('assets.company', 'assets.model', 'assets.assetstatus', 'assets.assigneduser');
2016-06-03 11:48:20 -07:00
$category_assets = $category->assets();
2016-03-25 01:18:05 -07:00
if (Input::has('search')) {
2016-12-15 16:42:47 -08:00
$category_assets = $category_assets->TextSearch(e($request->input('search')));
2016-03-25 01:18:05 -07:00
}
if (Input::has('offset')) {
2016-12-15 16:42:47 -08:00
$offset = e($request->input('offset'));
2016-03-25 01:18:05 -07:00
} else {
$offset = 0;
}
if (Input::has('limit')) {
2016-12-15 16:42:47 -08:00
$limit = e($request->input('limit'));
2016-03-25 01:18:05 -07:00
} else {
$limit = 50;
}
2016-12-15 16:42:47 -08:00
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
2016-03-25 01:18:05 -07:00
$allowed_columns = ['id','name','serial','asset_tag'];
2016-12-15 16:42:47 -08:00
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
2016-03-25 01:18:05 -07:00
$count = $category_assets->count();
2016-05-19 19:45:48 -07:00
$category_assets = $category_assets->skip($offset)->take($limit)->get();
2016-03-25 01:18:05 -07:00
$rows = array();
foreach ($category_assets as $asset) {
$actions = '';
$inout='';
if ($asset->deleted_at=='') {
2016-12-15 16:42:47 -08:00
$actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('hardware.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('hardware.destroy', ['aseset' => $asset->id]).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
2016-03-25 01:18:05 -07:00
} elseif ($asset->deleted_at!='') {
$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
}
if ($asset->availableForCheckout()) {
if (Gate::allows('assets.checkout')) {
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';
}
} else {
if (Gate::allows('assets.checkin')) {
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';
2016-03-25 01:18:05 -07:00
}
}
$rows[] = array(
2016-05-18 19:08:16 -07:00
'id' => $asset->id,
2016-12-15 16:42:47 -08:00
'name' => (string)link_to_route('hardware.show', $asset->showAssetName(), ['hardware' => $asset->id]),
2016-11-29 06:14:20 -08:00
'model' => ($asset->model) ? (string)link_to('hardware/models/'.$asset->model->id.'/view', $asset->model->name) : '',
2016-05-18 19:08:16 -07:00
'asset_tag' => $asset->asset_tag,
'serial' => $asset->serial,
'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', $asset->assigneduser->fullName()): '',
2016-05-18 19:08:16 -07:00
'change' => $inout,
'actions' => $actions,
'companyName' => is_null($asset->company) ? '' : e($asset->company->name)
2016-03-25 01:18:05 -07:00
);
}
$data = array('total' => $count, 'rows' => $rows);
return $data;
}
2016-05-18 19:08:16 -07:00
2016-06-22 12:27:41 -07:00
public function getDataViewAccessories($categoryID)
{
2016-05-18 19:08:16 -07:00
$category = Category::with('accessories.company')->find($categoryID);
$category_assets = $category->accessories;
if (Input::has('search')) {
2016-12-15 16:42:47 -08:00
$category_assets = $category_assets->TextSearch(e($request->input('search')));
2016-05-18 19:08:16 -07:00
}
if (Input::has('offset')) {
2016-12-15 16:42:47 -08:00
$offset = e($request->input('offset'));
2016-05-18 19:08:16 -07:00
} else {
$offset = 0;
}
if (Input::has('limit')) {
2016-12-15 16:42:47 -08:00
$limit = e($request->input('limit'));
2016-05-18 19:08:16 -07:00
} else {
$limit = 50;
}
2016-12-15 16:42:47 -08:00
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
2016-05-18 19:08:16 -07:00
$allowed_columns = ['id','name','serial','asset_tag'];
2016-12-15 16:42:47 -08:00
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
2016-05-18 19:08:16 -07:00
$count = $category_assets->count();
$rows = array();
foreach ($category_assets as $asset) {
$actions = '';
$inout='';
if ($asset->deleted_at=='') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('accessories.update', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('accessories.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
2016-05-18 19:08:16 -07:00
}
$rows[] = array(
'id' => $asset->id,
'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]),
'actions' => $actions,
'companyName' => Company::getName($asset),
);
}
$data = array('total' => $count, 'rows' => $rows);
return $data;
}
2016-06-22 12:27:41 -07:00
public function getDataViewConsumables($categoryID)
{
2016-05-18 19:08:16 -07:00
$category = Category::with('accessories.company')->find($categoryID);
$category_assets = $category->consumables;
if (Input::has('search')) {
2016-12-15 16:42:47 -08:00
$category_assets = $category_assets->TextSearch(e($request->input('search')));
2016-05-18 19:08:16 -07:00
}
if (Input::has('offset')) {
2016-12-15 16:42:47 -08:00
$offset = e($request->input('offset'));
2016-05-18 19:08:16 -07:00
} else {
$offset = 0;
}
if (Input::has('limit')) {
2016-12-15 16:42:47 -08:00
$limit = e($request->input('limit'));
2016-05-18 19:08:16 -07:00
} else {
$limit = 50;
}
2016-12-15 16:42:47 -08:00
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
2016-05-18 19:08:16 -07:00
$allowed_columns = ['id','name','serial','asset_tag'];
2016-12-15 16:42:47 -08:00
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
2016-05-18 19:08:16 -07:00
$count = $category_assets->count();
$rows = array();
foreach ($category_assets as $asset) {
$actions = '';
$inout='';
if ($asset->deleted_at=='') {
$actions = '<div style=" white-space: nowrap;"><a href="'.route('consumables.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('consumables.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
2016-05-18 19:08:16 -07:00
}
$rows[] = array(
'id' => $asset->id,
'name' => (string) link_to_route('view/consumable', $asset->name, [$asset->id]),
'actions' => $actions,
'companyName' => Company::getName($asset),
);
}
$data = array('total' => $count, 'rows' => $rows);
return $data;
}
2016-06-22 12:27:41 -07:00
public function getDataViewComponent($categoryID)
{
2016-05-18 19:08:16 -07:00
$category = Category::with('accessories.company')->find($categoryID);
$category_assets = $category->components;
if (Input::has('search')) {
2016-12-15 16:42:47 -08:00
$category_assets = $category_assets->TextSearch(e($request->input('search')));
2016-05-18 19:08:16 -07:00
}
if (Input::has('offset')) {
2016-12-15 16:42:47 -08:00
$offset = e($request->input('offset'));
2016-05-18 19:08:16 -07:00
} else {
$offset = 0;
}
if (Input::has('limit')) {
2016-12-15 16:42:47 -08:00
$limit = e($request->input('limit'));
2016-05-18 19:08:16 -07:00
} else {
$limit = 50;
}
2016-12-15 16:42:47 -08:00
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
2016-05-18 19:08:16 -07:00
$allowed_columns = ['id','name','serial','asset_tag'];
2016-12-15 16:42:47 -08:00
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
2016-05-18 19:08:16 -07:00
$count = $category_assets->count();
$rows = array();
foreach ($category_assets as $asset) {
$actions = '';
$inout='';
if ($asset->deleted_at=='') {
2016-12-15 19:59:42 -08:00
$actions = '<div style=" white-space: nowrap;"><a href="'.route('components.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('components.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
2016-05-18 19:08:16 -07:00
}
$rows[] = array(
'id' => $asset->id,
'name' => (string)link_to_route('view/accessory', $asset->name, [$asset->id]),
'actions' => $actions,
'companyName' => Company::getName($asset),
);
}
$data = array('total' => $count, 'rows' => $rows);
return $data;
}
2016-03-25 01:18:05 -07:00
}