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: Adding short description attribute to News #486

Merged
merged 6 commits into from
Jan 19, 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
7 changes: 6 additions & 1 deletion app/admin/news_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
decorate_with NewsArticleDecorator

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

filter :title
filter :content
filter :short_description
filter :publication_date

action_item :preview, priority: 0, only: :show do
Expand All @@ -23,6 +24,7 @@
tab :details do
attributes_table do
row :title
row :short_description
row :content
row :publication_date
list_row 'Sectors', :tpi_sector_links
Expand All @@ -43,6 +45,7 @@

index do
column 'Title', :title_link
column :short_description
column :publication_date
column :is_insight

Expand All @@ -52,6 +55,7 @@
csv do
column :id
column :title
column :short_description
column :content
column(:sectors) { |l| l.tpi_sectors.map(&:name).join(Rails.application.config.csv_options[:entity_sep]) }
column :keywords, &:keywords_csv
Expand All @@ -64,6 +68,7 @@

f.inputs do
f.input :title
f.input :short_description, as: :text
f.input :content, as: :trix, embed_youtube: true
f.input :publication_date, as: :date_time_picker
f.input :tpi_sector_ids, label: 'Sectors', as: :select,
Expand Down
4 changes: 2 additions & 2 deletions app/models/news_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class NewsArticle < ApplicationRecord
validates_presence_of :title, :content, :publication_date

def self.search(query)
where('title ilike ? OR content ilike ?',
"%#{query}%", "%#{query}%")
where('title ilike ? OR content ilike ? OR short_description ilike ?',
"%#{query}%", "%#{query}%", "%#{query}%")
end

def tags_and_sectors
Expand Down
2 changes: 1 addition & 1 deletion app/views/tpi/publications/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="content__message">
<p>
<% if publication.class.name.eql?("NewsArticle") %>
<%= truncate(strip_tags(publication.content), length: 100) %>
<%= publication.short_description.presence || truncate(strip_tags(publication.content), length: 100) %>
<% else %>
<%= publication.short_description %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddShortDescriptionToNewsArticles < ActiveRecord::Migration[6.1]
def change
add_column :news_articles, :short_description, :text
end
end
21 changes: 14 additions & 7 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

-- *not* creating schema, since initdb creates it


--
-- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -85,8 +92,6 @@ CREATE FUNCTION public.target_tsv_trigger() RETURNS trigger

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: active_admin_comments; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1549,7 +1554,8 @@ CREATE TABLE public.news_articles (
updated_by_id bigint,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
is_insight boolean DEFAULT false
is_insight boolean DEFAULT false,
short_description text
);


Expand Down Expand Up @@ -3594,21 +3600,21 @@ CREATE UNIQUE INDEX index_tpi_sectors_on_slug ON public.tpi_sectors USING btree
-- Name: legislations tsvectorupdate; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.legislations FOR EACH ROW EXECUTE FUNCTION public.legislation_tsv_trigger();
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.legislations FOR EACH ROW EXECUTE PROCEDURE public.legislation_tsv_trigger();


--
-- Name: litigations tsvectorupdate; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.litigations FOR EACH ROW EXECUTE FUNCTION public.litigation_tsv_trigger();
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.litigations FOR EACH ROW EXECUTE PROCEDURE public.litigation_tsv_trigger();


--
-- Name: targets tsvectorupdate; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.targets FOR EACH ROW EXECUTE FUNCTION public.target_tsv_trigger();
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON public.targets FOR EACH ROW EXECUTE PROCEDURE public.target_tsv_trigger();


--
Expand Down Expand Up @@ -4164,6 +4170,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20231023101859'),
('20231023120255'),
('20231108125346'),
('20231207082211');
('20231207082211'),
('20240119084250');


Binary file modified db/test-dump.psql
Binary file not shown.
2 changes: 2 additions & 0 deletions spec/controllers/admin/news_articles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
attributes_for(
:news_article,
title: 'My amazing title',
short_description: 'My amazing short description',
content: 'Test Content',
is_insight: true
)
Expand All @@ -48,6 +49,7 @@

last_news_article_created.tap do |g|
expect(g.title).to eq(valid_params[:title])
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
end
Expand Down
1 change: 1 addition & 0 deletions spec/factories/news_articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
FactoryBot.define do
factory :news_article do
title { 'MyString' }
short_description { 'MyText' }
content { 'MyText' }
tpi_sectors { |a| [a.association(:tpi_sector)] }
publication_date { '2019-11-29' }
Expand Down
Loading