From 64540a8a2895a33e74c593ee8de3d5a9fa048450 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Mon, 26 Sep 2022 09:28:19 +0100 Subject: [PATCH 1/5] Minor cleanup Fix: - Hash styling --- app/views/request/_incoming_correspondence.html.erb | 8 ++++---- app/views/request/_outgoing_correspondence.html.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/request/_incoming_correspondence.html.erb b/app/views/request/_incoming_correspondence.html.erb index 6a03aadecc..7555f2b425 100644 --- a/app/views/request/_incoming_correspondence.html.erb +++ b/app/views/request/_incoming_correspondence.html.erb @@ -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 } %> + <%= 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 } %>

<% if !@user.nil? && @user.admin_page_links? %> diff --git a/app/views/request/_outgoing_correspondence.html.erb b/app/views/request/_outgoing_correspondence.html.erb index e536a9fc6f..017b6858da 100644 --- a/app/views/request/_outgoing_correspondence.html.erb +++ b/app/views/request/_outgoing_correspondence.html.erb @@ -29,7 +29,7 @@

<%= link_to _('Try opening the logs in a new window.'), outgoing_message_delivery_status_path(outgoing_message), :target => '_blank' %>

- <%= render :partial => 'request/bubble', :locals => { :body => outgoing_message.get_body_for_html_display(), :attachments => nil } %> + <%= render partial: 'request/bubble', locals: { body: outgoing_message.get_body_for_html_display(), attachments: nil } %>

<% if outgoing_message.status == 'ready' && !@info_request.is_external? %> From d5b428024eac12d63c9386bf94c1299bd768d333 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Wed, 21 Sep 2022 22:52:56 +0100 Subject: [PATCH 2/5] Fix broken tag around message body The message body is passed through `simple_format` which, by defualt wraps in a `p` tag. Changes the surrounding tag to a `div` to prevent invalid HTML. --- app/views/request/_bubble.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/request/_bubble.html.erb b/app/views/request/_bubble.html.erb index fe8063c367..121c4dfc33 100644 --- a/app/views/request/_bubble.html.erb +++ b/app/views/request/_bubble.html.erb @@ -35,5 +35,5 @@ <% end %> -

<%= body %>

+
<%= body %>
From 42a99b438b4bed9243ca02a125a92f8e37e31796 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Fri, 23 Sep 2022 12:44:41 +0100 Subject: [PATCH 3/5] Drop bubble partial rendering for outgoing messages The bubble partial is mainly used to render incoming message attachments so if we don't use this for outgoing messages we can simplify rendering. The only useful element for outgoing messages is the correspondence container, this has been extracted out from the partial. --- app/views/request/_attachments.html.erb | 38 ++++++++++++++++++ app/views/request/_bubble.html.erb | 39 ------------------- .../request/_incoming_correspondence.html.erb | 8 ++-- .../request/_outgoing_correspondence.html.erb | 4 +- 4 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 app/views/request/_attachments.html.erb delete mode 100644 app/views/request/_bubble.html.erb diff --git a/app/views/request/_attachments.html.erb b/app/views/request/_attachments.html.erb new file mode 100644 index 0000000000..bfe20f8314 --- /dev/null +++ b/app/views/request/_attachments.html.erb @@ -0,0 +1,38 @@ +<% attachments = incoming_message.get_attachments_for_display %> +<% if not attachments.nil? and attachments.size > 0 %> +
+
+

+ <%= n_('{{count}} Attachment', + '{{count}} Attachments', + attachments.size, + :count => attachments.size) %> +

+
+ +
    + <% attachments.each do |a| %> +
  • + <%= attachment_link(incoming_message, a) %> + +

    + <%= h a.display_filename %> +

    + +

    + <%= 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 %> +

    +
  • + <% end %> +
+ + +
+<% end %> + +<%= tag.div incoming_message.get_body_for_html_display(@collapse_quotes) %> diff --git a/app/views/request/_bubble.html.erb b/app/views/request/_bubble.html.erb deleted file mode 100644 index 121c4dfc33..0000000000 --- a/app/views/request/_bubble.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -
- <% if not attachments.nil? and attachments.size > 0 %> -
-
-

- <%= n_('{{count}} Attachment', - '{{count}} Attachments', - attachments.size, - :count => attachments.size) %> -

-
- -
    - <% attachments.each do |a| %> -
  • - <%= attachment_link(incoming_message, a) %> - -

    - <%= h a.display_filename %> -

    - -

    - <%= 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 %> -

    -
  • - <% end %> -
