Merge pull request #5281 from consuldemocracy/pdf_links

Open PDF files in the same tab/window
This commit is contained in:
Javi Martín
2023-10-24 16:28:31 +02:00
committed by GitHub
64 changed files with 270 additions and 285 deletions

View File

@@ -9,9 +9,11 @@
App.Documentable.unlockUploads();
});
$("#nested-documents").on("cocoon:after-insert", function(e, nested_document) {
var input;
var input, document_fields;
input = $(nested_document).find(".js-document-attachment");
input.lockUpload = $(nested_document).closest("#nested-documents").find(".document:visible").length >= $("#nested-documents").data("max-documents-allowed");
document_fields = $(nested_document).closest("#nested-documents").find(".document-fields:visible");
input.lockUpload = document_fields.length >= $("#nested-documents").data("max-documents-allowed");
App.Documentable.initializeDirectUploadInput(input);
if (input.lockUpload) {
App.Documentable.lockUploads();

View File

@@ -9,7 +9,7 @@
$("#new_image_link").removeClass("hide");
});
$("#nested-image").on("cocoon:before-insert", function() {
$(".js-image-attachment").closest(".image").remove();
$(".js-image-attachment").closest(".image-fields").remove();
});
$("#nested-image").on("cocoon:after-insert", function(e, nested_image) {
var input;

View File

@@ -23,7 +23,7 @@
}
}
.images {
.images-nested {
@include direct-uploads;
}

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,21 @@
.document {
+ .document {
margin-top: $line-height / 3;
}
a:first-of-type {
word-wrap: break-word;
.document-metadata {
&::before,
&::after {
content: "";
display: block;
}
* + *::before {
@include vertical-separator;
}
}
}
}

View File

@@ -0,0 +1,33 @@
.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;
}
}
}

View File

