Project

General

Profile

Patch #709 ยป attached-image-view-patch.txt

jongyoon Choi, 2008-02-22 02:58

 
1
Index: app/models/attachment.rb
2
===================================================================
3
--- app/models/attachment.rb	(revision 1163)
4
+++ app/models/attachment.rb	(working copy)
5
@@ -31,6 +31,7 @@
6
 
7
   cattr_accessor :storage_path
8
   @@storage_path = "#{RAILS_ROOT}/files"
9
+  @@image_path = "#{RAILS_ROOT}/public/images/files"
10
   
11
   def validate
12
     errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes
13
@@ -54,6 +55,7 @@
14
 	
15
 	# Copy temp file to its final location
16
 	def before_save
17
+    FileUtils.makedirs(@@image_path) unless File.directory?(@@image_path) 
18
 		if @temp_file && (@temp_file.size > 0)
19
 			logger.debug("saving '#{self.diskfile}'")
20
 			File.open(diskfile, "wb") do |f| 
21
@@ -76,7 +78,11 @@
22
 	
23
 	# Returns file's location on disk
24
 	def diskfile
25
-		"#{@@storage_path}/#{self.disk_filename}"
26
+    if self.image?
27
+      "#{@@image_path}/#{self.disk_filename}" 
28
+    else
29
+      "#{@@storage_path}/#{self.disk_filename}"
30
+    end
31
 	end
32
   
33
   def increment_download
34
Index: app/views/attachments/_links.rhtml
35
===================================================================
36
--- app/views/attachments/_links.rhtml	(revision 1163)
37
+++ app/views/attachments/_links.rhtml	(working copy)
38
@@ -1,7 +1,12 @@
39
 <div class="attachments">
40
 <% for attachment in attachments %>
41
-  <p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %>
42
-  (<%= number_to_human_size attachment.filesize %>)
43
+  <p>
44
+  <% if attachment.image? and attachment.project.show_image? %>
45
+		<%=image_tag('files/'+attachment.disk_filename)%>
46
+	<% else %>
47
+		<%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %>
48
+	<% end %>
49
+	  (<%= number_to_human_size attachment.filesize %>)
50
   <% unless options[:no_author] %>
51
     <span class="author"><%= attachment.author.name %>, <%= format_date(attachment.created_on) %></span>
52
   <% end %>
53
Index: app/views/projects/_form.rhtml
54
===================================================================
55
--- app/views/projects/_form.rhtml	(revision 1163)
56
+++ app/views/projects/_form.rhtml	(working copy)
57
@@ -15,6 +15,7 @@
58
 <% end %></p>
59
 <p><%= f.text_field :homepage, :size => 40 %></p>
60
 <p><%= f.check_box :is_public %></p>
61
+<p><%= f.check_box :show_image %></p>
62
 <%= wikitoolbar_for 'project_description' %>
63
 
64
 <% for @custom_value in @custom_values %>
65
Index: lang/en.yml
66
===================================================================
67
--- lang/en.yml	(revision 1163)
68
+++ lang/en.yml	(working copy)
69
@@ -131,6 +131,7 @@
70
 field_role: Role
71
 field_homepage: Homepage
72
 field_is_public: Public
73
+field_show_image: Show attached images
74
 field_parent: Subproject of
75
 field_is_in_chlog: Issues displayed in changelog
76
 field_is_in_roadmap: Issues displayed in roadmap
77
Index: db/migrate/089_add_project_is_image_show.rb
78
===================================================================
79
--- db/migrate/089_add_project_is_image_show.rb	(revision 0)
80
+++ db/migrate/089_add_project_is_image_show.rb	(revision 0)
81
@@ -0,0 +1,9 @@
82
+class AddProjectIsImageShow < ActiveRecord::Migration
83
+  def self.up
84
+    add_column :projects, :show_image, :boolean, :default => false, :null => false
85
+  end
86
+
87
+  def self.down
88
+    remove_column :projects, :show_image
89
+  end
90
+end
    (1-1/1)