- - -
- <% end %> - -
<%= body %>
-
diff --git a/app/views/request/_incoming_correspondence.html.erb b/app/views/request/_incoming_correspondence.html.erb index 7555f2b425..0a8c090e36 100644 --- a/app/views/request/_incoming_correspondence.html.erb +++ b/app/views/request/_incoming_correspondence.html.erb @@ -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 } %> +
+ <%= render partial: 'request/attachments', + locals: { incoming_message: incoming_message } %> +

<% if !@user.nil? && @user.admin_page_links? %> diff --git a/app/views/request/_outgoing_correspondence.html.erb b/app/views/request/_outgoing_correspondence.html.erb index 017b6858da..1c1f16a97c 100644 --- a/app/views/request/_outgoing_correspondence.html.erb +++ b/app/views/request/_outgoing_correspondence.html.erb @@ -29,7 +29,9 @@

<%= link_to _('Try opening the logs in a new window.'), outgoing_message_delivery_status_path(outgoing_message), :target => '_blank' %>

- <%= render partial: 'request/bubble', locals: { body: outgoing_message.get_body_for_html_display(), attachments: nil } %> +
+
<%= outgoing_message.get_body_for_html_display %>
+

<% if outgoing_message.status == 'ready' && !@info_request.is_external? %> From d6c425a38d4574cd9b93a3dc596f1f61311f2fe3 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Wed, 21 Sep 2022 22:48:22 +0100 Subject: [PATCH 4/5] Add override for `dom_id` In helpers and views when linking to incoming or outgoing messages we manually generate anchors fragments. With minor changes we can replace the manual anchors with the `dom_id` helper. --- app/helpers/admin/link_helper.rb | 4 ++-- app/helpers/link_to_helper.rb | 19 ++++++++++++++----- .../request/_incoming_correspondence.html.erb | 2 +- .../request/_outgoing_correspondence.html.erb | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/helpers/admin/link_helper.rb b/app/helpers/admin/link_helper.rb index 57344d434a..86839d8516 100644 --- a/app/helpers/admin/link_helper.rb +++ b/app/helpers/admin/link_helper.rb @@ -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 @@ -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 diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index b7185d8172..5336fd314c 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -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 @@ -311,4 +308,16 @@ def message_path(message, options = {}) message_url(message, options.merge(:only_path => true)) end + def dom_id(record, prefix = nil) + case record + when IncomingMessage + param_key = 'incoming' + when OutgoingMessage + param_key = 'outgoing' + else + return super + end + + [prefix, param_key, record.to_param].compact.join('-') + end end diff --git a/app/views/request/_incoming_correspondence.html.erb b/app/views/request/_incoming_correspondence.html.erb index 0a8c090e36..3b35f8b89c 100644 --- a/app/views/request/_incoming_correspondence.html.erb +++ b/app/views/request/_incoming_correspondence.html.erb @@ -1,4 +1,4 @@ -

+
<% if incoming_message.specific_from_name? %> diff --git a/app/views/request/_outgoing_correspondence.html.erb b/app/views/request/_outgoing_correspondence.html.erb index 1c1f16a97c..0f320581d6 100644 --- a/app/views/request/_outgoing_correspondence.html.erb +++ b/app/views/request/_outgoing_correspondence.html.erb @@ -1,4 +1,4 @@ -
+
<%- if cannot?(:read, outgoing_message) %> <%= render :partial => 'request/hidden_correspondence', :locals => { :message => outgoing_message } %> <%- else %> From 9eb2ee50791e8187103f55f37dac6e28092f8ab5 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Wed, 21 Sep 2022 22:56:51 +0100 Subject: [PATCH 5/5] Add anchors to incoming message attachments --- app/helpers/link_to_helper.rb | 2 ++ app/views/request/_attachments.html.erb | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 5336fd314c..80daf19700 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -314,6 +314,8 @@ def dom_id(record, prefix = nil) param_key = 'incoming' when OutgoingMessage param_key = 'outgoing' + when FoiAttachment + param_key = 'attachment' else return super end diff --git a/app/views/request/_attachments.html.erb b/app/views/request/_attachments.html.erb index bfe20f8314..021f7d80ad 100644 --- a/app/views/request/_attachments.html.erb +++ b/app/views/request/_attachments.html.erb @@ -12,7 +12,7 @@
    <% attachments.each do |a| %> -
  • + <%= tag.li class: 'attachment', id: dom_id(a) do %> <%= attachment_link(incoming_message, a) %>

    @@ -27,7 +27,7 @@ <% end %> <%= a.extra_note %>

    -
  • + <% end %> <% end %>
@@ -35,4 +35,5 @@
<% end %> -<%= tag.div incoming_message.get_body_for_html_display(@collapse_quotes) %> +<%= tag.div incoming_message.get_body_for_html_display(@collapse_quotes), + id: dom_id(incoming_message.get_main_body_text_part) %>