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