Merge branch 'develop' of github.com:snipe/snipe-it into develop

This commit is contained in:
snipe 2016-12-23 19:23:27 -08:00
commit 8857faee65
10 changed files with 135 additions and 81 deletions

View file

@ -281,7 +281,7 @@ class StatuslabelsController extends Controller
$actions .= Helper::generateDatatableButton('edit', route('statuslabels.edit', $statuslabel->id)); $actions .= Helper::generateDatatableButton('edit', route('statuslabels.edit', $statuslabel->id));
$actions .= Helper::generateDatatableButton( $actions .= Helper::generateDatatableButton(
'delete', 'delete',
route('statuslabels.destroy', ['statuslabel' => $statuslabel->id]), route('statuslabels.destroy', $statuslabel->id),
true, /*enabled*/ true, /*enabled*/
trans('admin/statuslabels/message.delete.confirm'), trans('admin/statuslabels/message.delete.confirm'),
$statuslabel->name $statuslabel->name

View file

@ -42,7 +42,7 @@ class AssetModelPresenter extends Presenter
$results = []; $results = [];
$results['id'] = $this->id; $results['id'] = $this->id;
$results['manufacturer'] = $this->model->manufacturer->present()->nameUrl(); $results['manufacturer'] = $this->manufacturerUrl();
$results['name'] = $this->nameUrl(); $results['name'] = $this->nameUrl();
$results['image'] = $this->imageUrl(); $results['image'] = $this->imageUrl();
$results['model_number'] = $this->model_number; $results['model_number'] = $this->model_number;
@ -51,8 +51,8 @@ class AssetModelPresenter extends Presenter
if(($depreciation = $this->model->depreciation) and $depreciation->id > 0) { if(($depreciation = $this->model->depreciation) and $depreciation->id > 0) {
$results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')'; $results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')';
} }
$results['category'] = $this->model->category ? $this->model->category->present()->nameUrl() : ''; $results['category'] = $this->categoryUrl();
$results['eol'] = $this->eol ? $this->eol.' '.trans('general.months') : ''; $results['eol'] = $this->eolText();
$results['note'] = $this->note(); $results['note'] = $this->note();
$results['fieldset'] = $this->model->fieldset ? link_to_route('custom_fields/model', $this->model->fieldset->name, $this->model->fieldset->id) : ''; $results['fieldset'] = $this->model->fieldset ? link_to_route('custom_fields/model', $this->model->fieldset->name, $this->model->fieldset->id) : '';
$results['actions'] = $actions; $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 * Pretty name for this model
* @return string * @return string

View file

@ -71,24 +71,10 @@ class AssetPresenter extends Presenter
$results['serial'] = $this->serial; $results['serial'] = $this->serial;
$results['image'] = $this->imageUrl(); $results['image'] = $this->imageUrl();
// Presets for when conditionals fail. // Presets for when conditionals fail.
$results['model'] = 'No Model'; $results['model'] = $this->modelUrl();
$results['model_number'] = ''; $results['model_number'] = $this->model->model_number;
$results['category'] = ''; $results['category'] = $this->categoryUrl();
$results['manufacturer'] = ''; $results['manufacturer'] = $this->manufacturerUrl();
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['status_label'] = ''; $results['status_label'] = '';
$results['assigned_to'] = ''; $results['assigned_to'] = '';
@ -108,7 +94,7 @@ class AssetPresenter extends Presenter
$results['eol'] = $this->eol_date() ?: ''; $results['eol'] = $this->eol_date() ?: '';
$results['purchase_cost'] = Helper::formatCurrencyOutput($this->purchase_cost); $results['purchase_cost'] = Helper::formatCurrencyOutput($this->purchase_cost);
$results['purchase_date'] = $this->purchase_date ?: ''; $results['purchase_date'] = $this->purchase_date ?: '';
$results['notes'] = e($this->notes); $results['notes'] = $this->notes;
$results['order_number'] = ''; $results['order_number'] = '';
if(!empty($this->order_number)) { if(!empty($this->order_number)) {
$results['order_number'] = link_to_route('hardware.index', $this->order_number, ['order_number' => $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 Presenter
if(!empty($this->created_at)) { if(!empty($this->created_at)) {
$results['created_at'] = $this->created_at->format('F j, Y h:iA'); $results['created_at'] = $this->created_at->format('F j, Y h:iA');
} }
$results['companyName'] = $this->model->company ? $this->model->company->name : ''; $results['companyName'] = $this->companyUrl();
$results['actions'] = $actions ?: ''; $results['actions'] = $actions;
$results['change'] = $inout ?: ''; $results['change'] = $inout;
// Custom Field bits // Custom Field bits
@ -172,6 +158,14 @@ class AssetPresenter extends Presenter
return (string) link_to_route('hardware.show', e($this->name), $this->id); return (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. * Generate img tag to this items image.
* @return mixed|string * @return mixed|string

View file

@ -45,16 +45,16 @@ class ComponentPresenter extends Presenter
'id' => $this->id, 'id' => $this->id,
'name' => $this->nameUrl(), 'name' => $this->nameUrl(),
'serial_number' => $this->serial, 'serial_number' => $this->serial,
'location' => ($this->model->location) ? $this->model->location->present()->nameUrl() : '', 'location' => $this->locationUrl(),
'qty' => number_format($this->qty), 'qty' => number_format($this->qty),
'min_amt' => e($this->min_amt), 'min_amt' => e($this->min_amt),
'category' => ($this->model->category) ? $this->model->category->present()->nameUrl() : 'Missing category', 'category' => $this->categoryUrl(),
'order_number' => $this->order_number, 'order_number' => $this->order_number,
'purchase_date' => $this->purchase_date, 'purchase_date' => $this->purchase_date,
'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),
'numRemaining' => $this->numRemaining(), 'numRemaining' => $this->numRemaining(),
'actions' => $actions, 'actions' => $actions,
'companyName' => $this->model->company ? $this->model->company->present()->nameUrl() : '', 'companyName' => $this->companyUrl(),
]; ];
return $results; return $results;

View file

@ -39,21 +39,21 @@ class ConsumablePresenter extends Presenter
$actions .='</nobr>'; $actions .='</nobr>';
$results = [ $results = [
'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',
'order_number' => $this->order_number,
'purchase_date' => $this->purchase_date,
'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),
'numRemaining' => $this->numRemaining(),
'actions' => $actions, 'actions' => $actions,
'companyName' => $this->model->company ? $this->model->company->present()->nameUrl() : '', 'category' => $this->categoryUrl(),
'companyName' => $this->companyUrl(),
'id' => $this->id,
'item_no' => $this->item_no,
'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_cost' => Helper::formatCurrencyOutput($this->purchase_cost),
'purchase_date' => $this->purchase_date,
'qty' => $this->qty,
]; ];
return $results; return $results;
} }

View file

@ -46,22 +46,22 @@ class LicensePresenter extends Presenter
$actions .='</span>'; $actions .='</span>';
$results = [ $results = [
'actions' => $actions,
'company' => $this->companyUrl(),
'expiration_date' => $this->expiration_date,
'id' => $this->id, 'id' => $this->id,
'license_email' => $this->license_email,
'license_name' => $this->license_name,
'manufacturer' => $this->manufacturerUrl(),
'name' => $this->nameUrl(), '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(), 'serial' => $this->serialUrl(),
'totalSeats' => $this->model->licenseSeatsCount, '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; return $results;

View file

@ -29,19 +29,19 @@ class LocationPresenter extends Presenter
$actions .= '</nobr>'; $actions .= '</nobr>';
$results = [ $results = [
'id' => $this->id, 'actions' => $actions,
'name' => $this->nameUrl(), 'address' => $this->address,
'parent' => ($this->model->parent) ? $this->model->parent->present()->nameUrl() : '',
// 'assets' => ($this->assets->count() + $this->assignedassets->count()),
'assets_default' => $this->model->assignedassets()->count(),
'assets_checkedout' => $this->model->assets()->count(), 'assets_checkedout' => $this->model->assets()->count(),
'address' => $this->address, 'assets_default' => $this->model->assignedassets()->count(),
'city' => $this->city, 'city' => $this->city,
'state' => $this->state, 'country' => $this->country,
'zip' => $this->zip, 'currency' => $this->currency,
'country' => $this->country, 'id' => $this->id,
'currency' => $this->currency, 'name' => $this->nameUrl(),
'actions' => $actions 'parent' => ($this->model->parent) ? $this->model->parent->present()->nameUrl() : '',
'state' => $this->state,
'zip' => $this->zip,
// 'assets' => ($this->assets->count() + $this->assignedassets->count()),
]; ];
return $results; return $results;

View file

@ -30,13 +30,13 @@ class ManufacturerPresenter extends Presenter
$actions .= '</nobr>'; $actions .= '</nobr>';
$results = [ $results = [
'id' => $this->id,
'name' => $this->nameUrl(),
'assets' => $this->assets()->count(),
'licenses' => $this->licenses()->count(),
'accessories' => $this->accessories()->count(), 'accessories' => $this->accessories()->count(),
'actions' => $actions,
'assets' => $this->assets()->count(),
'consumables' => $this->consumables()->count(), 'consumables' => $this->consumables()->count(),
'actions' => $actions 'id' => $this->id,
'licenses' => $this->licenses()->count(),
'name' => $this->nameUrl(),
]; ];
return $results; return $results;

View file

@ -7,6 +7,7 @@ use App\Models\SnipeModel;
abstract class Presenter abstract class Presenter
{ {
/** /**
* @var SnipeModel * @var SnipeModel
*/ */
@ -21,6 +22,50 @@ abstract class Presenter
$this->model = $model; $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) public function __get($property)
{ {
if( method_exists($this, $property)) { if( method_exists($this, $property)) {
@ -34,4 +79,5 @@ abstract class Presenter
{ {
return $this->model->$method($args); return $this->model->$method($args);
} }
} }

View file

@ -65,12 +65,9 @@ class UserPresenter extends Presenter
$result = [ $result = [
'id' => $this->id, '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>' : '', '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, 'jobtitle' => $this->jobtitle,
'email' => ($this->email!='') ? 'email' => $this->emailLink(),
'<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>' : '',
'username' => $this->username, 'username' => $this->username,
'location' => ($this->model->userloc) ? $this->model->userloc->present()->nameUrl() : '', 'location' => ($this->model->userloc) ? $this->model->userloc->present()->nameUrl() : '',
'manager' => ($this->model->manager) ? $this->manager->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')) : '', '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>', 'activated' => ($this->activated=='1') ? '<i class="fa fa-check text-success"></i>' : '<i class="fa fa-times text-danger"></i>',
'actions' => $actions ?: '', 'actions' => $actions ?: '',
'companyName' => $this->company ? $this->company->name : '' 'companyName' => $this->companyUrl()
]; ];
return $result; 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 * Returns the user full name, it simply concatenates
* the user first and last name. * the user first and last name.