Skip to content

Commit

Permalink
Merge pull request #12243 from akemidx/new_grey_out_when_no_assets
Browse files Browse the repository at this point in the history
Created method in users.php for adding up all assigned to user and pr…
  • Loading branch information
snipe committed Dec 13, 2022
2 parents 389ec3a + f3e57d7 commit fabefa6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,24 @@ public function licenses()
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
*
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/admin/users/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'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(
Expand Down
8 changes: 7 additions & 1 deletion resources/views/users/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fabefa6

Please sign in to comment.