mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Merge pull request #12243 from akemidx/new_grey_out_when_no_assets
Created method in users.php for adding up all assigned to user and pr…
This commit is contained in:
commit
fabefa61b0
|
@ -338,6 +338,24 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
|||
return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes a count of all items assigned
|
||||
*
|
||||
* @author J. Vinsmoke
|
||||
* @since [v6.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
Public function allAssignedCount() {
|
||||
$assetsCount = $this->assets()->count();
|
||||
$licensesCount = $this->licenses()->count();
|
||||
$accessoriesCount = $this->accessories()->count();
|
||||
$consumablesCount = $this->consumables()->count();
|
||||
|
||||
$totalCount = $assetsCount + $licensesCount + $accessoriesCount + $consumablesCount;
|
||||
|
||||
return (int) $totalCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the user -> actionlogs relationship
|
||||
*
|
||||
|
|
|
@ -15,6 +15,7 @@ return array(
|
|||
'password_resets_sent' => 'The selected users who are activated and have a valid email addresses have been sent a password reset link.',
|
||||
'password_reset_sent' => 'A password reset link has been sent to :email!',
|
||||
'user_has_no_email' => 'This user does not have an email address in their profile.',
|
||||
'user_has_no_assets_assigned' => 'This user does not have any assets assigned',
|
||||
|
||||
|
||||
'success' => array(
|
||||
|
|
|
@ -179,17 +179,23 @@
|
|||
|
||||
@can('view', $user)
|
||||
<div class="col-md-12" style="padding-top: 5px;">
|
||||
@if($user->allAssignedCount() != '0')
|
||||
<a href="{{ route('users.print', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-primary hidden-print" target="_blank" rel="noopener">{{ trans('admin/users/general.print_assigned') }}</a>
|
||||
@else
|
||||
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener" disabled title="{{ trans('admin/users/message.user_has_no_assets_assigned') }}">{{ trans('admin/users/general.print_assigned') }}</button>
|
||||
@endif
|
||||
</div>
|
||||
@endcan
|
||||
|
||||
@can('view', $user)
|
||||
<div class="col-md-12" style="padding-top: 5px;">
|
||||
@if(!empty($user->email))
|
||||
@if(!empty($user->email) && ($user->allAssignedCount() != '0'))
|
||||
<form action="{{ route('users.email',['userId'=> $user->id]) }}" method="POST">
|
||||
{{ csrf_field() }}
|
||||
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener">{{ trans('admin/users/general.email_assigned') }}</button>
|
||||
</form>
|
||||
@elseif(!empty($user->email) && ($user->allAssignedCount() == '0'))
|
||||
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener" disabled title="{{ trans('admin/users/message.user_has_no_assets_assigned') }}">{{ trans('admin/users/general.email_assigned') }}</button>
|
||||
@else
|
||||
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener" disabled title="{{ trans('admin/users/message.user_has_no_email') }}">{{ trans('admin/users/general.email_assigned') }}</button>
|
||||
@endif
|
||||
|
|
Loading…
Reference in a new issue