@@ -2016,52 +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;
.icon-document {
color: #007bb7;
display: inline-block;
font-size: rem-calc(24);
line-height: $line-height;
vertical-align: middle;
}
p {
margin-bottom: 0;
}
}
}
.document-link a {
word-wrap: break-word;
}
.additional-document-link {
background: $highlight-soft;
border: 1px solid $highlight;
@@ -2074,12 +2028,8 @@ table {
word-wrap: break-word;
}
.icon-document {
color: #007bb7;
display: inline-block;
font-size: rem-calc(24);
line-height: $line-height;
vertical-align: middle;
> :first-child {
@include has-fa-icon(file, regular);
}
}

View File

@@ -0,0 +1,23 @@
@mixin separator {
content: "";
display: inline-block;
margin: 0 0.3em;
vertical-align: middle;
}
@mixin vertical-separator {
@include separator;
background: currentcolor;
height: 1em;
opacity: 0.5;
width: 1px;
}
@mixin circle-separator {
@include separator;
background: $text-light;
border-radius: 100%;
height: 0.25em;
opacity: 1;
width: 0.25em;
}

View File

@@ -10,8 +10,8 @@
margin-bottom: $line-height;
}
.document,
.image {
.document-fields,
.image-fields {
.document-attachment,
.image-attachment {

View File

@@ -8,29 +8,13 @@
@include link;
}
@mixin separator {
content: "";
display: inline-block;
margin: 0 0.3em;
vertical-align: middle;
}
> * + *::before {
@include separator;
background: currentcolor;
height: 1em;
opacity: 0.5;
width: 1px;
@include vertical-separator;
}
.comment & {
> *::before {
@include separator;
background: $text-light;
border-radius: 100%;
opacity: 1;
height: 0.25em;
width: 0.25em;
@include circle-separator;
}
}
}

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,21 @@
overflow: hidden;
}
}
.document-link {
> :first-child {
@include has-fa-icon(file, regular);
&::before {
position: relative;
top: -0.1rem;
}
}
a {
word-wrap: break-word;
}
}
}
.orbit-bullets button {

View File

@@ -56,8 +56,8 @@
<% end %>
<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render "images/nested_image", f: f %>
<div class="small-12 column">
<%= render Images::NestedComponent.new(f) %>
<p class="help-text"><%= t("admin.budget_phases.edit.image_description") %></p>
</div>
<% end %>

View File

@@ -54,8 +54,8 @@
<% end %>
<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render "/images/nested_image", f: f %>
<div class="small-12 column">
<%= render Images::NestedComponent.new(f) %>
<p class="help-text"><%= t("admin.budgets.edit.image_description") %></p>
</div>
<% end %>

View File

@@ -12,9 +12,7 @@
<%= form_for(Poll::Question::Answer.new, url: admin_answer_documents_path(answer)) do |f| %>
<%= render "shared/errors", resource: answer %>
<div class="documents">
<%= render "documents/nested_documents", f: f %>
</div>
<%= render Documents::NestedComponent.new(f) %>
<div class="small-12 medium-6 large-2">
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
@@ -36,7 +34,7 @@
<% documents.each do |document| %>
<tr>
<td>
<%= link_to document.title, document.attachment %>
<%= document.title %>
</td>
<td>
<%= render Admin::Poll::Questions::Answers::Documents::TableActionsComponent.new(document) %>

View File

@@ -3,6 +3,5 @@
<%= actions.action(:download,
text: t("documents.buttons.download_document"),
path: document.attachment,
target: "_blank",
rel: "nofollow") %>
<% end %>

View File

@@ -1,4 +1,4 @@
<div class="<%= singular_name %> direct-upload nested-fields">
<div class="<%= singular_name %>-fields direct-upload nested-fields">
<%= f.hidden_field :id %>
<%= f.hidden_field :user_id, value: current_user.id %>
<%= f.hidden_field :cached_attachment %>

View File

@@ -37,15 +37,11 @@
<legend><%= t("shared.optional") %></legend>
<% if feature?(:allow_images) %>
<div class="images">
<%= render "images/nested_image", f: f %>
</div>
<%= render Images::NestedComponent.new(f) %>
<% end %>
<% if feature?(:allow_attached_documents) %>
<div class="documents">
<%= render "documents/nested_documents", f: f %>
</div>
<%= render Documents::NestedComponent.new(f) %>
<% end %>
<% if feature?(:map) %>

View File

@@ -0,0 +1,17 @@
<div id="<%= dom_id(document) %>" class="document">
<%= link_to document.attachment, rel: "nofollow" do %>
<strong class="document-title"><%= document.title %></strong>
<small class="document-metadata">
<span class="document-content-type"><%= document.humanized_content_type %></span>
<span class="document-size"><%= number_to_human_size(document.attachment_file_size, precision: 2) %></span>
</small>
<% end %>
<% if show_destroy_link? && can?(:destroy, document) %>
<%= link_to t("documents.buttons.destroy_document"),
document,
method: :delete,
data: { confirm: t("documents.actions.destroy.confirm") },
class: "delete" %>
<% end %>
</div>

View File

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

View File

@@ -0,0 +1,11 @@
<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| %>
<li>
<%= render Documents::DocumentComponent.new(document, show_destroy_link: true) %>
</li>
<% 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

@@ -1,4 +1,4 @@
<fieldset class="documents-list">
<fieldset class="documents-list documents-nested">
<legend><%= t("documents.form.title") %></legend>
<p class="help-text"><%= note %></p>

View File

@@ -1,4 +1,4 @@
<fieldset>
<fieldset class="images-nested">
<legend><%= t("images.form.title") %></legend>
<p class="help-text"><%= note %></p>

View File

@@ -30,15 +30,11 @@
<% if answer.documents.present? %>
<div class="document-link">
<p>
<span class="icon-document"></span>&nbsp;
<strong><%= t("polls.show.documents") %></strong>
</p>
<% answer.documents.each do |document| %>
<%= link_to document.title,
document.attachment,
target: "_blank",
rel: "nofollow" %><br>
<%= render Documents::DocumentComponent.new(document) %>
<% end %>
</div>
<% end %>

View File

@@ -38,15 +38,11 @@
</div>
<% if feature?(:allow_images) %>
<div class="images">
<%= render "images/nested_image", f: f %>
</div>
<%= render Images::NestedComponent.new(f) %>
<% end %>
<% if feature?(:allow_attached_documents) %>
<div class="documents">
<%= render "documents/nested_documents", f: f %>
</div>
<%= render Documents::NestedComponent.new(f) %>
<% end %>
<% if Geozone.any? %>

View File

@@ -1,10 +0,0 @@
module DocumentsHelper
def document_item_link(document)
info_text = "#{document.humanized_content_type} | #{number_to_human_size(document.attachment_file_size)}"
link_to safe_join([document.title, tag.small("(#{info_text})")], " "),
document.attachment,
target: "_blank",
title: t("shared.target_blank")
end
end

View File

@@ -64,16 +64,13 @@
</div>
<% if feature?(:allow_attached_documents) %>
<div class="documents small-12 column">
<hr>
<%= render "documents/nested_documents", f: f %>
<hr>
<div class="small-12 column">
<%= render Documents::NestedComponent.new(f) %>
</div>
<% end %>
<div class="links small-12 column">
<%= render "links/nested_links", linkable: dashboard_action, f: f %>
<hr>
</div>
<div class="row expanded">

View File

@@ -109,20 +109,12 @@
</fieldset>
<div class="row">
<div class="documents small-12 column">
<%= render "documents/nested_documents", f: f %>
<div class="small-12 column">
<%= render Documents::NestedComponent.new(f) %>
</div>
<div class="small-12 column">
<hr>
</div>
<div class="images small-12 column">
<%= render "images/nested_image", f: f %>
</div>
<div class="small-12 column">
<hr>
<%= render Images::NestedComponent.new(f) %>
</div>
<div class="small-12 column">
@@ -154,10 +146,6 @@
</div>
</div>
</div>
<div class="small-12 column">
<hr>
</div>
</div>
<div class="row">

View File

@@ -27,11 +27,8 @@
<div class="column">
<%= f.date_field :publication_date %>
<%= render "images/nested_image", f: f %>
<div class="documents">
<%= render "documents/nested_documents", f: f %>
</div>
<%= render Images::NestedComponent.new(f) %>
<%= render Documents::NestedComponent.new(f) %>
<%= f.submit nil, class: "button success" %>
</div>

View File

@@ -48,7 +48,6 @@
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.attachment,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
<% end %>

View File

@@ -32,8 +32,8 @@
</div>
<div class="row">
<div class="images small-12 column">
<%= render "images/nested_image", f: f %>
<div class="small-12 column">
<%= render Images::NestedComponent.new(f) %>
</div>
<div class="clear">

View File

@@ -2,9 +2,7 @@
<%= form_for(@answer, url: admin_answer_images_path(@answer), method: :post) do |f| %>
<%= render "shared/errors", resource: @answer %>
<div class="images">
<%= render Images::NestedComponent.new(f, image_fields: :images) %>
</div>
<%= render Images::NestedComponent.new(f, image_fields: :images) %>
<%= f.submit t("admin.questions.answers.images.save_image"), class: "button success" %>
<% end %>

View File

@@ -13,25 +13,26 @@
<th scope="col"><%= t("admin.shared.title") %></th>
<th scope="col"><%= t("admin.documents.index.format") %></th>
<th scope="col"><%= t("admin.documents.index.size") %></th>
<th scope="col"><%= t("admin.documents.index.url") %></th>
<th scope="col"><%= t("admin.shared.actions") %></th>
</tr>
</thead>
<tbody id="documents">
<% @documents.each do |document| %>
<tr id="<%= dom_id(document) %>" class="document">
<tr id="<%= dom_id(document) %>" class="document-row">
<td><%= document.title %></td>
<td><%= document.attachment.content_type %></td>
<td><%= number_to_human_size(document.attachment.byte_size) %></td>
<td><%= link_to document.title, document.attachment, target: :blank %></td>
<td>
<div class="small-12 medium-6 column">
<%= render Admin::TableActionsComponent.new(
document,
actions: [:destroy],
destroy_path: admin_site_customization_document_path(document)
) %>
</div>
<%= render Admin::TableActionsComponent.new(
document,
actions: [:destroy],
destroy_path: admin_site_customization_document_path(document)
) do |actions| %>
<%= actions.action(:download,
text: t("documents.buttons.download_document"),
path: document.attachment,
rel: "nofollow") %>
<% end %>
</td>
</tr>
<% end %>

View File

@@ -45,7 +45,7 @@
<div class="row">
<div class="image-form">
<div class="image small-12 column">
<%= render "images/nested_image", f: f %>
<%= render Images::NestedComponent.new(f) %>
</div>
</div>
<div class="column">

View File

@@ -45,15 +45,13 @@
<% end %>
<% if feature?(:allow_attached_documents) %>
<%= render "documents/documents",
documents: investment.documents,
max_documents_allowed: Budget::Investment.max_documents_allowed %>
<%= 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

@@ -1,8 +0,0 @@
<p>
<%= link_to document.attachment, target: "_blank" do %>
<%= document.title %>
(<%= document.humanized_content_type %>
&nbsp;|&nbsp;
<%= number_to_human_size(document.attachment_file_size, precision: 2) %>)
<% end %>
</p>

View File

@@ -49,7 +49,9 @@
<p><%= link_to link.label, link.url, target: "_blank" %></p>
<% end %>
<%= render partial: "document", collection: proposed_action.documents %>
<% proposed_action.documents.each do |document| %>
<%= render Documents::DocumentComponent.new(document) %>
<% end %>
</div>
</div>
</div>

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

@@ -7,6 +7,5 @@
<%= link_to t("dashboard.poster.options.download"),
proposal_dashboard_poster_index_path(proposal, format: :pdf),
target: "_blank",
class: "button expanded" %>
</div>

View File

@@ -1,3 +0,0 @@
<p><span class="icon-document"></span>&nbsp;
<%= document_item_link(document) %>
</p>

View File

@@ -6,7 +6,9 @@
<p>
<strong><%= t("documents.additional") %></strong>
</p>
<%= render partial: "documents/additional_document", collection: documents, as: :document %>
<% documents.each do |document| %>
<%= render Documents::DocumentComponent.new(document) %>
<% end %>
</div>
</div>
</div>

View File

@@ -1,23 +0,0 @@
<li id="<%= dom_id(document) %>">
<%= link_to t("documents.buttons.download_document"),
document.attachment,
target: "_blank",
rel: "nofollow",
class: "button hollow medium float-right" %>
<strong><%= document.title %></strong>
<br>
<small>
<%= document.humanized_content_type %>&nbsp;|&nbsp;
<%= number_to_human_size(document.attachment_file_size, precision: 2) %>
</small>
<% if can?(:destroy, document) %>
<br>
<%= link_to t("documents.buttons.destroy_document"),
document,
method: :delete,
data: { confirm: t("documents.actions.destroy.confirm") },
class: "delete" %>
<% end %>
</li>

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

@@ -1 +0,0 @@
<%= render Documents::NestedComponent.new(f) %>

View File

@@ -1 +0,0 @@
<%= render Images::NestedComponent.new(f) %>

View File

@@ -27,13 +27,13 @@
</div>
<% if feature?(:allow_images) %>
<div class="images small-12 column">
<%= render "images/nested_image", f: f %>
<div class="small-12 column">
<%= render Images::NestedComponent.new(f) %>
</div>
<% end %>
<div class="documents small-12 column" data-max-documents="<%= Legislation::Proposal.max_documents_allowed %>">
<%= render "documents/nested_documents", f: f %>
<div class="small-12 column">
<%= render Documents::NestedComponent.new(f) %>
</div>
<% if Geozone.any? %>

View File

@@ -87,9 +87,7 @@
<% end %>
<% if feature?(:allow_attached_documents) %>
<%= render "documents/documents",
documents: @proposal.documents,
max_documents_allowed: Proposal.max_documents_allowed %>
<%= render Documents::DocumentsComponent.new(@proposal.documents) %>
<% end %>
<%= render "shared/tags", taggable: @proposal %>

View File

@@ -36,15 +36,7 @@
</p>
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.attachment,
target: "_blank",
rel: "nofollow" %><br>
<small>
<%= document.humanized_content_type %>&nbsp;|&nbsp;
<%= number_to_human_size(document.attachment_file_size, precision: 2) %>
</small>
<br>
<%= render Documents::DocumentComponent.new(document) %>
<% end %>
</div>
</div>

View File

@@ -67,9 +67,7 @@
<% end %>
<% if feature?(:allow_attached_documents) %>
<%= render "documents/documents",
documents: @proposal.documents,
max_documents_allowed: Proposal.max_documents_allowed %>
<%= render Documents::DocumentsComponent.new(@proposal.documents) %>
<% end %>
<%= render "shared/tags", taggable: @proposal %>