Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/Http/Controllers/Api/AssetMaintenancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Requests\ImageUploadRequest;
use App\Http\Transformers\AssetMaintenancesTransformer;
use App\Models\Asset;
use App\Models\AssetMaintenance;
Expand Down Expand Up @@ -126,14 +127,15 @@ public function index(Request $request) : JsonResponse | array
* @version v1.0
* @since [v1.8]
*/
public function store(Request $request) : JsonResponse | array
public function store(ImageUploadRequest $request) : JsonResponse | array
{
$this->authorize('update', Asset::class);

// create a new model instance
$maintenance = new AssetMaintenance();
$maintenance->fill($request->all());
$maintenance->created_by = auth()->id();

$maintenance = $request->handleImages($maintenance);
// Was the asset maintenance created?
if ($maintenance->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $maintenance, trans('admin/asset_maintenances/message.create.success')));
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/AssetMaintenancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Http\Requests\ImageUploadRequest;
use App\Models\Asset;
use App\Models\AssetMaintenance;
use App\Models\Company;
Expand Down Expand Up @@ -69,7 +70,7 @@ public function create() : View
* @version v1.0
* @since [v1.8]
*/
public function store(Request $request) : RedirectResponse
public function store(ImageUploadRequest $request) : RedirectResponse
{
$this->authorize('update', Asset::class);

Expand Down Expand Up @@ -101,6 +102,7 @@ public function store(Request $request) : RedirectResponse
$assetMaintenance->asset_maintenance_time = (int) $completionDate->diffInDays($startDate, true);
}

$assetMaintenance = $request->handleImages($assetMaintenance);

