Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom fields on legislation proposals #3354

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/controllers/admin/legislation/processes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ def update
end
end

def update_proposal_fields
if @process.update(process_params)
set_tag_list

link = legislation_process_path(@process).html_safe
redirect_to(admin_legislation_process_proposals_path(@process),
notice: t("admin.legislation.processes.update.notice", link: link))
else
flash.now[:error] = t("admin.legislation.processes.update.error")
render "admin/legislation/proposals/_form"
end
end

def destroy
@process.destroy
notice = t("admin.legislation.processes.destroy.notice")
Expand Down Expand Up @@ -71,6 +84,20 @@ def allowed_params
:custom_list,
:background_color,
:font_color,
:title_label,
:summary_label,
:description_enabled,
:description_label,
:video_url_enabled,
:video_url_label,
:image_enabled,
:image_label,
:documents_enabled,
:documents_label,
:geozone_enabled,
:geozone_label,
:tags_enabled,
:tags_label,
translation_params(::Legislation::Process),
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
image_attributes: image_attributes
Expand Down
39 changes: 39 additions & 0 deletions app/models/legislation/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class Legislation::Process < ApplicationRecord
validates :allegations_start_date, presence: true, if: :allegations_end_date?
validates :allegations_end_date, presence: true, if: :allegations_start_date?
validates :proposals_phase_end_date, presence: true, if: :proposals_phase_start_date?
validates :title_label, presence: true
validates :summary_label, presence: true
validates :description_label, presence:true, if: :description_enabled?
validates :video_url_label, presence: true, if: :video_url_enabled?
validates :image_label, presence: true, if: :image_enabled?
validates :documents_label, presence: true, if: :documents_enabled?
validates :geozone_label, presence: true, if: :geozone_enabled?
validates :tags_label, presence: true, if: :tags_enabled?
validate :valid_date_ranges
validates :background_color, format: { allow_blank: true, with: CSS_HEX_COLOR }
validates :font_color, format: { allow_blank: true, with: CSS_HEX_COLOR }
Expand Down Expand Up @@ -112,6 +120,37 @@ def status
end
end

def title_label
read_attribute(:title_label) || I18n.t("proposals.form.proposal_title")
end

def summary_label
read_attribute(:summary_label) || I18n.t("proposals.form.proposal_summary") end

def description_label
read_attribute(:description_label) || I18n.t("proposals.form.proposal_text")
end

def video_url_label
read_attribute(:video_url_label) || I18n.t("proposals.form.proposal_video_url")
end

def image_label
read_attribute(:image_label) || I18n.t("images.form.title")
end

def documents_label
read_attribute(:documents_label) || I18n.t("documents.form.title")
end

def geozone_label
read_attribute(:geozone_label) || I18n.t("proposals.form.geozone")
end

def tags_label
read_attribute(:tags_label) || I18n.t("legislation.proposals.form.tags_label")
end

private

def valid_date_ranges
Expand Down
70 changes: 69 additions & 1 deletion app/views/admin/legislation/proposals/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_for [:admin, @process], html: {data: {watch_changes: true}} do |f| %>
<%= form_for [:admin, @process], url: update_proposal_fields_admin_legislation_process_path(@process), html: {method: :patch, data: {watch_changes: true}} do |f| %>

<% if @process.errors.any? %>

Expand All @@ -25,6 +25,74 @@
aria: {describedby: "tag-list-help-text"} %>
</div>

<div class="small-12 medium-8 column">
<h4 class="inline-block"><%= t("proposals.form.form_title") %></h4>
</div>

<div class="small-12 medium-8 column">
<%= f.label :title_label, t("proposals.form.proposal_title") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :title_label, value: @process.title_label, label: false %>
</div>

<div class="small-12 medium-8 column">
<%= f.label :summary_label, t("proposals.form.proposal_summary") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :summary_label, value: @process.summary_label, label: false %>
</div>

<div class="small-12 medium-8 column">
<%= f.check_box :description_enabled, label: t("proposals.form.proposal_text") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :description_label, value: @process.description_label, label: false %>
</div>

<div class="small-12 medium-8 column">
<%= f.check_box :video_url_enabled, label: t("proposals.form.proposal_video_url") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :video_url_label, value: @process.video_url_label, label: false %>
</div>

<div class="small-12 medium-8 column">
<%= f.check_box :documents_enabled, label: t("documents.form.title") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :documents_label, value: @process.documents_label, label: false %>
</div>

<div class="small-12 medium-8 column">
<%= f.check_box :image_enabled, label: t("images.form.title") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :image_label, value: @process.image_label, label: false %>
</div>

