From a18cd4993cf17fa988503a1a6479ca091098ac20 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Fri, 10 Aug 2018 08:59:06 +0800 Subject: [PATCH] Update job detail layout Add job view layout Add nav-tabs on job detail page Update job show view to extends job layout Add job comments view that extends job layout --- app/Http/Controllers/Jobs/CommentsController.php | 24 ++++++++- resources/views/jobs/comments.blade.php | 54 +++++++++++++++++++ .../views/jobs/partials/comment-section.blade.php | 2 +- resources/views/jobs/partials/nav-tabs.blade.php | 12 +++++ resources/views/jobs/show.blade.php | 60 ++++------------------ resources/views/layouts/job.blade.php | 22 ++++++++ routes/web/projects.php | 1 + tests/Feature/Projects/JobCommentsTest.php | 18 +++---- 8 files changed, 132 insertions(+), 61 deletions(-) create mode 100755 resources/views/jobs/comments.blade.php create mode 100644 resources/views/jobs/partials/nav-tabs.blade.php create mode 100755 resources/views/layouts/job.blade.php diff --git a/app/Http/Controllers/Jobs/CommentsController.php b/app/Http/Controllers/Jobs/CommentsController.php index 409ae04..2fc978b 100644 --- a/app/Http/Controllers/Jobs/CommentsController.php +++ b/app/Http/Controllers/Jobs/CommentsController.php @@ -10,6 +10,26 @@ use App\Http\Controllers\Controller; class CommentsController extends Controller { /** + * Display a listing of the job comments. + * + * @param \App\Entities\Projects\Job $job + * @return \Illuminate\View\View + */ + public function index(Job $job) + { + $this->authorize('view-comments', $job); + + $editableComment = null; + $comments = $job->comments()->with('creator')->latest()->paginate(); + + if (request('action') == 'comment-edit' && request('comment_id') != null) { + $editableComment = Comment::find(request('comment_id')); + } + + return view('jobs.comments', compact('job', 'comments', 'editableComment')); + } + + /** * Store a new comment in storage. * * @param \Illuminate\Http\Request $request @@ -52,7 +72,7 @@ class CommentsController extends Controller $comment->update($commentData); flash(__('comment.updated'), 'success'); - return redirect()->route('jobs.show', [$job] + request(['page'])); + return redirect()->route('jobs.comments.index', [$job] + request(['page'])); } /** @@ -73,7 +93,7 @@ class CommentsController extends Controller $routeParam = [$job] + request(['page']); flash(__('comment.deleted'), 'warning'); - return redirect()->route('jobs.show', $routeParam); + return redirect()->route('jobs.comments.index', $routeParam); } flash(__('comment.undeleted'), 'error'); diff --git a/resources/views/jobs/comments.blade.php b/resources/views/jobs/comments.blade.php new file mode 100755 index 0000000..df0c010 --- /dev/null +++ b/resources/views/jobs/comments.blade.php @@ -0,0 +1,54 @@ +@extends('layouts.job') + +@section('subtitle', __('comment.list')) + +@section('content-job') +
+
+ {{ $comments->links() }} + @include('jobs.partials.comment-section') + {{ $comments->links() }} +
+
+ +@if (Request::get('action') == 'comment-edit' && $editableComment) + +@endif +@endsection + +@section('ext_css') + +@endsection + +@section('script') + +@endsection diff --git a/resources/views/jobs/partials/comment-section.blade.php b/resources/views/jobs/partials/comment-section.blade.php index 6f5b042..88809c8 100644 --- a/resources/views/jobs/partials/comment-section.blade.php +++ b/resources/views/jobs/partials/comment-section.blade.php @@ -16,7 +16,7 @@
@can('update', $comment) - {{ link_to_route('jobs.show', __('app.edit'), [$job, 'action' => 'comment-edit', 'comment_id' => $comment->id], ['id' => 'edit-comment-'.$comment->id, 'class' => 'small', 'title' => __('comment.edit')]) }} + {{ link_to_route('jobs.comments.index', __('app.edit'), [$job, 'action' => 'comment-edit', 'comment_id' => $comment->id], ['id' => 'edit-comment-'.$comment->id, 'class' => 'small', 'title' => __('comment.edit')]) }} @endcan @can('delete', $comment) {!! FormField::delete( diff --git a/resources/views/jobs/partials/nav-tabs.blade.php b/resources/views/jobs/partials/nav-tabs.blade.php new file mode 100644 index 0000000..e1fb60e --- /dev/null +++ b/resources/views/jobs/partials/nav-tabs.blade.php @@ -0,0 +1,12 @@ + + +
diff --git a/resources/views/jobs/show.blade.php b/resources/views/jobs/show.blade.php index e3062e6..f3ae9ec 100755 --- a/resources/views/jobs/show.blade.php +++ b/resources/views/jobs/show.blade.php @@ -1,22 +1,17 @@ -@extends('layouts.app') +@extends('layouts.job') -@section('title', __('job.detail') . ' | ' . $job->name . ' | ' . $job->project->name) +@section('subtitle', __('job.detail')) -@section('content') -@include('jobs.partials.breadcrumb') +@section('action-buttons') +@can('create', new App\Entities\Projects\Job) + {!! html_link_to_route('projects.jobs.create', __('job.create'), [$job->project_id], ['class' => 'btn btn-success','icon' => 'plus']) !!} +@endcan +@can('update', $job) + {{ link_to_route('jobs.edit', __('job.edit'), [$job], ['class' => 'btn btn-warning']) }} +@endcan +@endsection +@section('content-job') -

-
- @can('create', new App\Entities\Projects\Job) - {!! html_link_to_route('projects.jobs.create', __('job.create'), [$job->project_id], ['class' => 'btn btn-success','icon' => 'plus']) !!} - @endcan - @can('update', $job) - {{ link_to_route('jobs.edit', __('job.edit'), [$job], ['class' => 'btn btn-warning']) }} - @endcan - {{ link_to_route('projects.jobs.index', __('job.back_to_index'), [$job->project_id, '#' . $job->id], ['class' => 'btn btn-default']) }} -
- {{ $job->name }} {{ __('job.detail') }} -

@include('jobs.partials.job-show') @@ -29,39 +24,6 @@
@include('jobs.partials.job-tasks') - @can('view-comments', $job) -
-
- {{ $comments->links() }} - @include('jobs.partials.comment-section') - {{ $comments->links() }} -
-
- - @if (Request::get('action') == 'comment-edit' && $editableComment) - - @endif - @endcan
@endsection diff --git a/resources/views/layouts/job.blade.php b/resources/views/layouts/job.blade.php new file mode 100755 index 0000000..302dc99 --- /dev/null +++ b/resources/views/layouts/job.blade.php @@ -0,0 +1,22 @@ +@extends('layouts.app') + +@section('title') +@yield('subtitle', __('job.detail')) - {{ $job->name }} +@endsection + +@section('content') +@include('jobs.partials.breadcrumb') + +

+
+ @yield('action-buttons') + {{ link_to_route('projects.jobs.index', __('job.back_to_index'), [$job->project_id, '#' . $job->id], ['class' => 'btn btn-default']) }} +
+ {{ $job->name }} @yield('subtitle', __('job.detail')) +

+ +@include('jobs.partials.nav-tabs') + +@yield('content-job') + +@endsection diff --git a/routes/web/projects.php b/routes/web/projects.php index 64b4a41..949d7fc 100644 --- a/routes/web/projects.php +++ b/routes/web/projects.php @@ -82,6 +82,7 @@ Route::group(['middleware' => ['auth']], function () { /* * Project Comments Routes */ + Route::get('jobs/{job}/comments', 'Jobs\CommentsController@index')->name('jobs.comments.index'); Route::post('jobs/{job}/comments', 'Jobs\CommentsController@store')->name('jobs.comments.store'); Route::patch('jobs/{job}/comments/{comment}', 'Jobs\CommentsController@update')->name('jobs.comments.update'); Route::delete('jobs/{job}/comments/{comment}', 'Jobs\CommentsController@destroy')->name('jobs.comments.destroy'); diff --git a/tests/Feature/Projects/JobCommentsTest.php b/tests/Feature/Projects/JobCommentsTest.php index 8ecd4c2..4263a42 100644 --- a/tests/Feature/Projects/JobCommentsTest.php +++ b/tests/Feature/Projects/JobCommentsTest.php @@ -19,8 +19,8 @@ class JobCommentsTest extends TestCase 'body' => 'This is job comment.', ]); - $this->visitRoute('jobs.show', $job); - $this->seeRouteIs('jobs.show', $job); + $this->visitRoute('jobs.comments.index', $job); + $this->seeRouteIs('jobs.comments.index', $job); $this->seeText('This is job comment.'); } @@ -31,13 +31,13 @@ class JobCommentsTest extends TestCase $admin = $this->adminUserSigningIn(); $job = factory(Job::class)->create(); - $this->visitRoute('jobs.show', $job); + $this->visitRoute('jobs.comments.index', $job); $this->submitForm(__('comment.create'), [ 'body' => 'Komentar pertama.', ]); - $this->seePageIs(route('jobs.show', $job)); + $this->seePageIs(route('jobs.comments.index', $job)); $this->see(__('comment.created')); $this->seeInDatabase('comments', [ @@ -59,16 +59,16 @@ class JobCommentsTest extends TestCase 'body' => 'This is job comment.', ]); - $this->visitRoute('jobs.show', $job); + $this->visitRoute('jobs.comments.index', $job); $this->seeElement('a', ['id' => 'edit-comment-'.$comment->id]); $this->click('edit-comment-'.$comment->id); - $this->seeRouteIs('jobs.show', [$job, 'action' => 'comment-edit', 'comment_id' => $comment->id]); + $this->seeRouteIs('jobs.comments.index', [$job, 'action' => 'comment-edit', 'comment_id' => $comment->id]); $this->submitForm(__('comment.update'), [ 'body' => 'Komentar pertama.', ]); - $this->seePageIs(route('jobs.show', $job)); + $this->seePageIs(route('jobs.comments.index', $job)); $this->see(__('comment.updated')); $this->seeInDatabase('comments', [ @@ -90,11 +90,11 @@ class JobCommentsTest extends TestCase 'body' => 'This is job comment.', ]); - $this->visitRoute('jobs.show', $job); + $this->visitRoute('jobs.comments.index', $job); $this->seeElement('button', ['id' => 'delete-comment-'.$comment->id]); $this->press('delete-comment-'.$comment->id); - $this->seePageIs(route('jobs.show', $job)); + $this->seePageIs(route('jobs.comments.index', $job)); $this->see(__('comment.deleted')); $this->dontSeeInDatabase('comments', [