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
24 changes: 21 additions & 3 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ def show
end

def new
@story = Story.new.decorate
@story = @story.decorate
if params[:story_idea_id].present?
@story_idea = StoryIdea.find(params[:story_idea_id])
@story = Story.new(set_story_attributes_from(@story_idea))
else
@story = Story.new
end
@story.decorate
set_form_variables
end

Expand All @@ -52,7 +57,9 @@ def create
@story = Story.new(story_params)

if @story.save
if params.dig(:library_asset, :new_assets).present?
if params[:promote_idea_assets] == "true"
@story.attach_assets_from_idea!
elsif params.dig(:library_asset, :new_assets).present?
update_asset_owner(@story)
end

Expand Down Expand Up @@ -108,4 +115,15 @@ def story_params
:created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id
)
end

def set_story_attributes_from(idea)
{
rhino_body: idea.body,
project_id: idea.project.id,
workshop_id: idea.workshop_id,
external_workshop_title: idea.external_workshop_title,
windows_type_id: idea.windows_type_id,
youtube_url: idea.youtube_url
}
end
end
2 changes: 1 addition & 1 deletion app/controllers/workshop_ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create
notification_type: 0)

if params.dig(:library_asset, :new_assets).present?
update_asset_owner(@workshop)
update_asset_owner(@workshop_idea)
end

redirect_to workshop_ideas_path, notice: "Workshop idea was successfully created."
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def create
Workshop.transaction do
if @workshop.save
assign_associations(@workshop)
if params.dig(:library_asset, :new_assets).present?
if params[:promote_idea_assets] == "true"
@workshop.attach_assets_from_idea!
elsif params.dig(:library_asset, :new_assets).present?
update_asset_owner(@workshop)
end
success = true
Expand Down Expand Up @@ -298,7 +300,7 @@ def workshop_params
sector_ids: [],
workshop_series_children_attributes: [ :id, :workshop_child_id, :workshop_parent_id, :theme_name,
:series_description, :series_description_spanish,
:position, :_destroy ],
:position, :_destroy ]
)
end

Expand Down
10 changes: 10 additions & 0 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ def organization_locality
def organization_description
project&.organization_description
end

def attach_assets_from_idea!
return unless story_idea
story_idea.assets.find_each do |asset|
new_asset = assets.build(type: asset.type)
new_asset.file.attach(asset.file.blob)
end

save!
end
end
10 changes: 10 additions & 0 deletions app/models/workshop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ def featured_or_visitor_featured_changed?
featured_changed? || visitor_featured_changed? || inactive_changed?
end

def attach_assets_from_idea!
return unless workshop_idea

workshop_idea.assets.find_each do |asset|
new_asset = assets.build(type: asset.type)
new_asset.file.attach(asset.file.blob)
end

save!
end

private

Expand Down
57 changes: 34 additions & 23 deletions app/services/workshop_from_idea_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def initialize(workshop_idea, user:)
def call
Workshop.new(attributes_from_idea).tap do |workshop|
duplicate_series_children(workshop)
duplicate_assets(workshop)
end
end

Expand All @@ -19,26 +18,44 @@ def call

def attributes_from_idea
workshop_idea.attributes.slice(
"title", "objective", "objective_spanish",
"materials", "materials_spanish",
"optional_materials", "optional_materials_spanish",
"setup", "setup_spanish",
"introduction", "introduction_spanish",
"demonstration", "demonstration_spanish",
"warm_up", "warm_up_spanish",
"creation", "creation_spanish",
"closing", "closing_spanish",
"opening_circle", "opening_circle_spanish",
"notes", "notes_spanish",
"tips", "tips_spanish",
"windows_type_id", "age_range", "age_range_spanish",
"visualization", "visualization_spanish",
"extra_field", "extra_field_spanish",
"misc1", "misc1_spanish", "misc2", "misc2_spanish",
"title", "windows_type_id", "age_range",
"time_intro", "time_closing", "time_creation",
"time_demonstration", "time_warm_up",
"time_opening", "time_opening_circle"
).merge(
rhino_objective: workshop_idea.rhino_objective,
rhino_materials: workshop_idea.rhino_materials,
rhino_optional_materials: workshop_idea.rhino_optional_materials,
rhino_setup: workshop_idea.rhino_setup,
rhino_introduction: workshop_idea.rhino_introduction,
rhino_demonstration: workshop_idea.rhino_demonstration,
rhino_warm_up: workshop_idea.rhino_warm_up,
rhino_creation: workshop_idea.rhino_creation,
rhino_closing: workshop_idea.rhino_closing,
rhino_opening_circle: workshop_idea.rhino_opening_circle,
rhino_notes: workshop_idea.rhino_notes,
rhino_tips: workshop_idea.rhino_tips,
rhino_visualization: workshop_idea.rhino_visualization,
rhino_extra_field: workshop_idea.rhino_extra_field,
rhino_misc1: workshop_idea.rhino_misc1,
rhino_misc2: workshop_idea.rhino_misc2,
rhino_objective_spanish: workshop_idea.rhino_objective_spanish,
rhino_materials_spanish: workshop_idea.rhino_materials_spanish,
rhino_optional_materials_spanish: workshop_idea.rhino_optional_materials_spanish,
rhino_age_range_spanish: workshop_idea.rhino_age_range_spanish,
rhino_setup_spanish: workshop_idea.rhino_setup_spanish,
rhino_introduction_spanish: workshop_idea.rhino_introduction_spanish,
rhino_opening_circle_spanish: workshop_idea.rhino_opening_circle_spanish,
rhino_demonstration_spanish: workshop_idea.rhino_demonstration_spanish,
rhino_warm_up_spanish: workshop_idea.rhino_warm_up_spanish,
rhino_visualization_spanish: workshop_idea.rhino_visualization_spanish,
rhino_creation_spanish: workshop_idea.rhino_creation_spanish,
rhino_closing_spanish: workshop_idea.rhino_closing_spanish,
rhino_notes_spanish: workshop_idea.rhino_notes_spanish,
rhino_tips_spanish: workshop_idea.rhino_tips_spanish,
rhino_misc1_spanish: workshop_idea.rhino_misc1_spanish,
rhino_misc2_spanish: workshop_idea.rhino_misc2_spanish,
rhino_extra_field_spanish: workshop_idea.rhino_extra_field_spanish,
user_id: user.id,
workshop_idea_id: workshop_idea.id,
month: workshop_idea.created_at.month,
Expand All @@ -61,10 +78,4 @@ def duplicate_series_children(workshop)
end
)
end

