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

feat: Enhancing further separate publication page #463

Merged
merged 4 commits into from
Oct 23, 2023
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
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,
permit_params :title, :content, :publication_date, :is_insight,
:created_by_id, :updated_by_id,
:image, :keywords_string, tpi_sector_ids: []

Expand All @@ -30,6 +30,7 @@
row :image do |t|
image_tag(url_for(t.image)) if t.image.present?
end
row :is_insight
row :updated_at
row :updated_by
row :created_at
Expand All @@ -43,6 +44,7 @@
index do
column 'Title', :title_link
column :publication_date
column :is_insight

actions
end
Expand All @@ -54,6 +56,7 @@
column(:sectors) { |l| l.tpi_sectors.map(&:name).join(Rails.application.config.csv_options[:entity_sep]) }
column :keywords, &:keywords_csv
column :publication_date
column :is_insight
end

form html: {'data-controller' => 'check-modified'} do |f|
Expand All @@ -67,6 +70,7 @@
collection: TPISector.order(:name), input_html: {multiple: true}
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
end

f.actions
Expand Down
4 changes: 3 additions & 1 deletion app/admin/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
decorate_with PublicationDecorator

permit_params :title, :author, :author_image, :short_description, :publication_date,
:file, :image, :created_by_id, :updated_by_id,
:file, :image, :created_by_id, :updated_by_id, :summary,
:keywords_string, tpi_sector_ids: []

filter :title
Expand All @@ -20,6 +20,7 @@
attributes_table do
row :title
row :short_description
row :summary
row :author
row :author_image do |p|
if p.author_image.present?
Expand Down Expand Up @@ -63,6 +64,7 @@
f.input :author
f.input :author_image, as: :file, hint: preview_file_tag(f.object.author_image), input_html: {accept: 'image/*'}
f.input :short_description, as: :text
f.input :summary, as: :trix, embed_youtube: true
f.input :publication_date, as: :date_time_picker
f.input :tpi_sector_ids, label: 'Sectors', as: :select,
collection: TPISector.order(:name), input_html: {multiple: true}
Expand Down
10 changes: 10 additions & 0 deletions app/assets/stylesheets/tpi/_publications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ $max-lines: 3;
margin-bottom: 22px;
}
}

&__content-type {
color: $grey-dark;
margin-top: 10px;
font-size: $size-7;
border: 1px solid rgba($grey-dark, 0.5);
padding-left: $size-7;
padding-right: $size-7;
display: inline-block;
}
}

.publications__grid {
Expand Down
1 change: 1 addition & 0 deletions app/models/bank_assessment_indicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# comment :text
# is_placeholder :boolean default(FALSE)
#
class BankAssessmentIndicator < ApplicationRecord
INDICATOR_TYPES = %w[area sub_area indicator sub_indicator].freeze
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 @@ -10,6 +10,7 @@
# updated_by_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
#

class NewsArticle < ApplicationRecord
Expand All @@ -23,6 +24,8 @@ class NewsArticle < ApplicationRecord
has_and_belongs_to_many :tpi_sectors

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

validates_presence_of :title, :content, :publication_date

Expand Down
1 change: 1 addition & 0 deletions app/models/publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# updated_at :datetime not null
# author :string
# slug :text not null
# summary :text
#

class Publication < ApplicationRecord
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).uniq.sort_by(&:publication_date).reverse!
(publications + news + insights).uniq.sort_by(&:publication_date).reverse!
end

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

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

def insights
return NewsArticle.none if types.present? && !types.include?('Insights')

filter_scope(NewsArticle.published.insights)
end

