Skip to content

Commit

Permalink
Remove images single uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Senen committed Sep 27, 2017
1 parent 45f3454 commit eef8ad1
Show file tree
Hide file tree
Showing 18 changed files with 16 additions and 510 deletions.
24 changes: 0 additions & 24 deletions app/assets/stylesheets/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,6 @@
margin-bottom: $line-height;
}

.document-form,
.image-form {

.title{
margin-bottom: $line-height;
}

.document,
.image-form {
.file-name {
margin-top: 0;
}
}

.document,
.image {
.loading-bar.errors {
margin-top: $line-height * 2;
}
}
}

.document,
.image {

Expand Down Expand Up @@ -107,12 +85,10 @@

&.complete {
background-color: $success-color;
width: 100%;
}

&.errors {
background-color: $alert-color;
width: 100%;
margin-top: $line-height / 2;
}
}
Expand Down
8 changes: 2 additions & 6 deletions app/assets/stylesheets/participation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@
.spending-proposal-form,
.document-form,
.topic-new,
.topic-form,
.image-form,
.proposal .image-form {
.topic-form {

.icon-debates,
.icon-proposals,
Expand Down Expand Up @@ -306,8 +304,7 @@
.proposal-form,
.topic-form,
.topic-new,
.document-form,
.image-form {
.document-form {

.recommendations li::before {
color: $proposals;
Expand All @@ -317,7 +314,6 @@
.budget-investment-new,
.proposal-form,
.proposal-edit,
.image-form,
.document-form,
.new_poll_question,
.edit_poll_question {
Expand Down
37 changes: 0 additions & 37 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
class ImagesController < ApplicationController
before_action :authenticate_user!
before_filter :find_imageable, except: :destroy
before_filter :prepare_new_image, only: [:new]
before_filter :prepare_image_for_creation, only: :create

load_and_authorize_resource

def new
end

def create
if @image.save
flash[:notice] = t "images.actions.create.notice"
redirect_to params[:from]
else
flash[:alert] = t "images.actions.create.alert"
render :new
end
end

def destroy
respond_to do |format|
format.html do
Expand All @@ -39,25 +23,4 @@ def destroy
end
end

private

def image_params
params.require(:image).permit(:title, :imageable_type, :imageable_id,
:attachment, :cached_attachment, :user_id)
end

def find_imageable
@imageable = params[:imageable_type].constantize.find_or_initialize_by(id: params[:imageable_id])
end

def prepare_new_image
@image = Image.new(imageable: @imageable)
end

def prepare_image_for_creation
@image = Image.new(image_params)
@image.imageable = @imageable
@image.user = current_user
end

end
4 changes: 0 additions & 4 deletions app/helpers/imageables_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module ImageablesHelper

def can_create_image?(imageable)
can?(:create, Image.new(imageable: imageable))
end

def can_destroy_image?(imageable)
imageable.image.present? && can?(:destroy, imageable.image)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/abilities/administrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def initialize(user)
cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation]

can [:create, :destroy], Document
can [:create, :destroy], Image
can [:destroy], Image
can [:create, :destroy], DirectUpload
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/abilities/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(user)

can [:create, :destroy, :new], Document, documentable: { author_id: user.id }

can [:create, :destroy, :new], Image, imageable: { author_id: user.id }
can [:destroy], Image, imageable: { author_id: user.id }

can [:create, :destroy], DirectUpload

Expand Down
6 changes: 0 additions & 6 deletions app/views/budgets/investments/_investment_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
class: 'button hollow float-right' %>
<% end %>
<% if can_create_image?(investment) %>
<%= link_to t("images.upload_image"),
new_image_path(imageable_id:investment, imageable_type: investment.class.name, from: request.url),
class: 'button hollow float-right' %>
<% end %>
<% if can_destroy_image?(investment) %>
<%= link_to t("images.remove_image"),
image_path(investment.image, from: request.url),
Expand Down
65 changes: 0 additions & 65 deletions app/views/images/_form.html.erb

This file was deleted.

3 changes: 2 additions & 1 deletion app/views/images/_image.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<figure>
<%= image_tag image.attachment.url(version),
class: image_class(image),
alt: image.title %>
alt: image.title,
title: image.title %>
<% if show_caption %>
<figcaption class="text-right">
<em><%= image.title %></em>
Expand Down
2 changes: 1 addition & 1 deletion app/views/images/_image_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= f.hidden_field :cached_attachment %>

<div class="small-12 column title">
<%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %>
<%= f.text_field :title, placeholder: t("images.form.title_placeholder") %>
</div>

<%= render_image(f.object, :thumb, false) if f.object.attachment.exists? %>
Expand Down
30 changes: 0 additions & 30 deletions app/views/images/new.html.erb

This file was deleted.

10 changes: 1 addition & 9 deletions app/views/proposals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

<aside class="small-12 medium-3 column">
<% if can_create_document?(@proposal) || author_of_proposal?(@proposal) || current_editable?(@proposal) ||
can_create_image?(@proposal) || can_destroy_image?(@proposal) %>
can_destroy_image?(@proposal) %>
<div class="sidebar-divider"></div>
<h2><%= t("proposals.show.author") %></h2>
<div class="show-actions-menu">
Expand All @@ -129,14 +129,6 @@
<% end %>
<% end %>
<% if can_create_image?(@proposal) %>
<%= link_to new_image_path(imageable_id: @proposal, imageable_type: @proposal.class.name, from: request.url),
class: 'button hollow expanded' do %>
<span class="icon-document"></span>
<%= t("images.upload_image") %>
<% end %>
<% end %>
<% if can_destroy_image?(@proposal) %>
<%= link_to image_path(@proposal.image, from: request.url),
method: :delete,
Expand Down
24 changes: 2 additions & 22 deletions config/locales/en/images.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
en:
images:
upload_image: Upload image
remove_image: Remove image

form:
title: Descriptive image
title_placeholder: Add a descriptive title for the image
attachment_label: Choose image
submit_button: Upload image
delete_button: Remove image
note: "You can upload one image of following content types: %{accepted_content_types}, up to %{max_file_size} MB."
add_new_image: Add image

new:
title: Upload image
budget_investment:
note: 'Add an image to your investment project: %{title}'
proposal:
note: 'Add an image to your proposal: %{title}'
form:
title_placeholder: Add a descriptive title for the image

recommendations_title: File upload tips
proposal:
recommendation_one_html: Proposals with image attract the attention of users more than those that do not have image. This image will be displayed in the list of proposals and on the proposal page.
budget_investment:
recommendation_one_html: Investment project with image attract the attention of users more than those that do not have image. This image will be displayed in the list of project investments and on the project investments page.
recommendation_two_html: "You can upload images in following formats: <strong>%{accepted_content_types}</strong>."
recommendation_three_html: You can upload one image up to <strong>1 MB</strong>.

actions:
create:
notice: Image was created successfully.
alert: Cannot create image. Check form errors and try again.
destroy:
notice: Image was deleted successfully.
alert: Cannot destroy image.
confirm: Are you sure you want to delete the image? This action cannot be undone!

errors:
messages:
in_between: must be in between %{min} and %{max}
Expand Down
24 changes: 2 additions & 22 deletions config/locales/es/images.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
es:
images:
upload_image: Subir imagen
remove_image: Eliminar imagen

form:
title: Imagen descriptiva
attachment_label: Selecciona una imagen
submit_button: Subir imagen
delete_button: Eliminar imagen
note: "Puedes subir una imagen en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo."
add_new_image: Añadir imagen

new:
title: Subir una imagen
budget_investment:
note: 'Añade una imagen la propuesta de inversión: %{title}.'
proposal:
note: 'Añade una imagen a la propuesta: %{title}.'
form:
title_placeholder: Añade un título descriptivo para la imagen

recommendations_title: Consejos para subir imágenes
proposal:
recommendation_one_html: Las propuestas con imagen llaman más la atención de los usuarios que las que no tienen imagen. Esta imagen se mostrará en el listado de propuestas y en la página de la propuesta.
budget_investment:
recommendation_one_html: Las proyectos de inversión con imagen llaman más la atención de los usuarios que las que no tienen imagen. Esta imagen se mostrará en el listado de proyectos de inversión y en la página del proyecto de inversión.
recommendation_two_html: "Sólo puedes subir <strong>imágenes en los formatos: %{accepted_content_types}</strong>."
recommendation_three_html: Puedes subir una imagen de hasta <strong>1 MB</strong>.
title_placeholder: Añade un título descriptivo para la imagen

actions:
create:
notice: "La imagen se ha creado correctamente."
alert: "La imagen no se ha podido crear. Revise los errores del formulario."
destroy:
notice: "La imagen se ha eliminado correctamente."
alert: "La imagen no se ha podido eliminar."
confirm: "¿Está seguro de que desea eliminar la imagen? Esta acción no se puede deshacer!"

errors:
messages:
in_between: debe estar entre %{min} y %{max}
Expand Down
Loading

0 comments on commit eef8ad1

Please sign in to comment.