From 97fb986626341af2629270845ac3bfe47df33adc Mon Sep 17 00:00:00 2001 From: Manuel Ortega Date: Wed, 18 Oct 2017 19:50:34 +0200 Subject: [PATCH] Added documentable feature to legislation processes --- app/assets/stylesheets/layout.scss | 26 +++++++++++++++++++ app/assets/stylesheets/participation.scss | 4 ++- .../admin/legislation/processes_controller.rb | 3 ++- app/helpers/documentables_helper.rb | 7 +++++ app/models/legislation/process.rb | 4 +++ .../legislation/processes/_form.html.erb | 7 +++++ .../documents/_additional_documents.html.erb | 22 ++++++++++++++++ .../legislation/processes/debate.html.erb | 2 ++ 8 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 app/views/documents/_additional_documents.html.erb diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 06fdfd396..fc5ac0c6a 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -2395,3 +2395,29 @@ table { } } } + +.additional-document-link { + background: $highlight-soft; + border: 1px solid $highlight; + display: block; + margin: $line-height / 2 0; + padding: $line-height / 2; + position: relative; + + a { + word-wrap: break-word; + } + + .icon-document { + color: #007bb7; + display: inline-block; + font-size: rem-calc(24); + line-height: $line-height; + vertical-align: middle; + } +} + +.document-divider { + background: #fafafa; + border-bottom: 1px solid #eee; +} diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index a887d83de..456b10506 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -311,7 +311,9 @@ .proposal-form, .proposal-edit, .polls-form, -.poll-question-form { +.poll-question-form, +.legislation-process-new, +.legislation-process-edit { @include direct-uploads; } diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 5d8d828cd..aef452322 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -52,7 +52,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :allegations_phase_enabled, :draft_publication_enabled, :result_publication_enabled, - :published + :published, + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] ) end end diff --git a/app/helpers/documentables_helper.rb b/app/helpers/documentables_helper.rb index 3fe56abd2..8e832535f 100644 --- a/app/helpers/documentables_helper.rb +++ b/app/helpers/documentables_helper.rb @@ -38,4 +38,11 @@ module DocumentablesHelper documentable.documents.count >= documentable.class.max_documents_allowed end + def documentable_humanized_content_type(documentable_class) + documentable_class.attachment_content_type.split("/").last.upcase + end + + def documentable_humanized_file_size(documentable_class) + number_to_human_size(documentable_class.attachment_file_size) + end end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index b6043df57..03c8e3095 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -1,6 +1,10 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + include Documentable + documentable max_documents_allowed: 3, + max_file_size: 3.megabytes, + accepted_content_types: [ "application/pdf" ] PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase draft_publication result_publication).freeze diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 205d97361..43de37aa2 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -152,6 +152,13 @@ +
+ <%= render 'documents/nested_documents', documentable: @process, f: f %> +
+
+
+
+
<%= f.label :title %> diff --git a/app/views/documents/_additional_documents.html.erb b/app/views/documents/_additional_documents.html.erb new file mode 100644 index 000000000..9fb999de4 --- /dev/null +++ b/app/views/documents/_additional_documents.html.erb @@ -0,0 +1,22 @@ +<% if documents.any? %> +
+
+
+ +
+
+
+<% end %> diff --git a/app/views/legislation/processes/debate.html.erb b/app/views/legislation/processes/debate.html.erb index a387989a7..a6042bd84 100644 --- a/app/views/legislation/processes/debate.html.erb +++ b/app/views/legislation/processes/debate.html.erb @@ -2,6 +2,8 @@ <%= render 'legislation/processes/header', process: @process, header: :full %> +<%= render 'documents/additional_documents', documents: @process.documents %> + <%= render 'key_dates', process: @process, phase: :debate %>