Makes all manufacturer URLs dynamic, not just warranty lookup.

This commit is contained in:
steve@degga.net 2024-03-31 22:18:44 -04:00
parent c2d863da99
commit f7bbec6be4
3 changed files with 15 additions and 16 deletions

View file

@ -22,9 +22,9 @@ class Manufacturer extends SnipeModel
// Declare the rules for the form validation
protected $rules = [
'name' => 'required|min:2|max:255|unique:manufacturers,name,NULL,id,deleted_at,NULL',
'url' => 'url|nullable',
'url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://',
'support_email' => 'email|nullable',
'support_url' => 'nullable|url',
'support_url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://',
'warranty_lookup_url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://'
];

View file

@ -556,13 +556,12 @@ class AssetPresenter extends Presenter
}
/**
* Used to take user created warranty URL and dynamically fill in the needed values per asset
* Used to take user created URL and dynamically fill in the needed values per asset
* @return string
*/
public function dynamicWarrantyUrl()
public function dynamicWarrantyUrl($dynamic_url)
{
$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('{LOCALE}',\App\Models\Setting::getSettings()->locale, $dynamic_url));
$url = (str_replace('{SERIAL}', urlencode($this->model->serial), $url));
$url = (str_replace('{MODEL_NAME}', urlencode($this->model->model->name), $url));
$url = (str_replace('{MODEL_NUMBER}', urlencode($this->model->model->model_number), $url));

View file

@ -281,22 +281,22 @@
<li> {{ $asset->model->manufacturer->name }}</li>
@endcan
@if (($asset->model) && ($asset->model->manufacturer->url))
@if (($asset->model->manufacturer) && ($asset->model->manufacturer->url!=''))
<li>
<i class="fas fa-globe-americas" aria-hidden="true"></i>
<a href="{{ $asset->model->manufacturer->url }}" target="_blank">
{{ $asset->model->manufacturer->url }}
<i class="fa fa-external-link" aria-hidden="true"></i>
<a href="{{ $asset->present()->dynamicUrl($asset->model->manufacturer->url) }}" target="_blank">
{{ $asset->present()->dynamicUrl($asset->model->manufacturer->url) }}
<i class="fa fa-external-link" aria-hidden="true"><span class="sr-only"></span></i>
</a>
</li>
@endif
@if (($asset->model) && ($asset->model->manufacturer->support_url))
@if (($asset->model->manufacturer) && ($asset->model->manufacturer->support_url!=''))
<li>
<i class="far fa-life-ring" aria-hidden="true"></i>
<a href="{{ $asset->model->manufacturer->support_url }}" target="_blank">
{{ $asset->model->manufacturer->support_url }}
<i class="fa fa-external-link" aria-hidden="true"></i>
<a href="{{ $asset->present()->dynamicUrl($asset->model->manufacturer->support_url) }}" target="_blank">
{{$asset>present()>dynamicUrl($asset>model>manufacturer->support_url) }}
<i class="fa fa-external-link" aria-hidden="true"><span class="sr-only"></span></i>
</a>
</li>
@endif
@ -304,8 +304,8 @@
@if (($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!=''))
<li>
<i class="far fa-wrench" aria-hidden="true"></i>
<a href="{{ $asset->present()->dynamicWarrantyUrl() }}" target="_blank">
{{ $asset->present()->dynamicWarrantyUrl() }}
<a href="{{ $asset->present()->dynamicUrl($asset->model->manufacturer->warranty_lookup_url) }}" target="_blank">
{{ $asset->present()->dynamicUrl($asset->model->manufacturer->warranty_lookup_url) }}
<i class="fa fa-external-link" aria-hidden="true"><span class="sr-only">{{ trans('admin/hardware/general.mfg_warranty_lookup', ['manufacturer' => $asset->model->manufacturer->name]) }}</span></i>
</a>
</li>