Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added #14426: Makes all Manufacturer links dynamic, not just warranty lookup #14530

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions app/Models/Manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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://'
];

Expand Down
7 changes: 3 additions & 4 deletions app/Presenters/AssetPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,12 @@ public function warranty_expires()
}

/**
* 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 dynamicUrl($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));
Expand Down
22 changes: 11 additions & 11 deletions resources/views/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,31 +281,31 @@
<li> {{ $asset->model->manufacturer->name }}</li>
@endcan

@if (($asset->model) && ($asset->model->manufacturer->url))
@if (($asset->model->manufacturer) && ($asset->model->manufacturer->url!=''))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do actually have to keep the model check here, in case someone deleted a model directly from the database. In that case, ($asset->model->manufacturer) will 500, since we're looking for a property on a relationship that doesn't exist.

<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>
DrekiDegga marked this conversation as resolved.
Show resolved Hide resolved
</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

@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>
Expand Down Expand Up @@ -575,7 +575,7 @@
{{ trans('admin/hardware/form.months') }}

@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>
</a>
@endif
Expand Down