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