From a2e4b056eef24d9d32b4272acc4dc12ba9f97f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 13 Oct 2023 11:58:14 +0200 Subject: [PATCH] Move documents partials to components This way it'll be easier to change them. Note that there were two `.document-link` elements which aren't part of a `.documents` element. We're renaming the HTML class of the link in investments because it didn't contain links to download documents and are slightly duplicating the CSS in the poll answer documents in order to keep the `word-wrap` property. --- app/assets/stylesheets/application.scss | 1 + .../stylesheets/documents/documents.scss | 37 ++++++++++++++++++ app/assets/stylesheets/layout.scss | 38 ------------------- app/assets/stylesheets/participation.scss | 8 ++++ .../documents/document_component.html.erb} | 0 .../documents/document_component.rb | 8 ++++ .../documents/documents_component.html.erb | 9 +++++ .../documents/documents_component.rb | 11 ++++++ .../investments/_investment_detail.html.erb | 4 +- .../dashboard/actions/new_request.html.erb | 2 +- app/views/documents/_documents.html.erb | 9 ----- app/views/legislation/proposals/show.html.erb | 2 +- app/views/proposals/_info.html.erb | 2 +- 13 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 app/assets/stylesheets/documents/documents.scss rename app/{views/documents/_document.html.erb => components/documents/document_component.html.erb} (100%) create mode 100644 app/components/documents/document_component.rb create mode 100644 app/components/documents/documents_component.html.erb create mode 100644 app/components/documents/documents_component.rb delete mode 100644 app/views/documents/_documents.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 068a33797..0d44d672e 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -47,6 +47,7 @@ @import "admin/**/*"; @import "budgets/**/*"; @import "debates/**/*"; +@import "documents/**/*"; @import "layout/**/*"; @import "machine_learning/**/*"; @import "moderation/**/*"; diff --git a/app/assets/stylesheets/documents/documents.scss b/app/assets/stylesheets/documents/documents.scss new file mode 100644 index 000000000..d4cf19acb --- /dev/null +++ b/app/assets/stylesheets/documents/documents.scss @@ -0,0 +1,37 @@ +.documents { + + h2 { + font-size: rem-calc(24); + + span { + color: #4f4f4f; + font-weight: normal; + } + } + + ul li { + padding-top: $line-height / 2; + + &:not(:first-child) { + border-top: 1px solid $highlight; + } + } + + .document-link { + background: $highlight-soft; + border: 2px solid $highlight; + border-radius: rem-calc(5); + display: block; + margin: $line-height / 2 0; + padding: $line-height / 2; + position: relative; + + p { + margin-bottom: 0; + } + + a { + word-wrap: break-word; + } + } +} diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 2710af584..b8ac99ee4 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -2016,44 +2016,6 @@ table { // 20. Documents // ------------- -.documents { - - h2 { - font-size: rem-calc(24); - - span { - color: #4f4f4f; - font-weight: normal; - } - } - - ul li { - padding-top: $line-height / 2; - - &:not(:first-child) { - border-top: 1px solid $highlight; - } - } - - .document-link { - background: $highlight-soft; - border: 2px solid $highlight; - border-radius: rem-calc(5); - display: block; - margin: $line-height / 2 0; - padding: $line-height / 2; - position: relative; - - p { - margin-bottom: 0; - } - } -} - -.document-link a { - word-wrap: break-word; -} - .additional-document-link { background: $highlight-soft; border: 1px solid $highlight; diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 21a68e186..cca148e73 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -699,6 +699,10 @@ margin-top: rem-calc(10); } } + + .investment-external-link a { + word-wrap: break-word; + } } .budget-investment-show .supports { @@ -1437,6 +1441,10 @@ overflow: hidden; } } + + .document-link a { + word-wrap: break-word; + } } .orbit-bullets button { diff --git a/app/views/documents/_document.html.erb b/app/components/documents/document_component.html.erb similarity index 100% rename from app/views/documents/_document.html.erb rename to app/components/documents/document_component.html.erb diff --git a/app/components/documents/document_component.rb b/app/components/documents/document_component.rb new file mode 100644 index 000000000..ed418eda3 --- /dev/null +++ b/app/components/documents/document_component.rb @@ -0,0 +1,8 @@ +class Documents::DocumentComponent < ApplicationComponent + attr_reader :document + delegate :can?, to: :helpers + + def initialize(document) + @document = document + end +end diff --git a/app/components/documents/documents_component.html.erb b/app/components/documents/documents_component.html.erb new file mode 100644 index 000000000..d8912bd8c --- /dev/null +++ b/app/components/documents/documents_component.html.erb @@ -0,0 +1,9 @@ +
+

<%= t("documents.title") %> (<%= documents.count %>)

+ + +
diff --git a/app/components/documents/documents_component.rb b/app/components/documents/documents_component.rb new file mode 100644 index 000000000..5dfae9ecf --- /dev/null +++ b/app/components/documents/documents_component.rb @@ -0,0 +1,11 @@ +class Documents::DocumentsComponent < ApplicationComponent + attr_reader :documents + + def initialize(documents) + @documents = documents + end + + def render? + documents.any? + end +end diff --git a/app/views/budgets/investments/_investment_detail.html.erb b/app/views/budgets/investments/_investment_detail.html.erb index cab44899d..d8c8fff8f 100644 --- a/app/views/budgets/investments/_investment_detail.html.erb +++ b/app/views/budgets/investments/_investment_detail.html.erb @@ -45,13 +45,13 @@ <% end %> <% if feature?(:allow_attached_documents) %> - <%= render "documents/documents", documents: investment.documents %> + <%= render Documents::DocumentsComponent.new(investment.documents) %> <% end %> <%= render "shared/tags", taggable: investment %> <% if investment.external_url.present? %> -
- <%= render "documents/documents", documents: dashboard_action.documents %> + <%= render Documents::DocumentsComponent.new(dashboard_action.documents) %> <% if dashboard_action.links.any? %>
diff --git a/app/views/documents/_documents.html.erb b/app/views/documents/_documents.html.erb deleted file mode 100644 index a828ccc90..000000000 --- a/app/views/documents/_documents.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% if documents.any? %> -
-

<%= t("documents.title") %> (<%= documents.count %>)

- - -
-<% end %> diff --git a/app/views/legislation/proposals/show.html.erb b/app/views/legislation/proposals/show.html.erb index ec31d0f88..7f9123bd4 100644 --- a/app/views/legislation/proposals/show.html.erb +++ b/app/views/legislation/proposals/show.html.erb @@ -87,7 +87,7 @@ <% end %> <% if feature?(:allow_attached_documents) %> - <%= render "documents/documents", documents: @proposal.documents %> + <%= render Documents::DocumentsComponent.new(@proposal.documents) %> <% end %> <%= render "shared/tags", taggable: @proposal %> diff --git a/app/views/proposals/_info.html.erb b/app/views/proposals/_info.html.erb index 6bb723136..23def8f68 100644 --- a/app/views/proposals/_info.html.erb +++ b/app/views/proposals/_info.html.erb @@ -67,7 +67,7 @@ <% end %> <% if feature?(:allow_attached_documents) %> - <%= render "documents/documents", documents: @proposal.documents %> + <%= render Documents::DocumentsComponent.new(@proposal.documents) %> <% end %> <%= render "shared/tags", taggable: @proposal %>