From 9a4aba8d1c3b7b4928fa328349ca95278b2d6887 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 7 Feb 2024 12:56:30 +0000 Subject: [PATCH 1/3] Render an icon depicting citation type This information isn't really important enough individually (it's more useful when looked at as a whole), but fun to know what's being linked to, so add a little visual interest to display this. --- app/helpers/admin/citations_helper.rb | 17 +++++++++++++ app/helpers/admin_helper.rb | 1 + app/views/admin/citations/_list.html.erb | 1 + spec/helpers/admin/citations_helper_spec.rb | 27 +++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 app/helpers/admin/citations_helper.rb create mode 100644 spec/helpers/admin/citations_helper_spec.rb diff --git a/app/helpers/admin/citations_helper.rb b/app/helpers/admin/citations_helper.rb new file mode 100644 index 0000000000..bc0bf191e6 --- /dev/null +++ b/app/helpers/admin/citations_helper.rb @@ -0,0 +1,17 @@ +# Helpers for displaying Citations in the admin interface +module Admin::CitationsHelper + ICONS = { + news_story: '🗞️', + academic_paper: '🎓', + other: '🌐' + }.with_indifferent_access.freeze + + def citation_icon(citation) + html_attrs = { + title: citation.type.humanize, + class: "citation-icon citation-icon--#{citation.type}" + } + + tag.span(ICONS.fetch(citation.type), **html_attrs) + end +end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index b8fe71a8a3..27069eec66 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -1,6 +1,7 @@ module AdminHelper include Admin::BootstrapHelper include Admin::CensorRulesHelper + include Admin::CitationsHelper include Admin::LinkHelper include Admin::ProminenceHelper diff --git a/app/views/admin/citations/_list.html.erb b/app/views/admin/citations/_list.html.erb index c594b4ad65..d620a9b7f7 100644 --- a/app/views/admin/citations/_list.html.erb +++ b/app/views/admin/citations/_list.html.erb @@ -3,6 +3,7 @@ <% citations.each do |citation| %>
+ <%= citation_icon(citation) %> <%= link_to citation.source_url, citation.source_url %> diff --git a/spec/helpers/admin/citations_helper_spec.rb b/spec/helpers/admin/citations_helper_spec.rb new file mode 100644 index 0000000000..c7cb28167b --- /dev/null +++ b/spec/helpers/admin/citations_helper_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +RSpec.describe Admin::CitationsHelper do + include Admin::CitationsHelper + + describe '#citation_icon' do + subject { citation_icon(citation) } + + context 'with a news story' do + let(:citation) { FactoryBot.build(:citation, type: 'news_story') } + it { is_expected.to include('🗞️') } + it { is_expected.to include('citation-icon--news_story') } + end + + context 'with an academic paper' do + let(:citation) { FactoryBot.build(:citation, type: 'academic_paper') } + it { is_expected.to include('🎓') } + it { is_expected.to include('citation-icon--academic_paper') } + end + + context 'with a generic link' do + let(:citation) { FactoryBot.build(:citation, type: 'other') } + it { is_expected.to include('🌐') } + it { is_expected.to include('citation-icon--other') } + end + end +end From 84cf979e018683a114800150d235c3e6385052cb Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Fri, 9 Feb 2024 16:37:07 +0000 Subject: [PATCH 2/3] Broaden Citation#type classifications We care more about the general grouping rather than a citation being e.g. specifically an academic _paper_. It could be some other generally academic research that we'd want to track. --- app/helpers/admin/citations_helper.rb | 4 ++-- app/models/citation.rb | 2 +- app/views/citations/new.html.erb | 12 +++++----- ...40209162933_change_citation_type_values.rb | 22 +++++++++++++++++++ doc/CHANGES.md | 2 ++ spec/controllers/citations_controller_spec.rb | 2 +- spec/helpers/admin/citations_helper_spec.rb | 12 +++++----- spec/models/citation_spec.rb | 4 ++-- 8 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20240209162933_change_citation_type_values.rb diff --git a/app/helpers/admin/citations_helper.rb b/app/helpers/admin/citations_helper.rb index bc0bf191e6..316d65b9f5 100644 --- a/app/helpers/admin/citations_helper.rb +++ b/app/helpers/admin/citations_helper.rb @@ -1,8 +1,8 @@ # Helpers for displaying Citations in the admin interface module Admin::CitationsHelper ICONS = { - news_story: '🗞️', - academic_paper: '🎓', + journalism: '🗞️', + academic: '🎓', other: '🌐' }.with_indifferent_access.freeze diff --git a/app/models/citation.rb b/app/models/citation.rb index 8758f522fb..a9aa4e359b 100644 --- a/app/models/citation.rb +++ b/app/models/citation.rb @@ -29,7 +29,7 @@ class Citation < ApplicationRecord message: _('Source URL is too long') }, format: { with: /\Ahttps?:\/\/.*\z/, message: _('Please enter a Source URL') } - validates :type, inclusion: { in: %w(news_story academic_paper other), + validates :type, inclusion: { in: %w(journalism academic other), message: _('Please select a type') } scope :newest, ->(limit = 1) do diff --git a/app/views/citations/new.html.erb b/app/views/citations/new.html.erb index e5dd283201..de87a069df 100644 --- a/app/views/citations/new.html.erb +++ b/app/views/citations/new.html.erb @@ -23,14 +23,14 @@ <%= _('What type of article is it?') %> -