From 2ff12dbeb6d22f42d0b5d963273c803b6f6cc573 Mon Sep 17 00:00:00 2001
From: Ralf Teusner
Date: Mon, 27 Jun 2016 16:46:26 +0200
Subject: [PATCH] Cached displaynames of users Added solved state and #comments
to index of request_for_comments Added translations
---
app/models/code_ocean/file.rb | 1 +
app/models/external_user.rb | 6 ++++--
app/models/request_for_comment.rb | 6 +++++-
app/views/request_for_comments/index.html.slim | 10 ++++++++++
app/views/request_for_comments/show.html.erb | 12 +++++++++---
config/locales/de.yml | 5 +++++
config/locales/en.yml | 5 +++++
7 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/app/models/code_ocean/file.rb b/app/models/code_ocean/file.rb
index 58440f1b..22c6e877 100644
--- a/app/models/code_ocean/file.rb
+++ b/app/models/code_ocean/file.rb
@@ -35,6 +35,7 @@ module CodeOcean
has_many :files
has_many :testruns
+ has_many :comments
alias_method :descendants, :files
mount_uploader :native_file, FileUploader
diff --git a/app/models/external_user.rb b/app/models/external_user.rb
index 8038d2dc..24baa284 100644
--- a/app/models/external_user.rb
+++ b/app/models/external_user.rb
@@ -6,8 +6,10 @@ class ExternalUser < ActiveRecord::Base
def displayname
result = name
- if(consumer.name == 'openHPI')
- result = Xikolo::UserClient.get(external_id.to_s)[:display_name]
+ Rails.cache.fetch("#{cache_key}/displayname", expires_in: 12.hours) do
+ if(consumer.name == 'openHPI')
+ result = Xikolo::UserClient.get(external_id.to_s)[:display_name]
+ end
end
result
end
diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb
index 2107c31e..57b9a079 100644
--- a/app/models/request_for_comment.rb
+++ b/app/models/request_for_comment.rb
@@ -25,12 +25,16 @@ class RequestForComment < ActiveRecord::Base
limit 1").first
end
+ def comments_count
+ submission.files.map { |file| file.comments.size}.sum
+ end
+
def to_s
"RFC-" + self.id.to_s
end
private
def self.row_number_user_sql
- select("id, user_id, exercise_id, file_id, question, requested_at, created_at, updated_at, user_type, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql
+ select("id, user_id, exercise_id, file_id, question, requested_at, created_at, updated_at, user_type, solved, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql
end
end
diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim
index 6d4e059c..3bdbe6d0 100644
--- a/app/views/request_for_comments/index.html.slim
+++ b/app/views/request_for_comments/index.html.slim
@@ -4,18 +4,28 @@ h1 = RequestForComment.model_name.human(count: 2)
table.table.sortable
thead
tr
+ th
+ i class="fa fa-lightbulb-o" aria-hidden="true" title = t('request_for_comments.solved') align="right"
th = t('activerecord.attributes.request_for_comments.exercise')
th = t('activerecord.attributes.request_for_comments.question')
+ th
+ 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')
tbody
- @request_for_comments.each do |request_for_comment|
tr data-id=request_for_comment.id
+ - if request_for_comment.solved?
+ td
+ span class="fa fa-check" aria-hidden="true"
+ - else
+ td = ''
td = link_to(request_for_comment.exercise.title, request_for_comment)
- if request_for_comment.has_attribute?(:question) && request_for_comment.question
td = truncate(request_for_comment.question, length: 200)
- else
td = '-'
+ 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.requested_at))
diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb
index 606327bb..6ef176bd 100644
--- a/app/views/request_for_comments/show.html.erb
+++ b/app/views/request_for_comments/show.html.erb
@@ -14,15 +14,21 @@
%>
<%= user.displayname %> | <%= @request_for_comment.requested_at %>
+
+ <%= t('activerecord.attributes.exercise.instructions') %>: "<%= @request_for_comment.exercise.description %>"
+
+
<% if @request_for_comment.question and not @request_for_comment.question == '' %>
- <%= t('activerecord.attributes.request_for_comments.question')%>: "<%= @request_for_comment.question %>"
+ <%= t('activerecord.attributes.request_for_comments.question')%>: "<%= @request_for_comment.question %>"
<% else %>
- <%= t('request_for_comments.no_question') %>
+ <%= t('activerecord.attributes.request_for_comments.question')%>: <%= t('request_for_comments.no_question') %>
<% end %>
<% if (policy(@request_for_comment).mark_as_solved? and not @request_for_comment.solved?) %>
-
+
+ <% elsif (@request_for_comment.solved?) %>
+
<% else %>
<% end %>
diff --git a/config/locales/de.yml b/config/locales/de.yml
index d227e7b7..53df1858 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -78,6 +78,7 @@ de:
password_confirmation: Passwort-Bestätigung
role: Rolle
request_for_comments:
+ comments: Kommentare
exercise: Aufgabe
execution_environment: Sprache
username: Benutzername
@@ -161,6 +162,7 @@ de:
show:
link: Konsument
errors:
+ connection_refused: Verbindung abgelehnt
index:
count: Anzahl
execution_environments:
@@ -350,10 +352,13 @@ de:
body: 'Bitte besuchen Sie %{link}, sofern Sie Ihr Passwort zurücksetzen wollen.'
subject: Anweisungen zum Zurücksetzen Ihres Passworts
request_for_comments:
+ comments: Kommentare
index:
get_my_comment_requests: Meine Kommentaranfragen
all: "Alle Kommentaranfragen"
no_question: "Der Autor hat keine Frage zu dieser Anfrage gestellt."
+ mark_as_solved: "Diese Frage als beantwortet markieren"
+ solved: "Diese Frage wurde erfolgreich beantwortet"
sessions:
create:
failure: Fehlerhafte E-Mail oder Passwort.
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 684a350d..1e72cb34 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -78,6 +78,7 @@ en:
password_confirmation: Passwort Confirmation
role: Role
request_for_comments:
+ comments: Comments
exercise: Exercise
execution_environment: Language
username: Username
@@ -161,6 +162,7 @@ en:
show:
link: Consumer
errors:
+ connection_refused: Connection refused
index:
count: Count
execution_environments:
@@ -350,10 +352,13 @@ en:
body: 'Please visit %{link} if you want to reset your password.'
subject: Password reset instructions
request_for_comments:
+ comments: Comments
index:
all: All Requests for Comments
get_my_comment_requests: My Requests for Comments
no_question: "The author did not enter a question for this request."
+ mark_as_solved: "Mark this question as answered"
+ solved: "This question has been answered"
sessions:
create:
failure: Invalid email or password.