From 9965cc88b9943abca9a6d221a36d94d4758021a0 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 17 Jan 2024 18:06:13 +0000 Subject: [PATCH 1/2] Extract a notes/_note partial Makes it easier to add extra HTML elements. --- app/helpers/notes_helper.rb | 21 +++++++++++++++------ app/views/notes/_note.html.erb | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 app/views/notes/_note.html.erb diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 0ae51ccd91..403529de67 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -6,12 +6,7 @@ def render_notes(notes, batch: false, **options) tag.aside(**options.merge(id: 'notes')) do notes.each do |note| - note_classes = ['note'] - note_classes << "tag-#{note.notable_tag}" if note.notable_tag - - concat tag.article sanitize(note.body, tags: allowed_tags), - id: dom_id(note), - class: note_classes + concat render_note(note, allowed_tags: allowed_tags) end end end @@ -25,4 +20,18 @@ def notes_allowed_tags def batch_notes_allowed_tags notes_allowed_tags - %w(pre h1 h2 h3 h4 h5 h6 img blockquote font iframe) end + + private + + def render_note(note, allowed_tags: notes_allowed_tags) + note_classes = ['note'] + note_classes << "tag-#{note.notable_tag}" if note.notable_tag + + locals = { + note_classes: note_classes, + allowed_tags: allowed_tags + } + + render partial: note, locals: locals + end end diff --git a/app/views/notes/_note.html.erb b/app/views/notes/_note.html.erb new file mode 100644 index 0000000000..797bce47ca --- /dev/null +++ b/app/views/notes/_note.html.erb @@ -0,0 +1,3 @@ +<%= tag.article(id: dom_id(note), class: note_classes) do %> + <%= sanitize(note.body, tags: allowed_tags) %> +<% end %> From b8be3e99448044a86b55356289e876106cbf75e0 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 17 Jan 2024 18:06:30 +0000 Subject: [PATCH 2/2] Add admin link to notes --- app/views/notes/_note.html.erb | 6 ++++++ doc/CHANGES.md | 1 + 2 files changed, 7 insertions(+) diff --git a/app/views/notes/_note.html.erb b/app/views/notes/_note.html.erb index 797bce47ca..c793620eaa 100644 --- a/app/views/notes/_note.html.erb +++ b/app/views/notes/_note.html.erb @@ -1,3 +1,9 @@ <%= tag.article(id: dom_id(note), class: note_classes) do %> <%= sanitize(note.body, tags: allowed_tags) %> + + <% if @user&.admin_page_links? %> +

+ <%= link_to 'Admin', edit_admin_note_path(note) %> +

+ <% end %> <% end %> diff --git a/doc/CHANGES.md b/doc/CHANGES.md index bac7a1eb99..28587f8654 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -2,6 +2,7 @@ ## Highlighted Features +* Add admin link to notes (Gareth Rees) * Display metadata on admin attachment views (Graeme Porteous) * Change request URL patterns to be member routes (Alexander Griffen, Graeme Porteous)