Seed with demo images

This commit is contained in:
snipe 2017-10-28 05:46:43 -07:00
parent 46fb5c9d40
commit 4f1747023a
55 changed files with 199 additions and 20 deletions

View file

@ -159,6 +159,14 @@ class AssetModelsController extends Controller
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.assoc_users')));
}
if ($assetmodel->image) {
try {
unlink(public_path().'/uploads/models/'.$assetmodel->image);
} catch (\Exception $e) {
\Log::error($e);
}
}
$assetmodel->delete();
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/assetmodels/message.delete.success')));

View file

@ -93,7 +93,7 @@ class AssetModelsController extends Controller
if (Input::file('image')) {
$image = Input::file('image');
$file_name = str_random(25) . "." . $image->getClientOriginalExtension();
$file_name = slug($image->getClientOriginalName()) . "." . $image->getClientOriginalExtension();
$path = public_path('uploads/models/');
if ($image->getClientOriginalExtension()!='svg') {
@ -213,9 +213,17 @@ class AssetModelsController extends Controller
}
if (Input::file('image')) {
$image = Input::file('image');
$file_name = str_random(25) . "." . $image->getClientOriginalExtension();
$file_name = str_slug($image->getClientOriginalName()) . "." . $image->getClientOriginalExtension();
$path = public_path('uploads/models/');
$old_image = $path.$model->image;
try {
unlink($old_image);
} catch (\Exception $e) {
\Log::error($e);
}
if ($image->getClientOriginalExtension()!='svg') {
Image::make($image->getRealPath())->resize(500, null, function ($constraint) {
@ -259,6 +267,15 @@ class AssetModelsController extends Controller
// Throw an error that this model is associated with assets
return redirect()->route('models.index')->with('error', trans('admin/models/message.assoc_users'));
}
if ($model->image) {
try {
unlink(public_path().'/uploads/models/'.$model->image);
} catch (\Exception $e) {
\Log::error($e);
}
}
// Delete the model
$model->delete();

View file

@ -76,7 +76,7 @@ class ManufacturersController extends Controller
if ($request->file('image')) {
$image = $request->file('image');
$file_name = str_random(25).".".$image->getClientOriginalExtension();
$file_name = str_slug($image->getClientOriginalName()).".".$image->getClientOriginalExtension();
$path = public_path('uploads/manufacturers/'.$file_name);
Image::make($image->getRealPath())->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
@ -140,8 +140,17 @@ class ManufacturersController extends Controller
if ($request->file('image')) {
$image = $request->file('image');
$file_name = str_random(25).".".$image->getClientOriginalExtension();
$file_name = str_slug($image->getClientOriginalName()).".".$image->getClientOriginalExtension();
$path = public_path('uploads/manufacturers/'.$file_name);
$old_image = $path.$model->image;
try {
unlink($old_image);
} catch (\Exception $e) {
\Log::error($e);
}
Image::make($image->getRealPath())->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
@ -178,6 +187,16 @@ class ManufacturersController extends Controller
// Redirect to the asset management page
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.assoc_users'));
}
if ($manufacturer->image) {
try {
unlink(public_path().'/uploads/manufacturers/'.$manufacturer->image);
} catch (\Exception $e) {
\Log::error($e);
}
}
// Delete the manufacturer
$manufacturer->delete();
// Redirect to the manufacturers management page

View file

@ -34,7 +34,8 @@ $factory->defineAs(Actionlog::class, 'asset-checkout-user', function (Faker\Gene
->update(
[
'assigned_to' => $target->id,
'assigned_type' => App\Models\User::class
'assigned_type' => App\Models\User::class,
'assigned_to' => $target->location_id,
]
);
@ -59,7 +60,8 @@ $factory->defineAs(Actionlog::class, 'asset-checkout-location', function (Faker\
->update(
[
'assigned_to' => $target->id,
'assigned_type' => App\Models\Location::class
'assigned_type' => App\Models\Location::class,
'assigned_to' => $target->id,
]
);

View file

@ -16,7 +16,7 @@ use App\Models\Category;
$factory->define(Asset::class, function (Faker\Generator $faker) {
return [
'name' => null,
'rtd_location_id' => rand(1,30),
'rtd_location_id' => rand(1,10),
'serial' => $faker->uuid,
'status_id' => 1,
'user_id' => 1,

View file

@ -32,6 +32,7 @@ $factory->state(App\Models\AssetModel::class, 'mbp-13-model', function ($faker)
'manufacturer_id' => 1,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'mbp.jpg',
];
});
@ -43,6 +44,7 @@ $factory->state(App\Models\AssetModel::class, 'mbp-air-model', function ($faker)
'manufacturer_id' => 1,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'macbookair.jpg',
];
});
@ -54,6 +56,7 @@ $factory->state(App\Models\AssetModel::class, 'surface-model', function ($faker)
'manufacturer_id' => 2,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'surface.jpg',
];
});
@ -65,6 +68,7 @@ $factory->state(App\Models\AssetModel::class, 'xps13-model', function ($faker) {
'manufacturer_id' => 3,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'xps.jpg',
];
});
@ -76,6 +80,7 @@ $factory->state(App\Models\AssetModel::class, 'zenbook-model', function ($faker)
'manufacturer_id' => 4,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'zenbook.jpg',
];
});
@ -87,6 +92,7 @@ $factory->state(App\Models\AssetModel::class, 'spectre-model', function ($faker)
'manufacturer_id' => 5,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'spectre.jpg',
];
});
@ -98,6 +104,7 @@ $factory->state(App\Models\AssetModel::class, 'yoga-model', function ($faker) {
'manufacturer_id' => 6,
'eol' => '36',
'depreciation_id' => 1,
'image' => 'yoga.png',
];
});
@ -115,6 +122,7 @@ $factory->state(App\Models\AssetModel::class, 'macpro-model', function ($faker)
'manufacturer_id' => 1,
'eol' => '24',
'depreciation_id' => 1,
'image' => 'imacpro.jpg',
];
});
@ -125,6 +133,7 @@ $factory->state(App\Models\AssetModel::class, 'lenovo-i5-model', function ($fake
'manufacturer_id' => 6,
'eol' => '24',
'depreciation_id' => 1,
'image' => 'lenovoi5.png',
];
});
@ -136,6 +145,7 @@ $factory->state(App\Models\AssetModel::class, 'optiplex-model', function ($faker
'model_number' => '5040 (MRR81)',
'eol' => '24',
'depreciation_id' => 1,
'image' => 'optiplex.jpg',
];
});
@ -154,6 +164,7 @@ $factory->state(App\Models\AssetModel::class, 'polycom-model', function ($faker)
'manufacturer_id' => 8,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'soundstation.jpg',
];
});
@ -164,6 +175,7 @@ $factory->state(App\Models\AssetModel::class, 'polycomcx-model', function ($fake
'manufacturer_id' => 8,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'cx3000.png',
];
});
@ -181,6 +193,7 @@ $factory->state(App\Models\AssetModel::class, 'ipad-model', function ($faker) {
'manufacturer_id' => 1,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'ipad.jpg',
];
});
@ -192,6 +205,7 @@ $factory->state(App\Models\AssetModel::class, 'tab3-model', function ($faker) {
'manufacturer_id' => 6,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'tab3.png',
];
});
@ -209,6 +223,7 @@ $factory->state(App\Models\AssetModel::class, 'iphone6s-model', function ($faker
'manufacturer_id' => 1,
'eol' => '12',
'depreciation_id' => 3,
'image' => 'iphone6.jpg',
];
});
@ -219,6 +234,7 @@ $factory->state(App\Models\AssetModel::class, 'iphone7-model', function ($faker)
'manufacturer_id' => 1,
'eol' => '12',
'depreciation_id' => 1,
'image' => 'iphone7.jpg',
];
});
@ -235,6 +251,7 @@ $factory->state(App\Models\AssetModel::class, 'ultrafine', function ($faker) {
'manufacturer_id' => 7,
'eol' => '12',
'depreciation_id' => 2,
'image' => 'ultrafine.jpg',
];
});
@ -245,6 +262,7 @@ $factory->state(App\Models\AssetModel::class, 'ultrasharp', function ($faker) {
'manufacturer_id' => 3,
'eol' => '12',
'depreciation_id' => 2,
'image' => 'ultrasharp.jpg',
];
});

