# Class: FileAreaController

# FileAreaController

The Main Menu master controller.

# Public Instance Methods

### menu ()

FileArea Menu Handler

Show source...

         # File bbs/lib/controllers/filearea.rb, line 58
     58:   def menu
     59:     done = false
     60:     validkeys=['A','D','J','L','N','S','U','V',']','[','X']
     61:     until done == true
     62:
     63:       # Retrieve a list and count of File Areas - This is done each menu loop in the event soemthing changes
     64:       # by an admin during the user's session. Potentially, a change could cause the controller to crash.
     65:       arealist  = $db[:fileareas].select(:id).order(:id).map(:id)
     66:       areacount =  $db[:fileareas].count
     67:
     68:       # Track the user's current area from the session table.
     69:       if $session.filearea.nil? == true
     70:         curarea = arealist.first
     71:         $session.filearea = curarea
     72:         $session.save
     73:       else
     74:         curarea = $session.filearea
     75:       end
     76:       # Set the array iterator index location
     77:       areaindex = arealist.index(curarea)
     78:       # Get area's metadata info
     79:       areameta = $db[:fileareas].where(:id => curarea).first
     80:       # Get a count of total files in this area
     81:       filecount = $db[:files].filter(:tgfilearea_id => $session.filearea).count
     82:
     83:       # Display menu
     84:       key = Tgio::Input.menuprompt('menu_filearea.ftl',validkeys, {"areanum" => areameta[:id].to_s,"areaname" => areameta[:name].capitalize, "areadesc" => areameta[:description], "areacount" => filecount })
     85:       print "\n"
     86:       case key
     87:         when "A" # List all File Area Names/Descriptions
     88:           areas = Tgtemplate::Template.parse_dataset($db[:fileareas].all)
     89:           Tgtemplate.display('filearea_list_areas.ftl', {'areas' => areas})
     90:
     91:         when "D" # Prompt user to download a file by file.id
     92:           Telegard.unimplemented
     93:
     94:         when "J" # Jump to another area
     95:           Tgtemplate.display('filearea_jumpto.ftl', nil)
     96:           jumper = Tgio::Input::inputform(4).to_i
     97:           # Validate input for correctness before switching areas
     98:           if arealist.include?(jumper) == true
     99:             $session.filearea = jumper
    100:             $session.save
    101:           else
    102:             Tgtemplate.display('filearea_jumpto_invalid.ftl', nil)
    103:           end
    104:
    105:         when "L" # List files in current area
    106:           if areameta[:read] == true
    107:             filelist = Tgtemplate::Template.parse_dataset($db[:files].filter(:tgfilearea_id => $session.filearea, :enabled =>true).all)
    108:             Tgtemplate.display('filearea_list_files.ftl', {'files' => filelist, 'areaname' => areameta[:name].capitalize})
    109:           else
    110:             Tgtemplate.display('filearea_read_forbidden.ftl', {'areaname'=>areameta[:name].capitalize})
    111:           end
    112:
    113:         when "N"
    114:           Telegard.unimplemented
    115:
    116:         when "S" # Search for Files
    117:           Telegard.unimplemented
    118:
    119:         when "T" # Tag file for download queue
    120:           Telegard.unimplemented
    121:
    122:         when "U" # Upload a File
    123:           Telegard.unimplemented
    124:
    125:         when "V" # View File Metadata
    126:           filenum = Tgio::Input::inputform(6).to_i
    127:           metaset = $db[:files].where(:id => filenum).first
    128:           unless metaset.nil? == true # Check if result set is valid
    129:             if metaset[:enabled] == true # Only show data if file is enabled
    130:               metaset[:uploaded_by] =  $db[:users].select(:login).where(:id => metaset[:uploaded_by]).first[:login]
    131:               metaset[:approved_by] = $db[:users].select(:login).where(:id => metaset[:approved_by]).first[:login]
    132:               metaset[:owner_id] = $db[:users].select(:login).where(:id => metaset[:owner_id]).first[:login]
    133:               Tgtemplate.display('filearea_file_metadata.ftl', {'file'=> Tgtemplate::Template.parse_hash(metaset)})
    134:             else
    135:               Tgtemplate.display('filearea_file_invalid.ftl',nil)
    136:             end
    137:           else
    138:             Tgtemplate.display('filearea_file_invalid.ftl', nil)
    139:           end
    140:
    141:         when "]" # Next Area
    142:           if areaindex > (areacount - 1)
    143:             $session.filearea = arealist.first
    144:           else
    145:             $session.filearea = arealist.at(areaindex + 1)
    146:           end
    147:           $session.save
    148:
    149:         when "[" # Previous Area
    150:           if areaindex <= 0
    151:             $session.filearea = arealist.last
    152:           else
    153:             $session.filearea = arealist.at(areaindex - 1)
    154:           end
    155:           $session.save
    156:
    157:         when "X"
    158:           return 0
    159:       end #/case
    160:     end #/until
    161:   end