Class: Alchemy::Custom::Model::ElFinder::Volumes::AlchemyFile

Inherits:
Base
  • Object
show all
Defined in:
lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb

Direct Known Subclasses

AlchemyFiles, AlchemyImages, ComponentAttribute

Instance Attribute Summary

Attributes inherited from Base

#id, #name, #root, #url

Instance Method Summary collapse

Methods inherited from Base

#contains?, #disabled_commands, #encode

Methods included from TranslationScope

#acm_t

Constructor Details

#initialize(options = {root: '/alchemy_library', name: 'Alchemy Library', id: 'alchemy_library', url: '/'}) ⇒ AlchemyFile

Returns a new instance of AlchemyFile.



5
6
7
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 5

def initialize(options = {root: '/alchemy_library', name: 'Alchemy Library', id: 'alchemy_library', url: '/'})
  super
end

Instance Method Details

#copy(src) ⇒ ElFinder::Paths::Base

Copia un file di alchemy in questo volume

Parameters:

Returns:



144
145
146
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 144

def copy(src)
  raise 'Non si può copiare nella cartella di alchemy'
end

#cwd(target = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 10

def cwd(target = nil)

  target = Paths::Root.new(@root) if target.nil?

  Rails.logger.debug {"CWD:#{target.inspect} "}
  path_info(target)

end

#decode(hash) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 19

def decode(hash)
  super do |path|
    case path.to_s
    when 'images'
      Paths::Images.new(@root, path, volume: self)
    when 'files'
      Paths::Files.new(@root, path, volume: self)
    when /images\/*/
      Paths::Image.new(@root, path, volume: self)
    when /files\/*/
      Paths::File.new(@root, path, volume: self)
    when @root, '.'
      Paths::Root.new(@root, path, volume: self)
    else
      Rails.logger.debug {"PATH BASE:#{path}"}
      if block_given?
        Rails.logger.debug {"YIELDING:#{self.class.name}"}
        yield(path)
      else
        Paths::Base.new(@root, path, volume: self)
      end
    end
  end
end

#duplicable?(target) ⇒ Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 167

def duplicable?(target)
  false
end

#files(target = '.') ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 87

def files(target = '.')
  Rails.logger.debug {"FILES PER : #{target.inspect}"}
  unless target.is_a?(Paths::Base)
    if target == '.'
      target = Paths::Root.new(@root, '.', volume: self)
    else
      Rails.logger.debug {target.inspect}
      target = PathName.new(@root, target)
    end
  end

  #Elenco tutte le cartelle
  files = target.children.map {|p| path_info(p)}

  #inserisco sempre anche il padre delle cartelle
  files << cwd(target)
  files
end

#path_info(target) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 44

def path_info(target)
  is_dir = target.directory?
  mime = target.mime_type
  name = @name if target.is_root?
  name ||= target.name

  dirs = 0
  if is_dir
    # check if has sub directories
    dirs = 1 if target.with_sub_dirs?
  end

  size = 0
  unless is_dir
    size = target.size
  end

  result = {
      name: name,
      hash: encode(target.path.to_s),
      mime: mime,
      ts: target.mtime.to_i,
      size: size,
      dirs: dirs,
      read: 1,
      write: 1,
      locked: 0,
      class: target.class.name,
      tmb: nil,
      global_id: target.global_id
  }

  result = target.full_fill_paylod(result)

  if target.is_root?
    result[:volumeid] = "#{@id}_"
  else
    result[:phash] = encode(target.dirname.path.to_s)
  end

  result
end

#pathname(target) ⇒ Object



106
107
108
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 106

def pathname(target)
  target.fisical_path
end

#rm(target) ⇒ Object



159
160
161
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 159

def rm(target)
  raise "To Implement"
end

#search(type:, q:) ⇒ Object

Ricerca nel volume

Parameters:

  • type (String)

    tipo di ricerca

  • q (String)

    query di ricerca



152
153
154
155
156
157
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 152

def search(type:, q:)
  query_search = yield
  query_search.uniq.collect do |p|
    path_info(root_path.build_file_path(p))
  end
end

#upload(target, upload) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 110

def upload(target, upload)
  response = {}
  select = []
  added = []
  upload.to_a.each do |file|
    if file.respond_to?(:tempfile)
      the_file = file.tempfile
    else
      the_file = file
    end
    if upload_max_size_in_bytes > 0 && File.size(the_file.path) > upload_max_size_in_bytes
      response[:error] ||= "Some files were not uploaded"
      response[:errorData][@options[:original_filename_method].call(file)] = 'File exceeds the maximum allowed filesize'
    else

      dst = yield(file)

      select << encode(dst)
      added << path_info(dst)
    end
  end
  response[:select] = select unless select.empty?
  response[:added] = added unless added.empty?


  response
end

#upload_max_size_in_bytesObject



163
164
165
# File 'lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb', line 163

def upload_max_size_in_bytes
  999999999
end