// Was the asset maintenance created?
if (!$assetMaintenance->save()) {
Expand Down Expand Up @@ -143,7 +145,7 @@ public function edit(AssetMaintenance $maintenance) : View | RedirectResponse
* @version v1.0
* @since [v1.8]
*/
public function update(Request $request, AssetMaintenance $maintenance) : View | RedirectResponse
public function update(ImageUploadRequest $request, AssetMaintenance $maintenance) : View | RedirectResponse
{
$this->authorize('update', Asset::class);
$this->authorize('update', $maintenance->asset);
Expand Down Expand Up @@ -176,6 +178,7 @@ public function update(Request $request, AssetMaintenance $maintenance) : View |
$completionDate = Carbon::parse($maintenance->completion_date);
$maintenance->asset_maintenance_time = (int) $completionDate->diffInDays($startDate, true);
}
$maintenance = $request->handleImages($maintenance);

if ($maintenance->save()) {
return redirect()->route('maintenances.index')
Expand Down
13 changes: 10 additions & 3 deletions app/Http/Requests/ImageUploadRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Intervention\Image\Exception\NotReadableException;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;

class ImageUploadRequest extends Request
{
Expand Down Expand Up @@ -70,11 +71,12 @@ protected function base64FileKeys(): array
public function handleImages($item, $w = 600, $form_fieldname = 'image', $path = null, $db_fieldname = 'image')
{

$type = strtolower(class_basename(get_class($item)));
$type = Str::snake(class_basename(get_class($item)));

if (is_null($path)) {

$path = str_plural($type);
\Log::debug('path is null');
$path = Str::of(str_plural($type))->snake();

if ($type == 'assetmodel') {
$path = 'models';
Expand All @@ -85,6 +87,11 @@ public function handleImages($item, $w = 600, $form_fieldname = 'image', $path =
}
}


if (!Storage::exists($path)) {
Storage::makeDirectory($path);
}

if ($this->offsetGet($form_fieldname) instanceof UploadedFile) {
$image = $this->offsetGet($form_fieldname);
} elseif ($this->hasFile($form_fieldname)) {
Expand All @@ -96,7 +103,7 @@ public function handleImages($item, $w = 600, $form_fieldname = 'image', $path =
if (!config('app.lock_passwords')) {

$ext = $image->guessExtension();
$file_name = $type.'-'.$form_fieldname.'-'.$item->id.'-'.str_random(10).'.'.$ext;
$file_name = $type.'-'.$form_fieldname.($item->id ?? '-'.$item->id).'-'.str_random(10).'.'.$ext;

if (($image->getMimeType() == 'image/vnd.microsoft.icon') || ($image->getMimeType() == 'image/x-icon') || ($image->getMimeType() == 'image/avif') || ($image->getMimeType() == 'image/webp')) {
// If the file is an icon, webp or avif, we need to just move it since gd doesn't support resizing
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Transformers/AssetMaintenancesTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\AssetMaintenance;
use Illuminate\Support\Facades\Gate;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Storage;

class AssetMaintenancesTransformer
{
Expand All @@ -33,6 +34,7 @@ public function transformAssetMaintenance(AssetMaintenance $assetmaintenance)
'created_at' => Helper::getFormattedDateObject($assetmaintenance->asset->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmaintenance->asset->updated_at, 'datetime'),
] : null,
'image' => ($assetmaintenance->image != '') ? Storage::disk('public')->url('asset_maintenances/'.e($assetmaintenance->image)) : null,
'model' => (($assetmaintenance->asset) && ($assetmaintenance->asset->model)) ? [
'id' => (int) $assetmaintenance->asset->model->id,
'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null,
Expand Down
9 changes: 9 additions & 0 deletions app/Presenters/AssetMaintenancesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public static function dataTableLayout()
'visible' => true,
'formatter' => 'maintenancesLinkFormatter',
],
[
'field' => 'image',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.image'),
'visible' => true,
'formatter' => 'imageFormatter',
],
[
'field' => 'company',
'searchable' => true,
Expand Down
60 changes: 32 additions & 28 deletions app/Providers/SettingsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function boot()


// Make sure the limit is actually set, is an integer and does not exceed system limits
\App::singleton('api_limit_value', function () {
app()->singleton('api_limit_value', function () {
$limit = config('app.max_results');
$int_limit = intval(request('limit'));

Expand All @@ -43,7 +43,7 @@ public function boot()
});

// Make sure the offset is actually set and is an integer
\App::singleton('api_offset_value', function () {
app()->singleton('api_offset_value', function () {
$offset = intval(request('offset'));
return $offset;
});
Expand All @@ -57,117 +57,121 @@ public function boot()
// Model paths and URLs


\App::singleton('eula_pdf_path', function () {
app()->singleton('eula_pdf_path', function () {
return 'eula_pdf_path/';
});

\App::singleton('assets_upload_path', function () {
app()->singleton('assets_upload_path', function () {
return 'assets/';
});

\App::singleton('audits_upload_path', function () {
app()->singleton('asset_maintenances_path', function () {
return 'asset_maintenances/';
});

app()->singleton('audits_upload_path', function () {
return 'audits/';
});

\App::singleton('accessories_upload_path', function () {
app()->singleton('accessories_upload_path', function () {
return 'public/uploads/accessories/';
});

\App::singleton('models_upload_path', function () {
app()->singleton('models_upload_path', function () {
return 'models/';
});

\App::singleton('models_upload_url', function () {
app()->singleton('models_upload_url', function () {
return 'models/';
});

// Categories
\App::singleton('categories_upload_path', function () {
app()->singleton('categories_upload_path', function () {
return 'categories/';
});

\App::singleton('categories_upload_url', function () {
app()->singleton('categories_upload_url', function () {
return 'categories/';
});

// Locations
\App::singleton('locations_upload_path', function () {
app()->singleton('locations_upload_path', function () {
return 'locations/';
});

\App::singleton('locations_upload_url', function () {
app()->singleton('locations_upload_url', function () {
return 'locations/';
});

// Users
\App::singleton('users_upload_path', function () {
app()->singleton('users_upload_path', function () {
return 'avatars/';
});

\App::singleton('users_upload_url', function () {
app()->singleton('users_upload_url', function () {
return 'users/';
});

// Manufacturers
\App::singleton('manufacturers_upload_path', function () {
app()->singleton('manufacturers_upload_path', function () {
return 'manufacturers/';
});

\App::singleton('manufacturers_upload_url', function () {
app()->singleton('manufacturers_upload_url', function () {
return 'manufacturers/';
});

// Suppliers
\App::singleton('suppliers_upload_path', function () {
app()->singleton('suppliers_upload_path', function () {
return 'suppliers/';
});

\App::singleton('suppliers_upload_url', function () {
app()->singleton('suppliers_upload_url', function () {
return 'suppliers/';
});

// Departments
\App::singleton('departments_upload_path', function () {
app()->singleton('departments_upload_path', function () {
return 'departments/';
});

\App::singleton('departments_upload_url', function () {
app()->singleton('departments_upload_url', function () {
return 'departments/';
});

// Company paths and URLs
\App::singleton('companies_upload_path', function () {
app()->singleton('companies_upload_path', function () {
return 'companies/';
});

\App::singleton('companies_upload_url', function () {
app()->singleton('companies_upload_url', function () {
return 'companies/';
});

// Accessories paths and URLs
\App::singleton('accessories_upload_path', function () {
app()->singleton('accessories_upload_path', function () {
return 'accessories/';
});

\App::singleton('accessories_upload_url', function () {
app()->singleton('accessories_upload_url', function () {
return 'accessories/';
});

// Consumables paths and URLs
\App::singleton('consumables_upload_path', function () {
app()->singleton('consumables_upload_path', function () {
return 'consumables/';
});

\App::singleton('consumables_upload_url', function () {
app()->singleton('consumables_upload_url', function () {
return 'consumables/';
});

// Components paths and URLs
\App::singleton('components_upload_path', function () {
app()->singleton('components_upload_path', function () {
return 'components/';
});

\App::singleton('components_upload_url', function () {
app()->singleton('components_upload_url', function () {
return 'components/';
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('asset_maintenances', function (Blueprint $table) {
if (!Schema::hasColumn('asset_maintenances', 'image')) {
$table->text('image')->after('notes')->nullable()->default(null);
}
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('asset_maintenances', function (Blueprint $table) {
$table->dropColumn('image');
});
}
};
7 changes: 5 additions & 2 deletions resources/views/asset_maintenances/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<div class="row">
<div class="col-md-9">
@if ($item->id)
<form class="form-horizontal" method="post" action="{{ route('maintenances.update', $item->id) }}" autocomplete="off">
<form class="form-horizontal" method="post" action="{{ route('maintenances.update', $item->id) }}" autocomplete="off" enctype="multipart/form-data">
{{ method_field('PUT') }}
@else
<form class="form-horizontal" method="post" action="{{ route('maintenances.store') }}" autocomplete="off">
<form class="form-horizontal" method="post" action="{{ route('maintenances.store') }}" autocomplete="off" enctype="multipart/form-data">
@endif
<!-- CSRF Token -->
{{ csrf_field() }}
Expand Down Expand Up @@ -179,6 +179,9 @@
</div>
</div>

@include ('partials.forms.edit.image-upload', ['image_path' => app('asset_maintenances_path')])


<!-- Notes -->
<div class="form-group {{ $errors->has('notes') ? ' has-error' : '' }}">
<label for="notes" class="col-md-3 control-label">{{ trans('admin/asset_maintenances/form.notes') }}</label>
Expand Down
Loading
Loading