View file

@ -24,7 +24,8 @@ $factory->state(App\Models\Manufacturer::class, 'apple', function ($faker) {
return [
'name' => 'Apple',
'url' => 'https://apple.com',
'support_url' => 'https://support.apple.com'
'support_url' => 'https://support.apple.com',
'image' => 'apple.jpg',
];
});
@ -33,7 +34,8 @@ $factory->state(App\Models\Manufacturer::class, 'microsoft', function ($faker) {
return [
'name' => 'Microsoft',
'url' => 'https://microsoft.com',
'support_url' => 'https://support.microsoft.com'
'support_url' => 'https://support.microsoft.com',
'image' => 'microsoft.png',
];
});
@ -42,7 +44,8 @@ $factory->state(App\Models\Manufacturer::class, 'dell', function ($faker) {
return [
'name' => 'Dell',
'url' => 'https://dell.com',
'support_url' => 'https://support.dell.com'
'support_url' => 'https://support.dell.com',
'image' => 'dell.png',
];
});
@ -51,7 +54,8 @@ $factory->state(App\Models\Manufacturer::class, 'asus', function ($faker) {
return [
'name' => 'Asus',
'url' => 'https://asus.com',
'support_url' => 'https://support.asus.com'
'support_url' => 'https://support.asus.com',
'image' => 'asus.png',
];
});
@ -60,7 +64,8 @@ $factory->state(App\Models\Manufacturer::class, 'hp', function ($faker) {
return [
'name' => 'HP',
'url' => 'https://hp.com',
'support_url' => 'https://support.hp.com'
'support_url' => 'https://support.hp.com',
'image' => 'hp.png',
];
});
@ -69,7 +74,8 @@ $factory->state(App\Models\Manufacturer::class, 'lenovo', function ($faker) {
return [
'name' => 'Lenovo',
'url' => 'https://lenovo.com',
'support_url' => 'https://support.lenovo.com'
'support_url' => 'https://support.lenovo.com',
'image' => 'lenovo.jpg',
];
});
@ -78,7 +84,8 @@ $factory->state(App\Models\Manufacturer::class, 'lg', function ($faker) {
return [
'name' => 'LG',
'url' => 'https://lg.com',
'support_url' => 'https://support.lg.com'
'support_url' => 'https://support.lg.com',
'image' => 'lg.jpg',
];
});
@ -87,7 +94,8 @@ $factory->state(App\Models\Manufacturer::class, 'polycom', function ($faker) {
return [
'name' => 'Polycom',
'url' => 'https://polycom.com',
'support_url' => 'https://support.polycom.com'
'support_url' => 'https://support.polycom.com',
'image' => 'polycom.png',
];
});
@ -96,7 +104,8 @@ $factory->state(App\Models\Manufacturer::class, 'adobe', function ($faker) {
return [
'name' => 'Adobe',
'url' => 'https://adobe.com',
'support_url' => 'https://support.adobe.com'
'support_url' => 'https://support.adobe.com',
'image' => 'adobe.jpg',
];
});
@ -106,7 +115,8 @@ $factory->state(App\Models\Manufacturer::class, 'avery', function ($faker) {
return [
'name' => 'Avery',
'url' => 'https://avery.com',
'support_url' => 'https://support.avery.com'
'support_url' => 'https://support.avery.com',
'image' => 'avery.png',
];
});
@ -115,7 +125,8 @@ $factory->state(App\Models\Manufacturer::class, 'crucial', function ($faker) {
return [
'name' => 'Crucial',
'url' => 'https://crucial.com',
'support_url' => 'https://support.crucial.com'
'support_url' => 'https://support.crucial.com',
'image' => 'crucial.jpg',
];
});

