Added dynamic warranty URL to manufacturers

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2023-04-26 16:39:15 -07:00
parent ef69df2cdf
commit 54a766c4f9
11 changed files with 75 additions and 12 deletions

View file

@ -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'));
}

View file

@ -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');

View file

@ -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,

View file

@ -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;

View file

@ -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;
}
/**

View file

@ -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',

View file

@ -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',
];
});

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddWarrantyUrlToManufacturers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('manufacturers', function (Blueprint $table) {
$table->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');
});
}
}

View file

@ -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',

View file

@ -595,9 +595,9 @@
{{ $asset->warranty_months }}
{{ trans('admin/hardware/form.months') }}
@if ($asset->serial && $asset->model->manufacturer)
<a href="{{ $asset->present()->supportUrl() }}" target="_blank">
<i class="fa fa-external-link" style="width:25px;height:25px;"><span class="sr-only">{{ trans('hardware/general.mfg_warranty_lookup') }}</span></i>
@if (($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!=''))
<a href="{{ $asset->present()->dynamicVariableUrl() }}" target="_blank">
<i class="fa fa-external-link"><span class="sr-only">{{ trans('hardware/general.mfg_warranty_lookup') }}</span></i>
</a>
@endif
</div>

View file

@ -31,6 +31,17 @@
</div>
</div>
<!-- Warranty Lookup URL -->
<div class="form-group {{ $errors->has('warranty_lookup_url') ? ' has-error' : '' }}">
<label for="support_url" class="col-md-3 control-label">{{ trans('admin/manufacturers/table.warranty_lookup_url') }}
</label>
<div class="col-md-6">
<input class="form-control" type="text" name="warranty_lookup_url" id="warranty_lookup_url" value="{{ old('warranty_lookup_url', $item->warranty_lookup_url) }}" />
<p class="help-block">{!! trans('admin/manufacturers/message.support_url_help') !!}</p>
{!! $errors->first('warranty_lookup_url', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
<!-- Support Phone -->
<div class="form-group {{ $errors->has('support_phone') ? ' has-error' : '' }}">
<label for="support_phone" class="col-md-3 control-label">{{ trans('admin/manufacturers/table.support_phone') }}