mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
296de34e8a
I'm going ahead and merging this, since the upgrade doesn't break Flysystem any worse than the current develop is broken, so far as I can tell. * Upgraded framework to Laravel 6 ### TO DO: - Fix password restriction rules- the old library isn’t compatible with Laravel 6 :( - Figure out why in-app API calls are returning “Unauthorized” * More updates from Input:: to Request:: helper * Switch to Request:: from Input * Added passport config * Fixed goofy password minimum in seeder * Added laravel/helpers * Changed ($item) to ($item->id) in forms I have no idea why this is necessary * Changed ($item) to ($item->id) in forms * Updated API middleware to auth:api * Updated with added laravel auth.php values * FIxed *&!^$%^&$^%!!!! ajax issue * Switch to Request::get from Input::get * Switched to Request facade * Added password security minimums back in The package we were using has not been updated to Laravel v6, so I created custom validators instead * Added language strings for error messages for password rules * Fixed `($item)` issue in formActions for partials
139 lines
4.6 KiB
PHP
139 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\AssetModel;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Input;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
class BulkAssetModelsController extends Controller
|
|
{
|
|
/**
|
|
* Returns a view that allows the user to bulk edit model attrbutes
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
* @since [v1.7]
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(Request $request)
|
|
{
|
|
$models_raw_array = Request::get('ids');
|
|
|
|
// Make sure some IDs have been selected
|
|
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
|
|
|
$models = AssetModel::whereIn('id', $models_raw_array)
|
|
->withCount('assets as assets_count')
|
|
->orderBy('assets_count', 'ASC')
|
|
->get();
|
|
|
|
// If deleting....
|
|
if ($request->input('bulk_actions')=='delete') {
|
|
$valid_count = 0;
|
|
foreach ($models as $model) {
|
|
if ($model->assets_count == 0) {
|
|
$valid_count++;
|
|
}
|
|
}
|
|
return view('models/bulk-delete', compact('models'))->with('valid_count', $valid_count);
|
|
|
|
// Otherwise display the bulk edit screen
|
|
}
|
|
|
|
$nochange = ['NC' => 'No Change'];
|
|
return view('models/bulk-edit', compact('models'))
|
|
->with('fieldset_list', $nochange + Helper::customFieldsetList())
|
|
->with('depreciation_list', $nochange + Helper::depreciationList());
|
|
}
|
|
|
|
return redirect()->route('models.index')
|
|
->with('error', 'You must select at least one model to edit.');
|
|
}
|
|
|
|
/**
|
|
* Returns a view that allows the user to bulk edit model attrbutes
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
* @since [v1.7]
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function update(Request $request)
|
|
{
|
|
|
|
$models_raw_array = Request::get('ids');
|
|
$update_array = array();
|
|
|
|
if (($request->filled('manufacturer_id') && ($request->input('manufacturer_id')!='NC'))) {
|
|
$update_array['manufacturer_id'] = $request->input('manufacturer_id');
|
|
}
|
|
if (($request->filled('category_id') && ($request->input('category_id')!='NC'))) {
|
|
$update_array['category_id'] = $request->input('category_id');
|
|
}
|
|
if ($request->input('fieldset_id')!='NC') {
|
|
$update_array['fieldset_id'] = $request->input('fieldset_id');
|
|
}
|
|
if ($request->input('depreciation_id')!='NC') {
|
|
$update_array['depreciation_id'] = $request->input('depreciation_id');
|
|
}
|
|
|
|
|
|
|
|
if (count($update_array) > 0) {
|
|
AssetModel::whereIn('id', $models_raw_array)->update($update_array);
|
|
return redirect()->route('models.index')
|
|
->with('success', trans('admin/models/message.bulkedit.success'));
|
|
}
|
|
|
|
return redirect()->route('models.index')
|
|
->with('warning', trans('admin/models/message.bulkedit.error'));
|
|
|
|
}
|
|
|
|
/**
|
|
* Validate and delete the given Asset Models. An Asset Model
|
|
* cannot be deleted if there are associated assets.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
* @since [v1.0]
|
|
* @return Redirect
|
|
*/
|
|
public function destroy()
|
|
{
|
|
$models_raw_array = Request::get('ids');
|
|
|
|
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
|
|
|
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->get();
|
|
|
|
$del_error_count = 0;
|
|
$del_count = 0;
|
|
|
|
foreach ($models as $model) {
|
|
if ($model->assets_count > 0) {
|
|
$del_error_count++;
|
|
} else {
|
|
$model->delete();
|
|
$del_count++;
|
|
}
|
|
}
|
|
|
|
if ($del_error_count == 0) {
|
|
return redirect()->route('models.index')
|
|
->with('success', trans('admin/models/message.bulkdelete.success',['success_count'=> $del_count] ));
|
|
}
|
|
|
|
return redirect()->route('models.index')
|
|
->with('warning', trans('admin/models/message.bulkdelete.success_partial', ['fail_count'=>$del_error_count, 'success_count'=> $del_count]));
|
|
}
|
|
|
|
return redirect()->route('models.index')
|
|
->with('error', trans('admin/models/message.bulkdelete.error'));
|
|
|
|
}
|
|
|
|
}
|