file_share 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +147 -0
  3. data/README +0 -0
  4. data/Rakefile +38 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/application_controller.rb +4 -0
  7. data/app/controllers/file_attachments_controller.rb +123 -0
  8. data/app/controllers/file_share/application_controller.rb +5 -0
  9. data/app/helpers/file_attachments_helper.rb +9 -0
  10. data/app/helpers/file_share/application_helper.rb +60 -0
  11. data/app/models/file_attachment.rb +104 -0
  12. data/app/models/file_container.rb +30 -0
  13. data/app/views/file-share-shared/_flash.html.erb +7 -0
  14. data/app/views/file-share-shared/_main_menu.html.erb +3 -0
  15. data/app/views/file-share-shared/_navigation.html.erb +2 -0
  16. data/app/views/file_attachments/_file_attachment.html.erb +17 -0
  17. data/app/views/file_attachments/_file_attachments.html.erb +52 -0
  18. data/app/views/file_attachments/_file_container_option.html.erb +4 -0
  19. data/app/views/file_attachments/_file_container_select.html.erb +14 -0
  20. data/app/views/file_attachments/_plupload_with_listing.html.erb +142 -0
  21. data/app/views/file_attachments/_upload_form.html.erb +22 -0
  22. data/app/views/file_attachments/edit.html.erb +32 -0
  23. data/app/views/file_attachments/index.html.erb +1 -0
  24. data/app/views/file_attachments/update.js.rjs +13 -0
  25. data/app/views/layouts/application.html.erb +56 -0
  26. data/config/application.rb +42 -0
  27. data/config/blueprint_settings.yml +9 -0
  28. data/config/boot.rb +13 -0
  29. data/config/cucumber.yml +8 -0
  30. data/config/database.example.yml +22 -0
  31. data/config/environment.rb +5 -0
  32. data/config/environments/development.rb +26 -0
  33. data/config/environments/production.rb +49 -0
  34. data/config/environments/test.rb +35 -0
  35. data/config/initializers/backtrace_silencers.rb +7 -0
  36. data/config/initializers/inflections.rb +10 -0
  37. data/config/initializers/mime_types.rb +5 -0
  38. data/config/initializers/secret_token.rb +9 -0
  39. data/config/initializers/session_store.rb +10 -0
  40. data/config/locales/en.yml +5 -0
  41. data/config/routes.rb +64 -0
  42. data/db/migrate/20101020002635_create_file_attachments.rb +19 -0
  43. data/db/schema.rb +27 -0
  44. data/db/seeds.rb +7 -0
  45. data/lib/file_share.rb +3 -0
  46. data/lib/file_share/engine.rb +25 -0
  47. data/lib/generators/file_share/install/USAGE +5 -0
  48. data/lib/generators/file_share/install/install_generator.rb +19 -0
  49. data/lib/generators/file_share/install/templates/file_share.rake +169 -0
  50. data/lib/tasks/blueprint.rake +25 -0
  51. data/lib/tasks/cucumber.rake +53 -0
  52. data/public/404.html +26 -0
  53. data/public/422.html +26 -0
  54. data/public/500.html +26 -0
  55. data/public/favicon.ico +0 -0
  56. data/public/images/rails.png +0 -0
  57. data/public/javascripts/file_share.js +62 -0
  58. data/public/javascripts/file_share_behaviors.js +131 -0
  59. data/public/javascripts/idselector.js +538 -0
  60. data/public/javascripts/jquery-1.3.2.min.js +19 -0
  61. data/public/javascripts/jquery-ui-1.7.2.custom.min.js +298 -0
  62. data/public/javascripts/jquery.clonePosition.js +27 -0
  63. data/public/javascripts/jquery.js +154 -0
  64. data/public/javascripts/jquery.qtip-1.0.0-rc3.js +2149 -0
  65. data/public/javascripts/jquery.qtip-1.0.0-rc3.min.js +15 -0
  66. data/public/javascripts/jquery.string.1.0-min.js +6 -0
  67. data/public/javascripts/jquery.tablesorter.min.js +2 -0
  68. data/public/javascripts/lowpro.jquery.js +224 -0
  69. data/public/javascripts/plupload/gears_init.js +86 -0
  70. data/public/javascripts/plupload/jquery.plupload.queue.min.js +202 -0
  71. data/public/javascripts/plupload/plupload.browserplus.min.js +1 -0
  72. data/public/javascripts/plupload/plupload.flash.min.js +1 -0
  73. data/public/javascripts/plupload/plupload.flash.swf +0 -0
  74. data/public/javascripts/plupload/plupload.full.min.js +1 -0
  75. data/public/javascripts/plupload/plupload.gears.min.js +1 -0
  76. data/public/javascripts/plupload/plupload.html4.min.js +1 -0
  77. data/public/javascripts/plupload/plupload.html5.min.js +1 -0
  78. data/public/javascripts/plupload/plupload.min.js +1 -0
  79. data/public/javascripts/plupload/plupload.silverlight.min.js +1 -0
  80. data/public/javascripts/plupload/plupload.silverlight.xap +0 -0
  81. data/public/javascripts/rails.js +132 -0
  82. data/public/robots.txt +5 -0
  83. data/public/stylesheets/blueprint/grid.css +290 -0
  84. data/public/stylesheets/blueprint/icons/cross.png +0 -0
  85. data/public/stylesheets/blueprint/icons/doc.png +0 -0
  86. data/public/stylesheets/blueprint/icons/email.png +0 -0
  87. data/public/stylesheets/blueprint/icons/external.png +0 -0
  88. data/public/stylesheets/blueprint/icons/feed.png +0 -0
  89. data/public/stylesheets/blueprint/icons/im.png +0 -0
  90. data/public/stylesheets/blueprint/icons/key.png +0 -0
  91. data/public/stylesheets/blueprint/icons/pdf.png +0 -0
  92. data/public/stylesheets/blueprint/icons/tick.png +0 -0
  93. data/public/stylesheets/blueprint/icons/visited.png +0 -0
  94. data/public/stylesheets/blueprint/icons/xls.png +0 -0
  95. data/public/stylesheets/blueprint/ie.css +36 -0
  96. data/public/stylesheets/blueprint/oldgrid.css +161 -0
  97. data/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
  98. data/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
  99. data/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
  100. data/public/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
  101. data/public/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
  102. data/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
  103. data/public/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
  104. data/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
  105. data/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
  106. data/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
  107. data/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
  108. data/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
  109. data/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  110. data/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
  111. data/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
  112. data/public/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
  113. data/public/stylesheets/blueprint/plugins/link-icons/screen.css +40 -0
  114. data/public/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
  115. data/public/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
  116. data/public/stylesheets/blueprint/plugins/silksprite/sprite.css +1 -0
  117. data/public/stylesheets/blueprint/plugins/silksprite/sprites.png +0 -0
  118. data/public/stylesheets/blueprint/print.css +29 -0
  119. data/public/stylesheets/blueprint/readme.txt +12 -0
  120. data/public/stylesheets/blueprint/screen.css +402 -0
  121. data/public/stylesheets/error_messages.css +65 -0
  122. data/public/stylesheets/formtastic.css +138 -0
  123. data/public/stylesheets/formtastic_changes.css +33 -0
  124. data/public/stylesheets/main_elements.css +26 -0
  125. data/public/stylesheets/plupload/backgrounds.gif +0 -0
  126. data/public/stylesheets/plupload/buttons-disabled.png +0 -0
  127. data/public/stylesheets/plupload/buttons.png +0 -0
  128. data/public/stylesheets/plupload/delete.gif +0 -0
  129. data/public/stylesheets/plupload/done.gif +0 -0
  130. data/public/stylesheets/plupload/error.gif +0 -0
  131. data/public/stylesheets/plupload/screen.css +172 -0
  132. data/public/stylesheets/plupload/transp50.png +0 -0
  133. data/public/stylesheets/reset.css +60 -0
  134. data/public/stylesheets/scaffold.css +55 -0
  135. data/public/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  136. data/public/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  137. data/public/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  138. data/public/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  139. data/public/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  140. data/public/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  141. data/public/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  142. data/public/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  143. data/public/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
  144. data/public/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  145. data/public/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
  146. data/public/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
  147. data/public/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  148. data/public/stylesheets/smoothness/jquery-ui-1.7.2.custom.css +406 -0
  149. data/public/stylesheets/tablesorter/blue/asc.gif +0 -0
  150. data/public/stylesheets/tablesorter/blue/bg.gif +0 -0
  151. data/public/stylesheets/tablesorter/blue/desc.gif +0 -0
  152. data/public/stylesheets/tablesorter/blue/style.css +39 -0
  153. data/public/stylesheets/text_and_colors.css +49 -0
  154. data/spec/controllers/file_attachments_controller_spec.rb +305 -0
  155. data/spec/fixtures/file_share_file_attachments.yml +2 -0
  156. data/spec/fixtures/somefile.txt +1 -0
  157. data/spec/helpers/file_attachments_helper_spec.rb +11 -0
  158. data/spec/models/file_attachment_spec.rb +57 -0
  159. data/spec/models/file_container_spec.rb +23 -0
  160. data/spec/spec_helper.rb +27 -0
  161. metadata +474 -0
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.0.3'
4
+
5
+ gem 'sqlite3-ruby', :require => 'sqlite3'
6
+
7
+ gem "formtastic"
8
+
9
+ group :development, :test do
10
+ gem "engineer"
11
+ gem "rcov"
12
+ gem "rspec-rails"
13
+ gem "acts_as_fu"
14
+ gem "cucumber-rails"
15
+ gem "capybara"
16
+ end
@@ -0,0 +1,147 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ acts_as_fu (0.0.7.2)
32
+ activerecord
33
+ sqlite3-ruby
34
+ arel (2.0.6)
35
+ builder (2.1.2)
36
+ capybara (0.4.0)
37
+ celerity (>= 0.7.9)
38
+ culerity (>= 0.2.4)
39
+ mime-types (>= 1.16)
40
+ nokogiri (>= 1.3.3)
41
+ rack (>= 1.0.0)
42
+ rack-test (>= 0.5.4)
43
+ selenium-webdriver (>= 0.0.27)
44
+ xpath (~> 0.1.2)
45
+ celerity (0.8.4)
46
+ childprocess (0.1.4)
47
+ ffi (~> 0.6.3)
48
+ cucumber (0.9.4)
49
+ builder (~> 2.1.2)
50
+ diff-lcs (~> 1.1.2)
51
+ gherkin (~> 2.2.9)
52
+ json (~> 1.4.6)
53
+ term-ansicolor (~> 1.0.5)
54
+ cucumber-rails (0.3.2)
55
+ cucumber (>= 0.8.0)
56
+ culerity (0.2.12)
57
+ diff-lcs (1.1.2)
58
+ engineer (0.2.3)
59
+ jeweler (>= 1.4.0)
60
+ erubis (2.6.6)
61
+ abstract (>= 1.0.0)
62
+ ffi (0.6.3)
63
+ rake (>= 0.8.7)
64
+ formtastic (1.2.2)
65
+ actionpack (>= 2.3.7)
66
+ activesupport (>= 2.3.7)
67
+ i18n (>= 0.4.0)
68
+ gherkin (2.2.9)
69
+ json (~> 1.4.6)
70
+ term-ansicolor (~> 1.0.5)
71
+ git (1.2.5)
72
+ i18n (0.5.0)
73
+ jeweler (1.5.1)
74
+ bundler (~> 1.0.0)
75
+ git (>= 1.2.5)
76
+ rake
77
+ json (1.4.6)
78
+ json_pure (1.4.6)
79
+ mail (2.2.11)
80
+ activesupport (>= 2.3.6)
81
+ i18n (~> 0.5.0)
82
+ mime-types (~> 1.16)
83
+ treetop (~> 1.4.8)
84
+ mime-types (1.16)
85
+ nokogiri (1.4.4)
86
+ polyglot (0.3.1)
87
+ rack (1.2.1)
88
+ rack-mount (0.6.13)
89
+ rack (>= 1.0.0)
90
+ rack-test (0.5.6)
91
+ rack (>= 1.0)
92
+ rails (3.0.3)
93
+ actionmailer (= 3.0.3)
94
+ actionpack (= 3.0.3)
95
+ activerecord (= 3.0.3)
96
+ activeresource (= 3.0.3)
97
+ activesupport (= 3.0.3)
98
+ bundler (~> 1.0)
99
+ railties (= 3.0.3)
100
+ railties (3.0.3)
101
+ actionpack (= 3.0.3)
102
+ activesupport (= 3.0.3)
103
+ rake (>= 0.8.7)
104
+ thor (~> 0.14.4)
105
+ rake (0.8.7)
106
+ rcov (0.9.9)
107
+ rspec (2.2.0)
108
+ rspec-core (~> 2.2)
109
+ rspec-expectations (~> 2.2)
110
+ rspec-mocks (~> 2.2)
111
+ rspec-core (2.2.1)
112
+ rspec-expectations (2.2.0)
113
+ diff-lcs (~> 1.1.2)
114
+ rspec-mocks (2.2.0)
115
+ rspec-rails (2.2.1)
116
+ actionpack (~> 3.0)
117
+ activesupport (~> 3.0)
118
+ railties (~> 3.0)
119
+ rspec (~> 2.2.0)
120
+ rubyzip (0.9.4)
121
+ selenium-webdriver (0.1.1)
122
+ childprocess (= 0.1.4)
123
+ ffi (~> 0.6.3)
124
+ json_pure
125
+ rubyzip
126
+ sqlite3-ruby (1.3.2)
127
+ term-ansicolor (1.0.5)
128
+ thor (0.14.6)
129
+ treetop (1.4.9)
130
+ polyglot (>= 0.3.1)
131
+ tzinfo (0.3.23)
132
+ xpath (0.1.2)
133
+ nokogiri (~> 1.3)
134
+
135
+ PLATFORMS
136
+ ruby
137
+
138
+ DEPENDENCIES
139
+ acts_as_fu
140
+ capybara
141
+ cucumber-rails
142
+ engineer
143
+ formtastic
144
+ rails (= 3.0.3)
145
+ rcov
146
+ rspec-rails
147
+ sqlite3-ruby
data/README ADDED
File without changes
@@ -0,0 +1,38 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ FileShare::Application.load_tasks
8
+
9
+ excluded_files = %w(config/database.yml public/files)
10
+
11
+ Engineer::Tasks.new do |gem|
12
+ gem.name = "file_share"
13
+ gem.summary = %Q{Provides basic file management features.}
14
+ gem.description = %Q{Simple versioned event management for Rails 3.}
15
+ gem.email = ["jason.lapier@gmail.com", "jeremiah@inertialbit.net"]
16
+ gem.homepage = "http://github.com/inertialbit/file_share"
17
+ gem.authors = ["Jason LaPier", "Jeremiah Heller"]
18
+ gem.require_path = 'lib'
19
+ gem.files = FileList[
20
+ "[A-Z]*",
21
+ "{app,config,lib,public,spec,test}/**/*",
22
+ "db/**/*.rb"
23
+ ]
24
+ excluded_files.each{|f| gem.files.exclude(f)}
25
+
26
+ # Include Bundler dependencies
27
+ Bundler.definition.dependencies.each do |dependency|
28
+ next if dependency.name == "engineer"
29
+
30
+ if (dependency.groups & [:default, :production]).any?
31
+ gem.add_dependency dependency.name, *dependency.requirement.as_list
32
+ else
33
+ gem.add_development_dependency dependency.name, *dependency.requirement.as_list
34
+ end
35
+ end
36
+
37
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,4 @@
1
+ # stub for standalone
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery
4
+ end
@@ -0,0 +1,123 @@
1
+ class FileAttachmentsController < FileShare::ApplicationController
2
+
3
+ # before_filter :load_and_authorize_current_user, :except => [:index, :show, :download]
4
+
5
+ rescue_from Errno::ENOENT, :with => :file_not_found
6
+
7
+ helper_method :has_authorization?
8
+
9
+ private
10
+ def file_not_found(e)
11
+ logger.error("FileAttachmentsController[#{action_name}] was rescued with :file_not_found. #{e.message}")
12
+ flash[:warning] = "The physical file could not be located so your request could not be completed."
13
+ redirect_back_or_default(file_attachments_path)
14
+ end
15
+ def redirect_to_index_or_attachable(params={})
16
+ if defined?(@file_attachment)
17
+ unless @file_attachment.attachable_id.blank?
18
+ redirect_to(polymorphic_path(@file_attachment.attachable, params)) and return
19
+ else
20
+ redirect_to(file_attachments_path(params)) and return
21
+ end
22
+ else
23
+ redirect_back_or_default(file_attachments_path(params)) and return
24
+ end
25
+ end
26
+ def redirect_back_or_default(default)
27
+ #unless session[:return_to] && session[:return_to] == new_user_session_path
28
+ # redirect_to(session[:return_to] || default)
29
+ #else
30
+ redirect_to(default)
31
+ #end
32
+ #session[:return_to] = nil
33
+ end
34
+ def has_authorization?(*args)
35
+ # stub
36
+ true
37
+ end
38
+ def load_containers
39
+ @file_containers = FileContainer.all
40
+ end
41
+ protected
42
+ public
43
+ def new
44
+ end
45
+ def show
46
+ end
47
+ def index
48
+ @orphans = FileAttachment.orphans
49
+ @files = FileAttachment.attached
50
+ load_containers
51
+ end
52
+
53
+ def download
54
+ file_attachment = FileAttachment.find(params[:id])
55
+ file_itself = File.open(file_attachment.full_path, 'r')
56
+ logger.debug("FILE ATTACHMENT INFO: #{file_attachment.inspect}")
57
+ logger.debug("FILE INFO: #{file_itself.inspect}")
58
+ send_data(file_itself.read, :filename => File.basename(file_itself.path), :stream => true, :buffer_size => 1.megabyte)
59
+ end
60
+
61
+ def create
62
+ if params[:file]
63
+ file_params = {
64
+ :uploaded_file => params[:file]
65
+ }
66
+ if params[:attachable_id] && params[:attachable_type]
67
+ file_params.merge!({
68
+ :attachable_id => params[:attachable_id],
69
+ :attachable_type => params[:attachable_type]
70
+ })
71
+ end
72
+ @file_attachment = FileAttachment.new file_params
73
+ elsif params[:file_attachment] && params[:file_attachment][:uploaded_file]
74
+ @file_attachment = FileAttachment.new params[:file_attachment]
75
+ end
76
+
77
+ if @file_attachment && @file_attachment.save
78
+ flash[:notice] = "File uploaded."
79
+ else
80
+ if @file_attachment
81
+ flash[:warning] = "Unable to save file attachment: #{@file_attachment.errors.full_messages.join('; ')}"
82
+ else
83
+ flash[:warning] = "No files were selected for upload."
84
+ end
85
+ end
86
+ unless params[:file] # request.xhr? # html5 based multiple uploads are not xhr ?
87
+ redirect_to_index_or_attachable(:std => 1) # {:std => 1} - make sure the std html form displays
88
+ else
89
+ flash.discard
90
+ render :partial => 'file_attachments/file_attachment', :object => @file_attachment
91
+ end
92
+ end
93
+
94
+ def edit
95
+ @file_attachment = FileAttachment.find(params[:id])
96
+ load_containers
97
+ end
98
+
99
+ def update
100
+ @file_attachment = FileAttachment.find(params[:id])
101
+ respond_to do |format|
102
+ if @file_attachment.update_attributes(params[:file_attachment])
103
+ format.html do
104
+ flash[:notice] = "Updated File: #{@file_attachment.name}"
105
+ redirect_to_index_or_attachable
106
+ end
107
+ else
108
+ format.html do
109
+ flash.now[:warning] = "The description could not be saved, please try again."
110
+ render :edit
111
+ end
112
+ end
113
+ format.js
114
+ end
115
+ end
116
+
117
+ def destroy
118
+ @file_attachment = FileAttachment.find(params[:id])
119
+ @file_attachment.destroy
120
+ flash[:notice] = "Deleted File: #{@file_attachment.name}"
121
+ redirect_to_index_or_attachable
122
+ end
123
+ end
@@ -0,0 +1,5 @@
1
+ class FileShare::ApplicationController < ApplicationController
2
+ private
3
+ protected
4
+ public
5
+ end
@@ -0,0 +1,9 @@
1
+ module FileAttachmentsHelper
2
+
3
+ def description_display(file_attachment)
4
+ content_tag :p, :id => "file_attachment_#{file_attachment.id}_description", :style => "max-width: 70%; float: right;" do
5
+ file_attachment.description
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,60 @@
1
+ module FileShare
2
+ module ApplicationHelper
3
+ def link_wrapper(path, wrapper_options={}, link_options={})
4
+ tag = wrapper_options.delete(:tag) || :p
5
+ link_text = link_options.delete(:link_text) || path
6
+ highlight = wrapper_options.delete(:highlight)
7
+
8
+ unless path.blank?
9
+ if current_page?(path) && (highlight.nil? || highlight)
10
+ wrapper_options = {:class => (wrapper_options[:class] || '') + " nav_highlight"}
11
+ end
12
+ end
13
+
14
+ unless wrapper_options.delete(:no_wrapper)
15
+ return content_tag(tag, wrapper_options) do
16
+ link_to(link_text, path, link_options)
17
+ end
18
+ else
19
+ return link_to(link_text, path, link_options)
20
+ end
21
+ end
22
+
23
+ def link_to_file_attachments(wrapper_options={})
24
+ link_wrapper(file_attachments_path, wrapper_options, {
25
+ :link_text => 'List / Upload Files'
26
+ })
27
+ end
28
+
29
+ def render_file_share_main_menu
30
+ render :partial => 'file-share-shared/main_menu'
31
+ end
32
+
33
+ def render_file_share_navigation
34
+ render :partial => 'file-share-shared/navigation'
35
+ end
36
+ def file_share_javascript_includes
37
+ list = [
38
+ "jquery-ui-1.7.2.custom.min.js",
39
+ "jquery.tablesorter.min.js",
40
+ "jquery.string.1.0-min.js",
41
+ "jquery.clonePosition.js",
42
+ "lowpro.jquery.js",
43
+ "jquery.qtip-1.0.0-rc3.js",
44
+ "rails",
45
+ "file_share_behaviors",
46
+ "file_share",
47
+ "http://www.google.com/jsapi",
48
+ "plupload/gears_init",
49
+ "plupload/plupload.full.min.js",
50
+ "plupload/jquery.plupload.queue.min.js"
51
+ ]
52
+ unless Rails.env == 'production'
53
+ list.unshift("jquery")
54
+ else
55
+ list.unshift("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js")
56
+ end
57
+ list
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,104 @@
1
+ # t.string "name"
2
+ # t.text "description"
3
+ # t.string "filepath"
4
+ # t.integer "event_id"
5
+ # t.datetime "created_at"
6
+ # t.datetime "updated_at"
7
+
8
+ class FileAttachment < ActiveRecord::Base
9
+ set_table_name "file_share_file_attachments"
10
+
11
+ FOLDER = 'files'
12
+ FOLDER_ROOT = File.join(Rails.root.to_s, 'public')
13
+ FOLDER_PATH = File.join(FOLDER_ROOT, FOLDER)
14
+ TRASH_FOLDER = File.join(FOLDER_PATH, 'trash')
15
+
16
+ validates_presence_of :name, :filepath
17
+
18
+ # belongs_to :event
19
+ belongs_to :attachable, :polymorphic => true
20
+
21
+ #before_validation_on_create :autofill_blank_name
22
+ #before_validation_on_create :save_to_folder_path
23
+ before_validation :autofill_blank_name, :on => :create
24
+ before_validation :save_to_folder_path, :on => :create
25
+ before_save :normalize_attachable_fields
26
+ # before_validation_on_update :autofill_blank_name, :if => :file_uploaded?
27
+ # before_validation_on_update :save_to_folder_path, :if => :file_uploaded?
28
+ before_destroy :move_file_to_trash_folder!
29
+
30
+ attr_accessor :uploaded_file
31
+
32
+ scope :orphans, where('attachable_id IS NULL')
33
+ scope :attached, where('attachable_id IS NOT NULL')
34
+
35
+ private
36
+ def normalize_attachable_fields
37
+ if attachable_type.blank? || attachable_id.blank?
38
+ self.attachable_type = nil
39
+ self.attachable_id = nil
40
+ end
41
+ end
42
+ def move_file_to_trash_folder!
43
+ ensure_folder_path_exists(TRASH_FOLDER)
44
+ trash_filename = generate_unique_filename(TRASH_FOLDER)
45
+
46
+ FileUtils.mv(full_path, File.join(TRASH_FOLDER, trash_filename))
47
+
48
+ unless File.exists?(File.join(TRASH_FOLDER, trash_filename))
49
+ raise Errno::ENOENT("The file at #{File.join(FOLDER_ROOT, filepath)} should be in the trash at #{File.join(TRASH_FOLDER, trash_filename)}")
50
+ end
51
+ logger.info("Moved File Attachment to Trash: #{File.join(TRASH_FOLDER, trash_filename)}")
52
+ end
53
+ def save_to_folder_path
54
+ ensure_folder_path_exists
55
+ build_filepath
56
+ File.open(full_path, "wb") { |f| f.write(uploaded_file.read) }
57
+ return true if file_saved?
58
+ errors.add_to_base("The file could not be saved. Please try again or contact someone and make a note of how many files, what kind, etc.")
59
+ false
60
+ end
61
+ def generate_unique_filename(dest_path=FOLDER_PATH)
62
+ base_filename = File.basename(uploaded_file && uploaded_file.original_filename || filepath)
63
+ new_filename = base_filename
64
+ path = File.join dest_path, new_filename
65
+ count = 0
66
+ until !File.exists? path
67
+ count += 1
68
+ new_filename = base_filename.gsub File.extname(base_filename), "-#{count}#{File.extname(base_filename)}"
69
+ path = File.join dest_path, new_filename
70
+ end
71
+ new_filename
72
+ end
73
+ def ensure_folder_path_exists(dest_path=FOLDER_PATH)
74
+ FileUtils.mkdir_p dest_path
75
+ end
76
+ def build_filepath
77
+ self.filepath = File.join FOLDER, generate_unique_filename
78
+ end
79
+ def autofill_blank_name
80
+ if name.blank?
81
+ self.name = self.uploaded_file.original_filename
82
+ end
83
+ end
84
+ protected
85
+ public
86
+ def containers
87
+ return [] if attachables.count == 0
88
+ attachables.all.collect do |attachable|
89
+ attachable.container
90
+ end
91
+ end
92
+ def full_path
93
+ "#{FOLDER_ROOT}/#{filepath}"
94
+ end
95
+ def file_saved?
96
+ return true if File.exists?(full_path) && File.basename(full_path) != FOLDER
97
+ return false
98
+ end
99
+ def file_container=(container)
100
+ p = container.split("_")
101
+ self.attachable_type = p[0] unless p[0].blank?
102
+ self.attachable_id = p[1] unless p[1].blank?
103
+ end
104
+ end