Skip to content

Commit

Permalink
Change column names for location_option / Finish select location func…
Browse files Browse the repository at this point in the history
…tionality
  • Loading branch information
JoonasAapro committed Mar 20, 2024
1 parent 65c1495 commit 4e46f11
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def update_questionnaire_question(form_question)

form_question.location_options.each do |form_location_option|
location_option_attributes = {
location: form_location_option.location,
geojson: form_location_option.geojson
title: form_location_option.title,
body: form_location_option.body
}

update_nested_model(form_location_option, location_option_attributes, question.location_options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ def answer_questionnaire
session_token: form.context.session_token,
ip_hash: form.context.ip_hash
)
raise answer.inspect

form_answer.selected_choices.each do |choice|
answer.choices.build(
title: choice.title,
body: choice.body,
custom_body: choice.custom_body,
geojson: choice.geojson,
decidim_answer_option_id: choice.answer_option_id,
decidim_location_option_id: choice.location_option_id,
decidim_question_matrix_row_id: choice.matrix_row_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ module AnswerChoiceFormExtensions
end
end

attribute :geojson, JSON
attribute :title, String
attribute :location_option_id, Integer

validates :location_option_id, presence: true, if: :location_option?
validates :answer_option_id, presence: true, if: :answer_option?

def location_option?
geojson.present?
title.present?
end

def answer_option?
body.present?
title.nil?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ module AnswerFormExtensions

delegate :mandatory_body?, :mandatory_choices?, :mandatory_location?, :matrix?, to: :question

def selected_choices
choices.select { |choice| choice.body || choice.geojson }
end

private

def mandatory_location?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module Admin
# This class holds a Form to update answer options
class LocationOptionForm < Decidim::Form
attribute :deleted, Boolean, default: false
attribute :location, String
attribute :geojson, JSON
attribute :title, String
attribute :body, JSON

validates :location, presence: true, unless: :deleted
validates :geojson, presence: true, unless: :deleted
validates :title, presence: true, unless: :deleted
validates :body, presence: true, unless: :deleted

def to_param
return id if id.present?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ module AnswerChoiceExtensions
extend ActiveSupport::Concern

included do
attribute :geojson, :jsonb
attribute :decidim_location_option_id, :integer

belongs_to :location_option,
class_name: "LocationOption",
foreign_key: "decidim_location_option_id"
foreign_key: "decidim_location_option_id",
optional: true

belongs_to :answer_option,
class_name: "AnswerOption",
foreign_key: "decidim_answer_option_id",
optional: true
end
end
end
Expand Down
64 changes: 0 additions & 64 deletions decidim-module-forms_locations/app/models/decidim/forms/answer.rb

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Forms
#
class LocationOptionPresenter < SimpleDelegator
def as_json(*_args)
{ id: id, location: location, geojson: geojson }
{ id: id, title: title, body: body }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
<div class="row column">
<%=
form.text_field(
:location,
:title,
tabs_id: tabs_id_for_question_location_option(question, location_option),
label: t(".location_label"),
label: t(".statement"),
disabled: !editable
)
%>

<%=
form.text_area(
:geojson,
:body,
tabs_id: tabs_id_for_question_location_option(question, location_option),
label: t(".location_geojson"),
label: t(".geojson"),
disabled: !editable
)
%>
<p class="help-text"><%= t(".location_geojson_help") %></p>
<p class="help-text"><%= t(".geojson_help") %></p>
<% if editable %>
<%= form.button t("decidim.forms.admin.questionnaires.location_option.define"), class: "button small button--title location-option-define" %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

<div class="collection-input">
<%= label_tag do %>
<%= check_box_tag "questionnaire[responses][#{answer_idx}][choices][#{idx}][geojson]",
location_option.geojson,
<%= check_box_tag "questionnaire[responses][#{answer_idx}][choices][#{idx}][body]",
location_option.body,
choice.present?, disabled: disabled,
style: "display: none;" %>

<%= hidden_field_tag "questionnaire[responses][#{answer_idx}][choices][#{idx}][title]",
location_option.title %>
<%= hidden_field_tag "questionnaire[responses][#{answer_idx}][choices][#{idx}][location_option_id]",
location_option.id, disabled: true %>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions decidim-module-forms_locations/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ en:
location_option:
location_option: Location option
remove: Remove
location_geojson: Location GeoJSON
location_geojson_help: Insert GeoJSON to add option.
statement: Statement
geojson: Geojson
geojson_help: Insert GeoJSON to add option.
define: Define
location_label: Location
activemodel:
attributes:
questionnaire_question:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class CreateDecidimFormsLocationOptions < ActiveRecord::Migration[5.2]
def change
create_table :decidim_forms_location_options do |t|
t.references :decidim_question, index: { name: "index_decidim_forms_location_options_question_id" }
t.string :location
t.jsonb :geojson
t.string :title
t.jsonb :body
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddDecidimLocationOptionToAnswerChoices < ActiveRecord::Migration[5.2]
def change
add_reference :decidim_forms_answer_choices, :decidim_location_option,
index: { name: "index_decidim_forms_answer_choices_location_option_id" },
foreign_key: { to_table: :decidim_forms_location_options }
add_column :decidim_forms_answer_choices, :title, :string
end
end

0 comments on commit 4e46f11

Please sign in to comment.