Skip to content
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
11 changes: 8 additions & 3 deletions app/controllers/community_news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions app/controllers/resources_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/decorators/category_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class CategoryDecorator < ApplicationDecorator
def title
name
end

def detail
"#{category_type.name}: #{name}"
end
end
1 change: 1 addition & 0 deletions app/decorators/sector_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ def title
end

def detail
"Service population: #{name}"
end
end
5 changes: 3 additions & 2 deletions app/helpers/title_display_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions app/models/community_news.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ 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
community_news = community_news.search(params[:query]) if params[:query].present?
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
14 changes: 11 additions & 3 deletions app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/categories/_search_boxes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<!-- Name Search -->
<div>
<%= 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,
Expand Down
38 changes: 38 additions & 0 deletions app/views/community_news/_search_boxes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- Filters -->
<div class="mb-6 p-4 bg-white border border-gray-200 rounded-lg">
<%= 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| %>

<div>
<%= 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()" %>
</div>

<div>
<%= 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()" %>
</div>

<!-- Clear -->
<div>
<%= link_to "Clear",
community_news_index_path,
class: "btn btn-utility-outline whitespace-nowrap" %>
</div>

<% end %>
</div>
13 changes: 5 additions & 8 deletions app/views/community_news/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<div class="min-h-screen py-8">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="<%= DomainTheme.bg_class_for(:community_news) %> border border-gray-200 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-200 p-6">
<!-- Header Row -->
<div class="w-full">
<div class="community-news-index max-w-7xl mx-auto <%= DomainTheme.bg_class_for(:community_news) %> border border-gray-200 rounded-xl shadow p-6">
<div class="w-full">
<div class="flex items-start justify-between mb-6">
<div class="pr-6">
<h2 class="text-2xl font-semibold mb-2">Community news (<%= @community_news_count %>)</h2>
<h2 class="text-2xl font-semibold mb-2">Community news (<%= @count_display %>)</h2>
</div>
<div class="text-right text-end">
<% if current_user.super_user? %>
Expand All @@ -16,6 +13,8 @@
</div>
</div>

<%= render "search_boxes" %>

<% if @community_news.any? %>
<div class="overflow-x-auto bg-white border border-gray-200 rounded-xl shadow-sm">
<table class="min-w-full divide-y divide-gray-200">
Expand Down Expand Up @@ -108,7 +107,5 @@
</div>
<% end %>
</div>
</div>
</div>
</div>

4 changes: 2 additions & 2 deletions app/views/resources/_search_boxes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
class="block text-xs font-semibold uppercase text-gray-600 tracking-wide mb-1">
Published
</label>
<%= 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();" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/resources/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="w-full">
<div class="flex items-start justify-between mb-6">
<div class="pr-6">
<h2 class="text-2xl font-semibold mb-2">Resources (<%= @resources_count %>)</h2>
<h2 class="text-2xl font-semibold mb-2">Resources (<%= @count_display %>)</h2>
</div>
<div class="text-right text-end">
<% if current_user.super_user? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/sectors/_search_boxes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<!-- Name Search -->
<div>
<%= 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,
Expand Down
38 changes: 38 additions & 0 deletions app/views/stories/_search_boxes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- Filters -->
<div class="mb-6 p-4 bg-white border border-gray-200 rounded-lg">
<%= form_with url: stories_path,
method: :get,
local: true,
class: "grid grid-cols-1 md:grid-cols-5 gap-4 items-end" do |f| %>

<div>
<%= 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()" %>
</div>

<div>
<%= 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()" %>
</div>

<!-- Clear -->
<div>
<%= link_to "Clear",
stories_path,
class: "btn btn-utility-outline whitespace-nowrap" %>
</div>

<% end %>
</div>
4 changes: 3 additions & 1 deletion app/views/stories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="w-full">
<div class="flex items-start justify-between mb-6">
<div class="pr-6">
<h2 class="text-2xl font-semibold mb-2"><%= Story.model_name.human.pluralize %> (<%= @stories_count %>)</h2>
<h2 class="text-2xl font-semibold mb-2"><%= Story.model_name.human.pluralize %> (<%= @count_display %>)</h2>
</div>
<div class="text-right text-end">
<% if current_user.super_user? %>
Expand All @@ -16,6 +16,8 @@
</div>
</div>

<%= render "search_boxes" %>

<% if @stories.any? %>
<div class="overflow-x-auto bg-white border border-gray-200 rounded-xl shadow-sm">
<table class="min-w-full divide-y divide-gray-200">
Expand Down