Skip to content
Draft
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
6 changes: 5 additions & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def set_form_variables
@workshops = Workshop.all.order(:title)
@users = User.active.or(User.where(id: @story.created_by_id))
.order(:first_name, :last_name)
@categories = Category.story_categories.published.order(:position, :name)
end

# def remove_image
Expand All @@ -105,8 +106,11 @@ def story_params
:title, :body, :featured, :published, :youtube_url, :website_url,
:windows_type_id, :project_id, :workshop_id, :external_workshop_title,
:created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id,
story_populations: [],
primary_asset_attributes: [ :id, :file, :_destroy ],
gallery_assets_attributes: [ :id, :file, :_destroy ]
gallery_assets_attributes: [ :id, :file, :_destroy ],
categorizable_items_attributes: [ :id, :category_id, :_destroy ],
category_ids: []
)
end
end
6 changes: 5 additions & 1 deletion app/controllers/story_ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def set_form_variables
@workshops = Workshop.all.order(:title)
@users = User.active.or(User.where(id: @story_idea.created_by_id))
.order(:first_name, :last_name)
@categories = Category.story_categories.published.order(:position, :name)
end

# def remove_image
Expand All @@ -92,8 +93,11 @@ def story_idea_params
:permission_given, :publish_preferences, :promoted_to_story,
:windows_type_id, :project_id, :workshop_id, :external_workshop_title,
:created_by_id, :updated_by_id,
story_populations: [],
primary_asset_attributes: [ :id, :file, :_destroy ],
gallery_assets_attributes: [ :id, :file, :_destroy ]
gallery_assets_attributes: [ :id, :file, :_destroy ],
categorizable_items_attributes: [ :id, :category_id, :_destroy ],
category_ids: []
)
end
end
1 change: 1 addition & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Category < ApplicationRecord
has_many :workshops, through: :categorizable_items, source: :categorizable, source_type: "Workshop"

scope :age_ranges, -> { joins(:category_type).where("metadata.name = 'AgeRange'") }
scope :story_categories, -> { joins(:category_type).where("metadata.name = 'StoryCategory'") }
scope :published, -> { where(published: true) }

# Validations
Expand Down
1 change: 1 addition & 0 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Story < ApplicationRecord
# Nested attributes
accepts_nested_attributes_for :primary_asset, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :gallery_assets, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :categorizable_items, allow_destroy: true, reject_if: :all_blank

# SearchCop
include SearchCop
Expand Down
4 changes: 4 additions & 0 deletions app/models/story_idea.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class StoryIdea < ApplicationRecord
belongs_to :windows_type
belongs_to :workshop, optional: true
has_many :bookmarks, as: :bookmarkable, dependent: :destroy
has_many :categorizable_items, dependent: :destroy, inverse_of: :categorizable, as: :categorizable
has_many :notifications, as: :noticeable, dependent: :destroy
has_many :stories
# Asset associations
Expand All @@ -19,6 +20,8 @@ class StoryIdea < ApplicationRecord
has_many :gallery_assets, -> { where(type: "GalleryAsset") },
as: :owner, class_name: "GalleryAsset", dependent: :destroy
has_many :assets, as: :owner, dependent: :destroy
# has_many through
has_many :categories, through: :categorizable_items

# Validations
validates :created_by_id, presence: true
Expand All @@ -32,6 +35,7 @@ class StoryIdea < ApplicationRecord
# Nested attributes
accepts_nested_attributes_for :primary_asset, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :gallery_assets, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :categorizable_items, allow_destroy: true, reject_if: :all_blank

def name
"StoryIdea ##{id}"
Expand Down
31 changes: 31 additions & 0 deletions app/views/stories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,37 @@
input_html: { rows: 10, value: f.object.body || @story_idea&.body } %>
</div>

<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-3">
What category does your story fit into? (check all that apply)
</label>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
<%= f.collection_check_boxes :category_ids, @categories, :id, :name do |b| %>
<div class="flex items-center">
<%= b.check_box class: "rounded border-gray-300 text-purple-600 shadow-sm focus:border-purple-300 focus:ring focus:ring-purple-200 focus:ring-opacity-50" %>
<%= b.label class: "ml-2 text-sm text-gray-700" %>
</div>
<% end %>
</div>
</div>

