Code Cleanup: Usage of Polymorphic User instead of ExternalUser and InternalUser
Renamed requestor_user_id -> user_id Index of request_for_comments now returns the n (5?) newest requests per user. Solved via sliding windows in postgres, code added to model. Added route to /my_request_for_comments/ that shows all requests for the current user. Changed view from ERB to slim
This commit is contained in:
@ -12,8 +12,8 @@
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :requestor_user_id %><br>
|
||||
<%= f.number_field :requestor_user_id %>
|
||||
<%= f.label :user_id %><br>
|
||||
<%= f.number_field :user_id %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :exercise_id %><br>
|
||||
|
@ -1,21 +0,0 @@
|
||||
<h1><%= t('exercises.implement.comment.listing') %></h1>
|
||||
|
||||
<div class="list-group">
|
||||
<% @request_for_comments.each do |request_for_comment| %>
|
||||
<a href="<%= request_for_comment_path(request_for_comment) %>" class="list-group-item">
|
||||
<h4 class="list-group-item-heading"><%= Exercise.find(request_for_comment.exercise_id) %></h4>
|
||||
<p class="list-group-item-text">
|
||||
<%
|
||||
user = nil
|
||||
if (request_for_comment.user_type == 'InternalUser')
|
||||
user = InternalUser.find(request_for_comment.requestor_user_id)
|
||||
else
|
||||
user = ExternalUser.find(request_for_comment.requestor_user_id)
|
||||
end
|
||||
%>
|
||||
|
||||
<%= user %> | <%= request_for_comment.requested_at %>
|
||||
</p>
|
||||
</a>
|
||||
<% end %>
|
||||
</div>
|
19
app/views/request_for_comments/index.html.slim
Normal file
19
app/views/request_for_comments/index.html.slim
Normal file
@ -0,0 +1,19 @@
|
||||
h1 = RequestForComment.model_name.human(count: 2)
|
||||
|
||||
.table-responsive
|
||||
table.table
|
||||
thead
|
||||
tr
|
||||
th = t('activerecord.attributes.request_for_comments.exercise')
|
||||
th = t('activerecord.attributes.request_for_comments.execution_environment')
|
||||
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
|
||||
td = link_to(request_for_comment.exercise.title, request_for_comment)
|
||||
td = request_for_comment.exercise.execution_environment
|
||||
td = request_for_comment.user.name
|
||||
td = request_for_comment.requested_at
|
||||
|
||||
= render('shared/pagination', collection: @request_for_comments)
|
@ -1,4 +1,4 @@
|
||||
json.array!(@request_for_comments) do |request_for_comment|
|
||||
json.extract! request_for_comment, :id, :requestor_user_id, :exercise_id, :file_id, :requested_at, :user_type
|
||||
json.extract! request_for_comment, :id, :user_id, :exercise_id, :file_id, :requested_at, :user_type
|
||||
json.url request_for_comment_url(request_for_comment, format: :json)
|
||||
end
|
||||
|
@ -2,12 +2,9 @@
|
||||
<h4 class="list-group-item-heading"><%= Exercise.find(@request_for_comment.exercise_id) %></h4>
|
||||
<p class="list-group-item-text">
|
||||
<%
|
||||
user = nil
|
||||
if (@request_for_comment.user_type == 'InternalUser')
|
||||
user = InternalUser.find(@request_for_comment.requestor_user_id)
|
||||
else
|
||||
user = ExternalUser.find(@request_for_comment.requestor_user_id)
|
||||
end
|
||||
|
||||
user = @request_for_comment.user
|
||||
|
||||
%>
|
||||
<%= user %> | <%= @request_for_comment.requested_at %>
|
||||
</p>
|
||||
|
@ -1 +1 @@
|
||||
json.extract! @request_for_comment, :id, :requestor_user_id, :exercise_id, :file_id, :requested_at, :created_at, :updated_at, :user_type
|
||||
json.extract! @request_for_comment, :id, :user_id, :exercise_id, :file_id, :requested_at, :created_at, :updated_at, :user_type
|
||||
|
Reference in New Issue
Block a user