Skip to content

Commit

Permalink
Merge pull request #492 from Vizzuality/develop
Browse files Browse the repository at this point in the history
Prod release: Adding events to NewsArticles
  • Loading branch information
martintomas authored May 28, 2024
2 parents 4b4c92d + 716afe8 commit c8108c8
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 18 deletions.
12 changes: 7 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ GEM
mini_magick (4.11.0)
mini_mime (1.1.5)
mini_portile2 (2.8.6)
minitest (5.22.3)
minitest (5.23.1)
msgpack (1.5.3)
multi_json (1.15.0)
net-imap (0.4.9.1)
Expand All @@ -312,7 +312,7 @@ GEM
net-protocol
net-ssh (7.0.1)
nio4r (2.7.0)
nokogiri (1.16.4)
nokogiri (1.16.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
optimist (3.0.1)
Expand All @@ -338,7 +338,7 @@ GEM
public_suffix (4.0.7)
puma (5.6.8)
nio4r (~> 2.0)
racc (1.7.3)
racc (1.8.0)
rack (2.2.9)
rack-cors (1.1.1)
rack (>= 2.0.0)
Expand Down Expand Up @@ -405,7 +405,8 @@ GEM
actionpack (>= 5.2)
railties (>= 5.2)
retriable (3.1.2)
rexml (3.2.6)
rexml (3.2.8)
strscan (>= 3.0.9)
roo (2.10.0)
nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0)
Expand Down Expand Up @@ -497,6 +498,7 @@ GEM
sshkit (1.21.2)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
strscan (3.1.0)
super_diff (0.9.0)
attr_extras (>= 6.2.4)
diff-lcs
Expand Down Expand Up @@ -543,7 +545,7 @@ GEM
rails (>= 3.2.16)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.13)
zeitwerk (2.6.15)

PLATFORMS
ruby
Expand Down
6 changes: 5 additions & 1 deletion app/admin/news_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

decorate_with NewsArticleDecorator

permit_params :title, :content, :publication_date, :is_insight,
permit_params :title, :content, :publication_date, :is_insight, :is_event,
:created_by_id, :updated_by_id, :short_description,
:image, :keywords_string, tpi_sector_ids: []

Expand All @@ -33,6 +33,7 @@
image_tag(url_for(t.image)) if t.image.present?
end
row :is_insight
row :is_event
row :updated_at
row :updated_by
row :created_at
Expand All @@ -48,6 +49,7 @@
column :short_description
column :publication_date
column :is_insight
column :is_event

actions
end
Expand All @@ -61,6 +63,7 @@
column :keywords, &:keywords_csv
column :publication_date
column :is_insight
column :is_event
end

form html: {'data-controller' => 'check-modified'} do |f|
Expand All @@ -76,6 +79,7 @@
f.input :keywords_string, label: 'Keywords', hint: t('hint.tag'), as: :tags, collection: Keyword.pluck(:name)
f.input :image, as: :file, input_html: {accept: 'image/*'}
f.input :is_insight
f.input :is_event
end

f.actions
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/components/tpi/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const Filters = ({ types, tags, sectors, resultsSize }) => {
<div className="container publications">
<div className="filters__wrapper">
<div className="showing-count">
<p>Showing <strong>{resultsCount}</strong> items in <strong>All Publications and news</strong></p>
<p>Showing <strong>{resultsCount}</strong> items in <strong>All Publications, news and events</strong></p>
</div>
<div className="filters__button is-hidden-touch">
<button
Expand Down
3 changes: 3 additions & 0 deletions app/models/news_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
# short_description :text
# is_event :boolean default(FALSE)
#

class NewsArticle < ApplicationRecord
Expand All @@ -26,7 +27,9 @@ class NewsArticle < ApplicationRecord

scope :published, -> { where('publication_date <= ?', DateTime.now) }
scope :insights, -> { where(is_insight: true) }
scope :events, -> { where(is_event: true) }
scope :not_insights, -> { where(is_insight: false) }
scope :not_events, -> { where(is_event: false) }

validates_presence_of :title, :content, :publication_date

Expand Down
10 changes: 8 additions & 2 deletions app/services/queries/tpi/news_publications_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NewsPublicationsQuery
attr_accessor :tags, :sectors, :types

def call
(publications + news + insights).uniq.sort_by(&:publication_date).reverse!
(publications + news + insights + events).uniq.sort_by(&:publication_date).reverse!
end

private
Expand All @@ -21,7 +21,7 @@ def publications
def news
return NewsArticle.none if types.present? && !types.include?('News')

filter_scope(NewsArticle.published.not_insights)
filter_scope(NewsArticle.published.not_insights.not_events)
end

def insights
Expand All @@ -30,6 +30,12 @@ def insights
filter_scope(NewsArticle.published.insights)
end

def events
return NewsArticle.none if types.present? && !types.include?('Events')

filter_scope(NewsArticle.published.events)
end

def filter_scope(scope)
scope
.merge(filter_by_tags(scope))
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/tpi/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
])
},
{
entry: 'Publications and news',
entry: 'Publications, news and events',
path: tpi_publications_path,
active: active_menu_page?(tpi_publications_path)
},
Expand Down
8 changes: 7 additions & 1 deletion app/views/tpi/publications/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@