<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-3">
Who is your story about?
</label>
<div class="grid grid-cols-2 md:grid-cols-4 gap-3">
<% ["Adults", "Children", "Colleagues", "Community", "Families", "Self", "Teens"].each do |population| %>
<div class="flex items-center">
<%= check_box_tag "story[story_populations][]", population,
(f.object.story_populations || []).include?(population),
id: "story_story_populations_#{population.downcase}",
class: "rounded border-gray-300 text-purple-600 shadow-sm focus:border-purple-300 focus:ring focus:ring-purple-200 focus:ring-opacity-50" %>
<%= label_tag "story_story_populations_#{population.downcase}", population, class: "ml-2 text-sm text-gray-700" %>
</div>
<% end %>
</div>
</div>

<div class="flex gap-4 mb-6">
<div class="flex-1">
<%= f.input :youtube_url,
Expand Down
32 changes: 32 additions & 0 deletions app/views/story_ideas/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,38 @@
class: ("readonly" if promoted_to_story) } %>
</div>

<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-3">
What category does your story fit into? (check all that apply)
</label>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
<%= f.collection_check_boxes :category_ids, @categories, :id, :name do |b| %>
<div class="flex items-center">
<%= b.check_box class: "rounded border-gray-300 text-purple-600 shadow-sm focus:border-purple-300 focus:ring focus:ring-purple-200 focus:ring-opacity-50", disabled: promoted_to_story %>
<%= b.label class: "ml-2 text-sm text-gray-700" %>
</div>
<% end %>
</div>
</div>

<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-3">
Who is your story about?
</label>
<div class="grid grid-cols-2 md:grid-cols-4 gap-3">
<% ["Adults", "Children", "Colleagues", "Community", "Families", "Self", "Teens"].each do |population| %>
<div class="flex items-center">
<%= check_box_tag "story_idea[story_populations][]", population,
(f.object.story_populations || []).include?(population),
id: "story_idea_story_populations_#{population.downcase}",
disabled: promoted_to_story,
class: "rounded border-gray-300 text-purple-600 shadow-sm focus:border-purple-300 focus:ring focus:ring-purple-200 focus:ring-opacity-50" %>
<%= label_tag "story_idea_story_populations_#{population.downcase}", population, class: "ml-2 text-sm text-gray-700" %>
</div>
<% end %>
</div>
</div>

<div class="flex gap-4">
<%= f.input :publish_preferences,
as: :select,
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20260120005210_add_story_populations_to_stories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStoryPopulationsToStories < ActiveRecord::Migration[8.1]
def change
add_column :stories, :story_populations, :json
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStoryPopulationsToStoryIdeas < ActiveRecord::Migration[8.1]
def change
add_column :story_ideas, :story_populations, :json
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class AddStoryCategoryTypeAndCategories < ActiveRecord::Migration[8.1]
def up
# Create the StoryCategory type if it doesn't exist
story_category_type = CategoryType.find_or_create_by!(name: "StoryCategory")

# List of story categories from the WordPress form
story_categories = [
"Advocacy (legislation, voter mobilization, etc.)",
"Batterers Intervention (working with people who have caused harm)",
"Child Abuse / Neglect",
"Community Engagement",
"Community Violence (gang violence, police violence, mass shootings etc.)",
"Court & Legal System (including law enforcement and probation)",
"Disability Services",
"Domestic Violence",
"Donor Engagement",
"Foster Care",
"Grief & Loss",
"Homelessness",
"Human Trafficking",
"Immigration (family separation, deportation, refugees/asylees, etc.)",
"Incarceration",
"LGBTQIA+",
"Mental Health (DSM, suicidal ideation, etc.)",
"Military & Veterans",
"Physical & Terminal Illness",
"Schools & Universities",
"Self-Care & Personal Growth",
"Sexual Assault",
"Social Justice (anti-oppression, restorative justice, systems change, etc.)",
"Staff & Organizational Development",
"Substance Abuse Recovery"
]

# Create each category with proper ordering
story_categories.each_with_index do |category_name, index|
story_category_type.categories.find_or_create_by!(name: category_name) do |category|
category.position = (index + 1) * 10
category.published = true
end
end
end

def down
story_category_type = CategoryType.find_by(name: "StoryCategory")
story_category_type&.categories&.destroy_all
story_category_type&.destroy
end
end