Class: Alchemy::Custom::Model::ElFinder::Volumes::ComponentAttribute
- Inherits:
-
AlchemyFile
- Object
- Base
- AlchemyFile
- Alchemy::Custom::Model::ElFinder::Volumes::ComponentAttribute
- Defined in:
- lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#file_link_ref ⇒ Object
Returns the value of attribute file_link_ref.
-
#record ⇒ Object
Returns the value of attribute record.
-
#tags ⇒ Object
Returns the value of attribute tags.
Attributes inherited from Base
Instance Method Summary collapse
- #attribute_class ⇒ Object
- #copy(src) ⇒ Object
- #decode(hash) ⇒ Object
- #duplicable?(target) ⇒ Boolean
- #duplicate(t) ⇒ Object
- #files(target = '.') ⇒ Object
-
#initialize(opts = {}) ⇒ ComponentAttribute
constructor
Elenco opzioni da utilizzare per la configurazione - attribute = relazione dell'oggetto a cui si riferisce il collegamento del volume (la join table per esempio) - object = oggetto identificato con un global_id signed - file_link_ref = rispetto ad un'istanza della relazione come fare a trovare il valore del record alchemy(Picture o Attachment), nel caso avessimo più metodi da chiamare possiamo spezzarlo con il .
-
#remote_alchemy_relation ⇒ Object
Indica l'oggetto finale a cui viene legata la join table del componente.
-
#rm(target) ⇒ Object
Nel caso del componente, rm vuol dire dissociare il target elementi.
- #root_path ⇒ Object
- #search(type:, q:) ⇒ Object
- #upload(target, upload) ⇒ Object
Methods inherited from AlchemyFile
#cwd, #path_info, #pathname, #upload_max_size_in_bytes
Methods inherited from Base
#contains?, #cwd, #disabled_commands, #encode, #pathname
Methods included from TranslationScope
Constructor Details
#initialize(opts = {}) ⇒ ComponentAttribute
Elenco opzioni da utilizzare per la configurazione
- attribute = relazione dell'oggetto a cui si riferisce il collegamento del volume (la join table per esempio)
- object = oggetto identificato con un global_id signed
- file_link_ref = rispetto ad un'istanza della relazione come fare a trovare il valore del record alchemy(Picture o Attachment),
nel caso avessimo più metodi da chiamare possiamo spezzarlo con il . fra un metodo e l'altro
il programma dovrà spezzare per il . e usare dig per chiamare i valori definitivi
- tags = Array di stringhe per i tag da associare direttamente ai files caricati
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 15 def initialize(opts = {}) self.record = GlobalID::Locator.locate_signed opts.delete(:object) self.attribute = opts.delete(:attribute) self.file_link_ref = opts.delete(:file_link_ref) self. = opts.delete(:tags) {[]} identificativo_volume = "component_#{self.attribute}" #"_#{record.id}" # identificativo_volume='test_semplice_nome' # unless self.record.send(self.attribute).klass.new.respond_to?(:alchemy_file_instance) # raise "Attenzione, non è stata impostata la relazione per collegare la join table con l'elemento il record di alchemy [:alchemy_file_instance]" # end super({root: "/#{identificativo_volume}", name: 'Elementi associati', id: "#{identificativo_volume}", url: '/'}) end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
5 6 7 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 5 def attribute @attribute end |
#file_link_ref ⇒ Object
Returns the value of attribute file_link_ref.
5 6 7 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 5 def file_link_ref @file_link_ref end |
#record ⇒ Object
Returns the value of attribute record.
5 6 7 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 5 def record @record end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 5 def @tags end |
Instance Method Details
#attribute_class ⇒ Object
79 80 81 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 79 def attribute_class self.record.send(self.attribute).klass end |
#copy(src) ⇒ Object
41 42 43 44 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 41 def copy(src) new_rec = associate_record_to_active_instance(src.active_record_instance) root_path.build_file_path(new_rec) end |
#decode(hash) ⇒ Object
46 47 48 49 50 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 46 def decode(hash) super do |path| Paths::ComponentFile.new(@root, path, volume: self) end end |
#duplicable?(target) ⇒ Boolean
110 111 112 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 110 def duplicable?(target) remote_alchemy_relation == ::Alchemy::Picture end |
#duplicate(t) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 94 def duplicate(t) new_path = Rails.root.join('tmp', "copy_#{File.basename(t.name)}") ::FileUtils.cp(t.file.path, new_path) img = ::Alchemy::Picture.new( image_file: new_path ) img.name = img.humanized_name img.save new_rec = associate_record_to_active_instance(img) root_path.build_file_path(new_rec) end |
#files(target = '.') ⇒ Object
33 34 35 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 33 def files(target = '.') super(root_path) end |
#remote_alchemy_relation ⇒ Object
Indica l'oggetto finale a cui viene legata la join table del componente
75 76 77 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 75 def remote_alchemy_relation attribute_class.reflect_on_association(:alchemy_file_instance).klass end |
#rm(target) ⇒ Object
Nel caso del componente, rm vuol dire dissociare il target elementi
116 117 118 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 116 def rm(target) target.active_record_instance.destroy end |
#root_path ⇒ Object
37 38 39 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 37 def root_path Paths::ComponentFiles.new(@root, '.', volume: self) end |
#search(type:, q:) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 83 def search(type:, q:) query_search = search_query_build(klass: remote_alchemy_relation, type: type, q: q, mime_attribute: :image_file_format) self.record.send(self.attribute).joins(:alchemy_file_instance).merge(query_search).uniq.collect do |p| path_info(root_path.build_file_path(p)) end end |
#upload(target, upload) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb', line 52 def upload(target, upload) super do |file| if remote_alchemy_relation == ::Alchemy::Picture img = ::Alchemy::Picture.new( image_file: file ) img.name = img.humanized_name img.save #lego l'immagine ora al prodotto new_rec = associate_record_to_active_instance(img) root_path.build_file_path(new_rec) else raise "TO override" end end end |