Merge pull request #5281 from consuldemocracy/pdf_links
Open PDF files in the same tab/window
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.images {
|
||||
.images-nested {
|
||||
@include direct-uploads;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
@import "admin/**/*";
|
||||
@import "budgets/**/*";
|
||||
@import "debates/**/*";
|
||||
@import "documents/**/*";
|
||||
@import "layout/**/*";
|
||||
@import "machine_learning/**/*";
|
||||
@import "moderation/**/*";
|
||||
|
||||
21
app/assets/stylesheets/documents/document.scss
Normal file
21
app/assets/stylesheets/documents/document.scss
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
app/assets/stylesheets/documents/documents.scss
Normal file
33
app/assets/stylesheets/documents/documents.scss
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
app/assets/stylesheets/mixins/separators.scss
Normal file
23
app/assets/stylesheets/mixins/separators.scss
Normal 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;
|
||||
}
|
||||
@@ -10,8 +10,8 @@
|
||||
margin-bottom: $line-height;
|
||||
}
|
||||
|
||||
.document,
|
||||
.image {
|
||||
.document-fields,
|
||||
.image-fields {
|
||||
|
||||
.document-attachment,
|
||||
.image-attachment {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
<%= actions.action(:download,
|
||||
text: t("documents.buttons.download_document"),
|
||||
path: document.attachment,
|
||||
target: "_blank",
|
||||
rel: "nofollow") %>
|
||||
<% end %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
17
app/components/documents/document_component.html.erb
Normal file
17
app/components/documents/document_component.html.erb
Normal 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>
|
||||
10
app/components/documents/document_component.rb
Normal file
10
app/components/documents/document_component.rb
Normal 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
|
||||
11
app/components/documents/documents_component.html.erb
Normal file
11
app/components/documents/documents_component.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<div id="documents" class="documents">
|
||||
<h2><%= t("documents.title") %> <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>
|
||||
11
app/components/documents/documents_component.rb
Normal file
11
app/components/documents/documents_component.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Documents::DocumentsComponent < ApplicationComponent
|
||||
attr_reader :documents
|
||||
|
||||
def initialize(documents)
|
||||
@documents = documents
|
||||
end
|
||||
|
||||
def render?
|
||||
documents.any?
|
||||
end
|
||||
end
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<fieldset>
|
||||
<fieldset class="images-nested">
|
||||
<legend><%= t("images.form.title") %></legend>
|
||||
<p class="help-text"><%= note %></p>
|
||||
|
||||
|
||||
@@ -30,15 +30,11 @@
|
||||
<% if answer.documents.present? %>
|
||||
<div class="document-link">
|
||||
<p>
|
||||
<span class="icon-document"></span>
|
||||
<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 %>
|
||||
|
||||
@@ -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? %>
|
||||
|
||||
@@ -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
|
||||
@@ -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">
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
<% milestone.documents.each do |document| %>
|
||||
<%= link_to document.title,
|
||||
document.attachment,
|
||||
target: "_blank",
|
||||
rel: "nofollow" %><br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<p>
|
||||
<%= link_to document.attachment, target: "_blank" do %>
|
||||
<%= document.title %>
|
||||
(<%= document.humanized_content_type %>
|
||||
|
|
||||
<%= number_to_human_size(document.attachment_file_size, precision: 2) %>)
|
||||
<% end %>
|
||||
</p>
|
||||
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<p><span class="icon-document"></span>
|
||||
<%= document_item_link(document) %>
|
||||
</p>
|
||||
@@ -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>
|
||||
|
||||
@@ -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 %> |
|
||||
<%= 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>
|
||||
@@ -1,9 +0,0 @@
|
||||
<% if documents.any? %>
|
||||
<div id="documents" class="documents">
|
||||
<h2><%= t("documents.title") %> <span>(<%= documents.count %>)</span></h2>
|
||||
|
||||
<ul class="no-bullet document-link">
|
||||
<%= render partial: "documents/document", collection: documents %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1 +0,0 @@
|
||||
<%= render Documents::NestedComponent.new(f) %>
|
||||
@@ -1 +0,0 @@
|
||||
<%= render Images::NestedComponent.new(f) %>
|
||||
@@ -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? %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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 %> |
|
||||
<%= number_to_human_size(document.attachment_file_size, precision: 2) %>
|
||||
</small>
|
||||
<br>
|
||||
<%= render Documents::DocumentComponent.new(document) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -539,7 +539,6 @@ en:
|
||||
title: "Documents"
|
||||
format: "Format"
|
||||
size: "Size"
|
||||
url: "URL"
|
||||
create:
|
||||
success_notice: "Document uploaded successfully"
|
||||
unable_notice: "Invalid document"
|
||||
|
||||
@@ -539,7 +539,6 @@ es:
|
||||
title: "Documentos"
|
||||
format: "Formato"
|
||||
size: "Tamaño"
|
||||
url: "URL"
|
||||
create:
|
||||
success_notice: "Documento creado correctamente"
|
||||
unable_notice: "Documento inválido"
|
||||
|
||||
17
db/migrate/20231012141318_remove_paperclip_columns.rb
Normal file
17
db/migrate/20231012141318_remove_paperclip_columns.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class RemovePaperclipColumns < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
change_table :images do |t|
|
||||
t.remove :attachment_file_name, type: :string
|
||||
t.remove :attachment_content_type, type: :string
|
||||
t.remove :attachment_file_size, type: :bigint
|
||||
t.remove :attachment_updated_at, type: :datetime
|
||||
end
|
||||
|
||||
change_table :documents do |t|
|
||||
t.remove :attachment_file_name, type: :string
|
||||
t.remove :attachment_content_type, type: :string
|
||||
t.remove :attachment_file_size, type: :bigint
|
||||
t.remove :attachment_updated_at, type: :datetime
|
||||
end
|
||||
end
|
||||
end
|
||||
10
db/schema.rb
10
db/schema.rb
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2023_05_23_090028) do
|
||||
ActiveRecord::Schema.define(version: 2023_10_12_141318) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_trgm"
|
||||
@@ -585,10 +585,6 @@ ActiveRecord::Schema.define(version: 2023_05_23_090028) do
|
||||
|
||||
create_table "documents", id: :serial, force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.string "attachment_file_name"
|
||||
t.string "attachment_content_type"
|
||||
t.bigint "attachment_file_size"
|
||||
t.datetime "attachment_updated_at"
|
||||
t.integer "user_id"
|
||||
t.string "documentable_type"
|
||||
t.integer "documentable_id"
|
||||
@@ -684,10 +680,6 @@ ActiveRecord::Schema.define(version: 2023_05_23_090028) do
|
||||
t.string "title", limit: 80
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "attachment_file_name"
|
||||
t.string "attachment_content_type"
|
||||
t.bigint "attachment_file_size"
|
||||
t.datetime "attachment_updated_at"
|
||||
t.integer "user_id"
|
||||
t.index ["imageable_type", "imageable_id"], name: "index_images_on_imageable_type_and_imageable_id"
|
||||
t.index ["user_id"], name: "index_images_on_user_id"
|
||||
|
||||
@@ -52,6 +52,6 @@ describe Polls::Questions::ReadMoreComponent do
|
||||
|
||||
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
|
||||
|
||||
expect(page).to have_link("The yes movement")
|
||||
expect(page).to have_link text: "The yes movement"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,22 +11,14 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
|
||||
end
|
||||
|
||||
context "Show documents" do
|
||||
scenario "Download action should be able to anyone" do
|
||||
scenario "Download action should be availabe to anyone and open in the same tab" do
|
||||
visit send(documentable_path, arguments)
|
||||
|
||||
expect(page).to have_link("Download file")
|
||||
end
|
||||
|
||||
scenario "Download file link should have blank target attribute" do
|
||||
visit send(documentable_path, arguments)
|
||||
|
||||
expect(page).to have_selector("a[target=_blank]", text: "Download file")
|
||||
end
|
||||
|
||||
scenario "Download file links should have rel attribute setted to no follow" do
|
||||
visit send(documentable_path, arguments)
|
||||
|
||||
expect(page).to have_selector("a[rel=nofollow]", text: "Download file")
|
||||
within "#documents" do
|
||||
expect(page).to have_link text: document.title
|
||||
expect(page).to have_selector "a[rel=nofollow]", text: document.title
|
||||
expect(page).not_to have_selector "a[target=_blank]"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Destroy action" do
|
||||
|
||||
@@ -29,7 +29,7 @@ shared_examples "milestoneable" do |factory_name|
|
||||
expect(page).to have_content(Date.yesterday)
|
||||
expect(page).not_to have_content(Date.current)
|
||||
expect(page.find("#image_#{first_milestone.id}")["alt"]).to have_content(image.title)
|
||||
expect(page).to have_link(document.title)
|
||||
expect(page).to have_link text: document.title
|
||||
expect(page).to have_link("https://consul.dev")
|
||||
expect(page).to have_content(first_milestone.status.name)
|
||||
end
|
||||
|
||||
@@ -163,7 +163,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
click_link "Add new document"
|
||||
click_on submit_button
|
||||
|
||||
within "#nested-documents .document" do
|
||||
within "#nested-documents .document-fields" do
|
||||
expect(page).to have_content("can't be blank", count: 2)
|
||||
end
|
||||
end
|
||||
@@ -175,7 +175,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||
click_link "Remove document"
|
||||
|
||||
expect(page).not_to have_css("#nested-documents .document")
|
||||
expect(page).not_to have_css("#nested-documents .document-fields")
|
||||
end
|
||||
|
||||
scenario "Should show successful notice when
|
||||
@@ -248,7 +248,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
do_login_for user_to_login, management: management
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).to have_css ".document", count: 1
|
||||
expect(page).to have_css ".document-fields", count: 1
|
||||
end
|
||||
|
||||
scenario "Should not show add document button when
|
||||
@@ -264,7 +264,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
|
||||
do_login_for user_to_login, management: management
|
||||
visit send(path, arguments)
|
||||
last_document = all("#nested-documents .document").last
|
||||
last_document = all("#nested-documents .document-fields").last
|
||||
within last_document do
|
||||
click_on "Remove document"
|
||||
end
|
||||
@@ -278,7 +278,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
visit send(path, arguments)
|
||||
click_on "Remove document"
|
||||
|
||||
expect(page).not_to have_css ".document"
|
||||
expect(page).not_to have_css ".document-fields"
|
||||
end
|
||||
|
||||
scenario "Same attachment URL after editing the title" do
|
||||
@@ -291,14 +291,14 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
||||
|
||||
expect(page).to have_content documentable_success_notice
|
||||
|
||||
original_url = find_link("Download file")[:href]
|
||||
original_url = find_link(text: "Original")[:href]
|
||||
|
||||
visit send(path, arguments)
|
||||
within_fieldset("Documents") { fill_in "Title", with: "Updated" }
|
||||
click_button submit_button
|
||||
|
||||
expect(page).to have_content documentable_success_notice
|
||||
expect(find_link("Download file")[:href]).to eq original_url
|
||||
expect(find_link(text: "Updated")[:href]).to eq original_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
|
||||
visit send(path, arguments)
|
||||
|
||||
click_link "Add image"
|
||||
input_title = find(".image input[name$='[title]']")
|
||||
input_title = find(".image-fields input[name$='[title]']")
|
||||
fill_in input_title[:id], with: "Title"
|
||||
attach_file "Choose image", file_fixture("clippy.jpg")
|
||||
|
||||
@@ -119,7 +119,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
|
||||
click_link "Add image"
|
||||
click_on submit_button
|
||||
|
||||
within "#nested-image .image" do
|
||||
within "#nested-image .image-fields" do
|
||||
expect(page).to have_content("can't be blank", count: 2)
|
||||
end
|
||||
end
|
||||
@@ -143,11 +143,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
|
||||
|
||||
imageable_attach_new_file(file_fixture("clippy.jpg"))
|
||||
|
||||
within "#nested-image .image" do
|
||||
within "#nested-image .image-fields" do
|
||||
click_link "Remove image"
|
||||
end
|
||||
|
||||
expect(page).not_to have_selector("#nested-image .image")
|
||||
expect(page).not_to have_selector("#nested-image .image-fields")
|
||||
end
|
||||
|
||||
scenario "Should show successful notice when resource filled correctly without any nested images",
|
||||
@@ -216,7 +216,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
|
||||
|
||||
visit send(path, arguments)
|
||||
|
||||
expect(page).to have_css ".image", count: 1
|
||||
expect(page).to have_css ".image-fields", count: 1
|
||||
expect(page).not_to have_css "a#new_image_link"
|
||||
end
|
||||
|
||||
@@ -227,7 +227,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
|
||||
visit send(path, arguments)
|
||||
click_link "Remove image"
|
||||
|
||||
expect(page).not_to have_css ".image"
|
||||
expect(page).not_to have_css ".image-fields"
|
||||
expect(page).to have_link id: "new_image_link"
|
||||
end
|
||||
|
||||
@@ -239,7 +239,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
|
||||
click_link "Remove image"
|
||||
click_link "Add image"
|
||||
|
||||
expect(page).to have_css ".image", count: 1, visible: :all
|
||||
expect(page).to have_css ".image-fields", count: 1, visible: :all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ module Documents
|
||||
def documentable_attach_new_file(path, success = true)
|
||||
click_link "Add new document"
|
||||
|
||||
document = all(".document").last
|
||||
document = all(".document-fields").last
|
||||
attach_file "Choose document", path
|
||||
|
||||
within document do
|
||||
@@ -22,7 +22,7 @@ module Documents
|
||||
end
|
||||
|
||||
def expect_document_has_title(index, title)
|
||||
document = all(".document")[index]
|
||||
document = all(".document-fields")[index]
|
||||
|
||||
within document do
|
||||
expect(find("input[name$='[title]']").value).to eq title
|
||||
|
||||
@@ -11,7 +11,7 @@ module Images
|
||||
def imageable_attach_new_file(path, success = true)
|
||||
click_link "Add image"
|
||||
within "#nested-image" do
|
||||
image = find(".image")
|
||||
image = find(".image-fields")
|
||||
attach_file "Choose image", path
|
||||
within image do
|
||||
if success
|
||||
@@ -40,7 +40,7 @@ module Images
|
||||
end
|
||||
|
||||
def expect_image_has_title(title)
|
||||
image = find(".image")
|
||||
image = find(".image-fields")
|
||||
|
||||
within image do
|
||||
expect(find("input[name$='[title]']").value).to eq title
|
||||
|
||||
@@ -981,8 +981,7 @@ describe "Admin budget investments", :admin do
|
||||
expect(page).to have_content("Investment preview")
|
||||
expect(page).to have_content(budget_investment.image.title)
|
||||
expect(page).to have_content("Documents (1)")
|
||||
expect(page).to have_content(document.title)
|
||||
expect(page).to have_content("Download file")
|
||||
expect(page).to have_link text: document.title
|
||||
expect(page).to have_content("1234")
|
||||
expect(page).to have_content("1000")
|
||||
expect(page).to have_content("Unfeasible")
|
||||
|
||||
@@ -30,11 +30,16 @@ describe "Documents", :admin do
|
||||
|
||||
visit admin_answer_documents_path(answer)
|
||||
|
||||
expect(page).not_to have_link "Download file"
|
||||
|
||||
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/clippy.pdf"))
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_content "Document uploaded successfully"
|
||||
expect(page).to have_link "clippy.pdf"
|
||||
|
||||
within("tr", text: "clippy.pdf") do
|
||||
expect(page).to have_link "Download file"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "with invalid data" do
|
||||
|
||||
@@ -23,7 +23,7 @@ describe "Documents", :admin do
|
||||
visit admin_site_customization_documents_path
|
||||
|
||||
expect(page).to have_content "There are 3 documents"
|
||||
expect(page).to have_link document.title, href: url
|
||||
expect(page).to have_link "Download file", href: url
|
||||
end
|
||||
|
||||
scenario "Index (empty)" do
|
||||
@@ -39,7 +39,7 @@ describe "Documents", :admin do
|
||||
|
||||
visit admin_site_customization_documents_path
|
||||
|
||||
expect(page).to have_selector("#documents .document", count: per_page)
|
||||
expect(page).to have_selector("#documents .document-row", count: per_page)
|
||||
|
||||
within("ul.pagination") do
|
||||
expect(page).to have_content("1")
|
||||
@@ -48,7 +48,7 @@ describe "Documents", :admin do
|
||||
click_link "Next", exact: false
|
||||
end
|
||||
|
||||
expect(page).to have_selector("#documents .document", count: 2)
|
||||
expect(page).to have_selector("#documents .document-row", count: 2)
|
||||
end
|
||||
|
||||
scenario "Create" do
|
||||
@@ -58,7 +58,8 @@ describe "Documents", :admin do
|
||||
click_button "Upload"
|
||||
|
||||
expect(page).to have_content "Document uploaded successfully"
|
||||
expect(page).to have_link "logo.pdf"
|
||||
|
||||
within("tr", text: "logo.pdf") { expect(page).to have_link "Download file" }
|
||||
end
|
||||
|
||||
scenario "Errors on create" do
|
||||
|
||||
@@ -31,9 +31,9 @@ describe "Poster" do
|
||||
end
|
||||
|
||||
scenario "PDF contains the proposal details" do
|
||||
within_window(window_opened_by { click_link "Download" }) do
|
||||
expect(page).to have_content(proposal.title)
|
||||
expect(page).to have_content(proposal.code)
|
||||
end
|
||||
click_link "Download"
|
||||
|
||||
expect(page).to have_content(proposal.title)
|
||||
expect(page).to have_content(proposal.code)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user