# HG changeset patch # User Chris Cannam # Date 1313510479 -3600 # Node ID 251b380117cedf20b5a9248b16b1d0472f22b7e5 # Parent 3ebf9b76e57f1e34db3f0baa0988f0c435b15d75 Introduce a new latest_downloads plugin to manage active and shortcut for attachments. Add a table for attachment active/shortcut data. Move existing active-handler code into the new plugin (but still using the "old" active column in the attachments table). Note the files_controller stuff doesn't actually work here. diff -r 3ebf9b76e57f -r 251b380117ce app/controllers/attachments_controller.rb --- a/app/controllers/attachments_controller.rb Fri Aug 12 14:52:07 2011 +0100 +++ b/app/controllers/attachments_controller.rb Tue Aug 16 17:01:19 2011 +0100 @@ -20,7 +20,6 @@ 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 @@ -56,12 +55,6 @@ 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]) @@ -85,10 +78,6 @@ @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 3ebf9b76e57f -r 251b380117ce app/controllers/files_controller.rb --- a/app/controllers/files_controller.rb Fri Aug 12 14:52:07 2011 +0100 +++ b/app/controllers/files_controller.rb Tue Aug 16 17:01:19 2011 +0100 @@ -8,9 +8,8 @@ include SortHelper def index - sort_init 'active', 'desc' + 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" diff -r 3ebf9b76e57f -r 251b380117ce app/views/files/index.html.erb --- a/app/views/files/index.html.erb Fri Aug 12 14:52:07 2011 +0100 +++ b/app/views/files/index.html.erb Tue Aug 16 17:01:19 2011 +0100 @@ -5,11 +5,9 @@

<%=l(:label_attachment_plural)%>

<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> -<% active_change_allowed = delete_allowed %> - <%= sort_header_tag('active', :caption => l(:field_active)) %> <%= sort_header_tag('filename', :caption => l(:field_filename)) %> <%= sort_header_tag('created_on', :caption => l(:label_date), :default_order => 'desc') %> <%= sort_header_tag('size', :caption => l(:field_filesize), :default_order => 'desc') %> @@ -29,26 +27,8 @@ <% end -%> <% container.attachments.each do |file| %> - <%= "active" if file.active? %>"> - - <% if file.active? %> - - <% else %> - "> + @@ -65,6 +45,4 @@
- <% 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 %>
<%= h(file.description) %>
<%= link_to_attachment file, :download => true, :title => file.description %> - <% end %> +
<%= link_to_attachment file, :download => true, :title => file.description %> <%= format_time(file.created_on) %> <%= number_to_human_size(file.filesize) %>
-<%= l(:text_files_active_change) if active_change_allowed and have_file %> - <% html_title(l(:label_attachment_plural)) -%> diff -r 3ebf9b76e57f -r 251b380117ce config/locales/en.yml --- a/config/locales/en.yml Fri Aug 12 14:52:07 2011 +0100 +++ b/config/locales/en.yml Tue Aug 16 17:01:19 2011 +0100 @@ -990,7 +990,6 @@ text_zoom_in: Zoom in text_zoom_out: Zoom out text_warn_on_leaving_unsaved: "The current page contains unsaved text that will be lost if you leave this page." - text_files_active_change:
Click the star to switch active status for a download on or off.
Active files will be shown more prominently in the download page. text_settings_repo_creation: Creating repository...

The source code repository for a project will be set up automatically within a few minutes of the project being created.

Please check again in five minutes, and contact us if there is any problem.

If you wish to use this project to track a repository that is already hosted somewhere else, please wait until the repository has been created here and then return to this settings page to configure it.

If you don't want a repository at all, go to the Modules tab and switch it off there. text_scm_path_encoding_note: "Default: UTF-8" text_git_repository_note: "Bare and local repository (e.g. /gitrepo, c:\gitrepo)" diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/README.rdoc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/README.rdoc Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,3 @@ += latest_downloads + +Description goes here diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/app/controllers/attachments_controller.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/app/controllers/attachments_controller.rb Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,16 @@ + +class AttachmentsController < ApplicationController + + before_filter :active_authorize, :only => :toggle_active + + def toggle_active + @attachment.active = !@attachment.active? + @attachment.save! + render :layout => false + end + +private + def active_authorize + true + end +end diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/app/controllers/files_controller.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/app/controllers/files_controller.rb Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,15 @@ +class FilesController < ApplicationController + + def index + sort_init 'active', 'desc' + 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" + + @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)] + @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse + render :layout => !request.xhr? + end +end diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/config/locales/en.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/config/locales/en.yml Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,3 @@ +en: + field_active: Active + text_files_active_change:
Click the star to switch active status for a download on or off.
Active files will be shown more prominently in the download page. diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/db/migrate/001_create_attachment_shortcuts.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/db/migrate/001_create_attachment_shortcuts.rb Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,13 @@ +class CreateAttachmentShortcuts < ActiveRecord::Migration + def self.up + create_table :attachment_shortcuts do |t| + t.column :attachment_id, :integer + t.column :active, :boolean + t.column :shortcut, :string + end + end + + def self.down + drop_table :attachment_shortcuts + end +end diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/init.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/init.rb Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,10 @@ +require 'redmine' + +Redmine::Plugin.register :redmine_latest_downloads do + name 'Redmine Latest Downloads plugin' + author 'Author name' + description 'This is a plugin for Redmine' + version '0.0.1' + url 'http://example.com/path/to/plugin' + author_url 'http://example.com/about' +end diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/lang/en.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/lang/en.yml Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,2 @@ +# English strings go here +my_label: "My label" diff -r 3ebf9b76e57f -r 251b380117ce vendor/plugins/redmine_latest_downloads/test/test_helper.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_latest_downloads/test/test_helper.rb Tue Aug 16 17:01:19 2011 +0100 @@ -0,0 +1,5 @@ +# Load the normal Rails helper +require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper') + +# Ensure that we are using the temporary fixture path +Engines::Testing.set_fixture_path