From b2344cfd97b9a929500f03ba28c69379b1e372de Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Sun, 13 Aug 2017 14:33:12 +0200 Subject: [PATCH 1/6] Add last activity label to RFCs --- app/views/request_for_comments/index.html.slim | 3 +++ config/locales/de.yml | 1 + config/locales/en.yml | 1 + 3 files changed, 5 insertions(+) diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim index db16b562..51b3a01b 100644 --- a/app/views/request_for_comments/index.html.slim +++ b/app/views/request_for_comments/index.html.slim @@ -20,6 +20,7 @@ h1 = RequestForComment.model_name.human(count: 2) i class="fa fa-comment" aria-hidden="true" title = t('request_for_comments.comments') align="center" th = t('activerecord.attributes.request_for_comments.username') th = t('activerecord.attributes.request_for_comments.requested_at') + th = t('activerecord.attributes.request_for_comments.last_update') tbody - @request_for_comments.each do |request_for_comment| tr data-id=request_for_comment.id @@ -36,5 +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)) = 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 d0aef588..3e780d8f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -94,6 +94,7 @@ de: requested_at: Angefragezeitpunkt question: "Frage" close: "Fenster schließen" + last_update: "Letzte Aktivität" submission: cause: Anlass code: Code diff --git a/config/locales/en.yml b/config/locales/en.yml index 9a334697..47e97c9d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -115,6 +115,7 @@ en: requested_at: Request Date question: "Question" close: Close window + last_update: "Last Update" submission: cause: Cause code: Code From 726ef31ee7f2e8265b2728309e04066b228a6ae3 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Sun, 13 Aug 2017 15:01:11 +0200 Subject: [PATCH 2/6] 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' From ba8511fe4052622e9b5c5903af53edbab8c0e217 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Sun, 13 Aug 2017 16:09:15 +0200 Subject: [PATCH 3/6] Fall back on RFC update time when there are no comments --- app/views/request_for_comments/index.html.slim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim index 34316dd0..a081dd55 100644 --- a/app/views/request_for_comments/index.html.slim +++ b/app/views/request_for_comments/index.html.slim @@ -37,7 +37,6 @@ 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.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)) + td = t('shared.time.before', time: distance_of_time_in_words_to_now(request_for_comment.last_comment.nil? ? request_for_comment.updated_at : request_for_comment.last_comment)) = render('shared/pagination', collection: @request_for_comments) \ No newline at end of file From 06f11ae6f5dca13457bbb37042af65f931d69476 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Sun, 13 Aug 2017 16:09:44 +0200 Subject: [PATCH 4/6] Fix RFC lists for RFCs without comments --- .../request_for_comments_controller.rb | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index 020f1ba1..327d7aa7 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -11,28 +11,44 @@ class RequestForCommentsController < ApplicationController # GET /request_for_comments # GET /request_for_comments.json def index - @search = RequestForComment.last_per_user(2).search(params[:q]) + @search = RequestForComment + .last_per_user(2) + .joins('join "submissions" s on s.id = request_for_comments.submission_id + left outer join "files" f on f.context_id = s.id + left outer join "comments" on comments.file_id = f.id') + .group('request_for_comments.id, request_for_comments.user_id, request_for_comments.exercise_id, + request_for_comments.file_id, request_for_comments.question, request_for_comments.created_at, + request_for_comments.updated_at, request_for_comments.user_type, request_for_comments.solved, + request_for_comments.submission_id, request_for_comments.row_number') # ugly, but rails wants it this way + .select('request_for_comments.*, max(comments.updated_at) as last_comment') + .search(params[:q]) @request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page]) authorize! end def get_my_comment_requests - @search = RequestForComment.where(user_id: current_user.id).order('created_at DESC').search(params[:q]) - @request_for_comments = @search.result.paginate(page: params[:page]) + @search = RequestForComment + .where(user_id: current_user.id) + .joins('join "submissions" s on s.id = request_for_comments.submission_id + left outer join "files" f on f.context_id = s.id + left outer join "comments" on comments.file_id = f.id') + .group('request_for_comments.id') + .select('request_for_comments.*, max(comments.updated_at) as last_comment') + .search(params[:q]) + @request_for_comments = @search.result.order('created_at DESC').paginate(page: params[:page]) render 'index' end def get_rfcs_with_my_comments @search = RequestForComment - .joins(:comments) + .joins(:comments) # we don't need to outer join here, because we know the user has commented on these .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]) + @request_for_comments = @search.result.order('last_comment DESC').paginate(page: params[:page]) render 'index' end From 5de32edcc9a72ac332f079c79fc6fc2a9c773d1b Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Sun, 13 Aug 2017 16:13:40 +0200 Subject: [PATCH 5/6] Add link to comment activity to session menu --- app/views/application/_session.html.slim | 1 + config/locales/de.yml | 1 + config/locales/en.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/app/views/application/_session.html.slim b/app/views/application/_session.html.slim index cbbf3b12..eb9f4d23 100644 --- a/app/views/application/_session.html.slim +++ b/app/views/application/_session.html.slim @@ -10,6 +10,7 @@ li = link_to(t('internal_users.show.link'), current_user) li = link_to(t('request_for_comments.index.all'), request_for_comments_path) li = link_to(t('request_for_comments.index.get_my_comment_requests'), my_request_for_comments_path) + li = link_to(t('request_for_comments.index.get_my_rfc_activity'), my_rfc_activity_path) - if current_user.internal_user? li = link_to(t('sessions.destroy.link'), sign_out_path, method: :delete) - else diff --git a/config/locales/de.yml b/config/locales/de.yml index 18f2e667..59cd816c 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -458,6 +458,7 @@ de: get_my_comment_requests: Meine Kommentaranfragen all: "Alle Kommentaranfragen" get_rfcs_with_my_comments: Kommentaranfragen die ich kommentiert habe + get_my_rfc_activity: "Meine Kommentaraktivität" 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 8db86035..e20a0191 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -479,6 +479,7 @@ en: 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 + get_my_rfc_activity: "My Comment Activity" no_question: "The author did not enter a question for this request." mark_as_solved: "Mark this question as answered" show_all: "All requests" From 9e53fb4ea57a3c6f51e8f600ea75b412add26b2c Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 16 Aug 2017 16:03:49 +0200 Subject: [PATCH 6/6] Fix query for RFC activity --- app/controllers/request_for_comments_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index 327d7aa7..fca5c99b 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -43,10 +43,11 @@ class RequestForCommentsController < ApplicationController @search = RequestForComment .joins(:comments) # we don't need to outer join here, because we know the user has commented on these .where(comments: {user_id: current_user.id}) + .joins('join "submissions" s on s.id = request_for_comments.submission_id + left outer join "files" f on f.context_id = s.id + left outer join "comments" as c on c.file_id = f.id') .group('request_for_comments.id') - .joins(:comments) - .group('request_for_comments.id') - .select('request_for_comments.*, max(comments.updated_at) as last_comment') + .select('request_for_comments.*, max(c.updated_at) as last_comment') .search(params[:q]) @request_for_comments = @search.result.order('last_comment DESC').paginate(page: params[:page]) render 'index'