From f7bbec6be49c21c0319ab9046fb3e6450ac64281 Mon Sep 17 00:00:00 2001 From: "steve@degga.net" Date: Sun, 31 Mar 2024 22:18:44 -0400 Subject: [PATCH] Makes all manufacturer URLs dynamic, not just warranty lookup. --- app/Models/Manufacturer.php | 4 ++-- app/Presenters/AssetPresenter.php | 7 +++---- resources/views/hardware/view.blade.php | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php index 5408d50c36..85907f7ddb 100755 --- a/app/Models/Manufacturer.php +++ b/app/Models/Manufacturer.php @@ -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://' ]; diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index 163ee1b606..16bb384176 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -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)); diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 461f2a4688..570cf2745a 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -281,22 +281,22 @@
  • {{ $asset->model->manufacturer->name }}
  • @endcan - @if (($asset->model) && ($asset->model->manufacturer->url)) + @if (($asset->model->manufacturer) && ($asset->model->manufacturer->url!=''))
  • - - {{ $asset->model->manufacturer->url }} - + + {{ $asset->present()->dynamicUrl($asset->model->manufacturer->url) }} +
  • @endif - @if (($asset->model) && ($asset->model->manufacturer->support_url)) + @if (($asset->model->manufacturer) && ($asset->model->manufacturer->support_url!=''))
  • - - {{ $asset->model->manufacturer->support_url }} - + + {{$asset>present()>dynamicUrl($asset>model>manufacturer->support_url) }} +
  • @endif @@ -304,8 +304,8 @@ @if (($asset->model->manufacturer) && ($asset->model->manufacturer->warranty_lookup_url!=''))
  • - - {{ $asset->present()->dynamicWarrantyUrl() }} + + {{ $asset->present()->dynamicUrl($asset->model->manufacturer->warranty_lookup_url) }}