diff --git a/app/controllers/community_news_controller.rb b/app/controllers/community_news_controller.rb index 02a76d867..b6353f79d 100644 --- a/app/controllers/community_news_controller.rb +++ b/app/controllers/community_news_controller.rb @@ -4,9 +4,14 @@ class CommunityNewsController < ApplicationController def index per_page = params[:number_of_items_per_page].presence || 25 unpaginated = current_user.super_user? ? CommunityNews.all : Community_news.published - unpaginated = unpaginated.search_by_params(params) - @community_news_count = unpaginated.count - @community_news = unpaginated.paginate(page: params[:page], per_page: per_page) + filtered = unpaginated.search_by_params(params) + @community_news = filtered.paginate(page: params[:page], per_page: per_page) + + @count_display = if @community_news.total_entries == unpaginated.count + unpaginated.count + else + "#{@community_news.total_entries}/#{unpaginated.count}" + end end def show diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index 6bba8048b..dec1e935c 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -1,18 +1,19 @@ class ResourcesController < ApplicationController def index + per_page = params[:number_of_items_per_page].presence || 25 unpaginated = Resource.where(kind: Resource::PUBLISHED_KINDS) #TODO - #FIXME brittle .includes(:main_image, :gallery_images, :attachments) - .search_by_params(params) + filtered = unpaginated.search_by_params(params) .by_created - @resources = unpaginated.paginate(page: params[:page], per_page: 24) + @resources = filtered.paginate(page: params[:page], per_page: per_page) - @resources_count = unpaginated.size + @count_display = if @resources.total_entries == unpaginated.count + unpaginated.count + else + "#{@resources.total_entries}/#{unpaginated.count}" + end @sortable_fields = Resource::PUBLISHED_KINDS - - respond_to do |format| - format.html - end end def stories diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index c69da4bbd..8bfda0fff 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -4,12 +4,16 @@ class StoriesController < ApplicationController def index per_page = params[:number_of_items_per_page].presence || 25 unpaginated = current_user.super_user? ? Story.all : Story.published - unpaginated = unpaginated.search_by_params(params) - @stories = unpaginated.includes(:windows_type, :project, :workshop, :created_by, :updated_by) + filtered = unpaginated.includes(:windows_type, :project, :workshop, :created_by, :updated_by) + .search_by_params(params) .order(created_at: :desc) - .paginate(page: params[:page], per_page: per_page) + @stories = filtered.paginate(page: params[:page], per_page: per_page) - @stories_count = unpaginated.size + @count_display = if @stories.total_entries == unpaginated.count + unpaginated.count + else + "#{@stories.total_entries}/#{unpaginated.count}" + end end def show diff --git a/app/decorators/category_decorator.rb b/app/decorators/category_decorator.rb index 7e2a0116a..6e67851ad 100644 --- a/app/decorators/category_decorator.rb +++ b/app/decorators/category_decorator.rb @@ -1,2 +1,9 @@ class CategoryDecorator < ApplicationDecorator + def title + name + end + + def detail + "#{category_type.name}: #{name}" + end end diff --git a/app/decorators/sector_decorator.rb b/app/decorators/sector_decorator.rb index ecf1a9fd7..4d329db56 100644 --- a/app/decorators/sector_decorator.rb +++ b/app/decorators/sector_decorator.rb @@ -5,5 +5,6 @@ def title end def detail + "Service population: #{name}" end end diff --git a/app/helpers/title_display_helper.rb b/app/helpers/title_display_helper.rb index 447f70626..747ab8e54 100644 --- a/app/helpers/title_display_helper.rb +++ b/app/helpers/title_display_helper.rb @@ -5,8 +5,9 @@ def title_with_badges(record, font_size: "text-lg", record_title: nil, fragments = [] # --- Hidden badge --- - if show_hidden_badge && record.respond_to?(:inactive?) && - record.inactive? && controller_name != "dashboard" + if show_hidden_badge && controller_name != "dashboard" && ( + record.respond_to?(:inactive?) && record.inactive? && controller_name != "dashboard" || + record.respond_to?(:published?) && !record.published?) fragments << content_tag( :span, content_tag(:i, "", class: "fa-solid fa-eye-slash mr-1") + " Hidden", diff --git a/app/models/community_news.rb b/app/models/community_news.rb index 4b72411db..f6d771536 100644 --- a/app/models/community_news.rb +++ b/app/models/community_news.rb @@ -34,9 +34,13 @@ class CommunityNews < ApplicationRecord end scope :featured, -> { where(featured: true) } - scope :published, ->(published=nil) { published ? where(published: published) : where(published: true) } scope :category_names, ->(names) { tag_names(:categories, names) } scope :sector_names, ->(names) { tag_names(:sectors, names) } + scope :community_news_name, ->(community_news_name) { + community_news_name.present? ? where("community_news.name LIKE ?", "%#{community_news_name}%") : all } + scope :published, ->(published=nil) { + ["true", "false"].include?(published) ? where(published: published) : where(published: true) } + scope :published_search, ->(published_search) { published_search.present? ? published(published_search) : all } def self.search_by_params(params) community_news = self.all @@ -44,7 +48,7 @@ def self.search_by_params(params) community_news = community_news.sector_names(params[:sector_names]) if params[:sector_names].present? community_news = community_news.category_names(params[:category_names]) if params[:category_names].present? community_news = community_news.windows_type_name(params[:windows_type_name]) if params[:windows_type_name].present? - community_news = community_news.published(params[:published]) if params[:published].present? + community_news = community_news.published_search(params[:published_search]) if params[:published_search].present? community_news end end diff --git a/app/models/resource.rb b/app/models/resource.rb index 6bb32a5b7..6ac22ed04 100644 --- a/app/models/resource.rb +++ b/app/models/resource.rb @@ -62,8 +62,16 @@ class Resource < ApplicationRecord scope :kind, -> (kind) { where("kind like ?", kind ) } scope :leader_spotlights, -> { kind("LeaderSpotlight") } scope :published_kinds, -> { where(kind: PUBLISHED_KINDS) } - scope :published, -> (published=nil) { published.present? ? - where(inactive: !published).published_kinds : where(inactive: false).published_kinds } + scope :published, ->(published=nil) { + if ["true", "false"].include?(published) + result = where(inactive: published == "true" ? false : true) + else + result = where(inactive: false) + end + result.published_kinds + } + scope :published_search, ->(published_search=nil) { published_search.present? ? published(published_search) : published_kinds } + scope :recent, -> { published.by_created } scope :sector_impact, -> { where(kind: "SectorImpact") } scope :scholarship, -> { where(kind: "Scholarship") } @@ -79,7 +87,7 @@ def self.search_by_params(params) resources = resources.windows_type_name(params[:windows_type_name]) if params[:windows_type_name].present? resources = resources.title(params[:title]) if params[:title].present? resources = resources.kind(params[:kind]) if params[:kind].present? - resources = resources.published(params[:published]) if params[:published].present? + resources = resources.published_search(params[:published_search]) if params[:published_search].present? resources = resources.featured(params[:featured]) if params[:featured].present? resources end diff --git a/app/models/story.rb b/app/models/story.rb index 016d36a77..7a2e91889 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -39,15 +39,21 @@ class Story < ApplicationRecord # Scopes scope :featured, -> { where(featured: true) } - scope :published, ->(published=nil) { published ? where(published: published) : where(published: true) } scope :category_names, ->(names) { tag_names(:categories, names) } scope :sector_names, ->(names) { tag_names(:sectors, names) } + scope :story_name, ->(story_name) { + story_name.present? ? where("stories.name LIKE ?", "%#{story_name}%") : all } + scope :published, ->(published=nil) { + ["true", "false"].include?(published) ? where(published: published) : where(published: true) } + scope :published_search, ->(published_search) { published_search.present? ? published(published_search) : all } def self.search_by_params(params) stories = self.all stories = stories.search(params[:query]) if params[:query].present? stories = stories.sector_names(params[:sector_names]) if params[:sector_names].present? stories = stories.category_names(params[:category_names]) if params[:category_names].present? + stories = stories.story_name(params[:story_name]) if params[:story_name].present? + stories = stories.published_search(params[:published_search]) if params[:published_search].present? stories = stories.windows_type_name(params[:windows_type_name]) if params[:windows_type_name].present? stories end diff --git a/app/views/categories/_search_boxes.html.erb b/app/views/categories/_search_boxes.html.erb index ca9770c93..f99f90a06 100644 --- a/app/views/categories/_search_boxes.html.erb +++ b/app/views/categories/_search_boxes.html.erb @@ -19,7 +19,7 @@
- <%= f.label :category_name, "Name Contains", + <%= f.label :category_name, "Name contains", class: "block text-sm font-medium text-gray-700" %> <%= f.text_field :category_name, diff --git a/app/views/community_news/_search_boxes.html.erb b/app/views/community_news/_search_boxes.html.erb new file mode 100644 index 000000000..d5865a0d9 --- /dev/null +++ b/app/views/community_news/_search_boxes.html.erb @@ -0,0 +1,38 @@ + +
+ <%= form_with url: community_news_index_path, + method: :get, + local: true, + class: "grid grid-cols-1 md:grid-cols-5 gap-4 items-end" do |f| %> + +
+ <%= f.label :community_news_name, "Title contains", + class: "block text-sm font-medium text-gray-700" %> + + <%= f.text_field :community_news_name, + value: params[:community_news_name], + placeholder: "e.g. Art, Music…", + class: "mt-1 block w-full rounded-md border border-gray-300 p-2", + oninput: "this.form.requestSubmit()" %> +
+ +
+ <%= f.label :published_search, "Published", + class: "block text-sm font-medium text-gray-700" %> + + <%= f.select :published_search, + options_for_select([["All", ""], ["Published", "true"], ["Hidden", "false"]], params[:published_search]), + {}, + class: "mt-1 block w-full rounded-md border border-gray-300 p-2", + onchange: "this.form.requestSubmit()" %> +
+ + +
+ <%= link_to "Clear", + community_news_index_path, + class: "btn btn-utility-outline whitespace-nowrap" %> +
+ + <% end %> +
diff --git a/app/views/community_news/index.html.erb b/app/views/community_news/index.html.erb index 211e6e197..c7ad5e9c5 100644 --- a/app/views/community_news/index.html.erb +++ b/app/views/community_news/index.html.erb @@ -1,11 +1,8 @@ -
-
-
- -
+
+
-