<div class="small-12 medium-8 column">
<%= f.check_box :geozone_enabled, label: t("proposals.form.geozone") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :geozone_label, value: @process.geozone_label, label: false %>
</div>

<div class="small-12 medium-8 column">
<%= f.check_box :tags_enabled, label: t("legislation.proposals.form.tags_label") %>
</div>

<div class="small-12 column medium-8 column">
<%= f.text_field :tags_label, value: @process.tags_label, label: false %>
</div>

<div class="small-12 medium-3 column clear end">
<%= f.submit(class: "button expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %>
</div>
Expand Down
6 changes: 5 additions & 1 deletion app/views/documents/_nested_documents.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<div class="documents-list">
<%= f.label :documents, t("documents.form.title") %>
<% if local_assigns[:documents_label].present? %>
<%= f.label :documents, documents_label %>
<% else %>
<%= f.label :documents, t("documents.form.title") %>
<% end %>
<p class="help-text"><%= documentables_note(documentable) %></p>

<div id="nested-documents" data-max-documents-allowed="<%= documentable.class.max_documents_allowed%>">
Expand Down
6 changes: 5 additions & 1 deletion app/views/images/_nested_image.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<% image_fields ||= :image %>

<%= f.label image_fields, t("images.form.title") %>
<% if local_assigns[:image_label].present? %>
<%= f.label image_fields, image_label %>
<% else %>
<%= f.label image_fields, t("images.form.title") %>
<% end %>
<p class="help-text"><%= imageables_note(imageable) %></p>

<div id="nested-image">
Expand Down
86 changes: 48 additions & 38 deletions app/views/legislation/proposals/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,74 @@

<div class="row">
<div class="small-12 column">
<%= f.label :title, t("proposals.form.proposal_title") %>
<%= f.text_field :title, maxlength: Legislation::Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false %>
<%= f.label :title, @process.title_label %>
<%= f.text_field :title, maxlength: Legislation::Proposal.title_max_length, placeholder: @process.title_label, label: false %>
</div>

<%= f.invisible_captcha :subtitle %>

<div class="small-12 column">
<%= f.label :summary, t("proposals.form.proposal_summary") %>
<%= f.label :summary, @process.summary_label %>
<p class="help-text" id="summary-help-text"><%= t("proposals.form.proposal_summary_note") %></p>
<%= f.text_area :summary, rows: 4, maxlength: 200, label: false,
placeholder: t("proposals.form.proposal_summary"),
placeholder: @process.summary_label,
aria: {describedby: "summary-help-text"} %>
</div>

<div class="ckeditor small-12 column">
<%= f.label :description, t("proposals.form.proposal_text") %>
<%= f.cktext_area :description, maxlength: Legislation::Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
</div>
<% if @process.description_enabled %>
<div class="ckeditor small-12 column">
<%= f.label :description, @process.description_label %>
<%= f.cktext_area :description, placeholder: @process.description_label, maxlength: Legislation::Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
</div>
<% end %>

<div class="small-12 column">
<%= f.label :video_url, t("proposals.form.proposal_video_url") %>
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false,
aria: {describedby: "video-url-help-text"} %>
</div>
<% if @process.video_url_enabled %>
<div class="small-12 column">
<%= f.label :video_url, @process.video_url_label %>
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
<%= f.text_field :video_url, placeholder: @process.video_url_label, label: false,
aria: {describedby: "video-url-help-text"} %>
</div>
<% end %>

<% if feature?(:allow_images) %>
<% if feature?(:allow_images) && @process.image_enabled %>
<div class="images small-12 column">
<%= render "images/nested_image", imageable: @proposal, f: f %>
<%= render 'images/nested_image', imageable: @proposal, f: f, image_label: @process.image_label %>
</div>
<% end %>

<div class="documents small-12 column" data-max-documents="<%= Legislation::Proposal.max_documents_allowed %>">
<%= render "documents/nested_documents", documentable: @proposal, f: f %>
</div>
<% if @process.documents_enabled %>
<div class="documents small-12 column" data-max-documents="<%= Legislation::Proposal.max_documents_allowed %>">
<%= render 'documents/nested_documents', documentable: @proposal, f: f, documents_label: @process.documents_label %>
</div>
<% end %>

<div class="small-12 medium-6 column">
<%= f.label :geozone_id, t("proposals.form.geozone") %>
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
</div>
<% if @process.geozone_enabled %>
<div class="small-12 medium-6 column">
<%= f.label :geozone_id, @process.geozone_label %>
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
</div>
<% end %>

<div class="small-12 column">
<%= f.label :tag_list, t("legislation.proposals.form.tags_label") %>
<p class="help-text" id="tag-list-help-text"><%= t("proposals.form.tags_instructions") %></p>
<% if @process.tags_enabled %>
<div class="small-12 column">
<%= f.label :tag_list, @process.tags_label %>
<p class="help-text" id="tag-list-help-text"><%= t("proposals.form.tags_instructions") %></p>

<div id="category_tags" class="tags">
<% @process.tag_list_on(:customs).each do |tag| %>
<a class="js-add-tag-link"><%= tag %></a>
<% end %>
</div>
<div id="category_tags" class="tags">
<% @process.tag_list_on(:customs).each do |tag| %>
<a class="js-add-tag-link"><%= tag %></a>
<% end %>
</div>

<br>
<%= f.text_field :tag_list, value: @proposal.tag_list.to_s,
label: false,
placeholder: t("proposals.form.tags_placeholder"),
class: "js-tag-list",
aria: {describedby: "tag-list-help-text"} %>
</div>
<br>
<%= f.text_field :tag_list, value: @proposal.tag_list.to_s,
label: false,
placeholder: @process.tags_label,
class: 'js-tag-list',
aria: {describedby: "tag-list-help-text"} %>
</div>
<% end %>

<div class="small-12 column">
<% if @proposal.new_record? %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ en:
proposal_summary_note: "(maximum 200 characters)"
proposal_text: Proposal text
proposal_title: Proposal title
form_title: Form input fields
proposal_video_url: Link to external video
proposal_video_url_note: You may add a link to YouTube or Vimeo
tag_category_label: "Categories"
Expand Down
1 change: 1 addition & 0 deletions config/routes/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
resources :milestones
resources :progress_bars, except: :show
resource :homepage, only: [:edit, :update]
member { patch :update_proposal_fields }
end
end

Expand Down
10 changes: 9 additions & 1 deletion db/dev_seeds/legislation_processes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
draft_publication_enabled: true,
result_publication_enabled: true,
proposals_phase_enabled: true,
published: true)
published: true,
title_label: "Proposal title",
summary_label: "Proposal summary",
description_label: "Proposal text",
video_url_label: "Link to external video",
image_label: "Descriptive image",
documents_label: "Documents",
geozone_label: "Scope of operation",
tags_label: "Categories")
end

