From 77d0a551cff440cfc4339a2b02571b9ce8d5d105 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 28 Sep 2017 17:46:30 +0200 Subject: [PATCH 1/4] Migration for adding summary and description to polls created. Both text_areas were added to polls form. Imageable class included in polls model and the first aproach for adding images added to form. --- .../admin/poll/polls_controller.rb | 4 +- app/models/poll.rb | 2 + app/views/admin/poll/polls/_form.html.erb | 37 +++++++++++++++++++ config/locales/en/images.yml | 2 + config/locales/es/images.yml | 1 + ...02_add_summary_and_description_to_polls.rb | 6 +++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170928132402_add_summary_and_description_to_polls.rb diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index c95c8ed1f..db4fb567c 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -73,7 +73,9 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params - params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, geozone_ids: []) + params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description, + geozone_ids: [], + image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def search_params diff --git a/app/models/poll.rb b/app/models/poll.rb index 3873ac5e0..e852e912a 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,4 +1,6 @@ class Poll < ActiveRecord::Base + include Imageable + has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments has_many :partial_results, through: :booth_assignments diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 0b99ea9f5..3fa7daa4f 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -19,6 +19,43 @@ +
+
+ <%=f.text_area :summary, rows: 4%> +
+
+ +
+
+ <%=f.text_area :description, rows: 8%> +
+
+ +
+
+ <%= f.label :image, t("images.form.admin_title") %> + +
+ <%= f.fields_for :image do |image_builder| %> + <%= render 'images/image_fields', f: image_builder, imageable: @poll %> + <% end %> +
+
+ + <%= link_to_add_association t('images.form.add_new_image'), f, :image, + force_non_association_create: true, + partial: "images/image_fields", + id: "new_image_link", + class: "button hollow #{"hide" if @poll.image.present?}", + render_options: { + locals: { imageable: @poll } + }, + data: { + association_insertion_node: "#nested-image", + association_insertion_method: "append" + } %> +
+
<%= f.check_box :geozone_restricted, data: { checkbox_toggle: "#geozones" } %> diff --git a/config/locales/en/images.yml b/config/locales/en/images.yml index 6f16061fa..087c85021 100644 --- a/config/locales/en/images.yml +++ b/config/locales/en/images.yml @@ -9,6 +9,8 @@ en: delete_button: Remove image note: "You can upload one image of following content types: %{accepted_content_types}, up to %{max_file_size} MB." add_new_image: Add image + title_placeholder: Add a descriptive title for the image + admin_title: "Main image of the poll" actions: destroy: diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml index 869a0824e..0207bceed 100644 --- a/config/locales/es/images.yml +++ b/config/locales/es/images.yml @@ -9,6 +9,7 @@ es: note: "Puedes subir una imagen en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo." add_new_image: Añadir imagen title_placeholder: Añade un título descriptivo para la imagen + admin_title: "Imagen principal de la votación" actions: destroy: diff --git a/db/migrate/20170928132402_add_summary_and_description_to_polls.rb b/db/migrate/20170928132402_add_summary_and_description_to_polls.rb new file mode 100644 index 000000000..6fb965346 --- /dev/null +++ b/db/migrate/20170928132402_add_summary_and_description_to_polls.rb @@ -0,0 +1,6 @@ +class AddSummaryAndDescriptionToPolls < ActiveRecord::Migration + def change + add_column :polls, :summary, :text + add_column :polls, :description, :text + end +end From c67620fdef6919e1dbb1c33df490d28cdec6f50e Mon Sep 17 00:00:00 2001 From: iagirre Date: Fri, 29 Sep 2017 14:51:49 +0200 Subject: [PATCH 2/4] Table for links added (links to add images/documents). Custom partial for admins upload image created, so that it can be reused in upload images and documents. --- app/assets/stylesheets/participation.scss | 3 +- app/models/concerns/imageable.rb | 1 + app/models/poll.rb | 3 +- app/views/admin/poll/polls/_form.html.erb | 43 ++++++++-------- app/views/images/_admin_image.html.erb | 60 +++++++++++++++++++++++ config/locales/en/activerecord.yml | 2 + config/locales/es/activerecord.yml | 2 + config/locales/es/admin.yml | 6 +++ 8 files changed, 96 insertions(+), 24 deletions(-) create mode 100644 app/views/images/_admin_image.html.erb diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index fbcda0ebb..ab3369387 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -313,7 +313,8 @@ .proposal-form, .proposal-edit, .new_poll_question, -.edit_poll_question { +.edit_poll_question, +.edit_poll { @include direct-uploads; } diff --git a/app/models/concerns/imageable.rb b/app/models/concerns/imageable.rb index a2a2f537d..fea94d102 100644 --- a/app/models/concerns/imageable.rb +++ b/app/models/concerns/imageable.rb @@ -5,6 +5,7 @@ module Imageable included do has_one :image, as: :imageable, dependent: :destroy + has_many :images, as: :imageable, dependent: :destroy accepts_nested_attributes_for :image, allow_destroy: true, update_only: true def image_url(style) diff --git a/app/models/poll.rb b/app/models/poll.rb index e852e912a..9aa41cd16 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,5 +1,6 @@ class Poll < ActiveRecord::Base - include Imageable + include Imageable + include Documentable has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 3fa7daa4f..235522c65 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -31,29 +31,28 @@
-
-
- <%= f.label :image, t("images.form.admin_title") %> +
+ <%= render 'images/admin_image', imageable: @poll, f: f %> +
-
- <%= f.fields_for :image do |image_builder| %> - <%= render 'images/image_fields', f: image_builder, imageable: @poll %> - <% end %> -
-
- - <%= link_to_add_association t('images.form.add_new_image'), f, :image, - force_non_association_create: true, - partial: "images/image_fields", - id: "new_image_link", - class: "button hollow #{"hide" if @poll.image.present?}", - render_options: { - locals: { imageable: @poll } - }, - data: { - association_insertion_node: "#nested-image", - association_insertion_method: "append" - } %> +
+ + + + + + + + + + + + + + + + +
<%= t("admin.polls.attachments.title") %>
<%= t("admin.polls.attachments.images_title") %><%= t("admin.polls.attachments.documents_title") %>
<%= link_to "#{t("admin.polls.attachments.images_link")} (#{@poll.images.count})", root_path %><%= link_to "#{t("admin.polls.attachments.documents_link")} (#{@poll.documents.count})", root_path %>
diff --git a/app/views/images/_admin_image.html.erb b/app/views/images/_admin_image.html.erb new file mode 100644 index 000000000..7c5157216 --- /dev/null +++ b/app/views/images/_admin_image.html.erb @@ -0,0 +1,60 @@ +
+
+ <%= f.label :image, t("images.form.admin_title") %> + +
+ <%= f.fields_for :image do |image_builder| %> + <%#= render 'images/image_fields', f: image_builder, imageable: imageable %> + + + +
+ <%= image_builder.hidden_field :id %> + <%= image_builder.hidden_field :user_id, value: current_user.id %> + <%= image_builder.hidden_field :cached_attachment %> + + <%= image_builder.text_field :title, placeholder: t("images.form.title_placeholder") %> + + + <%= render_image(image_builder.object, :thumb, false) if image_builder.object.attachment.exists? %> + +
+
+ <%= render_image_attachment(image_builder, imageable, image_builder.object) %> +
+
+ <%= render_destroy_image_link(image_builder, image_builder.object) %> +
+
+ +
+

+ <%= image_attachment_file_name(image_builder.object) %> +

+
+ +
+
+
+ +
+ + + + <% end %> +
+
+ + <%= link_to_add_association t('images.form.add_new_image'), f, :image, + force_non_association_create: true, + partial: "images/image_fields", + id: "new_image_link", + class: "button hollow #{"hide" if imageable.image.present?}", + render_options: { + locals: { imageable: imageable } + }, + data: { + association_insertion_node: "#nested-image", + association_insertion_method: "append" + } %> +
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 1e3f62b1a..8bb2c3286 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -152,6 +152,8 @@ en: starts_at: "Start Date" ends_at: "Closing Date" geozone_restricted: "Restricted by geozone" + summary: "Summary" + description: "Description" poll/question: title: "Question" valid_answers: "Posibles answers" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 108f19fcf..415e81bed 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -146,6 +146,8 @@ es: starts_at: "Fecha de apertura" ends_at: "Fecha de cierre" geozone_restricted: "Restringida por zonas" + summary: "Resumen" + description: "Descripción" poll/question: title: "Pregunta" valid_answers: "Posibles respuestas" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 816cadd57..afa963c20 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -580,6 +580,12 @@ es: error_on_question_added: "No se pudo asignar la pregunta" question_removed: "Pregunta eliminada de esta votación" error_on_question_removed: "No se pudo quitar la pregunta" + attachments: + title: "Imágenes y documentos de la votación" + images_title: "Imágenes" + documents_title: "Documents" + images_link: "Lista de imágenes" + documents_link: "Lista de documentos" questions: index: title: "Preguntas ciudadanas" From 166caa3b4c01ca65857ec408024bbd8a1ba69337 Mon Sep 17 00:00:00 2001 From: iagirre Date: Mon, 2 Oct 2017 12:59:26 +0200 Subject: [PATCH 3/4] Deleted code in views and concerns that lets polls have more images and documentes attached, like it was at first. Added missing text for english and new texts in english and spanish. Cambios para hacer commit: modificado: app/assets/stylesheets/participation.scss modificado: app/models/concerns/imageable.rb modificado: app/models/poll.rb modificado: app/views/admin/poll/polls/_form.html.erb modificado: app/views/images/_admin_image.html.erb modificado: config/locales/en/images.yml modificado: config/locales/es/admin.yml modificado: config/locales/es/images.yml modificado: spec/features/admin/poll/polls_spec.rb --- app/assets/stylesheets/participation.scss | 1 + app/models/concerns/imageable.rb | 1 - app/models/poll.rb | 3 +- app/views/admin/poll/polls/_form.html.erb | 20 ------ app/views/images/_admin_image.html.erb | 75 +++++++++-------------- config/locales/en/images.yml | 1 + config/locales/es/admin.yml | 6 -- config/locales/es/images.yml | 1 + spec/features/admin/poll/polls_spec.rb | 2 + 9 files changed, 36 insertions(+), 74 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index ab3369387..5b0bcaea7 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -314,6 +314,7 @@ .proposal-edit, .new_poll_question, .edit_poll_question, +.new_poll, .edit_poll { @include direct-uploads; } diff --git a/app/models/concerns/imageable.rb b/app/models/concerns/imageable.rb index fea94d102..a2a2f537d 100644 --- a/app/models/concerns/imageable.rb +++ b/app/models/concerns/imageable.rb @@ -5,7 +5,6 @@ module Imageable included do has_one :image, as: :imageable, dependent: :destroy - has_many :images, as: :imageable, dependent: :destroy accepts_nested_attributes_for :image, allow_destroy: true, update_only: true def image_url(style) diff --git a/app/models/poll.rb b/app/models/poll.rb index 9aa41cd16..9706edd6e 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,7 +1,6 @@ class Poll < ActiveRecord::Base include Imageable - include Documentable - + has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments has_many :partial_results, through: :booth_assignments diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 235522c65..aff19d9d7 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -35,26 +35,6 @@ <%= render 'images/admin_image', imageable: @poll, f: f %>
-
- - - - - - - - - - - - - - - - -
<%= t("admin.polls.attachments.title") %>
<%= t("admin.polls.attachments.images_title") %><%= t("admin.polls.attachments.documents_title") %>
<%= link_to "#{t("admin.polls.attachments.images_link")} (#{@poll.images.count})", root_path %><%= link_to "#{t("admin.polls.attachments.documents_link")} (#{@poll.documents.count})", root_path %>
-
-
<%= f.check_box :geozone_restricted, data: { checkbox_toggle: "#geozones" } %> diff --git a/app/views/images/_admin_image.html.erb b/app/views/images/_admin_image.html.erb index 7c5157216..a782b743b 100644 --- a/app/views/images/_admin_image.html.erb +++ b/app/views/images/_admin_image.html.erb @@ -1,55 +1,13 @@
<%= f.label :image, t("images.form.admin_title") %> + -
- <%= f.fields_for :image do |image_builder| %> - <%#= render 'images/image_fields', f: image_builder, imageable: imageable %> - - - -
- <%= image_builder.hidden_field :id %> - <%= image_builder.hidden_field :user_id, value: current_user.id %> - <%= image_builder.hidden_field :cached_attachment %> - - <%= image_builder.text_field :title, placeholder: t("images.form.title_placeholder") %> - - - <%= render_image(image_builder.object, :thumb, false) if image_builder.object.attachment.exists? %> - -
-
- <%= render_image_attachment(image_builder, imageable, image_builder.object) %> -
-
- <%= render_destroy_image_link(image_builder, image_builder.object) %> -
-
- -
-

- <%= image_attachment_file_name(image_builder.object) %> -

-
- -
-
-
- -
- - - - <% end %> -
-
- - <%= link_to_add_association t('images.form.add_new_image'), f, :image, + <%= link_to_add_association t('images.form.add_new_image'), f, :image, force_non_association_create: true, partial: "images/image_fields", id: "new_image_link", - class: "button hollow #{"hide" if imageable.image.present?}", + class: "button hollow", render_options: { locals: { imageable: imageable } }, @@ -57,4 +15,31 @@ association_insertion_node: "#nested-image", association_insertion_method: "append" } %> + +
+ <%= f.fields_for :image do |image_builder| %> + +
+ <%= image_builder.hidden_field :id %> + <%= image_builder.hidden_field :user_id, value: current_user.id %> + <%= image_builder.hidden_field :cached_attachment %> + + <%= image_builder.text_field :title, placeholder: t("images.form.title_placeholder"), label: "#{t("images.form.admin_alt_text")}" %> + + +
+
+ <%= render_image_attachment(image_builder, imageable, image_builder.object) %> +
+
+ +
+
+
+ +
+ + <% end %> +
+
diff --git a/config/locales/en/images.yml b/config/locales/en/images.yml index 087c85021..afd8b2308 100644 --- a/config/locales/en/images.yml +++ b/config/locales/en/images.yml @@ -11,6 +11,7 @@ en: add_new_image: Add image title_placeholder: Add a descriptive title for the image admin_title: "Main image of the poll" + admin_alt_text: "Alternative text for the image" actions: destroy: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index afa963c20..816cadd57 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -580,12 +580,6 @@ es: error_on_question_added: "No se pudo asignar la pregunta" question_removed: "Pregunta eliminada de esta votación" error_on_question_removed: "No se pudo quitar la pregunta" - attachments: - title: "Imágenes y documentos de la votación" - images_title: "Imágenes" - documents_title: "Documents" - images_link: "Lista de imágenes" - documents_link: "Lista de documentos" questions: index: title: "Preguntas ciudadanas" diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml index 0207bceed..e842f3f5c 100644 --- a/config/locales/es/images.yml +++ b/config/locales/es/images.yml @@ -10,6 +10,7 @@ es: add_new_image: Añadir imagen title_placeholder: Añade un título descriptivo para la imagen admin_title: "Imagen principal de la votación" + admin_alt_text: "Texto alternativo para la imagen" actions: destroy: diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 6eb64f6e1..c282bee5d 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -58,6 +58,8 @@ feature 'Admin polls' do fill_in "poll_name", with: "Upcoming poll" fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y") fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") + fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..." + fill_in 'poll_description', with: "Upcomming poll's description. This poll..." click_button "Create poll" expect(page).to have_content "Poll created successfully" From ca42bc984534378b1616eb3015a3eaa2f7d0e616 Mon Sep 17 00:00:00 2001 From: iagirre Date: Mon, 2 Oct 2017 13:28:44 +0200 Subject: [PATCH 4/4] Added schema.rb with new columns for polls summary and description --- db/schema.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 500f03540..a3bc6065c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170927110953) do +ActiveRecord::Schema.define(version: 20170928132402) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -763,6 +763,8 @@ ActiveRecord::Schema.define(version: 20170927110953) do t.datetime "ends_at" t.boolean "published", default: false t.boolean "geozone_restricted", default: false + t.text "summary" + t.text "description" end add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree