diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index e76abf1419..9e59359abd 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -526,7 +526,7 @@ class AssetsController extends Controller $this->authorize('checkin', $asset); $admin = Auth::user(); - + $user = $asset->assignedUser; if (is_null($target = $asset->assignedTo)) { return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in')); } diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 95239d4eef..2c08b7cbde 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -288,12 +288,8 @@ class ReportsController extends Controller */ public function getActivityReport() { - $log_actions = Actionlog::orderBy('created_at', 'DESC') - ->with('item') - ->orderBy('created_at', 'DESC') - ->get(); - return View::make('reports/activity', compact('log_actions')); + return View::make('reports/activity'); } /** @@ -334,61 +330,7 @@ class ReportsController extends Controller $rows = array(); foreach ($activitylogs as $activity) { - - if (($activity->item) && ($activity->itemType()=="asset")) { - $activity_item = ''.e($activity->item->asset_tag).' - '. e($activity->item->present()->name()).''; - $item_type = 'asset'; - } elseif ($activity->item) { - $activity_item = '' . e($activity->item->name) . ''; - $item_type = $activity->itemType(); - } else { - $activity_item = "unkonwn"; - $item_type = "null"; - } - - - if (($activity->user) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) { - $activity_target = ''.$activity->user->present()->fullName().''; - } elseif ($activity->target_type === "App\Models\Asset") { - if ($activity->target) { - $activity_target = ''.$activity->target->present()->name().''; - } else { - $activity_target = ""; - } - } elseif ($activity->target_type === "App\Models\User") { - if ($activity->target) { - $activity_target = ''.$activity->target->present()->fullName().''; - } else { - $activity_target = ''; - } - } elseif (($activity->action_type=='accepted') || ($activity->action_type=='declined')) { - $activity_target = $activity->item->assignedTo->nameUrl(); - } elseif ($activity->action_type=='requested') { - if ($activity->user) { - $activity_target = ''.$activity->user->present()->fullName().''; - } else { - $activity_target = ''; - } - } else { - if ($activity->target) { - $activity_target = $activity->target->id; - } else { - $activity_target = ""; - } - } - - - $rows[] = array( - 'icon' => '', - 'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)), - 'action_type' => strtolower(trans('general.'.str_replace(' ', '_', $activity->action_type))), - 'admin' => $activity->user ? (string) link_to_route('users.show', $activity->user->present()->fullName(), [$activity->user_id]) : '', - 'target' => $activity_target, - 'item' => $activity_item, - 'item_type' => $item_type, - 'note' => e($activity->note), - - ); + $rows[] = $activity->present()->forDataTable(); } $data = array('total'=>$activityCount, 'rows'=>$rows); diff --git a/app/Http/Requests/AssetRequest.php b/app/Http/Requests/AssetRequest.php index 6a7be8bf7b..a7035e1994 100644 --- a/app/Http/Requests/AssetRequest.php +++ b/app/Http/Requests/AssetRequest.php @@ -38,9 +38,9 @@ class AssetRequest extends Request 'status' => 'integer|nullable', 'asset_tag' => 'required', 'purchase_cost' => 'numeric|nullable', - "assigned_user" => 'required_without_all:assigned_asset,assigned_location', - "assigned_asset" => 'required_without_all:assigned_user,assigned_location', - "assigned_location" => 'required_without_all:assigned_user,assigned_asset', + "assigned_user" => 'sometimes:required_without_all:assigned_asset,assigned_location', + "assigned_asset" => 'sometimes:required_without_all:assigned_user,assigned_location', + "assigned_location" => 'sometimes:required_without_all:assigned_user,assigned_asset', ]; $model = AssetModel::find($this->request->get('model_id')); diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index e83ca9f18c..a85f5fcde4 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -1,6 +1,6 @@ assignedType() == self::LOCATION) { return $this->assignedTo(); } - // Default to User -// var_dump($this); - return $this->assignedTo->userLoc(); + if($this->assignedTo) { + return $this->assignedTo->userLoc(); + } } return $this->defaultLoc(); } diff --git a/app/Presenters/ActionlogPresenter.php b/app/Presenters/ActionlogPresenter.php new file mode 100644 index 0000000000..cceb683a42 --- /dev/null +++ b/app/Presenters/ActionlogPresenter.php @@ -0,0 +1,70 @@ + '', + 'created_at' => date("M d, Y g:iA", strtotime($this->created_at)), + 'action_type' => strtolower(trans('general.'.str_replace(' ', '_', $this->action_type))), + 'admin' => $this->model->user ? $this->model->user->present()->nameUrl() : '', + 'target' => $this->target(), + 'item' => $this->item(), + 'item_type' => $this->itemType(), + 'note' => e($this->note), + + ]; + } + + public function admin() + { + } + + public function item() + {// + // oute('show/userfile', [$user->id, $file->id]) + if($this->action_type=='uploaded') { + return (string) link_to_route('show/userfile', $this->model->filename, [$this->model->item->id, $this->model->id]); + } + if ($this->model->item) { + return $this->model->item->present()->nameUrl(); + } + return ''; + } + + public function target() + { + // Target is messy. + // On an upload, the target is the item we are uploading to, stored as the "item" in the log. + if ($this->action_type=='uploaded') { + return $this->model->item->present()->nameUrl(); + } + // If we are logging an accept/reject, the target is not stored directly, + // so we access it through who the item is assigned to. + // FIXME: On a reject it's not assigned to anyone. + if (($this->action_type=='accepted') || ($this->action_type=='declined')) { + return $this->model->item->assignedTo->nameUrl(); + } elseif ($this->action_type=='requested') { + if ($this->model->user) { + return $this->model->user->present()->nameUrl(); + } + } + // Otherwise, we'll just take the target of the log. + if ($this->model->target) { + return $this->model->target->present()->nameUrl(); + } + return ''; + } +} diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 16c38b1721..e77e73bad4 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -159,6 +159,7 @@ 'supplier' => 'Supplier', 'suppliers' => 'Suppliers', 'submit' => 'Submit', + 'target' => 'Target', 'total_assets' => 'total assets', 'total_licenses' => 'total licenses', 'total_accessories' => 'total accessories', diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index 210866c34d..fc546ed5b2 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -236,47 +236,22 @@ View Assets for {{ $user->present()->fullName() }}
@foreach ($userlog as $log) + @php $result = $log->present()->forDataTable(); + @endphp| {{ trans('general.date') }} | {{ trans('general.admin') }} | {{ trans('button.actions') }} | -{{ trans('admin/licenses/general.user') }} | +{{ trans('general.target') }} | {{ trans('general.notes') }} | |
|---|---|---|---|---|---|---|
| {{ $log->created_at }} | +{{ $result['created_at'] }} | - @if (isset($log->user_id)) - {{ $log->user->present()->fullName() }} - @endif + {!! $result['admin'] !!} | -{{ $log->action_type }} | +{{ $result['action_type'] }} | - @if (($log->target) && ($log->target->id!='0')) - @if ($log->target_type == 'App\Models\User') - - {{ $log->userlog->present()->fullName() }} - - @elseif ($log->target_type == 'App\Models\Asset') - - {{ $log->userlog->present()->name() }} - - @endif - @elseif ($log->action_type=='uploaded') - {{ $log->filename }} - @endif + {!! $result['target'] !!} | - @if ($log->note) - {{ $log->note }} - @endif + {{ $result['note'] }} | @can('update', $user) - + @endcan | @@ -422,31 +422,19 @@ @foreach ($userlog as $log) + @php $result = $log->present()->forDataTable; + @endphp
| - + {!!$result['icon']!!} | -{{ $log->created_at }} | -{{ $log->action_type }} | +{{ $result['created_at'] }} | +{{ $result['action_type'] }} | - @if (($log->item) && ($log->itemType()=="asset")) - {!! $log->item->present()->nameUrl() !!} - @elseif ($log->item) - - {{ $log->item->name }} - - @else - {{ trans('general.bad_data') }} - @endif + {!! $result['item'] !!} | - @if ($log->action_type != 'requested') - @if (isset($log->user)) - {!! $log->user->present()->nameUrl() !!} - @else - Deleted Admin - @endif - @endif + {!! $result['admin'] !!} |