Browse Source

Change home view to users show (profile) page and restructured

pull/3/head
Nafies Luthfi 9 years ago
parent
commit
21637de3e2
  1. 2
      app/Http/Controllers/HomeController.php
  2. 2
      app/Http/Controllers/UsersController.php
  3. 3
      app/User.php
  4. 160
      resources/views/home.blade.php
  5. 2
      resources/views/layouts/app.blade.php
  6. 35
      resources/views/users/partials/childs.blade.php
  7. 91
      resources/views/users/partials/parent-spouse.blade.php
  8. 45
      resources/views/users/partials/profile.blade.php
  9. 16
      resources/views/users/show.blade.php
  10. 2
      tests/Feature/ManageUserFamiliesTest.php
  11. 2
      tests/Feature/UsersProfileTest.php

2
app/Http/Controllers/HomeController.php

@ -34,7 +34,7 @@ class HomeController extends Controller
$malePersonList = User::where('gender_id', 1)->pluck('nickname', 'id'); $malePersonList = User::where('gender_id', 1)->pluck('nickname', 'id');
$femalePersonList = User::where('gender_id', 2)->pluck('nickname', 'id'); $femalePersonList = User::where('gender_id', 2)->pluck('nickname', 'id');
return view('home', [
return view('users.show', [
'currentUser' => $user, 'currentUser' => $user,
'usersMariageList' => $usersMariageList, 'usersMariageList' => $usersMariageList,
'malePersonList' => $malePersonList, 'malePersonList' => $malePersonList,

2
app/Http/Controllers/UsersController.php

@ -54,7 +54,7 @@ class UsersController extends Controller
$malePersonList = User::where('gender_id', 1)->pluck('nickname', 'id'); $malePersonList = User::where('gender_id', 1)->pluck('nickname', 'id');
$femalePersonList = User::where('gender_id', 2)->pluck('nickname', 'id'); $femalePersonList = User::where('gender_id', 2)->pluck('nickname', 'id');
return view('home', [
return view('users.show', [
'currentUser' => $user, 'currentUser' => $user,
'usersMariageList' => $usersMariageList, 'usersMariageList' => $usersMariageList,
'malePersonList' => $malePersonList, 'malePersonList' => $malePersonList,

3
app/User.php

@ -92,8 +92,7 @@ class User extends Authenticatable
public function profileLink() public function profileLink()
{ {
$linkText = $this->name ?: $this->nickname;
return link_to_route('users.show', $linkText, [$this->id]);
return link_to_route('users.show', $this->name, [$this->id]);
} }
public function wifes() public function wifes()

160
resources/views/home.blade.php

@ -1,160 +0,0 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Profile : {{ $currentUser->name ?: $currentUser->nickname }}</div>
<div class="panel-body">
<table class="table table-condensed">
<tbody>
<tr>
<th class="col-sm-4">Nama Panggilan</th>
<td class="col-sm-6">{{ $currentUser->nickname }}</td>
</tr>
<tr>
<th>Nama</th>
<td>{{ $currentUser->profileLink() }}</td>
</tr>
<tr>
<th>Jenis Kelamin</th>
<td>{{ $currentUser->gender }}</td>
</tr>
<tr>
<th>Ayah</th>
<td>
@if ($currentUser->father_id)
{{ $currentUser->father->profileLink() }}
@else
{{ Form::open(['route' => ['family-actions.set-father', $currentUser->id]]) }}
{!! FormField::select('set_father_id', $malePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_father', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_father_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
<tr>
<th>Ibu</th>
<td>
@if ($currentUser->mother_id)
{{ $currentUser->mother->profileLink() }}
@else
{{ Form::open(['route' => ['family-actions.set-mother', $currentUser->id]]) }}
{!! FormField::select('set_mother_id', $femalePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_mother', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_mother_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">Keluarga</div>
<div class="panel-body">
<table class="table table-condensed">
<tbody>
@if ($currentUser->gender_id == 1)
<tr>
<th>Isteri</th>
<td>
@if ($currentUser->wifes->isEmpty() == false)
<ul>
@foreach($currentUser->wifes as $wife)
<li>{{ $wife->profileLink() }}</li>
@endforeach
</ul>
@else
{{ Form::open(['route' => ['family-actions.add-wife', $currentUser->id]]) }}
{!! FormField::select('set_wife_id', $femalePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_wife', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_wife_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
@else
<tr>
<th>Suami</th>
<td>
@if ($currentUser->husbands->isEmpty() == false)
<ul>
@foreach($currentUser->husbands as $husband)
<li>{{ $husband->profileLink() }}</li>
@endforeach
</ul>
@else
{{ Form::open(['route' => ['family-actions.add-husband', $currentUser->id]]) }}
{!! FormField::select('set_husband_id', $malePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_husband', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_husband_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
@endif
</tbody>
</table>
<legend>Anak-Anak</legend>
<ul class="list-group">
@foreach($currentUser->childs as $child)
<li class="list-group-item">
{{ $child->profileLink() }} ({{ $child->gender }})
</li>
@endforeach
<li class="list-group-item">
{{ Form::open(['route' => ['family-actions.add-child', $currentUser->id]]) }}
<div class="row">
<div class="col-md-4">
{!! FormField::text('add_child_name', ['label' => 'Nama Anak']) !!}
</div>
<div class="col-md-4">
{!! FormField::radios('add_child_gender_id', [1 => 'Laki-laki', 2 => 'Perempuan'], ['label' => 'Jenis Kelamin Anak']) !!}
</div>
<div class="col-md-4">
{!! FormField::select('add_child_parent_id', $usersMariageList, ['label' => 'Dari Pernikahan']) !!}
</div>
</div>
{{ Form::submit('Tambah Anak', ['class' => 'btn btn-success btn-sm']) }}
{{ Form::close() }}
</li>
</ul>
</div>
</div>
</div>
</div>
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
</div>
@endsection

2
resources/views/layouts/app.blade.php

@ -28,7 +28,7 @@
</button> </button>
<!-- Branding Image --> <!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}">
<a class="navbar-brand" href="{{ route('home') }}">
{{ config('app.name', 'Laravel') }} {{ config('app.name', 'Laravel') }}
</a> </a>
</div> </div>

35
resources/views/users/partials/childs.blade.php

@ -0,0 +1,35 @@
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right" style="margin: -3px -6px">
{{ link_to_route('users.show', 'Tambah Anak', [$user->id, 'action' => 'add_child'], ['class' => 'btn btn-success btn-xs']) }}
</div>
<h3 class="panel-title">Anak-Anak</h3>
</div>
<ul class="list-group">
@foreach($user->childs as $child)
<li class="list-group-item">
{{ $child->profileLink() }} ({{ $child->gender }})
</li>
@endforeach
@if (request('action') == 'add_child')
<li class="list-group-item">
{{ Form::open(['route' => ['family-actions.add-child', $user->id]]) }}
<div class="row">
<div class="col-md-4">
{!! FormField::text('add_child_name', ['label' => 'Nama Anak']) !!}
</div>
<div class="col-md-4">
{!! FormField::radios('add_child_gender_id', [1 => 'Laki-laki', 2 => 'Perempuan'], ['label' => 'Jenis Kelamin Anak']) !!}
</div>
<div class="col-md-4">
{!! FormField::select('add_child_parent_id', $usersMariageList, ['label' => 'Dari Pernikahan']) !!}
</div>
</div>
{{ Form::submit('Tambah Anak', ['class' => 'btn btn-success btn-sm']) }}
{{ link_to_route('users.show', 'Batal', [$user->id], ['class' => 'btn btn-default btn-sm']) }}
{{ Form::close() }}
</li>
@endif
</ul>
</div>

91
resources/views/users/partials/parent-spouse.blade.php

@ -0,0 +1,91 @@
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Keluarga</h3></div>
<table class="table">
<tbody>
<tr>
<th>Ayah</th>
<td>
@if ($user->father_id)
{{ $user->father->profileLink() }}
@else
{{ Form::open(['route' => ['family-actions.set-father', $user->id]]) }}
{!! FormField::select('set_father_id', $malePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_father', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_father_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
<tr>
<th>Ibu</th>
<td>
@if ($user->mother_id)
{{ $user->mother->profileLink() }}
@else
{{ Form::open(['route' => ['family-actions.set-mother', $user->id]]) }}
{!! FormField::select('set_mother_id', $femalePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_mother', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_mother_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
@if ($user->gender_id == 1)
<tr>
<th>Isteri</th>
<td>
@if ($user->wifes->isEmpty() == false)
<ul class="list-unstyled">
@foreach($user->wifes as $wife)
<li>{{ $wife->profileLink() }}</li>
@endforeach
</ul>
@else
{{ Form::open(['route' => ['family-actions.add-wife', $user->id]]) }}
{!! FormField::select('set_wife_id', $femalePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_wife', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_wife_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
@else
<tr>
<th>Suami</th>
<td>
@if ($user->husbands->isEmpty() == false)
<ul class="list-unstyled">
@foreach($user->husbands as $husband)
<li>{{ $husband->profileLink() }}</li>
@endforeach
</ul>
@else
{{ Form::open(['route' => ['family-actions.add-husband', $user->id]]) }}
{!! FormField::select('set_husband_id', $malePersonList, ['label' => false]) !!}
<div class="input-group">
{{ Form::text('set_husband', null, ['class' => 'form-control input-sm']) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_husband_button']) }}
</span>
</div>
{{ Form::close() }}
@endif
</td>
</tr>
@endif
</tbody>
</table>
</div>

45
resources/views/users/partials/profile.blade.php

@ -0,0 +1,45 @@
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Profil</h3></div>
<table class="table">
<tbody>
<tr>
<th class="col-sm-4">Nama</th>
<td class="col-sm-8">
{{ $user->profileLink() }}
</td>
</tr>
<tr>
<th>Nama Panggilan</th>
<td>{{ $user->nickname }}</td>
</tr>
<tr>
<th>Jenis Kelamin</th>
<td>{{ $user->gender }}</td>
</tr>
<tr>
<th>Tanggal Lahir</th>
<td>{{ $user->dob }}</td>
</tr>
@if ($user->dod)
<tr>
<th>Meninggal</th>
<td>{{ $user->dod }}</td>
</tr>
@endif
@if ($user->email)
<tr>
<th>Email</th>
<td>{{ $user->email }}</td>
</tr>
@endif
<tr>
<th>Telp</th>
<td>{{ $user->phone }}</td>
</tr>
<tr>
<th>Alamat</th>
<td>{!! nl2br($user->address) !!}</td>
</tr>
</tbody>
</table>
</div>

16
resources/views/users/show.blade.php

@ -0,0 +1,16 @@
@extends('layouts.app')
@section('content')
<div class="container">
<h3 class="page-header text-center">{{ $currentUser->profileLink() }}</h3>
<div class="row">
<div class="col-md-6">
@include('users.partials.profile', ['user' => $currentUser])
</div>
<div class="col-md-6">
@include('users.partials.parent-spouse', ['user' => $currentUser])
@include('users.partials.childs', ['user' => $currentUser])
</div>
</div>
</div>
@endsection

2
tests/Feature/ManageUserFamiliesTest.php

@ -54,6 +54,7 @@ class ManageUserFamiliesTest extends TestCase
$user = $this->loginAsUser(['gender_id' => 1]); $user = $this->loginAsUser(['gender_id' => 1]);
$this->visit(route('profile')); $this->visit(route('profile'));
$this->seePageIs(route('profile')); $this->seePageIs(route('profile'));
$this->click('Tambah Anak');
$this->seeElement('input', ['name' => 'add_child_name']); $this->seeElement('input', ['name' => 'add_child_name']);
$this->seeElement('input', ['name' => 'add_child_gender_id']); $this->seeElement('input', ['name' => 'add_child_gender_id']);
$this->seeElement('select', ['name' => 'add_child_parent_id']); $this->seeElement('select', ['name' => 'add_child_parent_id']);
@ -85,6 +86,7 @@ class ManageUserFamiliesTest extends TestCase
$this->visit(route('profile')); $this->visit(route('profile'));
$this->seePageIs(route('profile')); $this->seePageIs(route('profile'));
$this->click('Tambah Anak');
$this->seeElement('input', ['name' => 'add_child_name']); $this->seeElement('input', ['name' => 'add_child_name']);
$this->seeElement('input', ['name' => 'add_child_gender_id']); $this->seeElement('input', ['name' => 'add_child_gender_id']);
$this->seeElement('select', ['name' => 'add_child_parent_id']); $this->seeElement('select', ['name' => 'add_child_parent_id']);

2
tests/Feature/UsersProfileTest.php

@ -15,6 +15,6 @@ class UsersProfileTest extends TestCase
{ {
$user = factory(User::class)->create(); $user = factory(User::class)->create();
$this->visit(route('users.show', $user->id)); $this->visit(route('users.show', $user->id));
$this->see('Profile : ' . $user->nickname);
$this->see($user->name);
} }
} }
Loading…
Cancel
Save