From 01a8c559367405e2d5646a051ed82795dacc4278 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 14 Dec 2017 10:53:01 +0100 Subject: [PATCH] Make Budget::Investment::Milestone class Documentable. Add fields to the milestone form so that the admin can attach 0, 1 or multiple documents. Add column to milestone list with a link to documents (if there is any). Make documents accessible from the milestone view for users. --- app/assets/stylesheets/participation.scss | 3 ++- .../budget_investment_milestones_controller.rb | 3 ++- app/models/budget/investment/milestone.rb | 4 ++++ .../budget_investment_milestones/_form.html.erb | 5 +++++ .../admin/budget_investments/_milestones.html.erb | 11 +++++++++++ app/views/budgets/investments/_milestones.html.erb | 14 ++++++++++++++ config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + 8 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 53ae633e2..ed26fbaf6 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -334,7 +334,8 @@ .draft-panels, .debate-questions, .communities-show, -.topic-show { +.topic-show, +.milestone-content { p { word-wrap: break-word; diff --git a/app/controllers/admin/budget_investment_milestones_controller.rb b/app/controllers/admin/budget_investment_milestones_controller.rb index 2cea5f471..7736732a3 100644 --- a/app/controllers/admin/budget_investment_milestones_controller.rb +++ b/app/controllers/admin/budget_investment_milestones_controller.rb @@ -41,7 +41,8 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController def milestone_params params.require(:budget_investment_milestone) .permit(:title, :description, :budget_investment_id, - image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def load_budget_investment diff --git a/app/models/budget/investment/milestone.rb b/app/models/budget/investment/milestone.rb index b31b8640e..a70bd31d5 100644 --- a/app/models/budget/investment/milestone.rb +++ b/app/models/budget/investment/milestone.rb @@ -2,6 +2,10 @@ class Budget class Investment class Milestone < ActiveRecord::Base include Imageable + include Documentable + documentable max_documents_allowed: 3, + max_file_size: 3.megabytes, + accepted_content_types: [ "application/pdf" ] belongs_to :investment diff --git a/app/views/admin/budget_investment_milestones/_form.html.erb b/app/views/admin/budget_investment_milestones/_form.html.erb index 8ed5b8cca..40586986e 100644 --- a/app/views/admin/budget_investment_milestones/_form.html.erb +++ b/app/views/admin/budget_investment_milestones/_form.html.erb @@ -4,5 +4,10 @@ <%= f.text_area :description, rows: 5 %> <%= render 'images/admin_image', imageable: @milestone, f: f %> +
+
+ <%= render 'documents/nested_documents', documentable: @milestone, f: f %> +
+ <%= f.submit nil, class: "button success" %> <% end %> diff --git a/app/views/admin/budget_investments/_milestones.html.erb b/app/views/admin/budget_investments/_milestones.html.erb index 4002d9468..98a774ca5 100644 --- a/app/views/admin/budget_investments/_milestones.html.erb +++ b/app/views/admin/budget_investments/_milestones.html.erb @@ -6,6 +6,7 @@ <%= t("admin.milestones.index.table_title") %> <%= t("admin.milestones.index.table_description") %> <%= t("admin.milestones.index.image") %> + <%= t("admin.milestones.index.documents") %> <%= t("admin.milestones.index.table_actions") %> @@ -24,6 +25,16 @@ <%= link_to t("admin.milestones.index.show_image"), milestone.image_url(:large), target: :_blank if milestone.image.present? %> + + <% if milestone.documents.present? %> + <% milestone.documents.each do |document| %> + <%= link_to document.title, + document.attachment.url, + target: "_blank", + rel: "nofollow" %>
+ <% end %> + <% end %> + <%= link_to t("admin.milestones.index.delete"), admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone), method: :delete, diff --git a/app/views/budgets/investments/_milestones.html.erb b/app/views/budgets/investments/_milestones.html.erb index 0d0c38984..f175475bf 100644 --- a/app/views/budgets/investments/_milestones.html.erb +++ b/app/views/budgets/investments/_milestones.html.erb @@ -17,6 +17,20 @@ <%= image_tag(milestone.image_url(:large), {alt: milestone.image.title, class: "margin", id: "image_#{milestone.id}"}) if milestone.image.present? %>

<%= milestone.description %>

+ <% if milestone.documents.present? %> + + <% end %> <% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 13ef24aa5..b53deffd7 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -198,6 +198,7 @@ en: no_milestones: "Don't have defined milestones" image: "Image" show_image: "Show image" + documents: "Documents" new: creating: Create milestone edit: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index f2090ed1c..d7f55a83c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -198,6 +198,7 @@ es: no_milestones: "No hay hitos definidos" image: "Imagen" show_image: "Ver imagen" + documents: "Documentos" new: creating: Crear hito edit: