From 546b37f0988c140b6bbbf2627704ef5bd73ed958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasia=20Jarmo=C5=82kowicz?= Date: Tue, 22 May 2018 11:25:47 +0200 Subject: [PATCH] Clean up templates, fix main image upload --- app/models/campaign.rb | 5 -- app/models/campaign_template.rb | 67 ++----------------- .../campaign_template_main_image_uploader.rb | 29 ++++++++ .../campaign_templates/_new_modal.html.erb | 4 +- .../campaign_templates/index.html.erb | 2 +- 5 files changed, 37 insertions(+), 70 deletions(-) create mode 100644 app/uploaders/campaign_template_main_image_uploader.rb diff --git a/app/models/campaign.rb b/app/models/campaign.rb index a8d4b241..ab7605d8 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -164,11 +164,6 @@ class Campaign < ActiveRecord::Base (self.end_datetime.to_date - Date.today).to_i end - def self.create_from_template(template_id) - # building params handled by another object - # not sure this method is needed eventually - end - def customizable_attributes_list campaign_template.customizable_attributes_list if campaign_template end diff --git a/app/models/campaign_template.rb b/app/models/campaign_template.rb index 4d72b717..306ebb60 100644 --- a/app/models/campaign_template.rb +++ b/app/models/campaign_template.rb @@ -1,6 +1,4 @@ class CampaignTemplate < ActiveRecord::Base - # these are very arbitrary names – some are attrs of campaign, some are not - # might be a good idea to get the default list from settings CUSTOMIZABLE_ATTR = %i(goal_amount) attr_accessible \ @@ -20,59 +18,13 @@ class CampaignTemplate < ActiveRecord::Base :goal_customizable, :nonprofit_id - attr_accessor :goal_amount_dollars - attr_accessor :goal_customizable attr_accessor :end_datetime - attr_accessor :hide_activity_feed - attr_accessor :deleted - attr_accessor :hide_title - attr_accessor :slug - attr_accessor :custom_banner_url - attr_accessor :published - attr_accessor :show_total_raised - attr_accessor :show_total_count - attr_accessor :hide_goal - attr_accessor :hide_thermometer - attr_accessor :hide_custom_amounts - attr_accessor :receipt_message + attr_accessor :goal_amount_dollars has_many :campaigns belongs_to :nonprofit - def customizable_attribute?(attribute_name) - CUSTOMIZABLE_ATTR.include? attribute_name.to_sym - end - - def recurring_fund? - end - - def main_image_url(url) - end - - def slug - Format::Url.convert_to_slug(template_name) - end - - def customizable_attributes_list - CUSTOMIZABLE_ATTR - end - - def name - if self[:name] - self[:name] - else - 'no name' - end - end - - def url - "#{self.nonprofit.url}/campaigns/#{self.slug}" - end - - def days_left - return 0 if self.end_datetime.nil? - (self.end_datetime.to_date - Date.today).to_i - end + mount_uploader :main_image, CampaignTemplateMainImageUploader before_validation do if self.goal_amount_dollars.present? @@ -81,19 +33,12 @@ class CampaignTemplate < ActiveRecord::Base self end - after_create do - # user = self.profile.user - # Role.create(name: :campaign_editor, user_id: user.id, host: self) + def customizable_attribute?(attribute_name) + CUSTOMIZABLE_ATTR.include? attribute_name.to_sym end - before_validation(on: :create) do - self.set_defaults - self - end - - def set_defaults - # self.total_supporters = 1 - # self.published = false if self.published.nil? + def customizable_attributes_list + CUSTOMIZABLE_ATTR end def create_campaign_params diff --git a/app/uploaders/campaign_template_main_image_uploader.rb b/app/uploaders/campaign_template_main_image_uploader.rb new file mode 100644 index 00000000..400331ef --- /dev/null +++ b/app/uploaders/campaign_template_main_image_uploader.rb @@ -0,0 +1,29 @@ +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later + +class CampaignTemplateMainImageUploader < CarrierWave::Uploader::Base + include CarrierWave::MiniMagick + + def store_dir + "uploads/campaign_templates/#{mounted_as}/#{model.id}" + end + + def default_url + return Image::DefaultProfileUrl + end + + version :normal do + process :resize_to_fill => [524, 360] + end + + version :thumb do + process :resize_to_fill => [180, 150] + end + + def extension_white_list + %w(jpg jpeg png) + end + + def cache_dir + "#{Rails.root}/tmp/uploads" + end +end diff --git a/app/views/nonprofits/campaign_templates/_new_modal.html.erb b/app/views/nonprofits/campaign_templates/_new_modal.html.erb index 6fba6cb8..dfc089fe 100644 --- a/app/views/nonprofits/campaign_templates/_new_modal.html.erb +++ b/app/views/nonprofits/campaign_templates/_new_modal.html.erb @@ -57,8 +57,6 @@
- -
@@ -95,7 +93,7 @@
Upload - +
diff --git a/app/views/nonprofits/campaign_templates/index.html.erb b/app/views/nonprofits/campaign_templates/index.html.erb index 1a1da3f9..5f767909 100644 --- a/app/views/nonprofits/campaign_templates/index.html.erb +++ b/app/views/nonprofits/campaign_templates/index.html.erb @@ -35,7 +35,7 @@ <% @templates.each do |template|%> - # +