From 54a766c4f9753a5a2e9749800f532269d869712d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 26 Apr 2023 16:39:15 -0700 Subject: [PATCH 1/2] Added dynamic warranty URL to manufacturers Signed-off-by: snipe --- .../Api/ManufacturersController.php | 8 +++-- .../Controllers/ManufacturersController.php | 2 ++ .../Transformers/ManufacturersTransformer.php | 1 + app/Models/Manufacturer.php | 2 ++ app/Presenters/AssetPresenter.php | 12 +++---- app/Presenters/ManufacturerPresenter.php | 9 ++++++ database/factories/ManufacturerFactory.php | 3 ++ ...0235_add_warranty_url_to_manufacturers.php | 32 +++++++++++++++++++ .../lang/en/admin/manufacturers/table.php | 1 + resources/views/hardware/view.blade.php | 6 ++-- resources/views/manufacturers/edit.blade.php | 11 +++++++ 11 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 database/migrations/2023_04_26_160235_add_warranty_url_to_manufacturers.php diff --git a/app/Http/Controllers/Api/ManufacturersController.php b/app/Http/Controllers/Api/ManufacturersController.php index f3183238bf..9ff0a0c202 100644 --- a/app/Http/Controllers/Api/ManufacturersController.php +++ b/app/Http/Controllers/Api/ManufacturersController.php @@ -23,10 +23,10 @@ class ManufacturersController extends Controller public function index(Request $request) { $this->authorize('view', Manufacturer::class); - $allowed_columns = ['id', 'name', 'url', 'support_url', 'support_email', 'support_phone', 'created_at', 'updated_at', 'image', 'assets_count', 'consumables_count', 'components_count', 'licenses_count']; + $allowed_columns = ['id', 'name', 'url', 'support_url', 'support_email', 'warranty_lookup_url', 'support_phone', 'created_at', 'updated_at', 'image', 'assets_count', 'consumables_count', 'components_count', 'licenses_count']; $manufacturers = Manufacturer::select( - ['id', 'name', 'url', 'support_url', 'support_email', 'support_phone', 'created_at', 'updated_at', 'image', 'deleted_at'] + ['id', 'name', 'url', 'support_url', 'warranty_lookup_url', 'support_email', 'support_phone', 'created_at', 'updated_at', 'image', 'deleted_at'] )->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count'); if ($request->input('deleted') == 'true') { @@ -49,6 +49,10 @@ class ManufacturersController extends Controller $manufacturers->where('support_url', '=', $request->input('support_url')); } + if ($request->filled('warranty_lookup_url')) { + $manufacturers->where('warranty_lookup_url', '=', $request->input('warranty_lookup_url')); + } + if ($request->filled('support_phone')) { $manufacturers->where('support_phone', '=', $request->input('support_phone')); } diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index e849d70a14..e98644f46f 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -68,6 +68,7 @@ class ManufacturersController extends Controller $manufacturer->user_id = Auth::id(); $manufacturer->url = $request->input('url'); $manufacturer->support_url = $request->input('support_url'); + $manufacturer->warranty_lookup_url = $request->input('warranty_lookup_url'); $manufacturer->support_phone = $request->input('support_phone'); $manufacturer->support_email = $request->input('support_email'); $manufacturer = $request->handleImages($manufacturer); @@ -127,6 +128,7 @@ class ManufacturersController extends Controller $manufacturer->name = $request->input('name'); $manufacturer->url = $request->input('url'); $manufacturer->support_url = $request->input('support_url'); + $manufacturer->warranty_lookup_url = $request->input('warranty_lookup_url'); $manufacturer->support_phone = $request->input('support_phone'); $manufacturer->support_email = $request->input('support_email'); diff --git a/app/Http/Transformers/ManufacturersTransformer.php b/app/Http/Transformers/ManufacturersTransformer.php index bbcbda12b4..9c84fd50fe 100644 --- a/app/Http/Transformers/ManufacturersTransformer.php +++ b/app/Http/Transformers/ManufacturersTransformer.php @@ -29,6 +29,7 @@ class ManufacturersTransformer 'url' => e($manufacturer->url), 'image' => ($manufacturer->image) ? Storage::disk('public')->url('manufacturers/'.e($manufacturer->image)) : null, 'support_url' => e($manufacturer->support_url), + 'warranty_lookup_url' => e($manufacturer->warranty_lookup_url), 'support_phone' => e($manufacturer->support_phone), 'support_email' => e($manufacturer->support_email), 'assets_count' => (int) $manufacturer->assets_count, diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php index 099a978778..4f11708248 100755 --- a/app/Models/Manufacturer.php +++ b/app/Models/Manufacturer.php @@ -25,6 +25,7 @@ class Manufacturer extends SnipeModel 'url' => 'url|nullable', 'support_email' => 'email|nullable', 'support_url' => 'starts_with:http://,https://,afp://,facetime://,file://,irc://','nullable', + 'warranty_lookup_url' => 'starts_with:http://,https://,afp://,facetime://,file://,irc://','nullable' ]; protected $hidden = ['user_id']; @@ -51,6 +52,7 @@ class Manufacturer extends SnipeModel 'support_phone', 'support_url', 'url', + 'warranty_lookup_url', ]; use Searchable; diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index 06364fe31a..ef8ae632a6 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -538,14 +538,12 @@ class AssetPresenter extends Presenter * Used to take user created warranty URL and dynamically fill in the needed values per asset * @return string */ - public function supportUrl() + public function dynamicVariableUrl() { - $tempurl = $this->model->model->manufacturer->support_url; - - $tempurl = (str_replace('{LOCALE}',\App\Models\Setting::getSettings()->locale,$tempurl)); - $tempurl = (str_replace('{SERIAL}',$this->model->serial,$tempurl)); - - return $tempurl; + $warranty_lookup_url = $this->model->model->manufacturer->warranty_lookup_url; + $url = (str_replace('{LOCALE}',\App\Models\Setting::getSettings()->locale,$warranty_lookup_url)); + $url = (str_replace('{SERIAL}',$this->model->serial,$url)); + return $url; } /** diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.php index 5b44a76933..bc1f08c0d2 100644 --- a/app/Presenters/ManufacturerPresenter.php +++ b/app/Presenters/ManufacturerPresenter.php @@ -78,6 +78,15 @@ class ManufacturerPresenter extends Presenter 'visible' => true, 'formatter' => 'emailFormatter', ], + [ + 'field' => 'warranty_lookup_url', + 'searchable' => true, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('admin/manufacturers/table.warranty_lookup_url'), + 'visible' => false, + 'formatter' => 'linkFormatter', + ], [ 'field' => 'assets_count', diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.php index ab22262a78..4e736b8d8a 100644 --- a/database/factories/ManufacturerFactory.php +++ b/database/factories/ManufacturerFactory.php @@ -38,6 +38,7 @@ class ManufacturerFactory extends Factory 'name' => 'Apple', 'url' => 'https://apple.com', 'support_url' => 'https://support.apple.com', + 'warranty_lookup_url' => 'https://checkcoverage.apple.com', 'image' => 'apple.jpg', ]; }); @@ -50,6 +51,7 @@ class ManufacturerFactory extends Factory 'name' => 'Microsoft', 'url' => 'https://microsoft.com', 'support_url' => 'https://support.microsoft.com', + 'warranty_lookup_url' => 'https://account.microsoft.com/devices', 'image' => 'microsoft.png', ]; }); @@ -62,6 +64,7 @@ class ManufacturerFactory extends Factory 'name' => 'Dell', 'url' => 'https://dell.com', 'support_url' => 'https://support.dell.com', + 'warranty_lookup_url' => 'https://www.dell.com/support/home/en-us/Products/?app=warranty', 'image' => 'dell.png', ]; }); diff --git a/database/migrations/2023_04_26_160235_add_warranty_url_to_manufacturers.php b/database/migrations/2023_04_26_160235_add_warranty_url_to_manufacturers.php new file mode 100644 index 0000000000..52a655f2e4 --- /dev/null +++ b/database/migrations/2023_04_26_160235_add_warranty_url_to_manufacturers.php @@ -0,0 +1,32 @@ +string('warranty_lookup_url')->after('support_url')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('manufacturers', function (Blueprint $table) { + $table->dropColumn('warranty_lookup_url'); + }); + } +} diff --git a/resources/lang/en/admin/manufacturers/table.php b/resources/lang/en/admin/manufacturers/table.php index 4e3ea9904d..38cab6fd91 100644 --- a/resources/lang/en/admin/manufacturers/table.php +++ b/resources/lang/en/admin/manufacturers/table.php @@ -10,6 +10,7 @@ return array( 'support_email' => 'Support Email', 'support_phone' => 'Support Phone', 'support_url' => 'Support URL', + 'warranty_lookup_url' => 'Warranty Lookup URL', 'update' => 'Update Manufacturer', 'url' => 'URL', diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 1cea928469..673488960c 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -595,9 +595,9 @@ {{ $asset->warranty_months }} {{ trans('admin/hardware/form.months') }} - @if ($asset->serial && $asset->model->manufacturer) - - {{ trans('hardware/general.mfg_warranty_lookup') }} + @if (($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!='')) + + {{ trans('hardware/general.mfg_warranty_lookup') }} @endif diff --git a/resources/views/manufacturers/edit.blade.php b/resources/views/manufacturers/edit.blade.php index c533718b85..01d7c696d6 100755 --- a/resources/views/manufacturers/edit.blade.php +++ b/resources/views/manufacturers/edit.blade.php @@ -31,6 +31,17 @@ + +
+ +
+ +

{!! trans('admin/manufacturers/message.support_url_help') !!}

+ {!! $errors->first('warranty_lookup_url', '') !!} +
+
+
-

{!! trans('admin/manufacturers/message.support_url_help') !!}

{!! $errors->first('support_url', '') !!}