refactor solution for #3804
This commit is contained in:
@@ -1,2 +1,17 @@
|
|||||||
module UploadsHelper
|
module UploadsHelper
|
||||||
|
def render_status(upload)
|
||||||
|
case upload.status
|
||||||
|
when /duplicate: (\d+)/
|
||||||
|
dup_post_id = $1
|
||||||
|
link_to(upload.status.gsub(/error: RuntimeError - /, ""), post_path(dup_post_id))
|
||||||
|
|
||||||
|
when /\Aerror: /
|
||||||
|
search_params = params[:search].permit!
|
||||||
|
link_to(upload.sanitized_status, uploads_path(search: search_params.merge({ status: upload.sanitized_status })))
|
||||||
|
|
||||||
|
else
|
||||||
|
search_params = params[:search].permit!
|
||||||
|
link_to(upload.status, uploads_path(search: search_params.merge({ status: upload.status })))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -117,6 +117,14 @@ class Upload < ApplicationRecord
|
|||||||
status =~ /error:/
|
status =~ /error:/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitized_status
|
||||||
|
if is_errored?
|
||||||
|
status.sub(/DETAIL:.+/m, "...")
|
||||||
|
else
|
||||||
|
status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def duplicate_post_id
|
def duplicate_post_id
|
||||||
@duplicate_post_id ||= status[/duplicate: (\d+)/, 1]
|
@duplicate_post_id ||= status[/duplicate: (\d+)/, 1]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,18 +2,4 @@ class UploadPresenter < Presenter
|
|||||||
def initialize(upload)
|
def initialize(upload)
|
||||||
@upload = upload
|
@upload = upload
|
||||||
end
|
end
|
||||||
|
|
||||||
def status(template)
|
|
||||||
case @upload.status
|
|
||||||
when /duplicate: (\d+)/
|
|
||||||
dup_post_id = $1
|
|
||||||
template.link_to(@upload.status.gsub(/error: RuntimeError - /, ""), template.__send__(:post_path, dup_post_id))
|
|
||||||
|
|
||||||
when /\Aerror: /
|
|
||||||
@upload.status.gsub(/DETAIL:.+/m, "...")
|
|
||||||
|
|
||||||
else
|
|
||||||
@upload.status
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
<br><%= time_ago_in_words_tagged upload.created_at %>
|
<br><%= time_ago_in_words_tagged upload.created_at %>
|
||||||
</td>
|
</td>
|
||||||
<td class="col-normal">
|
<td class="col-normal">
|
||||||
<%= upload.presenter.status(self) %>
|
<%= render_status(upload) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<% elsif @upload.is_duplicate? %>
|
<% elsif @upload.is_duplicate? %>
|
||||||
<p>This upload is a duplicate: <%= link_to "post ##{@upload.duplicate_post_id}", post_path(@upload.duplicate_post_id) %></p>
|
<p>This upload is a duplicate: <%= link_to "post ##{@upload.duplicate_post_id}", post_path(@upload.duplicate_post_id) %></p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>An error occurred: <%= @upload.presenter.status(self) %></p>
|
<p>An error occurred: <%= render_status(@upload) %></p>
|
||||||
<% if CurrentUser.user.is_builder? %>
|
<% if CurrentUser.user.is_builder? %>
|
||||||
<ul>
|
<ul>
|
||||||
<% @upload.backtrace.to_s.split(/\n/).each do |line| %>
|
<% @upload.backtrace.to_s.split(/\n/).each do |line| %>
|
||||||
|
|||||||
Reference in New Issue
Block a user