Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1005] Preparation work before adding indivdual attachment prominence #7324

Merged
merged 5 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/helpers/admin/link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def outgoing_message_both_links(outgoing_message)
info_request = outgoing_message.info_request

link_to(icon, outgoing_message_path(outgoing_message), title: title) + ' ' +
link_to("#{info_request.title} #outgoing-#{outgoing_message.id}",
link_to("#{info_request.title} ##{dom_id(outgoing_message)}",
edit_admin_outgoing_message_path(outgoing_message),
title: admin_title)
end
Expand All @@ -33,7 +33,7 @@ def incoming_message_both_links(incoming_message)
info_request = incoming_message.info_request

link_to(icon, incoming_message_path(incoming_message), title: title) + ' ' +
link_to("#{info_request.title} #incoming-#{incoming_message.id}",
link_to("#{info_request.title} ##{dom_id(incoming_message)}",
edit_admin_incoming_message_path(incoming_message),
title: admin_title)
end
Expand Down
21 changes: 16 additions & 5 deletions app/helpers/link_to_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,12 @@ def current_path_as_json

# Private: Generate a request_url linking to the new correspondence
def message_url(message, options = {})
message_type = message.class.to_s.gsub('Message', '').downcase
anchor = "#{ message_type }-#{ message.id }"
anchor = dom_id(message)

return "##{anchor}" if options[:anchor_only]
default_options = { anchor: anchor }

if options.delete(:cachebust)
default_options.merge!(:nocache => "#{ message_type }-#{ message.id }")
end
default_options[:nocache] = anchor if options.delete(:cachebust)

request_url(message.info_request, options.merge(default_options))
end
Expand All @@ -311,4 +308,18 @@ def message_path(message, options = {})
message_url(message, options.merge(:only_path => true))
end

def dom_id(record, prefix = nil)
case record
when IncomingMessage
gbp marked this conversation as resolved.
Show resolved Hide resolved
param_key = 'incoming'
when OutgoingMessage
param_key = 'outgoing'
when FoiAttachment
param_key = 'attachment'
else
return super
gbp marked this conversation as resolved.
Show resolved Hide resolved
end

[prefix, param_key, record.to_param].compact.join('-')
end
end
39 changes: 39 additions & 0 deletions app/views/request/_attachments.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<% attachments = incoming_message.get_attachments_for_display %>
<% if not attachments.nil? and attachments.size > 0 %>
<div class="attachments">
<div class="attachments__header">
<h3>
<%= n_('{{count}} Attachment',
'{{count}} Attachments',
attachments.size,
:count => attachments.size) %>
</h3>
</div>

<ul class="list-of-attachments">
<% attachments.each do |a| %>
<%= tag.li class: 'attachment', id: dom_id(a) do %>
<%= attachment_link(incoming_message, a) %>

<p class="attachment__name">
<%= h a.display_filename %>
</p>

<p class="attachment__meta">
<%= a.display_size %>
<%= link_to "Download", attachment_path(a) %>
<% if a.has_body_as_html? && incoming_message.info_request.prominence(:decorate => true).is_public? %>
<%= link_to "View as HTML", attachment_path(a, :html => true) %>
<% end %>
<%= a.extra_note %>
</p>
<% end %>
<% end %>
</ul>

<a href="#" class="attachments__show-more" style="display: none;" data-show-all="<%= _('Show all attachments') %>" data-show-fewer="<%= _('Show fewer attachments') %>"></a>
</div>
<% end %>

<%= tag.div incoming_message.get_body_for_html_display(@collapse_quotes),
gbp marked this conversation as resolved.
Show resolved Hide resolved
id: dom_id(incoming_message.get_main_body_text_part) %>
39 changes: 0 additions & 39 deletions app/views/request/_bubble.html.erb

This file was deleted.

10 changes: 5 additions & 5 deletions app/views/request/_incoming_correspondence.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="incoming correspondence <%= incoming_message.prominence %> js-collapsable" id="incoming-<%= incoming_message.id %>">
<div class="incoming correspondence <%= incoming_message.prominence %> js-collapsable" id="<%= dom_id(incoming_message) %>">
<div class="correspondence__header">
<span class="correspondence__header__author js-collapsable-trigger">
<% if incoming_message.specific_from_name? %>
Expand All @@ -24,10 +24,10 @@
locals: { incoming_message: incoming_message } %>
<% end %>

<%= render :partial => 'request/bubble',
:locals => { :incoming_message => incoming_message,
:body => incoming_message.get_body_for_html_display(@collapse_quotes),
:attachments => incoming_message.get_attachments_for_display } %>
<div class="correspondence_text">
<%= render partial: 'request/attachments',
locals: { incoming_message: incoming_message } %>
</div>

<p class="event_actions">
<% if [email protected]? && @user.admin_page_links? %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/request/_outgoing_correspondence.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="outgoing correspondence js-collapsable" id="outgoing-<%= outgoing_message.id %>">
<div class="outgoing correspondence js-collapsable" id="<%= dom_id(outgoing_message) %>">
<%- if cannot?(:read, outgoing_message) %>
<%= render :partial => 'request/hidden_correspondence', :locals => { :message => outgoing_message } %>
<%- else %>
Expand Down Expand Up @@ -29,7 +29,9 @@
<p><%= link_to _('Try opening the logs in a new window.'), outgoing_message_delivery_status_path(outgoing_message), :target => '_blank' %></p>
</div>

<%= render :partial => 'request/bubble', :locals => { :body => outgoing_message.get_body_for_html_display(), :attachments => nil } %>
<div class="correspondence_text">
<div><%= outgoing_message.get_body_for_html_display %></div>
</div>

<p class="event_actions">
<% if outgoing_message.status == 'ready' && !@info_request.is_external? %>
Expand Down