Add comment functionality to tracks

This commit is contained in:
Rishabh Singh 2019-07-18 12:49:50 +05:30
parent 770a63e15c
commit 58208c73ac
19 changed files with 153 additions and 48 deletions

View file

@ -17,12 +17,12 @@ module Admin
private
# Returning all available comments, ordered by created_at: :desc and by event.title
# Returning all available comments, ordered by created_at: :desc
def accessible_ordered_comments
Comment.accessible_by(current_ability).joins('INNER JOIN events ON commentable_id = events.id').order('events.title', 'comments.created_at DESC')
Comment.accessible_by(current_ability).order('comments.created_at DESC')
end
# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}}
# Grouping all comments by conference, and by commentable obj. It returns {:conference => {:commentable => [{comment_2}, {comment_1 }]}}
def grouped_comments(remarks)
remarks.group_by{ |comment| comment.commentable.program.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
end

View file

@ -30,6 +30,9 @@ module Admin
end
def show
@comments = @track.root_comments
@comment_count = @track.comment_threads.count
respond_to do |format|
format.html { render }
format.json { render json: @conference.tracks.to_json }
@ -53,7 +56,20 @@ module Admin
end
end
def edit; end
def edit
@comments = @track.root_comments
@comment_count = @track.comment_threads.count
end
def comment
comment = Comment.new(comment_params)
comment.commentable = @track
comment.user_id = current_user.id
comment.save!
comment.move_to_child_of(params[:parent]) unless params[:parent].nil?
redirect_to admin_conference_program_track_path(@conference.short_title, @track)
end
def update
if @track.update_attributes(track_params)
@ -139,6 +155,10 @@ module Admin
params.require(:track).permit(:name, :description, :color, :short_name, :cfp_active, :start_date, :end_date, :room_id)
end
def comment_params
params.require(:comment).permit(:commentable, :body, :user_id)
end
def update_state(transition, notice)
errors = @track.update_state(transition)