View file

@ -55,7 +55,8 @@ $factory->define(App\Models\Location::class, function (Faker\Generator $faker) {
'state' => $faker->stateAbbr,
'country' => $faker->countryCode,
'currency' => $faker->currencyCode,
'zip' => $faker->postcode
'zip' => $faker->postcode,
'image' => rand(1,9).'.jpg',
];
});

View file

@ -39,6 +39,23 @@ class AssetModelSeeder extends Seeder
factory(AssetModel::class, 1)->states('ultrafine')->create(); // 17
factory(AssetModel::class, 1)->states('ultrasharp')->create(); // 18
$src = public_path('/img/demo/models');
$dst = public_path('/uploads/models');
$del_files = glob($dst."/*.*");
foreach($del_files as $del_file){ // iterate files
if(is_file($del_file))
unlink($del_file); // delete file
}
$add_files = glob($src."/*.*");
foreach($add_files as $add_file){
$file_to_copy = str_replace($src,$dst,$add_file);
copy($add_file, $file_to_copy);
}
}

View file

@ -35,5 +35,15 @@ class AssetSeeder extends Seeder
factory(Asset::class, 10)->states('ultrasharp')->create();
$dst = public_path('/uploads/assets');
$del_files = glob($dst."/*.*");
foreach($del_files as $del_file){ // iterate files
if(is_file($del_file))
unlink($del_file); // delete file
}
}
}