Legislation::Process.find_each do |process|
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20190201002839_add_options_to_legislation_process.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class AddOptionsToLegislationProcess < ActiveRecord::Migration
def change
add_column :legislation_processes, :title_label, :string
add_column :legislation_processes, :summary_label, :string
add_column :legislation_processes, :description_enabled, :boolean, default: true
add_column :legislation_processes, :description_label, :string
add_column :legislation_processes, :video_url_enabled, :boolean, default: true
add_column :legislation_processes, :video_url_label, :string
add_column :legislation_processes, :image_enabled, :boolean, default: true
add_column :legislation_processes, :image_label, :string
add_column :legislation_processes, :documents_enabled, :boolean, default: true
add_column :legislation_processes, :documents_label, :string
add_column :legislation_processes, :geozone_enabled, :boolean, default: true
add_column :legislation_processes, :geozone_label, :string
add_column :legislation_processes, :tags_enabled, :boolean, default: true
add_column :legislation_processes, :tags_label, :string
end
end
14 changes: 14 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,20 @@
t.boolean "homepage_enabled", default: false
t.text "background_color"
t.text "font_color"
t.string "title_label"
t.string "summary_label"
t.boolean "description_enabled", default: true
t.string "description_label"
t.boolean "video_url_enabled", default: true
t.string "video_url_label"
t.boolean "image_enabled", default: true
t.string "image_label"
t.boolean "documents_enabled", default: true
t.string "documents_label"
t.boolean "geozone_enabled", default: true
t.string "geozone_label"
t.boolean "tags_enabled", default: true
t.string "tags_label"
t.index ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree
t.index ["allegations_start_date"], name: "index_legislation_processes_on_allegations_start_date", using: :btree
t.index ["debate_end_date"], name: "index_legislation_processes_on_debate_end_date", using: :btree
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/legislations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
draft_publication_enabled true
result_publication_enabled true
published true
title_label "Proposal title"
summary_label "Proposal summary"
description_label "Proposal text"
video_url_label "Link to external video"
image_label "Descriptive image"
documents_label "Documents"
geozone_label "Scope of operation"
tags_label "Categories"

trait :past do
start_date { Date.current - 12.days }
Expand Down
Loading