Add new route to view all RFCs the user has commented on

This commit is contained in:
Maximilian Grundke
2017-08-13 15:01:11 +02:00
parent b2344cfd97
commit 726ef31ee7
5 changed files with 19 additions and 2 deletions

View File

@ -22,6 +22,20 @@ class RequestForCommentsController < ApplicationController
render 'index'
end
def get_rfcs_with_my_comments
@search = RequestForComment
.joins(:comments)
.where(comments: {user_id: current_user.id})
.group('request_for_comments.id')
.joins(:comments)
.group('request_for_comments.id')
.select('request_for_comments.*, max(comments.updated_at) as last_comment')
.order('last_comment DESC')
.search(params[:q])
@request_for_comments = @search.result.paginate(page: params[:page])
render 'index'
end
def mark_as_solved
authorize!
@request_for_comment.solved = true

View File

@ -37,7 +37,7 @@ h1 = RequestForComment.model_name.human(count: 2)
td = request_for_comment.comments_count
td = request_for_comment.user.displayname
td = t('shared.time.before', time: distance_of_time_in_words_to_now(request_for_comment.created_at))
- last_comment = request_for_comment.comments.order('created_at DESC').first
td = t('shared.time.before', time: distance_of_time_in_words_to_now(last_comment.nil? ? request_for_comment.updated_at : last_comment.updated_at))
//- last_comment = request_for_comment.last_comment || request_for_comment.comments.order('created_at DESC').try(:first).try(:updated_at)
td = t('shared.time.before', time: distance_of_time_in_words_to_now(request_for_comment.last_comment))
= render('shared/pagination', collection: @request_for_comments)

View File

@ -457,6 +457,7 @@ de:
index:
get_my_comment_requests: Meine Kommentaranfragen
all: "Alle Kommentaranfragen"
get_rfcs_with_my_comments: Kommentaranfragen die ich kommentiert habe
no_question: "Der Autor hat keine Frage zu dieser Anfrage gestellt."
mark_as_solved: "Diese Frage als beantwortet markieren"
show_all: "Alle Anfragen anzeigen"

View File

@ -478,6 +478,7 @@ en:
index:
all: All Requests for Comments
get_my_comment_requests: My Requests for Comments
get_rfcs_with_my_comments: Requests for Comments I have commented on
no_question: "The author did not enter a question for this request."
mark_as_solved: "Mark this question as answered"
show_all: "All requests"

View File

@ -20,6 +20,7 @@ Rails.application.routes.draw do
end
end
get '/my_request_for_comments', as: 'my_request_for_comments', to: 'request_for_comments#get_my_comment_requests'
get '/my_rfc_activity', as: 'my_rfc_activity', to: 'request_for_comments#get_rfcs_with_my_comments'
delete '/comment_by_id', to: 'comments#destroy_by_id'
put '/comments', to: 'comments#update'