From 726ef31ee7f2e8265b2728309e04066b228a6ae3 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Sun, 13 Aug 2017 15:01:11 +0200 Subject: [PATCH] Add new route to view all RFCs the user has commented on --- app/controllers/request_for_comments_controller.rb | 14 ++++++++++++++ app/views/request_for_comments/index.html.slim | 4 ++-- config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/routes.rb | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index eb2305cc..020f1ba1 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -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 diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim index 51b3a01b..34316dd0 100644 --- a/app/views/request_for_comments/index.html.slim +++ b/app/views/request_for_comments/index.html.slim @@ -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) \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index 3e780d8f..18f2e667 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -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" diff --git a/config/locales/en.yml b/config/locales/en.yml index 47e97c9d..8db86035 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/config/routes.rb b/config/routes.rb index d340a204..65a8f56a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'