Skip to content

Commit c8f1ab0

Browse files
authored
Rename image associations/models (#609)
* Rename media/images to Asset * Display Organization, rather than Project in notices * Adjust form_image_fields to render images and attachments, if those assns exist * Convert tabs to spaces for rubocop * Rename media -> asset or add comment * Don't carry over legacy paperclip data when copying to Asset * Convert Facilitator, User, Project to using has_one_attached, rather than associated 'SquareAsset' * Add rake tasks for converting header on workshop into primary asset, then making sure there's only one primary_asset * Rename SecondaryAsset to GalleryAsset * Remove trailing comma * Don't include avatar & logo, bc they are no longer associations * Remove extra line * Correct assn/class names
1 parent 834e8e3 commit c8f1ab0

File tree

111 files changed

+703
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+703
-352
lines changed

app/controllers/api/v1/workshops_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def index
1616
{ quotes: { only: :quote } },
1717
{ sectors: { only: :name } }
1818
],
19-
methods: [ :main_image_url, :sector_hashtags ]
19+
methods: [ :main_image_url, # leaving this until api is refactored
20+
:sector_hashtags ]
2021
}
2122
})
2223

app/controllers/community_news_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def destroy
6565

6666
# Optional hooks for setting variables for forms or index
6767
def set_form_variables
68-
@community_news.build_main_image if @community_news.main_image.blank?
69-
@community_news.gallery_images.build
68+
@community_news.build_primary_asset if @community_news.primary_asset.blank?
69+
@community_news.gallery_assets.build
7070

7171
@organizations = Project.pluck(:name, :id).sort_by(&:first)
7272
@windows_types = WindowsType.all
@@ -87,8 +87,8 @@ def community_news_params
8787
:reference_url, :youtube_url,
8888
:project_id, :windows_type_id,
8989
:author_id, :created_by_id, :updated_by_id,
90-
main_image_attributes: [ :id, :file, :_destroy ],
91-
gallery_images_attributes: [ :id, :file, :_destroy ]
90+
primary_asset_attributes: [ :id, :file, :_destroy ],
91+
gallery_assets_attributes: [ :id, :file, :_destroy ]
9292
)
9393
end
9494
end

app/controllers/dashboard_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ class DashboardController < ApplicationController
22
include AdminDashboardCardsHelper
33

44
def index
5-
workshops = Workshop.includes(:sectors, :categories, :windows_type, :main_image, :gallery_images)
5+
workshops = Workshop.includes(:sectors, :categories, :windows_type, :primary_asset, :gallery_assets)
66
.featured
77
.published
88
.decorate
99
@workshops = workshops.sort { |x, y| Date.parse(y.date) <=> Date.parse(x.date) }
1010

11-
@resources = Resource.includes(:windows_type, :main_image, :gallery_images)
11+
@resources = Resource.includes(:windows_type, :primary_asset, :gallery_assets)
1212
.featured
1313
.published
1414
.by_most_viewed(6)
1515
.order(ordering: :asc, created_at: :desc)
1616
.decorate
17-
@stories = Story.includes(:windows_type, :main_image, :gallery_images)
17+
@stories = Story.includes(:windows_type, :primary_asset, :gallery_assets)
1818
.featured
1919
.published
2020
.order(:title)
2121
.decorate
22-
@community_news = CommunityNews.includes(:windows_type, :main_image, :gallery_images)
22+
@community_news = CommunityNews.includes(:windows_type, :primary_asset, :gallery_assets)
2323
.featured
2424
.published
2525
.order(updated_at: :desc)
2626
.decorate
27-
@events = Event.includes(:event_registrations, :main_image, :gallery_images)
27+
@events = Event.includes(:event_registrations, :primary_asset, :gallery_assets)
2828
.featured
2929
.published
3030
.order(:start_date)

app/controllers/events_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def destroy
6767

6868
def set_form_variables
6969
@event = @event.decorate
70-
@event.build_main_image if @event.main_image.blank?
71-
@event.gallery_images.build
70+
@event.build_primary_asset if @event.primary_asset.blank?
71+
@event.gallery_assets.build
7272
end
7373