<div class="publication__content-type">
<% if publication.is_a?(NewsArticle) %>
<%= publication.is_insight? ? 'Insights' : 'News' %>
<% if publication.is_insight? %>
Insights
<% elsif publication.is_event? %>
Events
<% else %>
News
<% end %>
<% else %>
Publications
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/tpi/publications/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<% content_for :page_title, "Publications and news - Transition Pathway Initiative" %>
<% content_for :page_title, "Publications, news and events - Transition Pathway Initiative" %>

<div class=" publications">
<div class="titel__container container">
<h1 class="publications__title">Publications and news</h1>
<h1 class="publications__title">Publications, news and events</h1>
<button id="filter-button" type="button" class="button is-centered is-hidden-desktop filter-mobile-button filters__button-active">
<img src="<%= asset_path 'icons/filter-blue.svg'%>" class="filters__filter-icon" alt="filter icon">
</button>
</div>
<%= react_component("Filters", {
types: %w[Publications News Insights],
types: %w[Publications News Insights Events],
tags: @tags,
sectors: @sectors,
resultsSize: @publications_and_articles_count
Expand Down
2 changes: 1 addition & 1 deletion app/views/tpi/search/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<% end %>

<% if @publications_and_articles.any? %>
<h3 class="is-size-4">Publications and news</h3>
<h3 class="is-size-4">Publications, news and events</h3>
<%= render 'tpi/publications/promoted', publications_and_articles: @publications_and_articles, count: @publications_and_articles.count %>
<% end %>
</div>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240527100352_add_is_event_to_news_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIsEventToNewsArticles < ActiveRecord::Migration[6.1]
def change
add_column :news_articles, :is_event, :boolean, default: false
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,8 @@ CREATE TABLE public.news_articles (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
is_insight boolean DEFAULT false,
short_description text
short_description text,
is_event boolean DEFAULT false
);


Expand Down Expand Up @@ -4176,6 +4177,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20231207082211'),
('20240119084250'),
('20240202090401'),
('20240206094238');
('20240206094238'),
('20240527100352');


Binary file modified db/test-dump.psql
Binary file not shown.
4 changes: 3 additions & 1 deletion spec/controllers/admin/news_articles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
title: 'My amazing title',
short_description: 'My amazing short description',
content: 'Test Content',
is_insight: true
is_insight: true,
is_event: true
)
end

Expand All @@ -52,6 +53,7 @@
expect(g.short_description).to eq(valid_params[:short_description])
expect(g.content).to eq(valid_params[:content])
expect(g.is_insight).to be_truthy
expect(g.is_event).to be_truthy
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/factories/news_articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
# short_description :text
# is_event :boolean default(FALSE)
#

FactoryBot.define do
Expand All @@ -23,6 +24,7 @@
publication_date { '2019-11-29' }
image { fixture_file_upload(Rails.root.join('spec', 'support', 'fixtures', 'files', 'test.jpg'), 'jpg') }
is_insight { false }
is_event { false }

association :created_by, factory: :admin_user
updated_by { created_by }
Expand Down
1 change: 1 addition & 0 deletions spec/models/news_article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
# short_description :text
# is_event :boolean default(FALSE)
#

require 'rails_helper'
Expand Down

0 comments on commit c8108c8

Please sign in to comment.