# HG changeset patch # User Chris Cannam # Date 1299251014 0 # Node ID 1d51c9df069ba4df1642e062a6a8c2dcbc25b108 # Parent 7cec015f07ce4a03f4928f1dcf11dc26da6369ac# Parent 847add61573b92a976e731f149c74eebd6b84896 Merge from branch "feature_80" diff -r 7cec015f07ce -r 1d51c9df069b app/controllers/attachments_controller.rb --- a/app/controllers/attachments_controller.rb Tue Feb 22 16:48:15 2011 +0000 +++ b/app/controllers/attachments_controller.rb Fri Mar 04 15:03:34 2011 +0000 @@ -16,9 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AttachmentsController < ApplicationController + before_filter :find_project before_filter :file_readable, :read_authorize, :except => :destroy before_filter :delete_authorize, :only => :destroy + before_filter :active_authorize, :only => :toggle_active verify :method => :post, :only => :destroy @@ -54,6 +56,12 @@ redirect_to :controller => 'projects', :action => 'show', :id => @project end + def toggle_active + @attachment.active = !@attachment.active? + @attachment.save! + render :layout => false + end + private def find_project @attachment = Attachment.find(params[:id]) @@ -77,6 +85,10 @@ @attachment.deletable? ? true : deny_access end + def active_authorize + true + end + def detect_content_type(attachment) content_type = attachment.content_type if content_type.blank? diff -r 7cec015f07ce -r 1d51c9df069b app/controllers/files_controller.rb --- a/app/controllers/files_controller.rb Tue Feb 22 16:48:15 2011 +0000 +++ b/app/controllers/files_controller.rb Fri Mar 04 15:03:34 2011 +0000 @@ -10,6 +10,7 @@ def index sort_init 'filename', 'asc' sort_update 'filename' => "#{Attachment.table_name}.filename", + 'active' => "#{Attachment.table_name}.active", 'created_on' => "#{Attachment.table_name}.created_on", 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" @@ -33,4 +34,5 @@ end redirect_to project_files_path(@project) end + end diff -r 7cec015f07ce -r 1d51c9df069b app/views/attachments/toggle_active.rhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/attachments/toggle_active.rhtml Fri Mar 04 15:03:34 2011 +0000 @@ -0,0 +1,7 @@ +<%= +file = Attachment.find(params[:id]) +active_id = "active-" + file.id.to_s +link_to_remote image_tag(file.active? ? 'fav.png' : 'fav_off.png'), + :url => {:controller => 'attachments', :action => 'toggle_active', :project_id => @project.id, :id => file}, + :update => active_id +%> diff -r 7cec015f07ce -r 1d51c9df069b app/views/files/index.html.erb --- a/app/views/files/index.html.erb Tue Feb 22 16:48:15 2011 +0000 +++ b/app/views/files/index.html.erb Fri Mar 04 15:03:34 2011 +0000 @@ -5,29 +5,46 @@
MD5 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
+ | <%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %> | |||||||||||
<%= link_to_attachment file, :download => true, :title => file.description %> | +
+ <% have_file = true %>
+ <% if active_change_allowed
+ active_id = "active-" + file.id.to_s -%>
+
+ <%= link_to_remote image_tag(file.active? ? 'fav.png' : 'fav_off.png'),
+ :url => {:controller => 'attachments', :action => 'toggle_active', :project_id => @project.id, :id => file},
+ :update => active_id
+ %>
+
+ <% else -%>
+ <%= image_tag('fav.png') if file.active? %>
+ <% end -%>
+ |
+ "><%= link_to_attachment file, :download => true, :title => file.description %> | <%= format_time(file.created_on) %> | <%= number_to_human_size(file.filesize) %> | <%= file.downloads %> | @@ -43,4 +60,6 @@