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

Citations improvements #8126

Merged
merged 3 commits into from
Apr 9, 2024
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
18 changes: 18 additions & 0 deletions app/helpers/admin/citations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Helpers for displaying Citations in the admin interface
module Admin::CitationsHelper
ICONS = {
journalism: '🗞️',
campaigning: '📣',
academic: '🎓',
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
1 change: 1 addition & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module AdminHelper
include Admin::BootstrapHelper
include Admin::CensorRulesHelper
include Admin::CitationsHelper
include Admin::LinkHelper
include Admin::ProminenceHelper

Expand Down
2 changes: 1 addition & 1 deletion app/models/citation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 campaigning other),
message: _('Please select a type') }

scope :newest, ->(limit = 1) do
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/citations/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<% citations.each do |citation| %>
<div class="row">
<span class="item-title span6">
<%= citation_icon(citation) %>
<tt><%= link_to citation.source_url, citation.source_url %></tt>
</span>

Expand Down
17 changes: 11 additions & 6 deletions app/views/citations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
<%= _('What type of article is it?') %>
</span>

<label for="citation_type_news_story" class="form_label">
<%= f.radio_button :type, 'news_story' %>
<%= _('News story') %>
<label for="citation_type_journalism" class="form_label">
<%= f.radio_button :type, 'journalism' %>
<%= _('Journalism') %>
</label>

<label for="citation_type_academic_paper" class="form_label">
<%= f.radio_button :type, 'academic_paper' %>
<%= _('Academic paper') %>
<label for="citation_type_campaigning" class="form_label">
<%= f.radio_button :type, 'campaigning' %>
<%= _('Campaigning') %>
</label>

<label for="citation_type_academic" class="form_label">
<%= f.radio_button :type, 'academic' %>
<%= _('Academic') %>
</label>

<label for="citation_type_other" class="form_label">
Expand Down
22 changes: 22 additions & 0 deletions db/migrate/20240209162933_change_citation_type_values.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class ChangeCitationTypeValues < ActiveRecord::Migration[7.0]
CHANGES = {
'news_story' => 'journalism',
'academic_paper' => 'academic'
}

def up
perform(CHANGES)
end

def down
perform(CHANGES.invert)
end

private

def perform(data)
data.each_pair do |before, after|
Citation.where(type: before).update_all(type: after)
end
end
end
2 changes: 2 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Highlighted Features

* Broaden citation type classifications to cover wider thematic areas and add
"campaigning" type (Gareth Rees)
* Reduce amount of storage related background jobs (Graeme Porteous)
* Add automatic parsing of emails contain Excel spreadsheets (Graeme Porteous)
* Improve rendering of admin hidden request prominence and explanations (Graeme
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/citations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def action
end

let(:params) do
{ source_url: 'http://example.com/news', type: 'news_story' }
{ source_url: 'http://example.com/news', type: 'journalism' }
end
let(:apply_to_batch) { nil }

Expand Down
27 changes: 27 additions & 0 deletions spec/helpers/admin/citations_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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 journalism link' do
let(:citation) { FactoryBot.build(:citation, type: 'journalism') }
it { is_expected.to include('🗞️') }
it { is_expected.to include('citation-icon--journalism') }
end

context 'with an academic link' do
let(:citation) { FactoryBot.build(:citation, type: 'academic') }
it { is_expected.to include('🎓') }
it { is_expected.to include('citation-icon--academic') }
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
6 changes: 4 additions & 2 deletions spec/models/citation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ def setup_for_x_scope_data
it 'requires known type' do
citation.type = 'foobar'
is_expected.not_to be_valid
citation.type = 'news_story'
citation.type = 'journalism'
is_expected.to be_valid
citation.type = 'academic_paper'
citation.type = 'campaigning'
is_expected.to be_valid
citation.type = 'academic'
is_expected.to be_valid
citation.type = 'other'
is_expected.to be_valid
Expand Down
Loading