Commit b9730916 by Bui Minh Duc

implement comment inner pulls

parent 6ab05a6c
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class CommentsController < ApplicationController
def create
comment = Comment.new
comment.body = params[:comment][:content]
comment.score = params[:comment][:score]
comment.issue_id = params[:pull_id]
comment.user_id = User.first.id
comment.comment_type = 1
comment.save
redirect_to pull_path(id: params[:pull_id])
end
def update
comment = Comment.find_by(id: params[:id])
comment.score = params[:comment][:score].to_i
comment.save
render json: {comment: comment.id, score: comment.score}
end
def destroy
comment = Comment.find_by(id: params[:id])
comment.destroy
render json: {comment: params[:id], status: "success"}
end
end
class PullsController < ApplicationController class PullsController < ApplicationController
def show def show
@pull = Issue.find_by(id: params[:id]) @id = params[:id]
@pull = Issue.find_by(id: @id)
@issue = @pull.issue @issue = @pull.issue
@repo = @issue.repository @repo = @issue.repository
@comments = @pull.comments @comments = @pull.comments.where(comment_type: 0)
@rv_comments = @pull.review_comments @rv_comments = @pull.review_comments
@manager_comments = @pull.comments.where(comment_type: 1)
@options = [ @options = [
{id: 0, type: "None"}, {id: 0, type: "None"},
...@@ -16,10 +18,12 @@ class PullsController < ApplicationController ...@@ -16,10 +18,12 @@ class PullsController < ApplicationController
end end
def update def update
if !params[:rv_comment].nil?
@rv_comment = ReviewComment.find_by(id: params[:rv_comment][:id]) @rv_comment = ReviewComment.find_by(id: params[:rv_comment][:id])
@rv_comment.score = params[:rv_comment][:score] @rv_comment.score = params[:rv_comment][:score]
@rv_comment.save @rv_comment.save
render json: {comment: @rv_comment.id, score: @rv_comment.score} render json: {comment: @rv_comment.id, score: @rv_comment.score}
end end
end
end end
module CommentsHelper
end
...@@ -31,10 +31,12 @@ ...@@ -31,10 +31,12 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<% @rv_comments.each do |rv_comment| %> <% @rv_comments.each do |rv_comment| %>
<%= form_for :rv_comment, method: :patch, html: { class: "form-inline" } do |f| %> <%= form_for :rv_comment, method: :patch, html: { class: "form-inline rate-form" } do |f| %>
<div class="panel panel-default"> <div class="panel panel-default">
<%= f.hidden_field "id", value: rv_comment.id %> <%= f.hidden_field "id", value: rv_comment.id %>
<div class="panel-heading"><h5><%= link_to rv_comment.user.login, rv_comment.user.html_url %></h5></div> <div class="panel-heading">
<h5><%= link_to rv_comment.user.login, rv_comment.user.html_url %></h5>
</div>
<div class="panel-body"> <div class="panel-body">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
...@@ -63,12 +65,39 @@ ...@@ -63,12 +65,39 @@
<h4><b>After Release</b></h4> <h4><b>After Release</b></h4>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<% @manager_comments.each do |cmt| %>
<div class="panel panel-default">
<div class="panel-heading">
<%= form_for :comment, url: pull_comment_path(pull_id: @pull.id, id: cmt.id), method: :delete, html: { class: "delete-form" } do |f| %>
<h5>
<%= link_to cmt.user.login, cmt.user.html_url %>
<%= f.submit "Delete", class: "btn btn-danger btn-xs btn-delete", style: "float: right;" %>
</h5>
<% end %>
</div>
<%= form_for :comment, url: pull_comment_path(pull_id: @pull.id, id: cmt.id), method: :patch, html: { class: "form-inline rate-form" } do |f| %>
<div class="panel-body">
<div class="col-md-8">
<p><%= cmt.body %></p>
</div>
<div class="col-md-4">
<div class="form-group" style="float: right;">
<% @comment = OpenStruct.new({ score: cmt.score }) %>
<%= f.select("score", @options.collect { |x| [ x[:type], x[:id] ] }, {}, { class: 'form-control' }) %>
<%= f.submit "Save", class: "btn btn-default btn-save" %>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h5><b>Add a comment</b></h5> <h5><b>Add a comment</b></h5>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<%= form_for :comment, html: { class: "form-horizontal" } do |f| %> <%= form_for :comment, url: pull_comments_path(pull_id: @pull.id), method: :post, html: { class: "form-horizontal" } do |f| %>
<div class="form-group"> <div class="form-group">
<div class="col-md-12"> <div class="col-md-12">
<%= f.text_area :content, { class: "form-control", rows: 4 } %> <%= f.text_area :content, { class: "form-control", rows: 4 } %>
...@@ -79,7 +108,7 @@ ...@@ -79,7 +108,7 @@
<%= f.submit "Submit", class: "btn btn-default", style: "float: right;" %> <%= f.submit "Submit", class: "btn btn-default", style: "float: right;" %>
</div> </div>
<div class="col-md-3" style="float: right;"> <div class="col-md-3" style="float: right;">
<%= f.select("score", @options.collect { |x| [ x[:type], x[:id] ] }, {}, { class: 'form-control', style: "float: right;" }) %> <%= f.select(:score, @options.collect { |x| [ x[:type], x[:id] ] }, {}, { class: 'form-control', style: "float: right;" }) %>
</div> </div>
</div> </div>
<% end %> <% end %>
...@@ -111,10 +140,53 @@ ...@@ -111,10 +140,53 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Modal -->
<div class="modal fade" id="modal-delete" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Delete Comment</h4>
</div>
<div class="modal-body">
<p>Do you want to delete this comment?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger btn-delete-modal">Delete</button>
</div>
</div>
</div>
</div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$("form").submit(function() {
var submitData = null;
$(".btn-delete").click(function() {
$('#modal-delete').modal();
$(".delete-form").submit(function(event) {
submitData = $(this);
return false;
});
});
$(".btn-delete-modal").click(function() {
$('#modal-delete').modal("hide");
$.ajax({
type: "POST",
url: submitData.attr("action"),
data: submitData.serialize(),
dataType: "JSON"
}).success(function(json) {
location.reload();
});
});
$(".btn-save").click(function() {
$(".rate-form").submit(function(event) {
var submitVar = $(this).serialize(); var submitVar = $(this).serialize();
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -134,7 +206,7 @@ ...@@ -134,7 +206,7 @@
}); });
return false; return false;
}); });
});
</script> </script>
</div> </div>
...@@ -7,7 +7,9 @@ Rails.application.routes.draw do ...@@ -7,7 +7,9 @@ Rails.application.routes.draw do
get "/user", to: "user#index" get "/user", to: "user#index"
resources :issues resources :issues
resources :pulls resources :pulls do
resources :comments
end
resources :repositories resources :repositories
resources :comments resources :comments
......
require 'test_helper'
class CommentsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment