el_vfs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +28 -0
  4. data/app/assets/images/el_vfs/elfinder/arrows-active.png +0 -0
  5. data/app/assets/images/el_vfs/elfinder/arrows-normal.png +0 -0
  6. data/app/assets/images/el_vfs/elfinder/dialogs.png +0 -0
  7. data/app/assets/images/el_vfs/elfinder/icons-big.png +0 -0
  8. data/app/assets/images/el_vfs/elfinder/icons-small.png +0 -0
  9. data/app/assets/images/el_vfs/elfinder/logo.png +0 -0
  10. data/app/assets/images/el_vfs/elfinder/progress.gif +0 -0
  11. data/app/assets/images/el_vfs/elfinder/quicklook-bg.png +0 -0
  12. data/app/assets/images/el_vfs/elfinder/quicklook-icons.png +0 -0
  13. data/app/assets/images/el_vfs/elfinder/resize.png +0 -0
  14. data/app/assets/images/el_vfs/elfinder/spinner-mini.gif +0 -0
  15. data/app/assets/images/el_vfs/elfinder/toolbar.png +0 -0
  16. data/app/assets/images/el_vfs/ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  17. data/app/assets/images/el_vfs/ui/ui-bg_flat_75_ffffff_40x100.png +0 -0
  18. data/app/assets/images/el_vfs/ui/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  19. data/app/assets/images/el_vfs/ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
  20. data/app/assets/images/el_vfs/ui/ui-bg_glass_75_dadada_1x400.png +0 -0
  21. data/app/assets/images/el_vfs/ui/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  22. data/app/assets/images/el_vfs/ui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  23. data/app/assets/images/el_vfs/ui/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  24. data/app/assets/images/el_vfs/ui/ui-icons_222222_256x240.png +0 -0
  25. data/app/assets/images/el_vfs/ui/ui-icons_2e83ff_256x240.png +0 -0
  26. data/app/assets/images/el_vfs/ui/ui-icons_454545_256x240.png +0 -0
  27. data/app/assets/images/el_vfs/ui/ui-icons_888888_256x240.png +0 -0
  28. data/app/assets/images/el_vfs/ui/ui-icons_cd0a0a_256x240.png +0 -0
  29. data/app/assets/javascripts/el_vfs/elfinder.js +9601 -0
  30. data/app/assets/javascripts/el_vfs/i18n/elfinder.LANG.js +281 -0
  31. data/app/assets/javascripts/el_vfs/i18n/elfinder.ar.js +280 -0
  32. data/app/assets/javascripts/el_vfs/i18n/elfinder.ru.js +280 -0
  33. data/app/assets/stylesheets/el_vfs/el_vfs.sass +4 -0
  34. data/app/assets/stylesheets/el_vfs/elfinder.sass +1645 -0
  35. data/app/assets/stylesheets/el_vfs/jquery_ui.sass +1482 -0
  36. data/app/assets/stylesheets/el_vfs/reset.sass +3 -0
  37. data/app/assets/stylesheets/el_vfs/theme.sass +82 -0
  38. data/app/controllers/el_vfs/el_finder_controller.rb +17 -0
  39. data/app/helpers/el_vfs/application_helper.rb +4 -0
  40. data/app/models/el_vfs/directory.rb +30 -0
  41. data/app/models/el_vfs/entry.rb +91 -0
  42. data/app/models/el_vfs/file.rb +35 -0
  43. data/app/models/el_vfs/root.rb +36 -0
  44. data/app/views/el_vfs/directories/_form.html.erb +17 -0
  45. data/app/views/el_vfs/directories/edit.html.erb +6 -0
  46. data/app/views/el_vfs/directories/index.html.erb +21 -0
  47. data/app/views/el_vfs/directories/new.html.erb +5 -0
  48. data/app/views/el_vfs/directories/show.html.erb +5 -0
  49. data/app/views/el_vfs/files/_form.html.erb +17 -0
  50. data/app/views/el_vfs/files/edit.html.erb +6 -0
  51. data/app/views/el_vfs/files/index.html.erb +21 -0
  52. data/app/views/el_vfs/files/new.html.erb +5 -0
  53. data/app/views/el_vfs/files/show.html.erb +5 -0
  54. data/app/views/layouts/el_vfs/application.html.erb +14 -0
  55. data/config/dragonfly.rb +45 -0
  56. data/config/routes.rb +6 -0
  57. data/db/migrate/20111111111111_create_el_vfs_entries.rb +19 -0
  58. data/lib/el_finder_api/el_vfs/command.rb +66 -0
  59. data/lib/el_finder_api/el_vfs/command/change_working_directory.rb +36 -0
  60. data/lib/el_finder_api/el_vfs/command/copy_entries.rb +44 -0
  61. data/lib/el_finder_api/el_vfs/command/create_directory.rb +21 -0
  62. data/lib/el_finder_api/el_vfs/command/create_file.rb +24 -0
  63. data/lib/el_finder_api/el_vfs/command/create_thumbnail.rb +3 -0
  64. data/lib/el_finder_api/el_vfs/command/destroy_entries.rb +24 -0
  65. data/lib/el_finder_api/el_vfs/command/duplicate_entries.rb +24 -0
  66. data/lib/el_finder_api/el_vfs/command/get_ancestors.rb +22 -0
  67. data/lib/el_finder_api/el_vfs/command/get_descendants.rb +19 -0
  68. data/lib/el_finder_api/el_vfs/command/list_names.rb +14 -0
  69. data/lib/el_finder_api/el_vfs/command/pack_entries.rb +3 -0
  70. data/lib/el_finder_api/el_vfs/command/ping.rb +12 -0
  71. data/lib/el_finder_api/el_vfs/command/read_file_body.rb +17 -0
  72. data/lib/el_finder_api/el_vfs/command/rename_entry.rb +25 -0
  73. data/lib/el_finder_api/el_vfs/command/resize_image.rb +3 -0
  74. data/lib/el_finder_api/el_vfs/command/send_file.rb +15 -0
  75. data/lib/el_finder_api/el_vfs/command/unknown.rb +14 -0
  76. data/lib/el_finder_api/el_vfs/command/unpack_entry.rb +3 -0
  77. data/lib/el_finder_api/el_vfs/command/update_file_body.rb +28 -0
  78. data/lib/el_finder_api/el_vfs/command/upload_files.rb +22 -0
  79. data/lib/el_finder_api/el_vfs/connector.rb +22 -0
  80. data/lib/el_finder_api/el_vfs/model.rb +38 -0
  81. data/lib/el_vfs.rb +4 -0
  82. data/lib/el_vfs/engine.rb +28 -0
  83. data/lib/el_vfs/version.rb +3 -0
  84. data/lib/tasks/el_vfs_tasks.rake +4 -0
  85. metadata +290 -0
