Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Refactor thermometersController to work with both types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuuleh committed Nov 22, 2018
1 parent 187b7d3 commit 604de6b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/plugins/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
# # frozen_string_literal: true
class Plugins::BaseController < ApplicationController
before_action :authenticate_user!

Expand Down
20 changes: 14 additions & 6 deletions app/controllers/plugins/thermometers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
# frozen_string_literal: true

# This controller is only used for ActionsThermometers.
class Plugins::ThermometersController < Plugins::BaseController
def update
plugin = Plugins::Thermometer.find(params[:id])

respond_to do |format|
if plugin.update(permitted_params)
format.js { render json: {} }
else
format.js { render json: { errors: plugin.errors, name: plugin_symbol }, status: :unprocessable_entity }
end
end
end

private

def permitted_params
key = params[:plugins_actions_thermometer].blank? ? 'plugins_donations_thermometer' : 'plugins_actions_thermometer'
params
.require(:plugins_thermometer)
.require(key.to_sym)
.permit(:title, :offset, :goal, :active, :type)
end

def plugin_class
Plugins::ActionsThermometer
end

def plugin_symbol
:plugins_thermometer
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/pages/edit.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ section.page-edit-step#layout data-icon='cog'
- next if low_priority_plugins.include? plugin.class
section.page-edit-step id=plugin_section_id(plugin) data-icon=plugin_icon(plugin)
h1.page-edit-step__title= plugin_title(plugin)
= render "#{plugin.class.base_class.name.underscore.pluralize}/form", plugin: plugin, page: @page
= render "#{plugin.class.name.underscore.pluralize}/form", plugin: plugin, page: @page

section.page-edit-step#pictures data-icon='camera-retro'
h1.page-edit-step__title = t('.pictures')
Expand All @@ -33,7 +33,7 @@ section.page-edit-step#sources data-icon='link'
- next unless low_priority_plugins.include? plugin.class
section.page-edit-step id=plugin_section_id(plugin) data-icon=plugin_icon(plugin)
h1.page-edit-step__title= plugin_title(plugin)
= render "#{plugin.class.base_class.name.underscore.pluralize}/form", plugin: plugin, page: @page
= render "#{plugin.class.name.underscore.pluralize}/form", plugin: plugin, page: @page

section.page-edit-step.page-edit-step--just-title#review data-icon='eye' data-link-to=member_facing_page_url(@page)
h1.page-edit-step__title
Expand Down
12 changes: 12 additions & 0 deletions app/views/plugins/actions_thermometers/_form.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.col-md-7
= render partial: 'plugins/shared/toggle_form', locals: { plugin: plugin, path: plugins_thermometer_path(plugin) }

- name = "plugins_actions_thermometer_#{plugin.id}"
= form_for plugin, url: plugins_thermometer_path(plugin), remote: true, as: name, html: {class: 'plugin-settings one-form', data: {type: name }} do |f|
= render "shared/error_messages", target: plugin
= render "shared/success_message", success: (defined?(success) || false)
= render 'plugins/shared/plugin_metadata', f: f

.form-group
= label_with_tooltip(f, :offset, t('plugins.thermometer.offset'), t('tooltips.thermometer.actions.offset'))
= f.text_field(:offset, class: 'form-control')
Empty file.
12 changes: 12 additions & 0 deletions app/views/plugins/donations_thermometers/_form.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.col-md-7
= render partial: 'plugins/shared/toggle_form', locals: { plugin: plugin, path: plugins_thermometer_path(plugin) }

- name = "plugins_donations_thermometer_#{plugin.id}"
= form_for plugin, url: plugins_thermometer_path(plugin), remote: true, as: name, html: {class: 'plugin-settings one-form', data: {type: name }} do |f|
= render "shared/error_messages", target: plugin
= render "shared/success_message", success: (defined?(success) || false)
= render 'plugins/shared/plugin_metadata', f: f

.form-group
= label_with_tooltip(f, :offset, t('plugins.thermometer.offset'), t('tooltips.thermometer.donations.offset'))
= f.text_field(:offset, class: 'form-control')
6 changes: 5 additions & 1 deletion config/locales/champaign.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ en:
click_count: "How many times this share button has been clicked"
conversion_count: "How many times a page has been viewed through a share made out of this share variant."
local_conversion_rate: "Percentage of the clicks / shares of this variant that got at least one person to view the page."
thermometer_offset: "Number of fake signatures to add to true signature count. No commas or spaces."
thermometer:
actions:
offset: "Number of fake signatures to add to true signature count. No commas or spaces."
donations:
offset: "Unformatted amount in USD to add to the amount of donations collected. No commas or spaces."
fundraiser:
donation_band: "This determines the amounts displayed on the page to an unknown user without any information in their URL. Generally, you will want to stick with an option designed for non-donors."
recurring_default: 'This sets whether the recurring donation checkbox is checked and/or hidden by default. If the url param recurring_default=recurring, recurring_default=only_recurring or recurring_default=one_off is passed, that will override the behavior specified here.'
Expand Down

0 comments on commit 604de6b

Please sign in to comment.