Class: Tempo::Controllers::Update
- Defined in:
- lib/tempo/controllers/update_controller.rb
Class Method Summary collapse
Methods inherited from Base
filter_projects_by_title, fuzzy_match, reassemble_the
Class Method Details
.parse(options, args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tempo/controllers/update_controller.rb', line 11 def parse(, args) reassemble_the args return Views.project_assistance if Model::Project.index.empty? # Load last day, or specific day if options includes an on-date if [:on] day = Time.parse [:on] return Views.no_match_error( "valid timeframe", [:from], false ) if day.nil? @time_records.load_day_record day, else day = @time_records.load_last_day end # Load the last record, or record by id if options includes an id if [:id] record = @time_records.find_by_id( [:id], day ) return Views.no_match_error( "time record on #{day.strftime('%m/%d/%Y')}", "id = #{options[:id]}", false ) if !record else record = @time_records.index.last return Views.no_items( "time records on #{day.strftime('%m/%d/%Y')}", :error ) if ! record end # DELETE and existing record, no need to check for further updates if [:delete] # If only record on the given day, delete the file if Tempo::Model::TimeRecord.ids(record.d_id).length == 1 @time_records.delete_day_record record.d_id, else record.delete @time_records.save_to_file end Views.delete_time_record_view record else # check for flags and update one or all attributes # Update the START time of the record if [:start] start_time = Time.parse [:start] return Views.no_match_error( "valid timeframe", [:at], false ) if start_time.nil? # TODO: add "today " to start time and try again if not valid if record.valid_start_time? start_time record.start_time = start_time else return Views::ViewRecords::Message.new "cannot change start time to #{start_time.strftime('%H:%M')}", category: :error end end # Update the END time of the record if [:end] end_time = Time.parse [:end] return Views.no_match_error( "valid timeframe", [:at], false ) if end_time.nil? # TODO: add "today " to end time and try again if not valid if record.valid_end_time? end_time record.end_time = end_time else return Views::ViewRecords::Message.new "cannot change end time to #{end_time.strftime('%H:%M')}", category: :error end end # Update the PROJECT if [:project] record.project = @projects.current.id end # Update the DESCRIPTION [:description] = reassemble_the args record.description = [:description] if [:description] && ![:description].empty? @time_records.save_to_file Views.update_time_record_view record end end |