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.
This commit is contained in:
Javi Martín
2023-10-13 11:58:14 +02:00
parent e0c5be10aa
commit a2e4b056ee
13 changed files with 79 additions and 52 deletions

View File

@@ -47,6 +47,7 @@
@import "admin/**/*";
@import "budgets/**/*";
@import "debates/**/*";
@import "documents/**/*";
@import "layout/**/*";
@import "machine_learning/**/*";
@import "moderation/**/*";

View File

@@ -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;
}
}
}

View File

@@ -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;

View File

@@ -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 {

View File

@@ -0,0 +1,8 @@
class Documents::DocumentComponent < ApplicationComponent
attr_reader :document
delegate :can?, to: :helpers
def initialize(document)
@document = document
end
end

View File

@@ -0,0 +1,9 @@
<div id="documents" class="documents">
<h2><%= t("documents.title") %>&nbsp;<span>(<%= documents.count %>)</span></h2>
<ul class="no-bullet document-link">
<% documents.each do |document| %>
<%= render Documents::DocumentComponent.new(document) %>
<% end %>
</ul>
</div>

View File

@@ -0,0 +1,11 @@
class Documents::DocumentsComponent < ApplicationComponent
attr_reader :documents
def initialize(documents)
@documents = documents
end
def render?
documents.any?
end
end

View File

@@ -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? %>
<div class="document-link">
<div class="investment-external-link">
<%= sanitize_and_auto_link investment.external_url %>
</div>
<% end %>

View File

@@ -7,7 +7,7 @@
</div>
<div class="small-12 medium-4 column">
<%= render "documents/documents", documents: dashboard_action.documents %>
<%= render Documents::DocumentsComponent.new(dashboard_action.documents) %>
<% if dashboard_action.links.any? %>
<div class="margin-top">

View File

@@ -1,9 +0,0 @@
<% if documents.any? %>
<div id="documents" class="documents">
<h2><%= t("documents.title") %>&nbsp;<span>(<%= documents.count %>)</span></h2>
<ul class="no-bullet document-link">
<%= render partial: "documents/document", collection: documents %>
</ul>
</div>
<% end %>

View File

@@ -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 %>

View File

@@ -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 %>