View file

@ -15,5 +15,23 @@ class CompanySeeder extends Seeder
//
Company::truncate();
factory(Company::class, 4)->create();
$src = public_path('/img/demo/companies');
$dst = public_path('/uploads/companies');
$del_files = glob($dst."/*.*");
foreach($del_files as $del_file){ // iterate files
if(is_file($del_file))
unlink($del_file); // delete file
}
$add_files = glob($src."/*.*");
foreach($add_files as $add_file){
$file_to_copy = str_replace($src,$dst,$add_file);
copy($add_file, $file_to_copy);
}
}
}

View file

@ -8,6 +8,24 @@ class LocationSeeder extends Seeder
public function run()
{
Location::truncate();
factory(Location::class, 30)->create();
factory(Location::class, 10)->create();
$src = public_path('/img/demo/locations');
$dst = public_path('/uploads/locations');
$del_files = glob($dst."/*.*");
foreach($del_files as $del_file){ // iterate files
if(is_file($del_file))
unlink($del_file); // delete file
}
$add_files = glob($src."/*.*");
foreach($add_files as $add_file){
$file_to_copy = str_replace($src,$dst,$add_file);
copy($add_file, $file_to_copy);
}
}
}

View file

@ -17,6 +17,27 @@ class ManufacturerSeeder extends Seeder
factory(Manufacturer::class, 1)->states('polycom')->create(); // 8
factory(Manufacturer::class, 1)->states('adobe')->create(); // 9
factory(Manufacturer::class, 1)->states('avery')->create(); // 10
factory(Manufacturer::class, 1)->states('crucial')->create(); // 10
$src = public_path('/img/demo/manufacturers');
$dst = public_path('/uploads/manufacturers');
$del_files = glob($dst."/*.*");
foreach($del_files as $del_file){ // iterate files
if(is_file($del_file))
unlink($del_file); // delete file
}
$add_files = glob($src."/*.*");
foreach($add_files as $add_file){
$file_to_copy = str_replace($src,$dst,$add_file);
copy($add_file, $file_to_copy);
}
}
}

View file

@ -8,5 +8,23 @@ class SupplierSeeder extends Seeder
{
Supplier::truncate();
factory(Supplier::class, 5)->create();
$src = public_path('/img/demo/suppliers');
$dst = public_path('/uploads/suppliers');
$del_files = glob($dst."/*.*");
foreach($del_files as $del_file){ // iterate files
if(is_file($del_file))
unlink($del_file); // delete file
}
$add_files = glob($src."/*.*");
foreach($add_files as $add_file){
$file_to_copy = str_replace($src,$dst,$add_file);
copy($add_file, $file_to_copy);
}
}
}

View file

@ -18,5 +18,6 @@ class UserSeeder extends Seeder
factory(User::class, 3)->states('superuser')->create();
factory(User::class, 3)->states('admin')->create();
factory(User::class, 50)->states('view-assets')->create();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB