Skip to content

Commit

Permalink
Rework types filter
Browse files Browse the repository at this point in the history
  • Loading branch information
laurajaime committed Jul 30, 2024
1 parent cf638e7 commit ff0c4b5
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 42 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def copy_participatory_process
has_summary_record: @participatory_process.has_summary_record,
promoting_unit: @participatory_process.promoting_unit,
facilitators: @participatory_process.facilitators,
email: @participatory_process.email,
decidim_type_id: @participatory_process.decidim_type_id
email: @participatory_process.email
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def attributes
has_summary_record: form.has_summary_record,
promoting_unit: form.promoting_unit,
facilitators: form.facilitators,
email: form.email,
decidim_type: form.type
email: form.email
})
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,15 @@ def self.decorate
attribute :promoting_unit, String
attribute :cost, Float
attribute :has_summary_record, :boolean
attribute :type_id, Integer
attribute :email, String

validates :type, presence: true, if: proc { |object| object.type_id.present? }

def map_model(model)
self.scope_id = model.decidim_scope_id
self.participatory_process_group_id = model.decidim_participatory_process_group_id
self.participatory_process_type_id = model.decidim_participatory_process_type_id
self.type_id = model.decidim_type_id
self.related_process_ids = model.linked_participatory_space_resources(:participatory_process, "related_processes").pluck(:id)
@processes = Decidim::ParticipatoryProcess.where(organization: model.organization).where.not(id: model.id)
end

def type
@type ||= current_organization.types.find_by(id: type_id)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def attributes
has_summary_record: form.has_summary_record,
promoting_unit: form.promoting_unit,
facilitators: form.facilitators,
email: form.email,
decidim_type: form.type
email: form.email
})
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def initialize(process)
end

# Public: Returns a hash with the serialized data.
# rubocop:disable Metrics/CyclomaticComplexity
def serialize
{
# Process Information
Expand All @@ -30,8 +29,10 @@ def serialize
department_id: process.area&.id,
department_name_ca: process.area&.name.try(:[], "ca"),
participatory_space: process.participatory_process_group&.title.try(:[], "ca")&.downcase,
normative_type_id: process.decidim_type&.id,
normative_type_name_ca: process.decidim_type&.name.try(:[], "ca"),
participatory_process_type: {
id: process.participatory_process_type.try(:id),
title: process.participatory_process_type.try(:title) || empty_translatable
},
duration_days: duration_days,
start_date: process.start_date,
end_date: process.end_date,
Expand Down Expand Up @@ -61,7 +62,6 @@ def serialize
related_assembly_name_ca: related_assembly&.title.try(:[], "ca")
}
end
# rubocop:enable Metrics/CyclomaticComplexity

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@
selected: current_participatory_process.try(:decidim_area_id),
include_blank: t(".select_an_area") %>
</div>

<div class="columns xlarge-6">
<%= form.types_select :type_id,
types_for_select(current_organization),
selected: current_participatory_process.try(:decidim_type_id),
include_blank: t("decidim.themes.none") %>
</div>
</div>

<div class="card-divider">
Expand Down
1 change: 0 additions & 1 deletion decidim-process-extended/spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
require "decidim/core/test/factories"
require "decidim/participatory_processes/test/factories"
require "decidim/proposals/test/factories"
require "decidim/type/test/factories"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

describe "Admin manages participatory processes", type: :system do
let(:organization) { create(:organization) }
let!(:type) { create(:type, organization: organization) }
let!(:user) { create :user, :admin, :confirmed, organization: organization }

let!(:participatory_process_group) { nil }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ module Regulations
# public layout.
class RegulationController < Decidim::ParticipatoryProcesses::ApplicationController
include ParticipatorySpaceContext
participatory_space_layout only: [:show, :all_metrics]
include FilterResource

participatory_space_layout only: [:show, :all_metrics]

helper_method :collection,
:promoted_collection,
:participatory_processes,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Decidim::DecidimFormHelperDecorator
def self.decorate
Decidim::DecidimFormHelper.class_eval do
def types_for_select
Decidim::ParticipatoryProcessType.all
end
end
end
end

::Decidim::DecidimFormHelperDecorator.decorate
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Decidim::FilterFormBuilderDecorator
def self.decorate
Decidim::FilterFormBuilder.class_eval do
def types_select(method, collection, options = {})
fieldset_wrapper(options[:legend_title], "#{method}_types_select_filter") do
super(method, collection, options)
end
end
end
end
end

::Decidim::FilterFormBuilderDecorator.decorate
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Decidim::FormBuilderDecorate
def self.decorate
Decidim::FormBuilder.class_eval do
def types_select(name, collection, options = {})
selectables = if collection.first.is_a?(Decidim::ParticipatoryProcessType)
collection_transformed = collection
.map { |a| [a.title[I18n.locale.to_s], a.id] }
.sort_by { |arr| arr[0] }

@template.options_for_select(
collection_transformed,
selected: options[:selected]
)
else
@template.option_groups_from_collection_for_select(
collection,
:types,
:translated_name,
:id,
:translated_name,
selected: options[:selected]
)
end

select(name, selectables, options)
end
end
end
end

::Decidim::FormBuilderDecorate.decorate
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
<div class="columns mediumlarge-6 large-5">
<%= form.types_select :with_type,
types_for_select(current_organization),
types_for_select,
legend_title: t(".types"),
label: "",
selected: filter.with_type,
Expand Down

0 comments on commit ff0c4b5

Please sign in to comment.