diff --git a/app/Http/Requests/Users/UpdateRequest.php b/app/Http/Requests/Users/UpdateRequest.php index 0e9e3b4..ba34ff6 100644 --- a/app/Http/Requests/Users/UpdateRequest.php +++ b/app/Http/Requests/Users/UpdateRequest.php @@ -26,9 +26,9 @@ class UpdateRequest extends FormRequest public function rules() { return [ - 'nickname' => 'required|string|max:255', - 'name' => 'required|string|max:255', - 'gender_id' => 'required|numeric', + 'nickname' => 'sometimes|required|string|max:255', + 'name' => 'sometimes|required|string|max:255', + 'gender_id' => 'sometimes|required|numeric', 'dob' => 'nullable|date|date_format:Y-m-d', 'yob' => 'nullable|date_format:Y', 'dod' => 'nullable|date|date_format:Y-m-d', @@ -54,19 +54,10 @@ class UpdateRequest extends FormRequest { $formData = parent::validated(); - if ($formData['dod']) { - $formData['yod'] = substr($formData['dod'], 0, 4); - } else { - $formData['yod'] = $formData['yod']; - } - - if ($formData['dob']) { - $formData['yob'] = substr($formData['dob'], 0, 4); - } else { - $formData['yob'] = $formData['yob']; - } + $formData['yod'] = $this->getYod($formData); + $formData['yob'] = $this->getYob($formData); - if ($formData['password']) { + if (isset($formData['password']) && $formData['password']) { $formData['password'] = bcrypt($formData['password']); } else { unset($formData['password']); @@ -74,4 +65,30 @@ class UpdateRequest extends FormRequest return $formData; } + + private function getYob($formData) + { + if (isset($formData['yob'])) { + return $formData['yob']; + } + + if (isset($formData['dob']) && $formData['dob']) { + return substr($formData['dob'], 0, 4); + } + + return; + } + + private function getYod($formData) + { + if (isset($formData['yod'])) { + return $formData['yod']; + } + + if (isset($formData['dod']) && $formData['dod']) { + return substr($formData['dod'], 0, 4); + } + + return; + } } diff --git a/resources/lang/en/user.php b/resources/lang/en/user.php index ae87d63..e612bd0 100644 --- a/resources/lang/en/user.php +++ b/resources/lang/en/user.php @@ -11,6 +11,7 @@ return [ 'grand_childs' => 'Grand Childs', 'siblings' => 'Siblings', 'dead' => 'Dead', + 'death' => 'Death', 'child_name' => 'Child Name', 'child_gender' => 'Child Gender', 'grand_mother' => 'Grand Mother', diff --git a/resources/lang/id/user.php b/resources/lang/id/user.php index ced0d3b..8668553 100644 --- a/resources/lang/id/user.php +++ b/resources/lang/id/user.php @@ -11,6 +11,7 @@ return [ 'grand_childs' => 'Cucu-cucu', 'siblings' => 'Saudara', 'dead' => 'Meninggal', + 'death' => 'Kematian', 'child_name' => 'Nama Anak', 'child_gender' => 'Jenis Kelamin Anak', 'grand_mother' => 'Nenek', diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 920b1f6..2e06bb8 100644 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -5,48 +5,7 @@ @can('delete', $user)
-
-

{{ __('user.delete') }} : {{ $user->name }}

-
- - - - - - - - - - -
{{ __('user.name') }}{{ $user->name }}
{{ __('user.nickname') }}{{ $user->nickname }}
{{ __('user.gender') }}{{ $user->gender }}
{{ __('user.father') }}{{ $user->father_id ? $user->father->name : '' }}
{{ __('user.mother') }}{{ $user->mother_id ? $user->mother->name : '' }}
{{ __('user.childs_count') }}{{ $childsCount = $user->childs()->count() }}
{{ __('user.spouses_count') }}{{ $spousesCount = $user->marriages()->count() }}
{{ __('user.managed_user') }}{{ $managedUserCount = $user->managedUsers()->count() }}
{{ __('user.managed_couple') }}{{ $managedCoupleCount = $user->managedCouples()->count() }}
- @if ($childsCount + $spousesCount + $managedUserCount + $managedCoupleCount) - {{ __('user.replace_delete_text') }} - {{ Form::open([ - 'route' => ['users.destroy', $user], - 'method' => 'delete', - 'onsubmit' => 'return confirm("'.__('user.replace_confirm').'")', - ]) }} - {!! FormField::select('replacement_user_id', $replacementUsers, [ - 'label' => false, - 'placeholder' => __('user.replacement'), - ]) !!} - {{ Form::submit(__('user.replace_delete_button'), [ - 'name' => 'replace_delete_button', - 'class' => 'btn btn-danger', - ]) }} - {{ link_to_route('users.edit', __('app.cancel'), [$user], ['class' => 'btn btn-default pull-right']) }} - {{ Form::close() }} - @else - {!! FormField::delete( - ['route' => ['users.destroy', $user]], - __('user.delete_confirm_button'), - ['class' => 'btn btn-danger'], - ['user_id' => $user->id] - ) !!} - {{ link_to_route('users.edit', __('app.cancel'), [$user], ['class' => 'btn btn-default']) }} - @endif -
-
+ @include('users.partials.delete_confirmation')
@endcan @@ -58,71 +17,25 @@ {{ __('user.edit') }} {{ $user->profileLink() }}
- {{ Form::model($user, ['route' => ['users.update', $user->id], 'method' =>'patch', 'autocomplete' => 'off']) }} -
-
-

{{ __('user.edit') }}

-
- {!! FormField::text('name', ['label' => __('user.name')]) !!} - {!! FormField::text('nickname', ['label' => __('user.nickname')]) !!} -
-
{!! FormField::radios('gender_id', [1 => __('app.male_code'), __('app.female_code')], ['label' => __('user.gender')]) !!}
-
- {!! FormField::text('birth_order', ['label' => __('user.birth_order'), 'type' => 'number', 'min' => 1]) !!} -
-
-
-
{!! FormField::text('yob', ['label' => __('user.yob'), 'placeholder' => __('app.example').' 1959']) !!}
-
{!! FormField::text('dob', ['label' => __('user.dob'), 'placeholder' => __('app.example').' 1959-07-20']) !!}
-
-
-
{!! FormField::text('yod', ['label' => __('user.yod'), 'placeholder' => __('app.example').' 2003']) !!}
-
{!! FormField::text('dod', ['label' => __('user.dod'), 'placeholder' => __('app.example').' 2003-10-17']) !!}
+
@include('users.partials.edit_nav_tabs')
+
+
+ {{ Form::model($user, ['route' => ['users.update', $user->id], 'method' =>'patch', 'autocomplete' => 'off']) }} +
+ @includeWhen(request('tab') == null, 'users.partials.edit_profile') + @includeWhen(request('tab') == 'death', 'users.partials.edit_death') + @includeWhen(request('tab') == 'contact_address', 'users.partials.edit_contact_address') + @includeWhen(request('tab') == 'login_account', 'users.partials.edit_login_account') +
+ {{ Form::submit(__('app.update'), ['class' => 'btn btn-primary']) }} + {{ link_to_route('users.show', __('app.cancel'), [$user->id], ['class' => 'btn btn-default']) }}
-
-
- {{ Form::submit(__('app.update'), ['class' => 'btn btn-primary']) }} - {{ link_to_route('users.show', __('app.cancel'), [$user->id], ['class' => 'btn btn-default']) }} -
-
-
-
-

{{ __('app.address') }} & {{ __('app.contact') }}

-
- {!! FormField::textarea('address', ['label' => __('app.address')]) !!} - {!! FormField::text('city', ['label' => __('app.city'), 'placeholder' => __('app.example').' Jakarta']) !!} - {!! FormField::text('phone', ['label' => __('app.phone'), 'placeholder' => __('app.example').' 081234567890']) !!} -
-
-
-

{{ __('app.login_account') }}

-
- {!! FormField::email('email', ['label' => __('auth.email'), 'placeholder' => __('app.example').' nama@mail.com']) !!} - {!! FormField::password('password', ['label' => __('auth.password'), 'placeholder' => '******', 'value' => '']) !!} -
-
-
- {{ Form::close() }} -
-
-

{{ __('user.update_photo') }}

- {{ Form::open(['route' => ['users.photo-upload', $user], 'method' => 'patch', 'files' => true]) }} -
- {{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }} -
-
- {!! FormField::file('photo', ['required' => true, 'label' => __('user.reupload_photo'), 'info' => ['text' => 'Format jpg, maks: 200 Kb.', 'class' => 'warning']]) !!} -
- {{ Form::close() }} +
+ @includeWhen(request('tab') == null, 'users.partials.update_photo') +
- @can('delete', $user) - {{ link_to_route('users.edit', __('user.delete'), [$user, 'action' => 'delete'], ['class' => 'btn btn-danger pull-right', 'id' => 'del-user-'.$user->id]) }} - @endcan
@endif diff --git a/resources/views/users/partials/delete_confirmation.blade.php b/resources/views/users/partials/delete_confirmation.blade.php new file mode 100644 index 0000000..4d7e5e8 --- /dev/null +++ b/resources/views/users/partials/delete_confirmation.blade.php @@ -0,0 +1,42 @@ +
+

{{ __('user.delete') }} : {{ $user->name }}

+
+ + + + + + + + + + +
{{ __('user.name') }}{{ $user->name }}
{{ __('user.nickname') }}{{ $user->nickname }}
{{ __('user.gender') }}{{ $user->gender }}
{{ __('user.father') }}{{ $user->father_id ? $user->father->name : '' }}
{{ __('user.mother') }}{{ $user->mother_id ? $user->mother->name : '' }}
{{ __('user.childs_count') }}{{ $childsCount = $user->childs()->count() }}
{{ __('user.spouses_count') }}{{ $spousesCount = $user->marriages()->count() }}
{{ __('user.managed_user') }}{{ $managedUserCount = $user->managedUsers()->count() }}
{{ __('user.managed_couple') }}{{ $managedCoupleCount = $user->managedCouples()->count() }}
+ @if ($childsCount + $spousesCount + $managedUserCount + $managedCoupleCount) + {{ __('user.replace_delete_text') }} + {{ Form::open([ + 'route' => ['users.destroy', $user], + 'method' => 'delete', + 'onsubmit' => 'return confirm("'.__('user.replace_confirm').'")', + ]) }} + {!! FormField::select('replacement_user_id', $replacementUsers, [ + 'label' => false, + 'placeholder' => __('user.replacement'), + ]) !!} + {{ Form::submit(__('user.replace_delete_button'), [ + 'name' => 'replace_delete_button', + 'class' => 'btn btn-danger', + ]) }} + {{ link_to_route('users.edit', __('app.cancel'), [$user], ['class' => 'btn btn-default pull-right']) }} + {{ Form::close() }} + @else + {!! FormField::delete( + ['route' => ['users.destroy', $user]], + __('user.delete_confirm_button'), + ['class' => 'btn btn-danger'], + ['user_id' => $user->id] + ) !!} + {{ link_to_route('users.edit', __('app.cancel'), [$user], ['class' => 'btn btn-default']) }} + @endif +
+
diff --git a/resources/views/users/partials/edit_contact_address.blade.php b/resources/views/users/partials/edit_contact_address.blade.php new file mode 100644 index 0000000..0e57b87 --- /dev/null +++ b/resources/views/users/partials/edit_contact_address.blade.php @@ -0,0 +1,8 @@ +
+

{{ __('app.address') }} & {{ __('app.contact') }}

+
+ {!! FormField::textarea('address', ['label' => __('app.address')]) !!} + {!! FormField::text('city', ['label' => __('app.city'), 'placeholder' => __('app.example').' Jakarta']) !!} + {!! FormField::text('phone', ['label' => __('app.phone'), 'placeholder' => __('app.example').' 081234567890']) !!} +
+
diff --git a/resources/views/users/partials/edit_death.blade.php b/resources/views/users/partials/edit_death.blade.php new file mode 100644 index 0000000..6e8ff6e --- /dev/null +++ b/resources/views/users/partials/edit_death.blade.php @@ -0,0 +1,4 @@ +
+
{!! FormField::text('yod', ['label' => __('user.yod'), 'placeholder' => __('app.example').' 2003']) !!}
+
{!! FormField::text('dod', ['label' => __('user.dod'), 'placeholder' => __('app.example').' 2003-10-17']) !!}
+
diff --git a/resources/views/users/partials/edit_login_account.blade.php b/resources/views/users/partials/edit_login_account.blade.php new file mode 100644 index 0000000..c197ce4 --- /dev/null +++ b/resources/views/users/partials/edit_login_account.blade.php @@ -0,0 +1,7 @@ +
+

{{ __('app.login_account') }}

+
+ {!! FormField::email('email', ['label' => __('auth.email'), 'placeholder' => __('app.example').' nama@mail.com']) !!} + {!! FormField::password('password', ['label' => __('auth.password'), 'placeholder' => '******', 'value' => '']) !!} +
+
diff --git a/resources/views/users/partials/edit_nav_tabs.blade.php b/resources/views/users/partials/edit_nav_tabs.blade.php new file mode 100644 index 0000000..9ada6aa --- /dev/null +++ b/resources/views/users/partials/edit_nav_tabs.blade.php @@ -0,0 +1,19 @@ + + +
+@can('delete', $user) +{{ link_to_route('users.edit', __('user.delete'), [$user, 'action' => 'delete'], ['class' => 'btn btn-danger', 'id' => 'del-user-'.$user->id]) }} +@endcan diff --git a/resources/views/users/partials/edit_profile.blade.php b/resources/views/users/partials/edit_profile.blade.php new file mode 100644 index 0000000..63ba235 --- /dev/null +++ b/resources/views/users/partials/edit_profile.blade.php @@ -0,0 +1,17 @@ +
+

{{ __('user.edit') }}

+
+ {!! FormField::text('name', ['label' => __('user.name')]) !!} + {!! FormField::text('nickname', ['label' => __('user.nickname')]) !!} +
+
{!! FormField::radios('gender_id', [1 => __('app.male_code'), __('app.female_code')], ['label' => __('user.gender')]) !!}
+
+ {!! FormField::text('birth_order', ['label' => __('user.birth_order'), 'type' => 'number', 'min' => 1]) !!} +
+
+
+
{!! FormField::text('yob', ['label' => __('user.yob'), 'placeholder' => __('app.example').' 1959']) !!}
+
{!! FormField::text('dob', ['label' => __('user.dob'), 'placeholder' => __('app.example').' 1959-07-20']) !!}
+
+
+
diff --git a/resources/views/users/partials/update_photo.blade.php b/resources/views/users/partials/update_photo.blade.php new file mode 100644 index 0000000..60627ba --- /dev/null +++ b/resources/views/users/partials/update_photo.blade.php @@ -0,0 +1,15 @@ +
+

{{ __('user.update_photo') }}

+ {{ Form::open(['route' => ['users.photo-upload', $user], 'method' => 'patch', 'files' => true]) }} +
+ {{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }} +
+
+ {!! FormField::file('photo', ['required' => true, 'label' => __('user.reupload_photo'), 'info' => ['text' => 'Format jpg, maks: 200 Kb.', 'class' => 'warning']]) !!} +
+ + {{ Form::close() }} +
diff --git a/tests/Feature/UsersProfileTest.php b/tests/Feature/UsersProfileTest.php index 4cd0c4f..5b17f84 100644 --- a/tests/Feature/UsersProfileTest.php +++ b/tests/Feature/UsersProfileTest.php @@ -12,6 +12,21 @@ class UsersProfileTest extends TestCase use RefreshDatabase; /** @test */ + public function guest_can_search_users_profile() + { + $jono = factory(User::class)->create(['name' => 'Jono']); + $jeni = factory(User::class)->create(['name' => 'Jeni']); + $johan = factory(user::class)->create(['name' => 'Johan']); + + $this->visitRoute('users.search', ['q' => 'jo']); + $this->seeRouteIs('users.search', ['q' => 'jo']); + + $this->seeText('Jono'); + $this->seeText('Johan'); + $this->dontSeeText('Jeni'); + } + + /** @test */ public function user_can_view_other_users_profile() { $user = factory(User::class)->create(); @@ -32,13 +47,6 @@ class UsersProfileTest extends TestCase 'gender_id' => 1, 'dob' => '1959-06-09', 'yob' => '', - 'dod' => '2003-10-17', - 'yod' => '', - 'address' => 'Jln. Angkasa, No. 70', - 'city' => 'Nama Kota', - 'phone' => '081234567890', - 'email' => '', - 'password' => '', 'birth_order' => 3, ]); @@ -48,24 +56,114 @@ class UsersProfileTest extends TestCase 'gender_id' => 1, 'dob' => '1959-06-09', 'yob' => '1959', - 'dod' => '2003-10-17', - 'yod' => '2003', - 'address' => 'Jln. Angkasa, No. 70', - 'city' => 'Nama Kota', - 'phone' => '081234567890', - 'email' => null, - 'password' => null, 'birth_order' => 3, ]); } /** @test */ + public function user_can_update_yob_only() + { + $user = $this->loginAsUser(); + $this->visit(route('users.edit', $user->id)); + $this->seePageIs(route('users.edit', $user->id)); + + $this->submitForm(trans('app.update'), [ + 'dob' => '', + 'yob' => '2003', + ]); + + $this->seeInDatabase('users', [ + 'id' => $user->id, + 'dob' => null, + 'yob' => '2003', + ]); + } + + /** @test */ + public function user_can_edit_contact_address() + { + $user = $this->loginAsUser(); + $this->visit(route('users.edit', [$user->id, 'tab' => 'contact_address'])); + $this->seePageIs(route('users.edit', [$user->id, 'tab' => 'contact_address'])); + + $this->submitForm(trans('app.update'), [ + 'address' => 'Jln. Angkasa, No. 70', + 'city' => 'Nama Kota', + 'phone' => '081234567890', + ]); + + $this->seeInDatabase('users', [ + 'id' => $user->id, + 'address' => 'Jln. Angkasa, No. 70', + 'city' => 'Nama Kota', + 'phone' => '081234567890', + ]); + } + + /** @test */ + public function user_can_edit_login_account() + { + $user = $this->loginAsUser(); + $this->visit(route('users.edit', [$user->id, 'tab' => 'login_account'])); + $this->seePageIs(route('users.edit', [$user->id, 'tab' => 'login_account'])); + + $this->submitForm(trans('app.update'), [ + 'email' => '', + 'password' => '', + ]); + + $this->seeInDatabase('users', [ + 'id' => $user->id, + 'email' => null, + 'password' => null, + ]); + } + + /** @test */ + public function user_can_edit_death() + { + $user = $this->loginAsUser(); + $this->visit(route('users.edit', [$user->id, 'tab' => 'death'])); + $this->seePageIs(route('users.edit', [$user->id, 'tab' => 'death'])); + + $this->submitForm(trans('app.update'), [ + 'dod' => '2003-10-17', + 'yod' => '', + ]); + + $this->seeInDatabase('users', [ + 'id' => $user->id, + 'dod' => '2003-10-17', + 'yod' => '2003', + ]); + } + + /** @test */ + public function user_can_update_yod_only() + { + $user = $this->loginAsUser(); + $this->visit(route('users.edit', [$user->id, 'tab' => 'death'])); + $this->seePageIs(route('users.edit', [$user->id, 'tab' => 'death'])); + + $this->submitForm(trans('app.update'), [ + 'dod' => '', + 'yod' => '2003', + ]); + + $this->seeInDatabase('users', [ + 'id' => $user->id, + 'dod' => null, + 'yod' => '2003', + ]); + } + + /** @test */ public function manager_can_add_login_account_on_a_user() { $manager = $this->loginAsUser(); $user = factory(User::class)->create(['manager_id' => $manager->id]); - $this->visit(route('users.edit', $user->id)); - $this->seePageIs(route('users.edit', $user->id)); + $this->visit(route('users.edit', [$user->id, 'tab' => 'login_account'])); + $this->seePageIs(route('users.edit', [$user->id, 'tab' => 'login_account'])); $this->submitForm(trans('app.update'), [ 'email' => 'user@mail.com', @@ -82,8 +180,8 @@ class UsersProfileTest extends TestCase { $manager = $this->loginAsUser(); $user = factory(User::class)->create(['manager_id' => $manager->id]); - $this->visit(route('users.edit', $user->id)); - $this->seePageIs(route('users.edit', $user->id)); + $this->visit(route('users.edit', [$user->id, 'tab' => 'login_account'])); + $this->seePageIs(route('users.edit', [$user->id, 'tab' => 'login_account'])); $this->submitForm(trans('app.update'), [ 'email' => 'user@mail.com', @@ -103,8 +201,8 @@ class UsersProfileTest extends TestCase 'manager_id' => $manager->id, 'password' => 'some random string password', ]); - $this->visit(route('users.edit', $user->id)); - $this->seePageIs(route('users.edit', $user->id)); + $this->visit(route('users.edit', [$user->id, 'tab' => 'login_account'])); + $this->seePageIs(route('users.edit', [$user->id, 'tab' => 'login_account'])); $this->submitForm(trans('app.update'), [ 'email' => 'user@mail.com', @@ -137,11 +235,4 @@ class UsersProfileTest extends TestCase $this->assertNotNull($user->photo_path); Storage::assertExists($user->photo_path); } - - /** @test */ - public function guest_can_search_users_profile() - { - $this->visit(route('users.search')); - $this->seePageIs(route('users.search')); - } }