From c33e07ddff1d42b49ae914158d9d2dff2379037b Mon Sep 17 00:00:00 2001 From: Elie Gaboriau Date: Fri, 20 Jan 2023 17:22:41 +0100 Subject: [PATCH] use extends instead of override and refactor helper add overloads --- OVERLOADS.md | 8 +++ .../decidim/forms/step_navigation_cell.rb | 50 ------------------- .../decidim/forms/application_helper.rb | 28 ----------- config/initializers/extends.rb | 2 + .../forms/step_navigation_cell_extends.rb | 15 ++++++ .../forms/application_helper_extends.rb | 15 ++++++ 6 files changed, 40 insertions(+), 78 deletions(-) delete mode 100644 app/cells/decidim/forms/step_navigation_cell.rb delete mode 100644 app/helpers/decidim/forms/application_helper.rb create mode 100644 lib/extends/cells/decidim/forms/step_navigation_cell_extends.rb create mode 100644 lib/extends/cells/helpers/decidim/forms/application_helper_extends.rb diff --git a/OVERLOADS.md b/OVERLOADS.md index 92f1fd7421..32a5b9bf3d 100644 --- a/OVERLOADS.md +++ b/OVERLOADS.md @@ -166,3 +166,11 @@ end * `spec/mailers/decidim/budgets/vote_reminder_mailer_spec.rb` * `spec/services/decidim/budgets/order_reminder_generator_spec.rb` * `spec/system/admin_reminds_users_with_pending_orders_spec.rb` + +## Fix survey validation +* `app/cells/decidim/forms/step_navigation/show.erb` +* `app/packs/src/decidim/decidim_application.js` +* `app/views/decidim/forms/questionnaires/show.html.erb` +* `config/initializers/decidim_verifications.rb` +* `spec/shared/has_questionnaire.rb` +* `spec/system/survey_spec.rb` diff --git a/app/cells/decidim/forms/step_navigation_cell.rb b/app/cells/decidim/forms/step_navigation_cell.rb deleted file mode 100644 index 8865eba6ce..0000000000 --- a/app/cells/decidim/forms/step_navigation_cell.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Forms - # This cell renders the navigation of a questionnaire step. - class StepNavigationCell < Decidim::ViewModel - include Decidim::LayoutHelper - - def current_step_index - model - end - - def first_step? - current_step_index.zero? - end - - def last_step? - current_step_index + 1 == total_steps - end - - def total_steps - options[:total_steps] - end - - def form - options[:form] - end - - def button_disabled? - options[:button_disabled] - end - - def previous_step_dom_id - "step-#{current_step_index - 1}" - end - - def next_step_dom_id - "step-#{current_step_index + 1}" - end - - def current_step_dom_id - "step-#{current_step_index}" - end - - def errors - options[:errors] - end - end - end -end diff --git a/app/helpers/decidim/forms/application_helper.rb b/app/helpers/decidim/forms/application_helper.rb deleted file mode 100644 index af6f73a99e..0000000000 --- a/app/helpers/decidim/forms/application_helper.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Forms - # Custom helpers, scoped to the forms engine. - module ApplicationHelper - # Show cell for selected models - def show_represent_user_group? - model_name = questionnaire_for.model_name.element - - permited_models.include?(model_name) - end - alias show_public_participation? show_represent_user_group? - - def permited_models - %(meeting) - end - - def invalid?(responses) - bool = false - responses.each do |response| - bool ||= response.errors.any? - end - bool - end - end - end -end diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 6ec0b405ed..6842d3856d 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -2,3 +2,5 @@ require "extends/controllers/decidim/devise/account_controller_extends" require "extends/controllers/decidim/meetings/meetings_controller_extends" +require "extends/cells/decidim/forms/step_navigation_cell_extends" +require "extends/helpers/decidim/forms/application_helper_extends" diff --git a/lib/extends/cells/decidim/forms/step_navigation_cell_extends.rb b/lib/extends/cells/decidim/forms/step_navigation_cell_extends.rb new file mode 100644 index 0000000000..d41fa52852 --- /dev/null +++ b/lib/extends/cells/decidim/forms/step_navigation_cell_extends.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Decidim + module Forms + module StepNavigationCellExtends + def errors + options[:errors] + end + end + end +end + +Decidim::Forms::StepNavigationCell.class_eval do + prepend(Decidim::Forms::StepNavigationCellExtends) +end diff --git a/lib/extends/cells/helpers/decidim/forms/application_helper_extends.rb b/lib/extends/cells/helpers/decidim/forms/application_helper_extends.rb new file mode 100644 index 0000000000..ace1678df8 --- /dev/null +++ b/lib/extends/cells/helpers/decidim/forms/application_helper_extends.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Decidim + module Forms + class ApplicationHelperExtends + def invalid?(responses) + responses.map { |response| response.errors.any? }.any? + end + end + end +end + +Decidim::Forms::ApplicationHelper.class_eval do + prepend(Decidim::Forms::ApplicationHelperExtends) +end