def duplicate_assets(workshop)
workshop_idea.assets.each do |image|
workshop.assets.build(file: image.file.blob)
end
end
end
18 changes: 18 additions & 0 deletions app/views/stories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@
<%= f.button :submit, class: "btn btn-primary" %>
</div>
</div>

<% if story_idea %>
<div class="mt-6">
<%= label_tag :promote_idea_assets, class: "flex items-start space-x-3 cursor-pointer" do %>
<%= check_box_tag :promote_idea_assets, true, false, class: "mt-1 h-5 w-5 text-blue-600 rounded border-gray-300 focus:ring-blue-500" %>

<div class="ml-2 flex flex-col">
<span class="text-gray-900 font-medium">
If the story idea was submitted with attachments, check this box to transfer them to this new story.
</span>

<p class="text-gray-500 text-sm mt-1">
(This will override any attachments uploaded in the form below once you click submit.)
</p>
</div>
<% end %>
</div>
<% end %>
<% end %>

<div class="my-4"><%= render "assets/form", owner: @story %></div>
16 changes: 11 additions & 5 deletions app/views/workshop_ideas/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

<%= tag.div class: "unpersisted_resource_asset_params" %>

<% if current_user.super_user && f.object.workshops.any? %>
<%= f.hidden_field :created_by_id, value: current_user&.id unless f.object.persisted? %>
<%= f.hidden_field :updated_by_id, value: current_user&.id %>

<% promoted_to_workshop = f.object.workshops.any? %>
<% if promoted_to_workshop %>
<div class="admin-only bg-yellow-100 m-3 p-3">
This workshops idea has been promoted to a
<% f.object.workshops.each do |workshop| %>
Expand All @@ -16,11 +20,13 @@
<% end %>
and should not be edited here.
</div>
<% elsif current_user.super_user? && f.object.persisted? %>
<div class="admin-only bg-blue-100 m-3 p-3">
<%= link_to "Promote to Workshop", new_workshop_path(workshop_idea_id: @workshop_idea.id),
class: "btn btn-secondary-outline",
data: { confirm: "All edits must be saved before promoting. Are you sure you wish to promote?All edits must be saved before promoting." } %>
</div>
<% end %>

<%= f.hidden_field :created_by_id, value: current_user&.id unless f.object.persisted? %>
<%= f.hidden_field :updated_by_id, value: current_user&.id %>

<!-- Row 1 -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
<div>
Expand Down
18 changes: 18 additions & 0 deletions app/views/workshops/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,24 @@

<%= f.submit "Submit", class: "btn btn-primary" %>
</div>

<% if @workshop_idea %>
<div class="mt-6">
<%= label_tag :promote_idea_assets, class: "flex items-start space-x-3 cursor-pointer" do %>
<%= check_box_tag :promote_idea_assets, true, false, class: "mt-1 h-5 w-5 text-blue-600 rounded border-gray-300 focus:ring-blue-500" %>

<div class="ml-2 flex flex-col">
<span class="text-gray-900 font-medium">
If the workshop idea was submitted with attachments, check this box to transfer them to this new workshop.
</span>

<p class="text-gray-500 text-sm mt-1">
(This will override any attachments uploaded in the form below once you click submit.)
</p>
</div>
<% end %>
</div>
<% end %>
<% end %>
</div>

Expand Down