Fix asset create (#3929)

* Fix accidental commit of ImporterTest.

* Move the name() method to the presenter

This fixes some weird collisions between laravels voodoo and our
presenter voodoo that confused php.  It's also probably a cleaner place
to put it.  Should fix #3927

* Add missing parenthesis

* Add heading to tables on locations/view page.
This commit is contained in:
Daniel Meltzer 2017-09-06 19:24:43 -04:00 committed by snipe
parent c651c9f1ed
commit ae0573b3da
5 changed files with 164 additions and 155 deletions

View file

@ -82,8 +82,4 @@ class SnipeModel extends Model
{ {
return $this->name; return $this->name;
} }
public function name() {
return $this->name;
}
} }

View file

@ -65,6 +65,11 @@ abstract class Presenter
return ''; return '';
} }
public function name()
{
return $this->model->name;
}
public function __get($property) public function __get($property)
{ {
if (method_exists($this, $property)) { if (method_exists($this, $property)) {

View file

@ -32,7 +32,7 @@
name="category_assets" name="category_assets"
class="snipe-table" class="snipe-table"
id="table" id="table"
data-url="{{ route('api.'.$category_type_route.'.index',['category_id'=> $category->id]) }} data-url="{{ route('api.'.$category_type_route.'.index',['category_id'=> $category->id]) }}"
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"
data-cookie-id-table="category{{ $category_type_route }}Table"> data-cookie-id-table="category{{ $category_type_route }}Table">

View file

@ -21,6 +21,11 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="box box-default"> <div class="box box-default">
<div class="box-header with-border">
<div class="box-heading">
<h3 class="box-title">{{ trans('general.users') }}</h3>
</div>
</div>
<div class="box-body"> <div class="box-body">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@ -50,6 +55,11 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="box box-default"> <div class="box box-default">
<div class="box-header with-border">
<div class="box-heading">
<h3 class="box-title">{{ trans('general.assets') }}</h3>
</div>
</div>
<div class="box-body"> <div class="box-body">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">

View file

@ -18,181 +18,181 @@ class ImporterTest extends BaseTest
*/ */
protected $tester; protected $tester;
// public function testDefaultImportAsset() public function testDefaultImportAsset()
// { {
// $csv = <<<'EOT' $csv = <<<'EOT'
// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan
// EOT; EOT;
// $this->import(new AssetImporter($csv)); $this->import(new AssetImporter($csv));
// // Did we create a user? // Did we create a user?
// $this->tester->seeRecord('users', [ $this->tester->seeRecord('users', [
// 'first_name' => 'Bonnie', 'first_name' => 'Bonnie',
// 'last_name' => 'Nelson', 'last_name' => 'Nelson',
// 'email' => 'bnelson0@cdbaby.com', 'email' => 'bnelson0@cdbaby.com',
// ]); ]);
// $this->tester->seeRecord('categories', [ $this->tester->seeRecord('categories', [
// 'name' => 'quam' 'name' => 'quam'
// ]); ]);
// $this->tester->seeRecord('models', [ $this->tester->seeRecord('models', [
// 'name' => 'massa id', 'name' => 'massa id',
// 'model_number' => 6377018600094472 'model_number' => 6377018600094472
// ]); ]);
// $this->tester->seeRecord('manufacturers', [ $this->tester->seeRecord('manufacturers', [
// 'name' => 'Linkbridge' 'name' => 'Linkbridge'
// ]); ]);
// $this->tester->seeRecord('locations', [ $this->tester->seeRecord('locations', [
// 'name' => 'Daping' 'name' => 'Daping'
// ]); ]);
// $this->tester->seeRecord('companies', [ $this->tester->seeRecord('companies', [
// 'name' => 'Alpha' 'name' => 'Alpha'
// ]); ]);
// $this->tester->seeRecord('status_labels', [ $this->tester->seeRecord('status_labels', [
// 'name' => 'Undeployable' 'name' => 'Undeployable'
// ]); ]);
// $this->tester->seeRecord('suppliers', [ $this->tester->seeRecord('suppliers', [
// 'name' => 'Blogspan' 'name' => 'Blogspan'
// ]); ]);
// $this->tester->seeRecord('assets', [ $this->tester->seeRecord('assets', [
// 'name' => 'eget nunc donec quis', 'name' => 'eget nunc donec quis',
// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',
// 'asset_tag' => '970882174-8', 'asset_tag' => '970882174-8',
// 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.", 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",
// 'purchase_date' => '2016-04-05 00:00:01', 'purchase_date' => '2016-04-05 00:00:01',
// 'purchase_cost' => 133289.59, 'purchase_cost' => 133289.59,
// 'warranty_months' => 14 'warranty_months' => 14
// ]); ]);
// } }
// public function testUpdateAsset() public function testUpdateAsset()
// { {
// $csv = <<<'EOT' $csv = <<<'EOT'
// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan
// EOT; EOT;
// $this->import(new AssetImporter($csv)); $this->import(new AssetImporter($csv));
// $updatedCSV = <<<'EOT' $updatedCSV = <<<'EOT'
// item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier
// A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative
// EOT; EOT;
// $importer = new AssetImporter($updatedCSV); $importer = new AssetImporter($updatedCSV);
// $importer->setUserId(1) $importer->setUserId(1)
// ->setUpdating(true) ->setUpdating(true)
// ->setUsernameFormat('firstname.lastname') ->setUsernameFormat('firstname.lastname')
// ->import(); ->import();
// $this->tester->seeRecord('categories', [ $this->tester->seeRecord('categories', [
// 'name' => 'some other category' 'name' => 'some other category'
// ]); ]);
// $this->tester->seeRecord('models', [ $this->tester->seeRecord('models', [
// 'name' => 'Another Model', 'name' => 'Another Model',
// 'model_number' => 356 'model_number' => 356
// ]); ]);
// $this->tester->seeRecord('manufacturers', [ $this->tester->seeRecord('manufacturers', [
// 'name' => 'Linkbridge 32' 'name' => 'Linkbridge 32'
// ]); ]);
// $this->tester->seeRecord('locations', [ $this->tester->seeRecord('locations', [
// 'name' => 'New Location' 'name' => 'New Location'
// ]); ]);
// $this->tester->seeRecord('companies', [ $this->tester->seeRecord('companies', [
// 'name' => 'Another Company' 'name' => 'Another Company'
// ]); ]);
// $this->tester->seeRecord('status_labels', [ $this->tester->seeRecord('status_labels', [
// 'name' => 'Ready To Go' 'name' => 'Ready To Go'
// ]); ]);
// $this->tester->seeRecord('suppliers', [ $this->tester->seeRecord('suppliers', [
// 'name' => 'Not Creative' 'name' => 'Not Creative'
// ]); ]);
// $this->tester->seeRecord('assets', [ $this->tester->seeRecord('assets', [
// 'name' => 'A new name', 'name' => 'A new name',
// 'serial' => '67433477', 'serial' => '67433477',
// 'asset_tag' => '970882174-8', 'asset_tag' => '970882174-8',
// 'notes' => "I have no notes", 'notes' => "I have no notes",
// 'purchase_date' => '2018-04-05 00:00:01', 'purchase_date' => '2018-04-05 00:00:01',
// 'purchase_cost' => 25.59, 'purchase_cost' => 25.59,
// 'warranty_months' => 18 'warranty_months' => 18
// ]); ]);
// } }
// public function testCustomMappingImport() public function testCustomMappingImport()
// { {
// $csv = <<<'EOT' $csv = <<<'EOT'
// Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial number,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial number,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier
// Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan Bonnie Nelson,bnelson0@cdbaby.com,bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan
// EOT; EOT;
// $customFieldMap = [ $customFieldMap = [
// 'asset_tag' => 'Asset', 'asset_tag' => 'Asset',
// 'category' => 'Cat', 'category' => 'Cat',
// 'company' => 'comp', 'company' => 'comp',
// 'item_name' => 'object name', 'item_name' => 'object name',
// 'expiration_date' => 'expiration date', 'expiration_date' => 'expiration date',
// 'location' => 'loc', 'location' => 'loc',
// 'notes' => 'Some Notes', 'notes' => 'Some Notes',
// 'asset_model' => "model name", 'asset_model' => "model name",
// ]; ];
// $this->import(new AssetImporter($csv), $customFieldMap); $this->import(new AssetImporter($csv), $customFieldMap);
// // Did we create a user? // Did we create a user?
// $this->tester->seeRecord('users', [ $this->tester->seeRecord('users', [
// 'first_name' => 'Bonnie', 'first_name' => 'Bonnie',
// 'last_name' => 'Nelson', 'last_name' => 'Nelson',
// 'email' => 'bnelson0@cdbaby.com', 'email' => 'bnelson0@cdbaby.com',
// ]); ]);
// $this->tester->seeRecord('categories', [ $this->tester->seeRecord('categories', [
// 'name' => 'quam' 'name' => 'quam'
// ]); ]);
// $this->tester->seeRecord('models', [ $this->tester->seeRecord('models', [
// 'name' => 'massa id', 'name' => 'massa id',
// 'model_number' => 6377018600094472 'model_number' => 6377018600094472
// ]); ]);
// $this->tester->seeRecord('manufacturers', [ $this->tester->seeRecord('manufacturers', [
// 'name' => 'Linkbridge' 'name' => 'Linkbridge'
// ]); ]);
// $this->tester->seeRecord('locations', [ $this->tester->seeRecord('locations', [
// 'name' => 'Daping' 'name' => 'Daping'
// ]); ]);
// $this->tester->seeRecord('companies', [ $this->tester->seeRecord('companies', [
// 'name' => 'Alpha' 'name' => 'Alpha'
// ]); ]);
// $this->tester->seeRecord('status_labels', [ $this->tester->seeRecord('status_labels', [
// 'name' => 'Undeployable' 'name' => 'Undeployable'
// ]); ]);
// $this->tester->seeRecord('suppliers', [ $this->tester->seeRecord('suppliers', [
// 'name' => 'Blogspan' 'name' => 'Blogspan'
// ]); ]);
// $this->tester->seeRecord('assets', [ $this->tester->seeRecord('assets', [
// 'name' => 'eget nunc donec quis', 'name' => 'eget nunc donec quis',
// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147', 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',
// 'asset_tag' => '970882174-8', 'asset_tag' => '970882174-8',
// 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.", 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",
// 'purchase_date' => '2016-04-05 00:00:01', 'purchase_date' => '2016-04-05 00:00:01',
// 'purchase_cost' => 133289.59, 'purchase_cost' => 133289.59,
// 'warranty_months' => 14 'warranty_months' => 14
// ]); ]);
// } }
public function testDefaultAccessoryImport() public function testDefaultAccessoryImport()
{ {
@ -546,8 +546,6 @@ EOT;
if ($mappings) { if ($mappings) {
$importer->setFieldMappings($mappings); $importer->setFieldMappings($mappings);
} }
dd($this);
$importer->setUserId(1) $importer->setUserId(1)
->setUpdating(false) ->setUpdating(false)
->setUsernameFormat('firstname.lastname') ->setUsernameFormat('firstname.lastname')