A free open source IT asset/license management system
View presenters (#3099)
Daniel Meltzer02c1a4502548
diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.phpindex ca3be474eb..1f557bdf15 100755--- a/app/Http/Controllers/StatuslabelsController.php+++ b/app/Http/Controllers/StatuslabelsController.php@@ -281,7 +281,7 @@ class StatuslabelsController extends Controller$actions .= Helper::generateDatatableButton('edit', route('statuslabels.edit', $statuslabel->id));$actions .= Helper::generateDatatableButton('delete',- route('statuslabels.destroy', ['statuslabel' => $statuslabel->id]),+ route('statuslabels.destroy', $statuslabel->id),true, /*enabled*/trans('admin/statuslabels/message.delete.confirm'),$statuslabel->namediff --git a/app/Presenters/AssetModelPresenter.php b/app/Presenters/AssetModelPresenter.phpindex 6938fcf583..23268a3d11 100644--- a/app/Presenters/AssetModelPresenter.php+++ b/app/Presenters/AssetModelPresenter.php@@ -42,7 +42,7 @@ class AssetModelPresenter extends Presenter$results = [];$results['id'] = $this->id;- $results['manufacturer'] = $this->model->manufacturer->present()->nameUrl();+ $results['manufacturer'] = $this->manufacturerUrl();$results['name'] = $this->nameUrl();$results['image'] = $this->imageUrl();$results['model_number'] = $this->model_number;@@ -51,8 +51,8 @@ class AssetModelPresenter extends Presenterif(($depreciation = $this->model->depreciation) and $depreciation->id > 0) {$results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')';}- $results['category'] = $this->model->category ? $this->model->category->present()->nameUrl() : '';- $results['eol'] = $this->eol ? $this->eol.' '.trans('general.months') : '';+ $results['category'] = $this->categoryUrl();+ $results['eol'] = $this->eolText();$results['note'] = $this->note();$results['fieldset'] = $this->model->fieldset ? link_to_route('custom_fields/model', $this->model->fieldset->name, $this->model->fieldset->id) : '';$results['actions'] = $actions;@@ -74,6 +74,14 @@ class AssetModelPresenter extends Presenter}+ public function eolText()+ {+ if($this->eol) {+ return $this->eol.' '.trans('general.months');+ }+ return '';+ }+/*** Pretty name for this model* @return stringdiff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.phpindex 18d1a76067..56596c6144 100644--- a/app/Presenters/AssetPresenter.php+++ b/app/Presenters/AssetPresenter.php@@ -71,24 +71,10 @@ class AssetPresenter extends Presenter$results['serial'] = $this->serial;$results['image'] = $this->imageUrl();// Presets for when conditionals fail.- $results['model'] = 'No Model';- $results['model_number'] = '';- $results['category'] = '';- $results['manufacturer'] = '';- if($model = $this->model->model) {- $results['model'] = $model->present()->nameUrl();-- if(!empty($model->model_number)) {- $results['model_number'] = $model->model_number;- }- if ($model->category) {- $results['category'] = $model->category->present()->nameUrl();- }-- if($model->manufacturer) {- $results['manufacturer'] = $model->manufacturer->present()->nameUrl();- }- }+ $results['model'] = $this->modelUrl();+ $results['model_number'] = $this->model->model_number;+ $results['category'] = $this->categoryUrl();+ $results['manufacturer'] = $this->manufacturerUrl();$results['status_label'] = '';$results['assigned_to'] = '';@@ -108,7 +94,7 @@ class AssetPresenter extends Presenter$results['eol'] = $this->eol_date() ?: '';$results['purchase_cost'] = Helper::formatCurrencyOutput($this->purchase_cost);$results['purchase_date'] = $this->purchase_date ?: '';- $results['notes'] = e($this->notes);+ $results['notes'] = $this->notes;$results['order_number'] = '';if(!empty($this->order_number)) {$results['order_number'] = link_to_route('hardware.index', $this->order_number, ['order_number' => $this->order_number]);@@ -120,9 +106,9 @@ class AssetPresenter extends Presenterif(!empty($this->created_at)) {$results['created_at'] = $this->created_at->format('F j, Y h:iA');}- $results['companyName'] = $this->model->company ? $this->model->company->name : '';- $results['actions'] = $actions ?: '';- $results['change'] = $inout ?: '';+ $results['companyName'] = $this->companyUrl();+ $results['actions'] = $actions;+ $results['change'] = $inout;// Custom Field bits@@ -172,6 +158,14 @@ class AssetPresenter extends Presenterreturn (string) link_to_route('hardware.show', e($this->name), $this->id);}+ public function modelUrl()+ {+ if($this->model->model) {+ return $this->model->model->present()->nameUrl();+ }+ return '';+ }+/*** Generate img tag to this items image.* @return mixed|stringdiff --git a/app/Presenters/ComponentPresenter.php b/app/Presenters/ComponentPresenter.phpindex 6f965da902..439f7bc782 100644--- a/app/Presenters/ComponentPresenter.php+++ b/app/Presenters/ComponentPresenter.php@@ -45,16 +45,16 @@ class ComponentPresenter extends Presenter'id' => $this->id,'name' => $this->nameUrl(),'serial_number' => $this->serial,- 'location' => ($this->model->location) ? $this->model->location->present()->nameUrl() : '',+ 'location' => $this->locationUrl(),'qty' => number_format($this->qty),- 'min_amt' => e($this->min_amt),- 'category' => ($this->model->category) ? $this->model->category->present()->nameUrl() : 'Missing category',+ 'min_amt' => e($this->min_amt),+ 'category' => $this->categoryUrl(),'order_number' => $this->order_number,- 'purchase_date' => $this->purchase_date,- 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),+ 'purchase_date' => $this->purchase_date,+ 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),'numRemaining' => $this->numRemaining(),'actions' => $actions,- 'companyName' => $this->model->company ? $this->model->company->present()->nameUrl() : '',+ 'companyName' => $this->companyUrl(),];return $results;diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.phpindex fe558b7853..be8f09931c 100644--- a/app/Presenters/ConsumablePresenter.php+++ b/app/Presenters/ConsumablePresenter.php@@ -39,21 +39,21 @@ class ConsumablePresenter extends Presenter$actions .='</nobr>';$results = [+ 'actions' => $actions,+ 'category' => $this->categoryUrl(),+ 'companyName' => $this->companyUrl(),'id' => $this->id,- 'name' => $this->nameUrl(),- 'location' => ($this->model->location) ? $this->model->location->present()->nameUrl() : '',- 'min_amt' => $this->min_amt,- 'qty' => $this->qty,- 'manufacturer' => ($this->model->manufacturer) ? $this->model->manufacturer->present()->nameUrl() : '',- 'model_number' => $this->model_number,'item_no' => $this->item_no,- 'category' => ($this->model->category) ? $this->model->category->present()->nameUrl() : 'Missing category',+ 'location' => $this->locationUrl(),+ 'manufacturer' => $this->manufacturerUrl(),+ 'min_amt' => $this->min_amt,+ 'model_number' => $this->model_number,+ 'name' => $this->nameUrl(),+ 'numRemaining' => $this->numRemaining(),'order_number' => $this->order_number,- 'purchase_date' => $this->purchase_date,'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),- 'numRemaining' => $this->numRemaining(),- 'actions' => $actions,- 'companyName' => $this->model->company ? $this->model->company->present()->nameUrl() : '',+ 'purchase_date' => $this->purchase_date,+ 'qty' => $this->qty,];return $results;}diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.phpindex 8adc48b234..a761864558 100644--- a/app/Presenters/LicensePresenter.php+++ b/app/Presenters/LicensePresenter.php@@ -46,22 +46,22 @@ class LicensePresenter extends Presenter$actions .='</span>';$results = [+ 'actions' => $actions,+ 'company' => $this->companyUrl(),+ 'expiration_date' => $this->expiration_date,'id' => $this->id,+ 'license_email' => $this->license_email,+ 'license_name' => $this->license_name,+ 'manufacturer' => $this->manufacturerUrl(),'name' => $this->nameUrl(),+ 'notes' => $this->notes,+ 'order_number' => $this->order_number,+ 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),+ 'purchase_date' => $this->purchase_date,+ 'purchase_order' => $this->purchase_order,+ 'remaining' => $this->remaincount(),'serial' => $this->serialUrl(),'totalSeats' => $this->model->licenseSeatsCount,- 'remaining' => $this->remaincount(),- 'license_name' => $this->license_name,- 'license_email' => $this->license_email,- 'purchase_date' => ($this->purchase_date) ?: '',- 'expiration_date' => ($this->expiration_date) ?: '',- 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),- 'purchase_order' => ($this->purchase_order) ?: '',- 'order_number' => ($this->order_number) ?: '',- 'notes' => ($this->notes) ?: '',- 'actions' => $actions,- 'company' => $this->model->company ? e($this->model->company->present()->nameUrl()) : '',- 'manufacturer' => $this->model->manufacturer ? $this->model->manufacturer->present()->nameUrl() : ''];return $results;diff --git a/app/Presenters/LocationPresenter.php b/app/Presenters/LocationPresenter.phpindex 9d1d40f11d..214a301b9a 100644--- a/app/Presenters/LocationPresenter.php+++ b/app/Presenters/LocationPresenter.php@@ -29,19 +29,19 @@ class LocationPresenter extends Presenter$actions .= '</nobr>';$results = [- 'id' => $this->id,- 'name' => $this->nameUrl(),- 'parent' => ($this->model->parent) ? $this->model->parent->present()->nameUrl() : '',- // 'assets' => ($this->assets->count() + $this->assignedassets->count()),- 'assets_default' => $this->model->assignedassets()->count(),+ 'actions' => $actions,+ 'address' => $this->address,'assets_checkedout' => $this->model->assets()->count(),- 'address' => $this->address,- 'city' => $this->city,- 'state' => $this->state,- 'zip' => $this->zip,- 'country' => $this->country,- 'currency' => $this->currency,- 'actions' => $actions+ 'assets_default' => $this->model->assignedassets()->count(),+ 'city' => $this->city,+ 'country' => $this->country,+ 'currency' => $this->currency,+ 'id' => $this->id,+ 'name' => $this->nameUrl(),+ 'parent' => ($this->model->parent) ? $this->model->parent->present()->nameUrl() : '',+ 'state' => $this->state,+ 'zip' => $this->zip,+ // 'assets' => ($this->assets->count() + $this->assignedassets->count()),];return $results;diff --git a/app/Presenters/ManufacturerPresenter.php b/app/Presenters/ManufacturerPresenter.phpindex b25c7a0193..e695b55cb9 100644--- a/app/Presenters/ManufacturerPresenter.php+++ b/app/Presenters/ManufacturerPresenter.php@@ -30,13 +30,13 @@ class ManufacturerPresenter extends Presenter$actions .= '</nobr>';$results = [- 'id' => $this->id,- 'name' => $this->nameUrl(),- 'assets' => $this->assets()->count(),- 'licenses' => $this->licenses()->count(),'accessories' => $this->accessories()->count(),+ 'actions' => $actions,+ 'assets' => $this->assets()->count(),'consumables' => $this->consumables()->count(),- 'actions' => $actions+ 'id' => $this->id,+ 'licenses' => $this->licenses()->count(),+ 'name' => $this->nameUrl(),];return $results;diff --git a/app/Presenters/Presenter.php b/app/Presenters/Presenter.phpindex ba8bbcfd93..877568da19 100644--- a/app/Presenters/Presenter.php+++ b/app/Presenters/Presenter.php@@ -7,6 +7,7 @@ use App\Models\SnipeModel;abstract class Presenter{+/*** @var SnipeModel*/@@ -21,6 +22,50 @@ abstract class Presenter$this->model = $model;}+ // Convenience functions for datatables stuff+ public function categoryUrl()+ {+ $model = $this->model;+ // Category of Asset belongs to model.+ if($model->model) {+ $model = $this->model->model;+ }++ if($model->category) {+ return $model->category->present()->nameUrl();+ }+ return '';+ }++ public function locationUrl()+ {+ if ($this->model->location) {+ return $this->model->location->present()->nameUrl();+ }+ return '';+ }++ public function companyUrl()+ {+ if ($this->model->company) {+ return $this->model->company->present()->nameUrl();+ }+ return '';+ }+ public function manufacturerUrl()+ {+ $model = $this->model;+ // Category of Asset belongs to model.+ if($model->model) {+ $model = $this->model->model;+ }++ if ($model->manufacturer) {+ return $model->manufacturer->present()->nameUrl();+ }+ return '';+ }+public function __get($property){if( method_exists($this, $property)) {@@ -34,4 +79,5 @@ abstract class Presenter{return $this->model->$method($args);}+}diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.phpindex c309cb6855..0d17aa2836 100644--- a/app/Presenters/UserPresenter.php+++ b/app/Presenters/UserPresenter.php@@ -65,12 +65,9 @@ class UserPresenter extends Presenter$result = ['id' => $this->id,'checkbox' => ($status!='deleted') ? '<div class="text-center hidden-xs hidden-sm"><input type="checkbox" name="edit_user['.e($this->id).']" class="one_required"></div>' : '',- 'name' => $this->present()->fullName(),+ 'name' => $this->fullName(),'jobtitle' => $this->jobtitle,- 'email' => ($this->email!='') ?- '<a href="mailto:'.$this->email.'" class="hidden-md hidden-lg">'.$this->email.'</a>'- .'<a href="mailto:'.$this->email.'" class="hidden-xs hidden-sm"><i class="fa fa-envelope"></i></a>'- .'</span>' : '',+ 'email' => $this->emailLink(),'username' => $this->username,'location' => ($this->model->userloc) ? $this->model->userloc->present()->nameUrl() : '','manager' => ($this->model->manager) ? $this->manager->present()->nameUrl() : '',@@ -86,12 +83,21 @@ class UserPresenter extends Presenter'created_at' => ($this->model->created_at!='') ? e($this->model->created_at->format('F j, Y h:iA')) : '','activated' => ($this->activated=='1') ? '<i class="fa fa-check text-success"></i>' : '<i class="fa fa-times text-danger"></i>','actions' => $actions ?: '',- 'companyName' => $this->company ? $this->company->name : ''+ 'companyName' => $this->companyUrl()];return $result;}++ public function emailLink()+ {+ if ($this->email) {+ return '<a href="mailto:'.$this->email.'">'.$this->email.'</a>'+ .'<a href="mailto:'.$this->email.'" class="hidden-xs hidden-sm"><i class="fa fa-envelope"></i></a>';+ }+ return '';+ }/*** Returns the user full name, it simply concatenates* the user first and last name.