7474
def set_event
@@ -83,8 +83,8 @@ def event_params
8383
:start_date, :end_date,
8484
:registration_close_date,
8585
:publicly_visible,
86-
main_image_attributes: [ :id, :file, :_destroy ],
87-
gallery_images_attributes: [ :id, :file, :_destroy ]
86+
primary_asset_attributes: [ :id, :file, :_destroy ],
87+
gallery_assets_attributes: [ :id, :file, :_destroy ]
8888
)
8989
end
9090

app/controllers/facilitators_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def set_user
7979
def set_form_variables
8080
set_user
8181
# @facilitator.build_user if @facilitator.user.blank? # Build a fresh one if missing
82-
@facilitator.build_avatar_image if @facilitator.avatar_image.blank?
8382

8483
if @facilitator.user
8584
@facilitator.user.project_users.first || @facilitator.user.project_users.build
@@ -96,6 +95,7 @@ def set_form_variables
9695
# Only allow a list of trusted parameters through.
9796
def facilitator_params
9897
params.require(:facilitator).permit(
98+
:avatar,
9999
:first_name, :last_name,
100100
:email, :email_type,
101101
:email_2, :email_2_type,
@@ -128,7 +128,6 @@ def facilitator_params
128128
:youtube_url,
129129
:twitter_url,
130130
:created_by_id, :updated_by_id,
131-
avatar_image_attributes: [ :id, :file, :_destroy ],
132131
sectorable_items_attributes: [ :id, :sector_id, :is_leader, :_destroy ],
133132
addresses_attributes: [
134133
:id,

app/controllers/projects_controller.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create
5454
@project = Project.new(project_params)
5555

5656
if @project.save
57-
redirect_to projects_path, notice: "Project was successfully created."
57+
redirect_to projects_path, notice: "Organization was successfully created."
5858
else
5959
set_form_variables
6060
render :new, status: :unprocessable_content
@@ -63,7 +63,7 @@ def create
6363

6464
def update
6565
if @project.update(project_params)
66-
redirect_to projects_path, notice: "Project was successfully updated.", status: :see_other
66+
redirect_to projects_path, notice: "Organization was successfully updated.", status: :see_other
6767
else
6868
set_form_variables
6969
render :edit, status: :unprocessable_content
@@ -72,13 +72,11 @@ def update
7272

7373
def destroy
7474
@project.destroy!
75-
redirect_to projects_path, notice: "Project was successfully destroyed."
75+
redirect_to projects_path, notice: "Organization was successfully destroyed."
7676
end
7777

7878
# Optional hooks for setting variables for forms or index
7979
def set_form_variables
80-
@project.build_logo_image if @project.logo_image.blank?
81-
8280
@project_statuses = ProjectStatus.all
8381
@facilitators_array = Facilitator.joins(:user)
8482
.order(:first_name, :last_name)
@@ -102,9 +100,8 @@ def set_project
102100
def project_params
103101
params.require(:project).permit(
104102
:name, :description, :start_date, :end_date, :mission_vision_values, :internal_id,
105-
:inactive, :notes, :agency_type, :agency_type_other, :website_url,
103+
:inactive, :logo, :notes, :agency_type, :agency_type_other, :website_url,
106104
:project_status_id, :location_id, :windows_type_id,
107-
logo_image_attributes: [ :id, :file, :_destroy ],
108105
sectorable_items_attributes: [
109106
:id,
110107
:sector_id,

app/controllers/reports_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def report_params
253253
:owner_type, :windows_type_id, report_form_field_answers_attributes:
254254
[ :form_field_id, :answer_option_id, :answer, :_create ],
255255
media_files_attributes: [ :file ],
256-
main_image_attributes: [ :id, :file, :_destroy ],
257-
gallery_images_attributes: [ :id, :file, :_destroy ]
256+
primary_asset_attributes: [ :id, :file, :_destroy ],
257+
gallery_assets_attributes: [ :id, :file, :_destroy ]
258258
)
259259
end
260260

app/controllers/resources_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def index
44
if turbo_frame_request?
55
per_page = params[:number_of_items_per_page].presence || 25
66
unfiltered = Resource.where(kind: Resource::PUBLISHED_KINDS) # TODO - #FIXME brittle
7-
.includes(:main_image, :gallery_images, :attachments)
7+
.includes(:primary_asset, :gallery_assets, :attachments)
88
filtered = unfiltered.search_by_params(params)
99
.by_created
1010
@resources = filtered.paginate(page: params[:page], per_page: per_page)
@@ -114,8 +114,8 @@ def download
114114
private
115115

116116
def set_form_variables
117-
@resource.build_main_image if @resource.main_image.blank?
118-
@resource.gallery_images.build
117+
@resource.build_primary_asset if @resource.primary_asset.blank?
118+
@resource.gallery_assets.build
119119

120120
@windows_types = WindowsType.all
121121
@authors = User.active.or(User.where(id: @resource.user_id))
@@ -137,8 +137,8 @@ def resource_params
137137
params.require(:resource).permit(
138138
:text, :rhino_text, :kind, :male, :female, :title, :featured, :inactive, :url,
139139
:agency, :author, :filemaker_code, :windows_type_id, :ordering,
140-
main_image_attributes: [ :id, :file, :_destroy ],
141-
gallery_images_attributes: [ :id, :file, :_destroy ],
140+
primary_asset_attributes: [ :id, :file, :_destroy ],
141+
gallery_assets_attributes: [ :id, :file, :_destroy ],
142142
categorizable_items_attributes: [ :id, :category_id, :_destroy ], category_ids: [],
143143
sectorable_items_attributes: [ :id, :sector_id, :is_leader, :_destroy ], sector_ids: []
144144
)

app/controllers/stories_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def destroy
6767

6868
# Optional hooks for setting variables for forms or index
6969
def set_form_variables
70-
@story.build_main_image if @story.main_image.blank?
71-
@story.gallery_images.build
70+
@story.build_primary_asset if @story.primary_asset.blank?
71+
@story.gallery_assets.build
7272

7373
@story_idea = StoryIdea.find(params[:story_idea_id]) if params[:story_idea_id].present?
7474
@user = User.find(params[:user_id]) if params[:user_id].present?
@@ -89,7 +89,7 @@ def set_form_variables
8989
#
9090
# respond_to do |format|
9191
# format.turbo_stream
92-
# format.html { redirect_to edit_story_path(@story), notice: "Image removed." }
92+
# format.html { redirect_to edit_story_path(@story), notice: "Asset removed." }
9393
# end
9494
# end
9595

@@ -105,8 +105,8 @@ def story_params
105105
:title, :body, :featured, :published, :youtube_url, :website_url,
106106
:windows_type_id, :project_id, :workshop_id, :external_workshop_title,
107107
:created_by_id, :updated_by_id, :story_idea_id, :spotlighted_facilitator_id,
108-
main_image_attributes: [ :id, :file, :_destroy ],
109-
gallery_images_attributes: [ :id, :file, :_destroy ]
108+
primary_asset_attributes: [ :id, :file, :_destroy ],
109+
gallery_assets_attributes: [ :id, :file, :_destroy ]
110110
)
111111
end
112112
end

app/controllers/story_ideas_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def destroy
5151

5252
# Optional hooks for setting variables for forms or index
5353
def set_form_variables
54-
@story_idea.build_main_image if @story_idea.main_image.blank?
55-
@story_idea.gallery_images.build
54+
@story_idea.build_primary_asset if @story_idea.primary_asset.blank?
55+
@story_idea.gallery_assets.build
5656

5757
@user = User.find(params[:user_id]) if params[:user_id].present?
5858
@projects = (@user || current_user).projects.order(:name)
@@ -69,7 +69,7 @@ def set_form_variables
6969
#
7070
# respond_to do |format|
7171
# format.turbo_stream
72-
# format.html { redirect_to edit_story_path(@story_idea), notice: "Image removed." }
72+
# format.html { redirect_to edit_story_path(@story_idea), notice: "Asset removed." }
7373
# end
7474
# end
7575

@@ -86,8 +86,8 @@ def story_idea_params
8686
:permission_given, :publish_preferences, :promoted_to_story,
8787
:windows_type_id, :project_id, :workshop_id, :external_workshop_title,
8888
:created_by_id, :updated_by_id,
89-
main_image_attributes: [ :id, :file, :_destroy ],
90-
gallery_images_attributes: [ :id, :file, :_destroy ]
89+
primary_asset_attributes: [ :id, :file, :_destroy ],
90+
gallery_assets_attributes: [ :id, :file, :_destroy ]
9191
)
9292
end
9393
end

0 commit comments

Comments
 (0)