Community news (<%= @community_news_count %>)

+

Community news (<%= @count_display %>)

<% if current_user.super_user? %> @@ -16,6 +13,8 @@
+ <%= render "search_boxes" %> + <% if @community_news.any? %>
@@ -108,7 +107,5 @@ <% end %> - - diff --git a/app/views/resources/_search_boxes.html.erb b/app/views/resources/_search_boxes.html.erb index 9b2b284b3..fbc40a91e 100644 --- a/app/views/resources/_search_boxes.html.erb +++ b/app/views/resources/_search_boxes.html.erb @@ -24,10 +24,10 @@ class="block text-xs font-semibold uppercase text-gray-600 tracking-wide mb-1"> Published - <%= select_tag :published, + <%= select_tag :published_search, options_for_select( [["All", ""], ["Published", "true"], ["Hidden", "false"]], - params[:published] + params[:published_search] ), class: "border border-gray-300 rounded-lg px-3 py-2 text-gray-700 w-full", onchange: "this.form.submit();" %> diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb index 781a7452f..67752ea04 100644 --- a/app/views/resources/index.html.erb +++ b/app/views/resources/index.html.erb @@ -3,7 +3,7 @@
-

Resources (<%= @resources_count %>)

+

Resources (<%= @count_display %>)

<% if current_user.super_user? %> diff --git a/app/views/sectors/_search_boxes.html.erb b/app/views/sectors/_search_boxes.html.erb index a39c51595..197763031 100644 --- a/app/views/sectors/_search_boxes.html.erb +++ b/app/views/sectors/_search_boxes.html.erb @@ -7,7 +7,7 @@
- <%= f.label :sector_name, "Name Contains", + <%= f.label :sector_name, "Name contains", class: "block text-sm font-medium text-gray-700" %> <%= f.text_field :sector_name, diff --git a/app/views/stories/_search_boxes.html.erb b/app/views/stories/_search_boxes.html.erb new file mode 100644 index 000000000..c70799d33 --- /dev/null +++ b/app/views/stories/_search_boxes.html.erb @@ -0,0 +1,38 @@ + +
+ <%= form_with url: stories_path, + method: :get, + local: true, + class: "grid grid-cols-1 md:grid-cols-5 gap-4 items-end" do |f| %> + +
+ <%= f.label :story_name, "Title contains", + class: "block text-sm font-medium text-gray-700" %> + + <%= f.text_field :story_name, + value: params[:story_name], + placeholder: "e.g. Art, Music…", + class: "mt-1 block w-full rounded-md border border-gray-300 p-2", + oninput: "this.form.requestSubmit()" %> +
+ +
+ <%= f.label :published_search, "Published", + class: "block text-sm font-medium text-gray-700" %> + + <%= f.select :published_search, + options_for_select([["All", ""], ["Published", "true"], ["Hidden", "false"]], params[:published_search]), + {}, + class: "mt-1 block w-full rounded-md border border-gray-300 p-2", + onchange: "this.form.requestSubmit()" %> +
+ + +
+ <%= link_to "Clear", + stories_path, + class: "btn btn-utility-outline whitespace-nowrap" %> +
+ + <% end %> +
diff --git a/app/views/stories/index.html.erb b/app/views/stories/index.html.erb index edef0e303..b2c07e17e 100644 --- a/app/views/stories/index.html.erb +++ b/app/views/stories/index.html.erb @@ -5,7 +5,7 @@
-

<%= Story.model_name.human.pluralize %> (<%= @stories_count %>)

+

<%= Story.model_name.human.pluralize %> (<%= @count_display %>)

<% if current_user.super_user? %> @@ -16,6 +16,8 @@
+ <%= render "search_boxes" %> + <% if @stories.any? %>