@@ -0,0 +1,45 @@
1
+ require 'dragonfly'
2
+
3
+ vfs = Dragonfly[:vfs]
4
+ vfs.configure_with(:rails)
5
+ vfs.configure_with(:imagemagick)
6
+ vfs.define_macro(ActiveRecord::Base, :file_accessor)
7
+ vfs.content_filename = ->(job, request) { request[:entry_name] }
8
+
9
+ if defined?(Settings) && Settings[:s3]
10
+ require 'fog'
11
+ vfs.datastore = Dragonfly::DataStorage::S3DataStore.new
12
+ vfs.datastore.configure do |datastore|
13
+ Settings[:s3].each do | key, value |
14
+ datastore.send("#{key}=", value)
15
+ end
16
+ end
17
+
18
+ class Fog::Storage::AWS::Real
19
+ def initialize_with_openteam(options={})
20
+ initialize_without_openteam(options.merge(:scheme => :http, :port => 80, :host => 's3.openteam.ru'))
21
+ end
22
+ alias_method_chain :initialize, :openteam
23
+ end
24
+
25
+ class Fog::Connection
26
+ def request_with_openteam(params, &block)
27
+ request_without_openteam(params.merge(:path => "/#{Settings[:s3][:bucket_name]}/#{params[:path]}"), &block)
28
+ end
29
+ alias_method_chain :request, :openteam
30
+ end
31
+ else
32
+ vfs.datastore.configure do |datastore|
33
+ datastore.root_path = "#{Rails.root}/files/#{Rails.env}"
34
+ datastore.store_meta = false
35
+ end
36
+ end
37
+
38
+ require 'dragonfly/image_magick/utils'
39
+ module Dragonfly::ImageMagick::Utils
40
+ def raw_identify(temp_object, args='')
41
+ @cache ||= {}
42
+ @cache["#{temp_object}#{args}"] ||= run "#{identify_command} #{args} \"#{temp_object.path}\" 2>/dev/null"
43
+ end
44
+ end
45
+
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ module ElVfs
2
+ Engine.routes.draw do
3
+ match '/api/elfinder' => 'el_finder#run'
4
+ resources :entries
5
+ end
6
+ end
@@ -0,0 +1,19 @@
1
+ class CreateElVfsEntries < ActiveRecord::Migration
2
+ def change
3
+ create_table :el_vfs_entries do |t|
4
+ t.string :type
5
+ t.string :ancestry
6
+ t.integer :ancestry_depth
7
+ t.text :entry_path
8
+ t.text :entry_path_hash
9
+ t.string :entry_name
10
+ t.string :entry_mime_type
11
+ t.integer :entry_size
12
+ t.integer :root_number
13
+ t.timestamps
14
+ end
15
+ add_index :el_vfs_entries, :entry_name
16
+ add_index :el_vfs_entries, :ancestry
17
+ add_index :el_vfs_entries, :entry_path_hash
18
+ end
19
+ end
@@ -0,0 +1,66 @@
1
+ module ElVfs
2
+
3
+ class ::IsAFileValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ record.errors[attribute] << "must be an instance of ElVfs::File (was #{value.class})" unless value.is_a?(ElVfs::File)
6
+ end
7
+ end
8
+
9
+ class ::IsADirectoryValidator < ActiveModel::EachValidator
10
+ def validate_each(record, attribute, value)
11
+ record.errors[attribute] << "must be an instance of ElVfs::Directory (was #{value.class})" unless value.is_a?(ElVfs::Directory) || value.is_a?(ElVfs::Root)
12
+ end
13
+ end
14
+
15
+ class ::IsAnEntryValidator < ActiveModel::EachValidator
16
+ def validate_each(record, attribute, value)
17
+ record.errors[attribute] << "must be an instance of ElVfs::Entry (was #{value.class})" unless value.is_a?(ElVfs::Entry)
18
+ end
19
+ end
20
+
21
+ class Command < Model
22
+
23
+ attr_accessor :arguments, :error, :result
24
+
25
+ class Arguments < Model
26
+ def entry
27
+ @entry ||= Entry.find_by_entry_path_hash target
28
+ end
29
+ def entries
30
+ @entries ||= targets.map{|target| Entry.find_by_entry_path_hash target}
31
+ end
32
+ end
33
+
34
+ class Result < Model
35
+ attr_accessor :arguments, :execute_command
36
+ end
37
+
38
+ class_attribute :command_name
39
+
40
+ class Error < Model
41
+ attr_accessor :error
42
+ end
43
+
44
+ def initialize(init_params)
45
+ self.arguments = "#{self.class.name}::Arguments".constantize.new(init_params)
46
+ end
47
+
48
+ def run
49
+ self.result = "#{self.class.name}::Result".constantize.new(:arguments => arguments, :execute_command => execute_command)
50
+ end
51
+
52
+ def headers
53
+ @headers ||= {}
54
+ end
55
+
56
+ protected
57
+
58
+ def execute_command
59
+ end
60
+
61
+ def self.register_in_connector(command_name=nil)
62
+ self.command_name = command_name || name.demodulize.underscore
63
+ Connector.commands[self.command_name] = self
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,36 @@
1
+ module ElVfs
2
+
3
+ class Command::ChangeWorkingDirectory < Command
4
+ register_in_connector :open
5
+
6
+ class Arguments < Command::Arguments
7
+ attr_accessor :init, :target, :tree
8
+
9
+ validates_presence_of :init, :unless => :target
10
+ validates :entry, :is_a_directory => true
11
+
12
+ def initialize(params)
13
+ super
14
+ self.target ||= Entry.root.target if init
15
+ end
16
+ end
17
+
18
+ class Result < Command::Result
19
+ def api; 2 end
20
+ def cwd; arguments.entry end
21
+ def uplMaxSize; '16m' end
22
+
23
+ def files
24
+ files = arguments.entry.children.all
25
+ files += Entry.where(['ancestry_depth <= ?', 2]).only_directories if arguments.tree
26
+ files.uniq
27
+ end
28
+
29
+ def options
30
+ {path: arguments.entry.el_vfs_path, url: arguments.entry.url, disabled: [], separator: '/', copyOverwrite: 1, archivers: {create: [], extract: []}}
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,44 @@
1
+ module ElVfs
2
+ class Command::CopyEntries < ElVfs::Command
3
+ register_in_connector :paste
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :targets, :src, :dst, :cut
7
+ validates_presence_of :src, :dst, :targets
8
+
9
+ validates :source, :destination, :is_a_directory => true
10
+ validates :entries, :is_an_entry => true
11
+
12
+ def cut?
13
+ cut == '1' || cut == 'true' || cut == true
14
+ end
15
+
16
+ def source
17
+ @source ||= Entry..find_by_entry_path_hash(src)
18
+ end
19
+
20
+ def destination
21
+ @destination ||= Entry.find_by_entry_path_hash(dst)
22
+ end
23
+ end
24
+
25
+ class Result < Command::Result
26
+ def added
27
+ execute_command
28
+ end
29
+ def removed
30
+ arguments.cut? ? arguments.targets : []
31
+ end
32
+ end
33
+
34
+ protected
35
+ def execute_command
36
+ arguments.entries.map do | entry |
37
+ entry = entry.dup unless arguments.cut?
38
+ entry.tap do | entry |
39
+ entry.update_attributes! :parent => arguments.destination
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ module ElVfs
2
+ class Command::CreateDirectory < ElVfs::Command
3
+ register_in_connector :mkdir
4
+ class Arguments < Command::Arguments
5
+ attr_accessor :target, :name
6
+ validates_presence_of :target, :name
7
+ validates :entry, :is_a_directory => true
8
+ end
9
+
10
+ class Result < Command::Result
11
+ def added
12
+ [ execute_command ]
13
+ end
14
+ end
15
+
16
+ protected
17
+ def execute_command
18
+ Directory.create!(:parent => arguments.entry, :entry_name => arguments.name)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module ElVfs
2
+ class Command::CreateFile < ElVfs::Command
3
+ register_in_connector :mkfile
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :target, :name
7
+ validates_presence_of :target, :name
8
+ validates :entry, :is_a_directory => true
9
+ end
10
+
11
+ class Result < Command::Result
12
+ def added
13
+ [ execute_command ]
14
+ end
15
+ end
16
+
17
+ def execute_command
18
+ ElVfs::File.new(:parent => arguments.entry).tap do | file |
19
+ Dir.mktmpdir{|dir| file.entry = ::File.open("#{dir}/#{arguments.name}", "w") }
20
+ file.save!
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class ElVfs::Command::CreateThumbnail < ElVfs::Command
2
+ register_in_connector :tmb
3
+ end
@@ -0,0 +1,24 @@
1
+ module ElVfs
2
+ class Command::DestroyEntries < ElVfs::Command
3
+ register_in_connector :rm
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :targets
7
+ validates_presence_of :targets
8
+ validates :entries, :is_an_entry => true
9
+ end
10
+
11
+ class Result < Command::Result
12
+ def removed
13
+ arguments.targets
14
+ end
15
+ end
16
+
17
+ protected
18
+
19
+ def execute_command
20
+ arguments.entries.map(&:destroy)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module ElVfs
2
+ class Command::DuplicateEntries < ElVfs::Command
3
+ register_in_connector :duplicate
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :targets
7
+ validates_presence_of :targets
8
+ validates :entries, :is_an_entry => true
9
+ end
10
+
11
+
12
+ class Result < Command::Result
13
+ def added
14
+ execute_command
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def execute_command
21
+ arguments.entries.map(&:duplicate)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module ElVfs
2
+ class Command::GetAncestors < ElVfs::Command
3
+ register_in_connector :parents
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :target
7
+ validates_presence_of :target
8
+ validates :entry, :is_a_directory => true
9
+ end
10
+
11
+ class Result < Command::Result
12
+ def tree
13
+ tree = arguments.entry.ancestors
14
+ tree += arguments.entry.ancestors.from_depth(1).map(&:directories).flatten
15
+ tree << arguments.entry
16
+ tree += Entry.where(['ancestry_depth <= ?', 2]).only_directories
17
+ tree.uniq
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module ElVfs
2
+ class Command::GetDescendants < ElVfs::Command
3
+ register_in_connector :tree
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :target
7
+
8
+ validates_presence_of :target
9
+ validates :entry, :is_a_directory => true
10
+ end
11
+
12
+ class Result < Command::Result
13
+ def tree
14
+ arguments.entry.descendants(:to_depth => 2)
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ class ElVfs::Command::ListNames < ElVfs::Command
2
+ register_in_connector :ls
3
+ options :target
4
+
5
+ protected
6
+
7
+ def hash
8
+ if target
9
+ { list: directory.files.map(&:entry_name) }
10
+ else
11
+ wrong_params_hash
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ class ElVfs::Command::PackEntries < ElVfs::Command
2
+ register_in_connector :archive
3
+ end
@@ -0,0 +1,12 @@
1
+ module ElVfs
2
+ class Command::Ping < Command
3
+ register_in_connector
4
+
5
+ class Arguments < Command::Arguments
6
+ end
7
+
8
+ def run
9
+ self.headers['Connection'] = 'close'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module ElVfs
2
+ class Command::ReadFileBody < ElVfs::Command
3
+ register_in_connector :get
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :target
7
+ validates_presence_of :target
8
+ validates :entry, :is_a_file => true
9
+ end
10
+
11
+ class Result < Command::Result
12
+ def content
13
+ arguments.entry.entry.data
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module ElVfs
2
+ class Command::RenameEntry < ElVfs::Command
3
+ register_in_connector :rename
4
+
5
+ class Arguments < Command::Arguments
6
+ attr_accessor :target, :name
7
+ validates_presence_of :target, :name
8
+ validates :entry, :is_an_entry => true
9
+ end
10
+
11
+ class Result < Command::Result
12
+ def added
13
+ [arguments.entry]
14
+ end
15
+ def removed
16
+ [arguments.target]
17
+ end
18
+ end
19
+
20
+ protected
21
+ def execute_command
22
+ arguments.entry.update_attributes! :entry_name => arguments.name
23
+ end
24
+ end
25
+ end