diff --git a/app/admin/news_article.rb b/app/admin/news_article.rb
index b2de584e7..f12cc1e6f 100644
--- a/app/admin/news_article.rb
+++ b/app/admin/news_article.rb
@@ -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
@@ -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
@@ -43,6 +45,7 @@
index do
column 'Title', :title_link
+ column :short_description
column :publication_date
column :is_insight
@@ -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
@@ -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,
diff --git a/app/models/news_article.rb b/app/models/news_article.rb
index 0b2f51561..78a517259 100644
--- a/app/models/news_article.rb
+++ b/app/models/news_article.rb
@@ -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
diff --git a/app/views/tpi/publications/_list.html.erb b/app/views/tpi/publications/_list.html.erb
index 00526d4e7..f98fc81a9 100644
--- a/app/views/tpi/publications/_list.html.erb
+++ b/app/views/tpi/publications/_list.html.erb
@@ -32,7 +32,7 @@
<% 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 %>
diff --git a/db/migrate/20240119084250_add_short_description_to_news_articles.rb b/db/migrate/20240119084250_add_short_description_to_news_articles.rb
new file mode 100644
index 000000000..6871ae131
--- /dev/null
+++ b/db/migrate/20240119084250_add_short_description_to_news_articles.rb
@@ -0,0 +1,5 @@
+class AddShortDescriptionToNewsArticles < ActiveRecord::Migration[6.1]
+ def change
+ add_column :news_articles, :short_description, :text
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 05c16014e..d001381a5 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -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: -
--
@@ -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: -
--
@@ -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
);
@@ -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();
--
@@ -4164,6 +4170,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20231023101859'),
('20231023120255'),
('20231108125346'),
-('20231207082211');
+('20231207082211'),
+('20240119084250');
diff --git a/db/test-dump.psql b/db/test-dump.psql
index 82aead210..32f95c519 100644
Binary files a/db/test-dump.psql and b/db/test-dump.psql differ
diff --git a/spec/controllers/admin/news_articles_controller_spec.rb b/spec/controllers/admin/news_articles_controller_spec.rb
index c2993ed47..c45e89586 100644
--- a/spec/controllers/admin/news_articles_controller_spec.rb
+++ b/spec/controllers/admin/news_articles_controller_spec.rb
@@ -36,6 +36,7 @@
attributes_for(
:news_article,
title: 'My amazing title',
+ short_description: 'My amazing short description',
content: 'Test Content',
is_insight: true
)
@@ -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
diff --git a/spec/factories/news_articles.rb b/spec/factories/news_articles.rb
index 9bef6a7a1..dc915fa85 100644
--- a/spec/factories/news_articles.rb
+++ b/spec/factories/news_articles.rb
@@ -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' }