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