# Brett Bates class GTDNote attr_accessor :comm_list, :gtd def initialize(comm_list, gtd) @comm_list = comm_list @gtd = gtd end # Find the command to run def command_switch case @comm_list[1].downcase when "add" return comm_add when "bucket" # Move note to bucket when "delete" # Delete note when "get" # Get note when "list" # List all Notes when "priority" # Set the priority when "search" # Find note when "share" # Share the note with others (groups for example) when "sort" # Sort the list else return false, "No such command #{@comm_list[2]}" end end def comm_list end def comm_sort end # Add a note def comm_add begin check_user_dir(File.join(@gtd.conf['root'], @gtd.vars['user'])) nid = get_last_nid['value'].next note_file_name = File.join(@gtd.conf['root'], @gtd.vars['user'], 'note' + nid + '.txt') # TODO: Needs to ensure that the note isn't on the server either if File.exist?(note_file_name) @gtd.send_answer(false, "Note: #{note_file_name} already exists") end note_file = File.open(note_file_name, 'w+') # Write all the "excess" arguments to the note-file for i in 2..@comm_list.length do if @comm_list[i] note_file.puts(@comm_list[i]) end end note_file.close # Add file to server @gtd.p4.run_add(note_file_name) @gtd.p4.run_submit('-d', "Adding note: #{note_file_name} For user: #{@gtd.conf['user']}") @gtd.p4.run_counter('gtd', nid) rescue P4Exception File.delete(note_file_name) @gtd.send_fail rescue Exception => msg File.delete(note_file_name) @gtd.send_answer(false, msg) end @gtd.send_debug(true, "Filessucces") return true, "File successfulllly added" end def comm_delete end def comm_search end def comm_bucket end def comm_priority end # p4 counter gtd def get_last_nid begin return @gtd.p4.run_counter('gtd')[0] rescue P4Exception @gtd.send_answer(false, "Errors: " + @gtd.p4.errors.join('|') + " Warnings: " + @gtd.p4.warnings.join('|')) end end # Ensure a directory exists, if not create it # Dir: Directory to check against def check_user_dir(dir) if !File.directory?(dir) Dir::mkdir(dir) end end def run bool, msg = command_switch return bool, msg end end