From 01a8c559367405e2d5646a051ed82795dacc4278 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 14 Dec 2017 10:53:01 +0100 Subject: [PATCH 1/2] 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 53ae633e2a1..ed26fbaf68a 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 2cea5f47190..7736732a31c 100644 --- a/app/controllers/admin/budget_investment_milestones_controller.rb +++ b/app/controllers/admin/budget_investment_milestones_controller.rb @@ -41,7 +41,8 @@ def destroy 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 b31b8640e90..a70bd31d5b9 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 8ed5b8cca03..40586986ed1 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 4002d946877..98a774ca521 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 0d0c3898485..f175475bfdf 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 13ef24aa52c..b53deffd70b 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 f2090ed1c9a..d7f55a83ca6 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: From ff50dc1a0098d91938e847bf10a4d91d4c8d5d46 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 14 Dec 2017 13:53:03 +0100 Subject: [PATCH 2/2] Add feature specs to test new admin features and documents' show in users view --- .../admin/budget_investment_milestones_spec.rb | 10 +++++++++- spec/features/budgets/investments_spec.rb | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/features/admin/budget_investment_milestones_spec.rb b/spec/features/admin/budget_investment_milestones_spec.rb index 7f9e3ff630a..7ea460c9603 100644 --- a/spec/features/admin/budget_investment_milestones_spec.rb +++ b/spec/features/admin/budget_investment_milestones_spec.rb @@ -12,12 +12,16 @@ context "Index" do scenario 'Displaying milestones' do milestone = create(:budget_investment_milestone, investment: @investment) + create(:image, imageable: milestone) + document = create(:document, documentable: milestone) visit admin_budget_budget_investment_path(@investment.budget, @investment) expect(page).to have_content("Milestone") expect(page).to have_content(milestone.title) expect(page).to have_content(milestone.id) + expect(page).to have_link 'Show image' + expect(page).to have_link document.title end scenario 'Displaying no_milestones text' do @@ -60,11 +64,13 @@ end context "Edit" do - scenario "Change title and description" do + scenario "Change title, description and document names" do milestone = create(:budget_investment_milestone, investment: @investment) create(:image, imageable: milestone) + document = create(:document, documentable: milestone) visit admin_budget_budget_investment_path(@investment.budget, @investment) + expect(page).to have_link document.title click_link milestone.title @@ -72,12 +78,14 @@ fill_in 'budget_investment_milestone_title', with: 'Changed title' fill_in 'budget_investment_milestone_description', with: 'Changed description' + fill_in 'budget_investment_milestone_documents_attributes_0_title', with: 'New document title' click_button 'Update milestone' expect(page).to have_content 'Changed title' expect(page).to have_content 'Changed description' expect(page).to have_link 'Show image' + expect(page).to have_link 'New document title' end end diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 9cb1326b1d7..8fc21126743 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -496,6 +496,7 @@ def investments_order milestone = create(:budget_investment_milestone, investment: investment, title: "New text to show", created_at: DateTime.new(2015, 9, 19).utc) image = create(:image, imageable: milestone) + document = create(:document, documentable: milestone) login_as(user) visit budget_investment_path(budget_id: investment.budget.id, id: investment.id) @@ -507,6 +508,7 @@ def investments_order expect(page).to have_content(milestone.description) expect(page).to have_content("Published 2015-09-19") expect(page.find("#image_#{milestone.id}")['alt']).to have_content image.title + expect(page).to have_link document.title end end