class FileTunelFile < ApplicationRecord
  belongs_to :file_tunel
  
  before_create { generate_token() }
  
  def generate_token()
    begin
      self[:token] = SecureRandom.urlsafe_base64
    end while FileTunelFile.exists?(:token => self[:token])
  end
  
  mount_uploader :file, OdrUploader
  
  validates :file, :presence => true
  
  
  
  QI_DYNAMICS = %w()

  eval(QI_DYNAMICS_CORE)
    
  def self.qi_table_order
    {
      :created_at => {:name => "Date", :reorder => true},
      :name => {:name => "Nom", :reorder => true},
      
      :file => {:name => "Fichier", :reorder => true},
      
      :actions => "Actions",
     
    }
    
  end
  
  def self.valid_sort
    r = []
    self.qi_table_order.each do |key, value|
      if value.instance_of? Hash
        if value[:reorder] and value[:reorder] == true
          r << key.to_s if value[:reorder]
        end
      end
    end
    return r
    
    
  end
  
  
end
