changeset 599:251b380117ce feature_227

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.
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 16 Aug 2011 17:01:19 +0100
parents 3ebf9b76e57f
children
files app/controllers/attachments_controller.rb app/controllers/files_controller.rb app/views/files/index.html.erb config/locales/en.yml vendor/plugins/redmine_latest_downloads/README.rdoc vendor/plugins/redmine_latest_downloads/app/controllers/attachments_controller.rb vendor/plugins/redmine_latest_downloads/app/controllers/files_controller.rb vendor/plugins/redmine_latest_downloads/config/locales/en.yml vendor/plugins/redmine_latest_downloads/db/migrate/001_create_attachment_shortcuts.rb vendor/plugins/redmine_latest_downloads/init.rb vendor/plugins/redmine_latest_downloads/lang/en.yml vendor/plugins/redmine_latest_downloads/test/test_helper.rb
diffstat 12 files changed, 70 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- 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?
--- 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"
--- 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 @@
 <h2><%=l(:label_attachment_plural)%></h2>
 
 <% delete_allowed = User.current.allowed_to?(:manage_files, @project) %>
-<% active_change_allowed = delete_allowed %>
 
 <table class="list files">
   <thead><tr>
-    <%= 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 @@
 	</tr>
 	<% end -%>
   <% container.attachments.each do |file| %>		
-  <tr class="file <%= cycle("odd", "even") %> <%= "active" if file.active? %>">
-    <td class="active">
-      <% have_file = true %>
-      <% if active_change_allowed
-           active_id = "active-" + file.id.to_s -%>
-        <div id="<%= active_id %>">
-        <%= 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
-        %>
-        </div>
-      <% else -%>
-        <%= image_tag('fav.png') if file.active? %>
-      <% end -%>
-    </td>
-    <% if file.active? %>
-      <td class="filename active"><%= link_to_attachment file, :download => true %><br><span class="description"><%= h(file.description) %></span></td>
-    <% else %>
-      <td class="filename"><%= link_to_attachment file, :download => true, :title => file.description %>
-    <% end %>
+  <tr class="file <%= cycle("odd", "even") %>">
+    <td class="filename"><%= link_to_attachment file, :download => true, :title => file.description %>
     </td>
     <td class="created_on"><%= format_time(file.created_on) %></td>
     <td class="filesize"><%= number_to_human_size(file.filesize) %></td>
@@ -65,6 +45,4 @@
   </tbody>
 </table>
 
-<%= l(:text_files_active_change) if active_change_allowed and have_file %>
-
 <% html_title(l(:label_attachment_plural)) -%>
--- 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: <br>Click the star to switch active status for a download on or off.<br>Active files will be shown more prominently in the download page.
   text_settings_repo_creation: <b>Creating repository...</b></p><p>The source code repository for a project will be set up automatically within a few minutes of the project being created.</p><p>Please check again in five minutes, and <a href="/projects/soundsoftware-site/wiki/Help">contact us</a> if there is any problem.</p><p>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.</p><p>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)"
--- /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
--- /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
--- /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
--- /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: <br>Click the star to switch active status for a download on or off.<br>Active files will be shown more prominently in the download page.
--- /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
--- /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
--- /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"
--- /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