diff --git a/app/Http/Controllers/Issues/CommentController.php b/app/Http/Controllers/Issues/CommentController.php index 8288f3b..31f9888 100644 --- a/app/Http/Controllers/Issues/CommentController.php +++ b/app/Http/Controllers/Issues/CommentController.php @@ -4,11 +4,11 @@ namespace App\Http\Controllers\Issues; use Illuminate\Http\Request; use App\Entities\Projects\Issue; +use App\Entities\Projects\Comment; use App\Http\Controllers\Controller; class CommentController extends Controller { - /** * Store a new comment in storage. * @@ -33,4 +33,23 @@ class CommentController extends Controller return back(); } + + /** + * Update the specified comment. + * + * @param \Illuminate\Http\Request $request + * @param \App\Entities\Projects\Issue $issue + * @param \App\Entities\Projects\Comment $comment + * @return \Illuminate\Http\Response + */ + public function update(Request $request, Issue $issue, Comment $comment) + { + $commentData = $request->validate([ + 'body' => 'required|string|max:255', + ]); + $comment->update($commentData); + flash(__('comment.updated'), 'success'); + + return redirect()->route('projects.issues.show', [$issue->project, $issue]); + } } diff --git a/app/Http/Controllers/Projects/IssueController.php b/app/Http/Controllers/Projects/IssueController.php index 2164c7b..830df9c 100644 --- a/app/Http/Controllers/Projects/IssueController.php +++ b/app/Http/Controllers/Projects/IssueController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Projects; use App\Entities\Users\User; use Illuminate\Http\Request; use App\Entities\Projects\Issue; +use App\Entities\Projects\Comment; use App\Entities\Projects\Project; use App\Entities\Projects\Priority; use App\Http\Controllers\Controller; @@ -50,13 +51,19 @@ class IssueController extends Controller public function show(Project $project, Issue $issue) { + $editableComment = null; $priorities = Priority::toArray(); $statuses = IssueStatus::toArray(); $users = User::pluck('name', 'id'); $comments = $issue->comments()->with('creator')->get(); + if (request('action') == 'comment-edit' && request('comment_id') != null) { + $editableComment = Comment::find(request('comment_id')); + } + return view('projects.issues.show', compact( - 'project', 'issue', 'users', 'statuses', 'priorities', 'comments' + 'project', 'issue', 'users', 'statuses', 'priorities', 'comments', + 'editableComment' )); } diff --git a/resources/lang/id/comment.php b/resources/lang/id/comment.php index 95a1586..b79cd50 100644 --- a/resources/lang/id/comment.php +++ b/resources/lang/id/comment.php @@ -12,7 +12,7 @@ return [ 'created' => 'Input Komentar berhasil.', 'edit' => 'Edit Komentar', 'update' => 'Update Komentar', - 'updated' => 'Update data Komentar telah berhasil.', + 'updated' => 'Update Komentar berhasil.', 'delete' => 'Hapus Komentar', 'delete_confirm' => 'Anda yakin akan menghapus Komentar ini?', 'deleted' => 'Komentar berhasil dihapus.', diff --git a/resources/views/projects/issues/partials/comment-section.blade.php b/resources/views/projects/issues/partials/comment-section.blade.php index dff082a..094df69 100644 --- a/resources/views/projects/issues/partials/comment-section.blade.php +++ b/resources/views/projects/issues/partials/comment-section.blade.php @@ -4,6 +4,9 @@ {{ $comment->time_display }} {{ $comment->creator->name }} +
+ {{ link_to_route('projects.issues.show', __('app.edit'), [$project, $issue, 'action' => 'comment-edit', 'comment_id' => $comment->id], ['id' => 'edit-comment-'.$comment->id, 'class' => 'small', 'title' => __('comment.edit')]) }} +
{!! nl2br($comment->body) !!} @endforeach @@ -15,3 +18,27 @@ {{ Form::close() }}

@endcan + +@if (Request::get('action') == 'comment-edit' && $editableComment) + +@endif diff --git a/resources/views/projects/issues/show.blade.php b/resources/views/projects/issues/show.blade.php index 906d5f3..beb3017 100755 --- a/resources/views/projects/issues/show.blade.php +++ b/resources/views/projects/issues/show.blade.php @@ -52,3 +52,14 @@ @endsection + +@section('script') + +@endsection diff --git a/routes/web/projects.php b/routes/web/projects.php index 1b585a1..c162b54 100644 --- a/routes/web/projects.php +++ b/routes/web/projects.php @@ -110,3 +110,4 @@ Route::patch('issues/{issue}/options', 'Issues\OptionController@update')->name(' * Issue Comments Routes */ Route::post('issues/{issue}/comments', 'Issues\CommentController@store')->name('issues.comments.store'); +Route::patch('issues/{issue}/comments/{comment}', 'Issues\CommentController@update')->name('issues.comments.update'); diff --git a/tests/Feature/Projects/IssueCommentsTest.php b/tests/Feature/Projects/IssueCommentsTest.php index fe8c2db..a57cc29 100644 --- a/tests/Feature/Projects/IssueCommentsTest.php +++ b/tests/Feature/Projects/IssueCommentsTest.php @@ -49,4 +49,36 @@ class IssueCommentsTest extends TestCase 'creator_id' => $admin->id, ]); } + + /** @test */ + public function user_can_edit_an_issue_comment() + { + $this->adminUserSigningIn(); + $issue = factory(Issue::class)->create(); + $comment = factory(Comment::class)->create([ + 'commentable_type' => 'issues', + 'commentable_id' => $issue->id, + 'body' => 'This is issue comment.', + ]); + + $this->visitRoute('projects.issues.show', [$issue->project, $issue]); + $this->seeElement('a', ['id' => 'edit-comment-'.$comment->id]); + $this->click('edit-comment-'.$comment->id); + $this->seeRouteIs('projects.issues.show', [$issue->project, $issue, 'action' => 'comment-edit', 'comment_id' => $comment->id]); + + $this->submitForm(__('comment.update'), [ + 'body' => 'Edited comment.', + ]); + + $this->seePageIs(route('projects.issues.show', [$issue->project, $issue])); + $this->see(__('comment.updated')); + + $this->seeInDatabase('comments', [ + 'id' => $comment->id, + 'commentable_type' => 'issues', + 'commentable_id' => $issue->id, + 'body' => 'Edited comment.', + ]); + } + }