repository = $worklog; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Project\Pm\Repositories\Criteria\WorklogResourceCriteria::class); } /** * Display a list of worklog. * * @return Response */ public function index(WorklogRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Project\Pm\Repositories\Presenter\WorklogPresenter::class) ->$function(); } $worklogs = $this->repository->paginate(); return $this->response->setMetaTitle(trans('pm::worklog.names')) ->view('pm::worklog.index', true) ->data(compact('worklogs', 'view')) ->output(); } /** * Display worklog. * * @param Request $request * @param Model $worklog * * @return Response */ public function show(WorklogRequest $request, Worklog $worklog) { if ($worklog->exists) { $view = 'pm::worklog.show'; } else { $view = 'pm::worklog.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('pm::worklog.name')) ->data(compact('worklog')) ->view($view, true) ->output(); } /** * Show the form for creating a new worklog. * * @param Request $request * * @return Response */ public function create(WorklogRequest $request) { $worklog = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('pm::worklog.name')) ->view('pm::worklog.create', true) ->data(compact('worklog')) ->output(); } /** * Create new worklog. * * @param Request $request * * @return Response */ public function store(WorklogRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $worklog = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('pm::worklog.name')])) ->code(204) ->status('success') ->url(guard_url('pm/worklog/' . $worklog->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/pm/worklog')) ->redirect(); } } /** * Show worklog for editing. * * @param Request $request * @param Model $worklog * * @return Response */ public function edit(WorklogRequest $request, Worklog $worklog) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('pm::worklog.name')) ->view('pm::worklog.edit', true) ->data(compact('worklog')) ->output(); } /** * Update the worklog. * * @param Request $request * @param Model $worklog * * @return Response */ public function update(WorklogRequest $request, Worklog $worklog) { try { $attributes = $request->all(); $worklog->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('pm::worklog.name')])) ->code(204) ->status('success') ->url(guard_url('pm/worklog/' . $worklog->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('pm/worklog/' . $worklog->getRouteKey())) ->redirect(); } } /** * Remove the worklog. * * @param Model $worklog * * @return Response */ public function destroy(WorklogRequest $request, Worklog $worklog) { try { $worklog->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('pm::worklog.name')])) ->code(202) ->status('success') ->url(guard_url('pm/worklog/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('pm/worklog/' . $worklog->getRouteKey())) ->redirect(); } } /** * Remove multiple worklog. * * @param Model $worklog * * @return Response */ public function delete(WorklogRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('pm::worklog.name')])) ->status("success") ->code(202) ->url(guard_url('pm/worklog')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/pm/worklog')) ->redirect(); } } /** * Restore deleted worklogs. * * @param Model $worklog * * @return Response */ public function restore(WorklogRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('pm::worklog.name')])) ->status("success") ->code(202) ->url(guard_url('/pm/worklog')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/pm/worklog/')) ->redirect(); } } }