From 6405bf5d1abfc5b63acab5df983abe0d9bc92fd1 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Sun, 6 Jul 2014 22:29:19 +0200 Subject: [PATCH] wire up downloading attachments from todo partial --- app/assets/stylesheets/tracks.css.scss | 5 +++++ app/controllers/todos_controller.rb | 18 +++++++++++++++++- app/helpers/todos_helper.rb | 8 ++++++++ app/views/todos/_todo.html.erb | 1 + config/routes.rb | 3 +-- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/tracks.css.scss b/app/assets/stylesheets/tracks.css.scss index 3bb46e3c..6cbd2653 100644 --- a/app/assets/stylesheets/tracks.css.scss +++ b/app/assets/stylesheets/tracks.css.scss @@ -124,6 +124,11 @@ img.delete_item { } } +a.todo_attachment { + background: image-url('bottom_off.png') no-repeat top; + border: none; +} + a.undecorated_link {background-color:transparent;color:transparent;} img.todo_star {background-image: image-url('staricons.png'); background-repeat: no-repeat; border:none; background-position: -32px 0px;} img.todo_star.starred{ background-position: 0px 0px; } diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 515450f6..4bffd371 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -701,7 +701,6 @@ class TodosController < ApplicationController @tag = Tag.where(:name => @tag_name).first_or_create end - def tags # TODO: limit to current_user tags_beginning = Tag.where('name like ?', params[:term]+'%') @@ -815,6 +814,23 @@ class TodosController < ApplicationController end end + def attachment + id = params[:id] + filename = params[:filename] + attachment = Attachment.where(id: id).first + + if attachment + if attachment.todo.user == current_user + send_file(attachment.file.path) + else + head :forbidden + end + else + head :not_found + end + + end + private def set_group_view_by diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 75a651ad..7bec8b48 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -204,6 +204,14 @@ module TodosHelper link_to(t('todos.convert_to_project'), url, {:class => "icon_item_to_project", :id => dom_id(todo, "to_project")}) end + def attachment_image(todo) + link_to( + image_tag('blank.png', width: 16, height: 16, border:0), + todo.attachments.first.file.url, + {:class => 'todo_attachment', title: 'Get attachments of this todo'} + ) + end + def collapsed_notes_image(todo) link = link_to( image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), diff --git a/app/views/todos/_todo.html.erb b/app/views/todos/_todo.html.erb index 07e8da70..13335d37 100644 --- a/app/views/todos/_todo.html.erb +++ b/app/views/todos/_todo.html.erb @@ -41,6 +41,7 @@ cache [todo, current_user.date.strftime("%Y%m%d"), @source_view, current_user.pr <%= project_and_context_links( todo, parent_container_type, :suppress_context => suppress_context, :suppress_project => suppress_project ) %> <%= collapsed_notes_image(todo) if todo.notes.present? %> <%= collapsed_successors_image(todo) if todo.has_pending_successors %> + <%= attachment_image(todo) if todo.attachments.present? %>