Refactorings

- Cleanup Translatable module (`translation_params` method too large)
- Move globalize_helpers partial to admin folder
- Use any class for method translation_params
- Helpers in `GlobalizeHelpers` make sure all are in use and see if they can be more legible
- Review js name clases and methods see if they can be more legible
- Refactor milestone views into partials with nice spacing between attributes
This commit is contained in:
iagirre
2018-04-16 17:48:53 +02:00
parent 747db0ea35
commit 471c9730cc
9 changed files with 38 additions and 78 deletions

View File

@@ -48,7 +48,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
attributes = [:title, :description, :publication_date, :budget_investment_id,
image_attributes: image_attributes, documents_attributes: documents_attributes]
params.require(:budget_investment_milestone).permit(*attributes, translation_params)
params.require(:budget_investment_milestone).permit(*attributes, translation_params(params[:budget_investment_milestone]))
end
def load_budget_investment
@@ -56,7 +56,19 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
end
def load_budget_investment_milestone
@milestone = Budget::Investment::Milestone.find(params[:id])
@milestone = get_milestone
end
def get_milestone
Budget::Investment::Milestone.find(params[:id])
end
def resource_model
Budget::Investment::Milestone
end
def resource
get_milestone
end
end

View File

@@ -8,9 +8,8 @@ module Translatable
private
def translation_params
Budget::Investment::Milestone.globalize_attribute_names.
select { |k, v| params[:budget_investment_milestone].include?(k.to_sym) && params[:budget_investment_milestone][k].present? }
def translation_params(params)
resource_model.globalize_attribute_names.select { |k, v| params.include?(k.to_sym) && params[k].present? }
end
def set_translation_locale
@@ -18,12 +17,11 @@ module Translatable
end
def delete_translations
locales = Budget::Investment::Milestone.globalize_locales.
locales = resource_model.globalize_locales.
select { |k, v| params[:delete_translations].include?(k.to_sym) && params[:delete_translations][k] == "1" }
milestone = Budget::Investment::Milestone.find(params[:id])
locales.each do |l|
Globalize.with_locale(l) do
milestone.translation.destroy
resource.translation.destroy
end
end
end