def filter_scope(scope)
Expand Down
13 changes: 12 additions & 1 deletion app/views/tpi/publications/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<div class="content__title-wrapper">
<div class="content__title">
<% if publication.is_a?(Publication) %>
<%= link_to publication.title, tpi_publication_path(id: publication.slug), class: 'link is-strong' %>
<% if publication.summary.present? %>
<%= link_to publication.title, tpi_publication_path(id: publication.slug), class: 'link is-strong' %>
<% else %>
<%= link_to publication.title, tpi_publication_download_file_path(slug: publication.slug), target: '_blank', class: 'link is-strong' %>
<% end %>
<% else %>
<%= link_to publication.title, show_news_article_tpi_publication_path(id: publication.id), class: "link is-strong" %>
<% end %>
Expand All @@ -25,6 +29,13 @@
<% end %>
</p>
</div>
<div class="publication__content-type">
<% if publication.is_a?(NewsArticle) %>
<%= publication.is_insight? ? 'Insights' : 'News' %>
<% else %>
Publications
<% end %>
</div>
<% if publication.keywords.any? || publication.tpi_sectors.any? %>
<div class="publication__tags">
<% publication.tags_and_sectors.each do |tag| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/tpi/publications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</button>
</div>
<%= react_component("Filters", {
types: %w[Publications News],
types: %w[Publications News Insights],
tags: @tags,
sectors: @sectors,
resultsSize: @publications_and_articles_count
Expand Down
5 changes: 4 additions & 1 deletion app/views/tpi/publications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="pages__content__flex">
<% if @publication.image.present? %>
<div class="pages__image"><%= image_tag(@publication.image) %></div>
<div class="pages__image" style="margin-bottom: 0;"><%= image_tag(@publication.image) %></div>
<% end %>
<div class="pages__description">
<p><%= @publication.short_description %></p>
Expand All @@ -20,6 +20,9 @@
<% end %>
</div>
<% end %>
<div class="pages__description">
<%= @publication.summary&.html_safe %>
</div>

<%= link_to 'Download file', tpi_publication_download_file_path(slug: @publication.slug), target: '_blank', class: 'button is-primary' %>
</div>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231023101859_add_is_insight_to_news_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIsInsightToNewsArticles < ActiveRecord::Migration[6.1]
def change
add_column :news_articles, :is_insight, :boolean, default: false
end
end
5 changes: 5 additions & 0 deletions db/migrate/20231023120255_add_summary_to_publications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSummaryToPublications < ActiveRecord::Migration[6.1]
def change
add_column :publications, :summary, :text
end
end
10 changes: 7 additions & 3 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,8 @@ CREATE TABLE public.news_articles (
created_by_id bigint,
updated_by_id bigint,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
updated_at timestamp(6) without time zone NOT NULL,
is_insight boolean DEFAULT false
);


Expand Down Expand Up @@ -1633,7 +1634,8 @@ CREATE TABLE public.publications (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
author character varying,
slug text NOT NULL
slug text NOT NULL,
summary text
);


Expand Down Expand Up @@ -4158,6 +4160,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230915064402'),
('20230920083300'),
('20230926075145'),
('20230927112905');
('20230927112905'),
('20231023101859'),
('20231023120255');


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 @@ -36,7 +36,8 @@
attributes_for(
:news_article,
title: 'My amazing title',
content: 'Test Content'
content: 'Test Content',
is_insight: true
)
end

Expand All @@ -48,6 +49,7 @@
last_news_article_created.tap do |g|
expect(g.title).to eq(valid_params[:title])
expect(g.content).to eq(valid_params[:content])
expect(g.is_insight).to be_truthy
end
end

Expand Down
4 changes: 3 additions & 1 deletion spec/controllers/admin/publications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
attributes_for(
:publication,
title: 'My amazing title',
short_description: 'Test short_description'
short_description: 'Test short_description',
summary: 'Test summary'
)
end

Expand All @@ -48,6 +49,7 @@
last_publication_created.tap do |g|
expect(g.title).to eq(valid_params[:title])
expect(g.short_description).to eq(valid_params[:short_description])
expect(g.summary).to eq(valid_params[:summary])
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/factories/bank_assessment_indicators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# comment :text
# is_placeholder :boolean default(FALSE)
#
FactoryBot.define do
factory :bank_assessment_indicator, class: BankAssessmentIndicator do
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 @@ -10,6 +10,7 @@
# updated_by_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
#

FactoryBot.define do
Expand All @@ -19,6 +20,7 @@
tpi_sectors { |a| [a.association(:tpi_sector)] }
publication_date { '2019-11-29' }
image { fixture_file_upload(Rails.root.join('spec', 'support', 'fixtures', 'files', 'test.jpg'), 'jpg') }
is_insight { false }

association :created_by, factory: :admin_user
updated_by { created_by }
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/publications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# updated_at :datetime not null
# author :string
# slug :text not null
# summary :text
#

FactoryBot.define do
Expand All @@ -23,6 +24,7 @@
title { 'MyString' }
author { 'Author' }
short_description { 'MyText' }
summary { 'MyText' }
publication_date { '2019-12-02' }
file { fixture_file_upload(Rails.root.join('spec', 'support', 'fixtures', 'files', 'test.pdf'), 'pdf') }

Expand Down
1 change: 1 addition & 0 deletions spec/models/bank_assessment_indicator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# comment :text
# is_placeholder :boolean default(FALSE)
#
require 'rails_helper'

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 @@ -10,6 +10,7 @@
# updated_by_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
#

require 'rails_helper'
Expand Down
1 change: 1 addition & 0 deletions spec/models/publication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# updated_at :datetime not null
# author :string
# slug :text not null
# summary :text
#

require 'rails_helper'
Expand Down
Loading