Browse Source

User can edit issue comment

pull/37/head
Nafies Luthfi 7 years ago
parent
commit
f07912eb81
  1. 21
      app/Http/Controllers/Issues/CommentController.php
  2. 9
      app/Http/Controllers/Projects/IssueController.php
  3. 2
      resources/lang/id/comment.php
  4. 27
      resources/views/projects/issues/partials/comment-section.blade.php
  5. 11
      resources/views/projects/issues/show.blade.php
  6. 1
      routes/web/projects.php
  7. 32
      tests/Feature/Projects/IssueCommentsTest.php

21
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]);
}
}

9
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'
));
}

2
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.',

27
resources/views/projects/issues/partials/comment-section.blade.php

@ -4,6 +4,9 @@
<span class="label label-default pull-right">{{ $comment->time_display }}</span>
<strong>{{ $comment->creator->name }}</strong>
</legend>
<div class="pull-right">
{{ 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')]) }}
</div>
{!! nl2br($comment->body) !!}
</div>
@endforeach
@ -15,3 +18,27 @@
{{ Form::close() }}
<div class="clearfix"></div><br>
@endcan
@if (Request::get('action') == 'comment-edit' && $editableComment)
<div id="commentModal" class="modal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
{{ link_to_route('projects.issues.show', '&times;', [$issue->project, $issue], ['class' => 'close']) }}
<h4 class="modal-title">{{ __('comment.edit') }}</h4>
</div>
{!! Form::model($editableComment, ['route' => ['issues.comments.update', $issue, $editableComment],'method' => 'patch']) !!}
<div class="modal-body">
{!! FormField::textarea('body', ['label' => __('comment.body')]) !!}
{{ Form::hidden('page', request('page')) }}
</div>
<div class="modal-footer">
{!! Form::submit(__('comment.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('projects.issues.show', __('app.cancel'), [$project->issue, $issue] + request(['page']), ['class' => 'btn btn-default']) }}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
@endif

11
resources/views/projects/issues/show.blade.php

@ -52,3 +52,14 @@
</div>
</div>
@endsection
@section('script')
<script>
(function () {
$('#commentModal').modal({
show: true,
backdrop: 'static',
});
})();
</script>
@endsection

1
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');

32
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.',
]);
}
}
Loading…
Cancel
Save