Merge pull request #14530 from DrekiDegga/develop

Added #14426: Makes all Manufacturer links dynamic, not just warranty lookup
This commit is contained in:
snipe 2024-07-19 19:07:25 +01:00 committed by GitHub
commit b7ab8b9e8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 16 deletions

View file

@ -22,9 +22,9 @@ class Manufacturer extends SnipeModel
// Declare the rules for the form validation // Declare the rules for the form validation
protected $rules = [ protected $rules = [
'name' => 'required|min:2|max:255|unique:manufacturers,name,NULL,id,deleted_at,NULL', '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_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://' '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 * @return string
*/ */
public function dynamicWarrantyUrl() public function dynamicUrl($dynamic_url)
{ {
$warranty_lookup_url = $this->model->model->manufacturer->warranty_lookup_url; $url = (str_replace('{LOCALE}',\App\Models\Setting::getSettings()->locale, $dynamic_url));
$url = (str_replace('{LOCALE}',\App\Models\Setting::getSettings()->locale, $warranty_lookup_url));
$url = (str_replace('{SERIAL}', urlencode($this->model->serial), $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_NAME}', urlencode($this->model->model->name), $url));
$url = (str_replace('{MODEL_NUMBER}', urlencode($this->model->model->model_number), $url)); $url = (str_replace('{MODEL_NUMBER}', urlencode($this->model->model->model_number), $url));

View file

@ -299,21 +299,21 @@
<li> {{ $asset->model->manufacturer->name }}</li> <li> {{ $asset->model->manufacturer->name }}</li>
@endcan @endcan
@if (($asset->model) && ($asset->model->manufacturer->url)) @if (($asset->model->manufacturer) && ($asset->model->manufacturer->url!=''))
<li> <li>
<i class="fas fa-globe-americas" aria-hidden="true"></i> <i class="fas fa-globe-americas" aria-hidden="true"></i>
<a href="{{ $asset->model->manufacturer->url }}" target="_blank"> <a href="{{ $asset->present()->dynamicUrl($asset->model->manufacturer->url) }}" target="_blank">
{{ $asset->model->manufacturer->url }} {{ $asset->present()->dynamicUrl($asset->model->manufacturer->url) }}
<i class="fa fa-external-link" aria-hidden="true"></i> <i class="fa fa-external-link" aria-hidden="true"></i>
</a> </a>
</li> </li>
@endif @endif
@if (($asset->model) && ($asset->model->manufacturer->support_url)) @if (($asset->model->manufacturer) && ($asset->model->manufacturer->support_url!=''))
<li> <li>
<i class="far fa-life-ring" aria-hidden="true"></i> <i class="far fa-life-ring" aria-hidden="true"></i>
<a href="{{ $asset->model->manufacturer->support_url }}" target="_blank"> <a href="{{ $asset->present()->dynamicUrl($asset->model->manufacturer->support_url) }}" target="_blank">
{{ $asset->model->manufacturer->support_url }} {{ $asset->present()->dynamicUrl($asset->model->manufacturer->support_url) }}
<i class="fa fa-external-link" aria-hidden="true"></i> <i class="fa fa-external-link" aria-hidden="true"></i>
</a> </a>
</li> </li>
@ -321,9 +321,10 @@
@if (($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!='')) @if (($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!=''))
<li> <li>
<i class="fa-solid fa-wrench" aria-hidden="true"></i> <i class="far fa-wrench" aria-hidden="true"></i>
<a href="{{ $asset->present()->dynamicWarrantyUrl() }}" target="_blank"> <a href="{{ $asset->present()->dynamicUrl($asset->model->manufacturer->warranty_lookup_url) }}" target="_blank">
{{ $asset->present()->dynamicWarrantyUrl() }} {{ $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> <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> </a>
</li> </li>
@ -598,7 +599,7 @@
{{ trans('admin/hardware/form.months') }} {{ trans('admin/hardware/form.months') }}
@if (($asset->model) && ($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!='')) @if (($asset->model) && ($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!=''))
<a href="{{ $asset->present()->dynamicWarrantyUrl() }}" target="_blank"> <a href="{{ $asset->present()->dynamicUrl($asset->model->manufacturer->warranty_lookup_url) }}" target="_blank">
<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> <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> </a>
@endif @endif