class AdminFilesManage
AdminFilesManage
offers an interface to add files to the files.profeda.org site. Files
are stored in a two-level structure: first os, then categories. A possible structure is as follows: Windows/Antivirus Windows/Office Mac/Office Mac/Utils Each file in the directory is accompanied by a .file that holds information about it like description, URL, tags.
Attributes
files_dir[RW]
Public Instance Methods
empty_fields(lvl)
click to toggle source
# File Views/Admin/FilesManage.rb, line 189 def empty_fields(lvl) rep = %w(name url_file url_page description tags) if lvl > 0 rep.push :files_stored end if lvl > 1 rep.push :dirs_type end if lvl > 2 rep.push :dirs_os end reply(:empty, rep) end
get_file(data)
click to toggle source
# File Views/Admin/FilesManage.rb, line 203 def get_file(data) unless data._dirs_type.length > 0 && data._dirs_os.length > 0 && data._files_stored.length > 0 return nil end dir = FMDirs.search_by_path(data._dirs_type.first, data._dirs_os.first) FMEntries.search_by_name(data._files_stored.first).find { |e| e._directory == dir } end
in_file() { |f| ... }
click to toggle source
# File Views/Admin/FilesManage.rb, line 214 def in_file %w(name url_file url_page description tags).each { |f| yield f } end
layout()
click to toggle source
# File Views/Admin/FilesManage.rb, line 14 def layout @order = 50 @update = true @functions_need = [:files_manage] @files_dir = '/opt/Files' gui_vbox do gui_hboxg :nogroup do gui_vbox :nogroup do gui_vbox :nogroup do show_list_single :dirs_os, callback: true, flexheight: 1 show_button :dirs_os_add, :dirs_os_del end gui_vbox :nogroup do show_list_single :dirs_type, callback: true, flexheight: 1 end end gui_vbox :nogroup do show_list_single :files_stored, '[]', callback: true, flexheight: 1 show_button :file_del end gui_vbox :nogroup do show_str_ro :name, width: 300 show_str_ro :url_file show_str :url_page show_str :description show_str :tags show_button :file_save, :file_rename end gui_window :win_chose do show_list :win_list show_button :win_add_os end gui_window :win_rename do show_str :new_name, width: 300 show_button :rename_ok, :cancel end gui_window :win_update do show_html :update_txt show_button :update_ok end end gui_vbox :nogroup do show_button :files_search, :files_update end end end
list_dirs(base)
click to toggle source
# File Views/Admin/FilesManage.rb, line 68 def list_dirs(base) Dir.glob("#{base}/*").collect { |d| d.gsub(/^#{base}\//, '') }.sort end
rpc_list_choice_dirs_os(session, data)
click to toggle source
# File Views/Admin/FilesManage.rb, line 164 def rpc_list_choice_dirs_os(session, data) return [] unless data._dirs_os.length > 0 dir = data._dirs_os.first dirs = FMDirs.sub_dirs(dir).map { |f| f._name }.sort empty_fields(2) + reply(:update, dirs_type: dirs) end
rpc_list_choice_dirs_type(session, data)
click to toggle source
# File Views/Admin/FilesManage.rb, line 172 def rpc_list_choice_dirs_type(session, data) return [] unless data._dirs_type.length > 0 dir = FMDirs.search_by_path(data._dirs_type.first, data._dirs_os.first) entries = FMEntries.search_by_directory(dir) empty_fields(1) + reply(:update, files_stored: entries.map { |e| e._name }.sort) end
rpc_list_choice_files_stored(session, data)
click to toggle source
# File Views/Admin/FilesManage.rb, line 180 def rpc_list_choice_files_stored(session, data) file = get_file(data) fields = {} in_file { |f| fields[f] = file.data_get(f) } fields._tags = fields._tags.join(', ') empty_fields(0) + reply(:update, fields) end
rpc_update(session)
click to toggle source
# File Views/Admin/FilesManage.rb, line 158 def rpc_update(session) empty_fields(3) + reply(:update, dirs_os: FMDirs.base_dirs.map { |f| f._name }.sort) end