Skip to content

Commit

Permalink
feat: Adding summary to Publications
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Oct 23, 2023
1 parent acc8cf1 commit 99948cd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
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
6 changes: 5 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 Down
3 changes: 3 additions & 0 deletions app/views/tpi/publications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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/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
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1634,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 @@ -4160,6 +4161,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230920083300'),
('20230926075145'),
('20230927112905'),
('20231023101859');
('20231023101859'),
('20231023120255');


Binary file modified db/test-dump.psql
Binary file not shown.
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
2 changes: 1 addition & 1 deletion spec/factories/publications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
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') }
is_insight { false }

trait :published do
publication_date { 20.days.ago }
Expand Down

0 comments on commit 99948cd

Please sign in to comment.