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