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 @@