Skip to content

Commit d722ed3

Browse files
mnemoniclysnipe
authored andcommitted
Partialize forms (snipe#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.
1 parent 84e06f4 commit d722ed3

File tree

186 files changed

+3991
-3670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+3991
-3670
lines changed

.env.tests

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
APP_ENV=local
2+
APP_DEBUG=true
3+
APP_URL=http://snipe-it.localapp
4+
DB_CONNECTION=mysql
5+
DB_HOST=localhost
6+
DB_DATABASE=snipeittests
7+
DB_USERNAME=snipeit
8+
DB_PASSWORD=snipe
9+
APP_KEY=base64:tu9NRh/a6+dCXBDGvg0Gv/0TcABnFsbT4AKxrr8mwQo=

app/Console/Commands/ObjectImportCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function fire()
100100
$this->locations = Location::All(['name', 'id']);
101101
$this->categories = Category::All(['name', 'category_type', 'id']);
102102
$this->manufacturers = Manufacturer::All(['name', 'id']);
103-
$this->asset_models = AssetModel::All(['name','modelno','category_id','manufacturer_id', 'id']);
103+
$this->asset_models = AssetModel::All(['name','model_number','category_id','manufacturer_id', 'id']);
104104
$this->companies = Company::All(['name', 'id']);
105105
$this->status_labels = Statuslabel::All(['name', 'id']);
106106
$this->suppliers = Supplier::All(['name', 'id']);
@@ -348,7 +348,7 @@ public function createOrFetchAssetModel(array $row, $category, $manufacturer)
348348
$editingModel = false;
349349
foreach ($this->asset_models as $tempmodel) {
350350
if (strcasecmp($tempmodel->name, $asset_model_name) == 0
351-
&& $tempmodel->modelno == $asset_modelno) {
351+
&& $tempmodel->model_number == $asset_modelno) {
352352
$this->log('A matching model ' . $asset_model_name . ' already exists');
353353
if (!$this->option('update')) {
354354
return $tempmodel;
@@ -366,7 +366,7 @@ public function createOrFetchAssetModel(array $row, $category, $manufacturer)
366366
$asset_model->name = $asset_model_name;
367367
}
368368
isset($manufacturer) && $manufacturer->exists && $asset_model->manufacturer_id = $manufacturer->id;
369-
isset($asset_modelno) && $asset_model->modelno = $asset_modelno;
369+
isset($asset_modelno) && $asset_model->model_number = $asset_modelno;
370370
if (isset($category) && $category->exists) {
371371
$asset_model->category_id = $category->id;
372372
}

app/Helpers/Helper.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ public static function checkLowInventory()
434434
foreach ($consumables as $consumable) {
435435
$avail = $consumable->numRemaining();
436436
if ($avail < ($consumable->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
437-
if ($consumable->total_qty > 0) {
438-
$percent = number_format((($consumable->numRemaining() / $consumable->total_qty) * 100), 0);
437+
if ($consumable->qty > 0) {
438+
$percent = number_format((($consumable->numRemaining() / $consumable->qty) * 100), 0);
439439
} else {
440440
$percent = 100;
441441
}
@@ -456,8 +456,8 @@ public static function checkLowInventory()
456456
$avail = $accessory->numRemaining();
457457
if ($avail < ($accessory->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
458458

459-
if ($accessory->total_qty > 0) {
460-
$percent = number_format((($accessory->numRemaining() / $accessory->total_qty) * 100), 0);
459+
if ($accessory->qty > 0) {
460+
$percent = number_format((($accessory->numRemaining() / $accessory->qty) * 100), 0);
461461
} else {
462462
$percent = 100;
463463
}
@@ -476,8 +476,8 @@ public static function checkLowInventory()
476476
foreach ($components as $component) {
477477
$avail = $component->numRemaining();
478478
if ($avail < ($component->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
479-
if ($component->total_qty > 0) {
480-
$percent = number_format((($component->numRemaining() / $component->total_qty) * 100), 0);
479+
if ($component->qty > 0) {
480+
$percent = number_format((($component->numRemaining() / $component->qty) * 100), 0);
481481
} else {
482482
$percent = 100;
483483
}

app/Http/Controllers/AccessoriesController.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
use App\Models\Company;
88
use App\Models\Setting;
99
use App\Models\User;
10+
use Auth;
1011
use Carbon\Carbon;
1112
use Config;
1213
use DB;
14+
use Gate;
1315
use Input;
1416
use Lang;
1517
use Mail;
1618
use Redirect;
19+
use Request;
1720
use Slack;
1821
use Str;
1922
use View;
20-
use Auth;
21-
use Request;
22-
use Gate;
2323

2424
/** This controller handles all actions related to Accessories for
2525
* the Snipe-IT Asset Management application.
@@ -54,7 +54,7 @@ public function getCreate(Request $request)
5454
{
5555
// Show the page
5656
return View::make('accessories/edit')
57-
->with('accessory', new Accessory)
57+
->with('item', new Accessory)
5858
->with('category_list', Helper::categoryList('accessory'))
5959
->with('company_list', Helper::companyList())
6060
->with('location_list', Helper::locationsList())
@@ -119,14 +119,14 @@ public function postCreate(Request $request)
119119
public function getEdit(Request $request, $accessoryId = null)
120120
{
121121
// Check if the accessory exists
122-
if (is_null($accessory = Accessory::find($accessoryId))) {
122+
if (is_null($item = Accessory::find($accessoryId))) {
123123
// Redirect to the blogs management page
124124
return redirect()->to('admin/accessories')->with('error', trans('admin/accessories/message.does_not_exist'));
125-
} elseif (!Company::isCurrentUserHasAccess($accessory)) {
125+
} elseif (!Company::isCurrentUserHasAccess($item)) {
126126
return redirect()->to('admin/accessories')->with('error', trans('general.insufficient_permissions'));
127127
}
128128

129-
return View::make('accessories/edit', compact('accessory'))
129+
return View::make('accessories/edit', compact('item'))
130130
->with('category_list', Helper::categoryList('accessory'))
131131
->with('company_list', Helper::companyList())
132132
->with('location_list', Helper::locationsList())

app/Http/Controllers/AssetModelsController.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getCreate()
6262
->with('category_list', $category_list)
6363
->with('depreciation_list', $depreciation_list)
6464
->with('manufacturer_list', $manufacturer_list)
65-
->with('model', new AssetModel);
65+
->with('item', new AssetModel);
6666
}
6767

6868

@@ -94,10 +94,10 @@ public function postCreate()
9494

9595
// Save the model data
9696
$model->name = e(Input::get('name'));
97-
$model->modelno = e(Input::get('modelno'));
97+
$model->model_number = e(Input::get('model_number'));
9898
$model->manufacturer_id = e(Input::get('manufacturer_id'));
9999
$model->category_id = e(Input::get('category_id'));
100-
$model->note = e(Input::get('note'));
100+
$model->notes = e(Input::get('notes'));
101101
$model->user_id = Auth::user()->id;
102102
$model->requestable = Input::has('requestable');
103103

@@ -146,7 +146,7 @@ public function store()
146146
$model->name=e(Input::get('name'));
147147
$model->manufacturer_id = e(Input::get('manufacturer_id'));
148148
$model->category_id = e(Input::get('category_id'));
149-
$model->modelno = e(Input::get('modelno'));
149+
$model->model_number = e(Input::get('model_number'));
150150
$model->user_id = Auth::user()->id;
151151
$model->note = e(Input::get('note'));
152152
$model->eol= null;
@@ -176,15 +176,16 @@ public function store()
176176
public function getEdit($modelId = null)
177177
{
178178
// Check if the model exists
179-
if (is_null($model = AssetModel::find($modelId))) {
179+
if (is_null($item = AssetModel::find($modelId))) {
180180
// Redirect to the model management page
181181
return redirect()->to('assets/models')->with('error', trans('admin/models/message.does_not_exist'));
182182
}
183183

184184
$depreciation_list = Helper::depreciationList();
185185
$manufacturer_list = Helper::manufacturerList();
186186
$category_list = Helper::categoryList('asset');
187-
$view = View::make('models/edit', compact('model'));
187+
188+
$view = View::make('models/edit', compact('item'));
188189
$view->with('category_list', $category_list);
189190
$view->with('depreciation_list', $depreciation_list);
190191
$view->with('manufacturer_list', $manufacturer_list);
@@ -221,13 +222,12 @@ public function postEdit($modelId = null)
221222
} else {
222223
$model->eol = e(Input::get('eol'));
223224
}
224-
225225
// Update the model data
226226
$model->name = e(Input::get('name'));
227-
$model->modelno = e(Input::get('modelno'));
227+
$model->model_number = e(Input::get('model_number'));
228228
$model->manufacturer_id = e(Input::get('manufacturer_id'));
229229
$model->category_id = e(Input::get('category_id'));
230-
$model->note = e(Input::get('note'));
230+
$model->notes = e(Input::get('notes'));
231231

232232
$model->requestable = Input::has('requestable');
233233

@@ -442,7 +442,7 @@ public function getDatatable($status = null)
442442
}
443443

444444

445-
$allowed_columns = ['id','name','modelno'];
445+
$allowed_columns = ['id','name','model_number'];
446446
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
447447
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at';
448448

@@ -465,7 +465,7 @@ public function getDatatable($status = null)
465465
'manufacturer' => (string)link_to('/admin/settings/manufacturers/'.$model->manufacturer->id.'/view', $model->manufacturer->name),
466466
'name' => (string)link_to('/hardware/models/'.$model->id.'/view', $model->name),
467467
'image' => ($model->image!='') ? '<img src="'.config('app.url').'/uploads/models/'.$model->image.'" height=50 width=50>' : '',
468-
'modelnumber' => $model->modelno,
468+
'modelnumber' => $model->model_number,
469469
'numassets' => $model->assets->count(),
470470
'depreciation' => (($model->depreciation)&&($model->depreciation->id > 0)) ? $model->depreciation->name.' ('.$model->depreciation->months.')' : trans('general.no_depreciation'),
471471
'category' => ($model->category) ? $model->category->name : '',

app/Http/Controllers/AssetsController.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function getCreate($model_id = null)
124124
$view->with('statuslabel_list', $statuslabel_list);
125125
$view->with('assigned_to', $assigned_to);
126126
$view->with('location_list', $location_list);
127-
$view->with('asset', new Asset);
127+
$view->with('item', new Asset);
128128
$view->with('manufacturer', $manufacturer_list);
129129
$view->with('category', $category_list);
130130
$view->with('statuslabel_types', $statuslabel_types);
@@ -290,10 +290,10 @@ public function getEdit($assetId = null)
290290
{
291291

292292
// Check if the asset exists
293-
if (!$asset = Asset::find($assetId)) {
293+
if (!$item = Asset::find($assetId)) {
294294
// Redirect to the asset management page
295295
return redirect()->to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
296-
} elseif (!Company::isCurrentUserHasAccess($asset)) {
296+
} elseif (!Company::isCurrentUserHasAccess($item)) {
297297
return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
298298
}
299299

@@ -308,7 +308,7 @@ public function getEdit($assetId = null)
308308
$assigned_to = Helper::usersList();
309309
$statuslabel_types =Helper::statusTypeList();
310310

311-
return View::make('hardware/edit', compact('asset'))
311+
return View::make('hardware/edit', compact('item'))
312312
->with('model_list', $model_list)
313313
->with('supplier_list', $supplier_list)
314314
->with('company_list', $company_list)
@@ -1038,7 +1038,7 @@ public function getClone($assetId = null)
10381038
->with('statuslabel_list', $statuslabel_list)
10391039
->with('statuslabel_types', $statuslabel_types)
10401040
->with('assigned_to', $assigned_to)
1041-
->with('asset', $asset)
1041+
->with('item', $asset)
10421042
->with('location_list', $location_list)
10431043
->with('manufacturer', $manufacturer_list)
10441044
->with('category', $category_list)
@@ -1798,7 +1798,7 @@ public function getDatatable(Request $request, $status = null)
17981798
'asset_tag' => '<a title="'.e($asset->asset_tag).'" href="hardware/'.$asset->id.'/view">'.e($asset->asset_tag).'</a>',
17991799
'serial' => e($asset->serial),
18001800
'model' => ($asset->model) ? (string)link_to('/hardware/models/'.$asset->model->id.'/view', e($asset->model->name)) : 'No model',
1801-
'model_number' => ($asset->model && $asset->model->modelno) ? (string)$asset->model->modelno : '',
1801+
'model_number' => ($asset->model && $asset->model->model_number) ? (string)$asset->model->model_number : '',
18021802
'status_label' => ($asset->assigneduser) ? 'Deployed' : ((e($asset->assetstatus)) ? e($asset->assetstatus->name) : ''),
18031803
'assigned_to' => ($asset->assigneduser) ? (string)link_to(config('app.url').'/admin/users/'.$asset->assigned_to.'/view', e($asset->assigneduser->fullName())) : '',
18041804
'location' => (($asset->assigneduser) && ($asset->assigneduser->userloc!='')) ? (string)link_to('admin/settings/locations/'.$asset->assigneduser->userloc->id.'/view', e($asset->assigneduser->userloc->name)) : (($asset->defaultLoc!='') ? (string)link_to('admin/settings/locations/'.$asset->defaultLoc->id.'/view', e($asset->defaultLoc->name)) : ''),

app/Http/Controllers/CategoriesController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getCreate()
5353
{
5454
// Show the page
5555
$category_types= Helper::categoryTypeList();
56-
return View::make('categories/edit')->with('category', new Category)
56+
return View::make('categories/edit')->with('item', new Category)
5757
->with('category_types', $category_types);
5858
}
5959

@@ -109,7 +109,7 @@ public function postCreate()
109109
public function getEdit($categoryId = null)
110110
{
111111
// Check if the category exists
112-
if (is_null($category = Category::find($categoryId))) {
112+
if (is_null($item = Category::find($categoryId))) {
113113
// Redirect to the blogs management page
114114
return redirect()->to('admin/settings/categories')->with('error', trans('admin/categories/message.does_not_exist'));
115115
}
@@ -120,7 +120,7 @@ public function getEdit($categoryId = null)
120120
$category_options = array('' => 'Top Level') + DB::table('categories')->where('id', '!=', $categoryId)->lists('name', 'id');
121121
$category_types= Helper::categoryTypeList();
122122

123-
return View::make('categories/edit', compact('category'))
123+
return View::make('categories/edit', compact('item'))
124124
->with('category_options', $category_options)
125125
->with('category_types', $category_types);
126126
}

app/Http/Controllers/CompaniesController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getIndex()
3838
*/
3939
public function getCreate()
4040
{
41-
return View::make('companies/edit')->with('company', new Company);
41+
return View::make('companies/edit')->with('item', new Company);
4242
}
4343

4444
/**
@@ -74,11 +74,11 @@ public function postCreate()
7474
*/
7575
public function getEdit($companyId)
7676
{
77-
if (is_null($company = Company::find($companyId))) {
77+
if (is_null($item = Company::find($companyId))) {
7878
return redirect()->to('admin/settings/companies')
7979
->with('error', trans('admin/companies/message.does_not_exist'));
8080
} else {
81-
return View::make('companies/edit')->with('company', $company);
81+
return View::make('companies/edit')->with('item', $item);
8282
}
8383
}
8484

0 commit comments

Comments
 (0)