From d1f496023be43178729a431409542064b3ed457a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 15 Dec 2016 14:17:10 +0200 Subject: [PATCH] Adjustments to task projects --- app/Http/Controllers/ProjectController.php | 4 ++-- app/Http/Requests/CreateProjectRequest.php | 1 + app/Http/Requests/UpdateProjectRequest.php | 1 - app/Models/Project.php | 1 - app/Ninja/Repositories/ProjectRepository.php | 1 + app/Services/ProjectService.php | 4 ++-- resources/views/projects/edit.blade.php | 20 ++++++++++++++------ 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 40d1a8846b..9e43e2c639 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -79,7 +79,7 @@ class ProjectController extends BaseController public function store(CreateProjectRequest $request) { - $project = $this->projectRepo->save($request->input()); + $project = $this->projectService->save($request->input()); Session::flash('message', trans('texts.created_project')); @@ -88,7 +88,7 @@ class ProjectController extends BaseController public function update(UpdateProjectRequest $request) { - $project = $this->projectRepo->save($request->input(), $request->entity()); + $project = $this->projectService->save($request->input(), $request->entity()); Session::flash('message', trans('texts.updated_project')); diff --git a/app/Http/Requests/CreateProjectRequest.php b/app/Http/Requests/CreateProjectRequest.php index 2c55f9a7cb..000286e927 100644 --- a/app/Http/Requests/CreateProjectRequest.php +++ b/app/Http/Requests/CreateProjectRequest.php @@ -21,6 +21,7 @@ class CreateProjectRequest extends ProjectRequest { return [ 'name' => sprintf('required|unique:projects,name,,id,account_id,%s', $this->user()->account_id), + 'client_id' => 'required', ]; } } diff --git a/app/Http/Requests/UpdateProjectRequest.php b/app/Http/Requests/UpdateProjectRequest.php index 1f9e8e860e..cbc4a5b321 100644 --- a/app/Http/Requests/UpdateProjectRequest.php +++ b/app/Http/Requests/UpdateProjectRequest.php @@ -20,7 +20,6 @@ class UpdateProjectRequest extends ProjectRequest public function rules() { return [ - 'name' => 'required', 'name' => sprintf('required|unique:projects,name,%s,id,account_id,%s', $this->entity()->id, $this->user()->account_id), ]; } diff --git a/app/Models/Project.php b/app/Models/Project.php index 4ef9e16401..7e34f0bbf1 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -22,7 +22,6 @@ class Project extends EntityModel */ protected $fillable = [ 'name', - 'client_id', ]; /** diff --git a/app/Ninja/Repositories/ProjectRepository.php b/app/Ninja/Repositories/ProjectRepository.php index aa802a069b..64ba210ba3 100644 --- a/app/Ninja/Repositories/ProjectRepository.php +++ b/app/Ninja/Repositories/ProjectRepository.php @@ -65,6 +65,7 @@ class ProjectRepository extends BaseRepository if ( ! $project) { $project = Project::createNew(); + $project['client_id'] = $input['client_id']; } $project->fill($input); diff --git a/app/Services/ProjectService.php b/app/Services/ProjectService.php index 1b16ea52ea..b1989b964c 100644 --- a/app/Services/ProjectService.php +++ b/app/Services/ProjectService.php @@ -45,13 +45,13 @@ class ProjectService extends BaseService * @param $data * @return mixed|null */ - public function save($data) + public function save($data, $project) { if (isset($data['client_id']) && $data['client_id']) { $data['client_id'] = Client::getPrivateId($data['client_id']); } - return $this->projectRepo->save($data); + return $this->projectRepo->save($data, $project); } /** diff --git a/resources/views/projects/edit.blade.php b/resources/views/projects/edit.blade.php index 3ed64c9e73..0fae1de1cd 100644 --- a/resources/views/projects/edit.blade.php +++ b/resources/views/projects/edit.blade.php @@ -7,6 +7,7 @@ ->method($method) ->rules([ 'name' => 'required', + 'client_id' => 'required', ]) !!} @if ($project) @@ -26,11 +27,18 @@
+ @if ($project) + {!! Former::plaintext('client_name') + ->value($project->client->getDisplayName()) !!} + @else + {!! Former::select('client_id') + ->addOption('', '') + ->label(trans('texts.client')) + ->addGroupClass('client-select') !!} + @endif + {!! Former::text('name') !!} - {!! Former::select('client_id') - ->addOption('', '') - ->label(trans('texts.client')) !!}
@@ -51,8 +59,6 @@ var clients = {!! $clients !!}; $(function() { - $('#name').focus(); - var $clientSelect = $('select#client_id'); for (var i=0; i