diff --git a/lib/wlog/commands/new_entry.rb b/lib/wlog/commands/new_entry.rb index 97a9776..75062dc 100644 --- a/lib/wlog/commands/new_entry.rb +++ b/lib/wlog/commands/new_entry.rb @@ -7,16 +7,17 @@ module Wlog # @author Simon Symeonidis class NewEntry < Commandable - def initialize(desc, issue_id) - @desc, @iid = desc, issue_id - @db = db + def initialize(desc, issue) + @desc, @issue = desc, issue end def execute - log_entry = LogEntry.new(@db) - log_entry.description = @desc - log_entry.issue_id = @iid - log_entry.insert + log_entry = LogEntry.new( + :description => @desc, + :created_at => Time.now, + :updated_at => Time.now) + + @issue.log_entries << log_entry end end end diff --git a/lib/wlog/domain/issue.rb b/lib/wlog/domain/issue.rb index ce4c61c..7df2020 100644 --- a/lib/wlog/domain/issue.rb +++ b/lib/wlog/domain/issue.rb @@ -11,6 +11,8 @@ module Wlog # @author Simon Symeonidis class Issue < ActiveRecord::Base + has_many :log_entries + StatusNew = 0 StatusStarted = 1 StatusFinished = 2 diff --git a/lib/wlog/domain/log_entry.rb b/lib/wlog/domain/log_entry.rb index b5fec43..75a0328 100644 --- a/lib/wlog/domain/log_entry.rb +++ b/lib/wlog/domain/log_entry.rb @@ -21,8 +21,8 @@ class LogEntry < ActiveRecord::Base # Print things nicely formmated no more than 80 cars (well, unless you stick # the time in the end which is not counted for). def to_s - str = "[#{@id}] " - tmp = "#{@description} [#{@date.strftime("%H:%M:%S")}]" + str = "[#{id}] " + tmp = "#{description} [#{created_at.strftime("%H:%M:%S")}]" desc = Helpers.break_string(tmp,80) indent = " " * (id.to_s.split('').count + 5) desc.gsub!(/#{$/}/, "#{$/}#{indent}") diff --git a/lib/wlog/ui/cli_interface.rb b/lib/wlog/ui/cli_interface.rb index 9af24d4..e721c17 100644 --- a/lib/wlog/ui/cli_interface.rb +++ b/lib/wlog/ui/cli_interface.rb @@ -134,6 +134,8 @@ def archive(cmd) end def attach + puts "Migration of implementation pending" and return + issue_id = Readline.readline('Attach to issue id: ').to_i loc = Readline.readline('Absolute file location: ') loc.strip! @@ -167,9 +169,9 @@ def focus(cmd) issue_id = issue_id.to_i end - issue = Issue.find(@db, issue_id) + issue = Issue.find(issue_id) if issue - IssueUi.new(@db, issue).run + IssueUi.new(issue).run else puts "No such issue" end diff --git a/lib/wlog/ui/issue_ui.rb b/lib/wlog/ui/issue_ui.rb index 8bd5e1b..12e62f9 100644 --- a/lib/wlog/ui/issue_ui.rb +++ b/lib/wlog/ui/issue_ui.rb @@ -14,9 +14,8 @@ module Wlog # The interface when focusing on an issue # @author Simon class IssueUi - def initialize(db, issue) + def initialize(issue) @issue = issue - @db = db @strmaker = SysConfig.string_decorator end @@ -88,8 +87,8 @@ def new_entry description = Readline.readline("Enter new issue:#{$/} ") description.chomp! @issue.mark_working! - @issue.update - NewEntry.new(@db, description, @issue.id).execute + @issue.save + NewEntry.new(description, @issue).execute end def delete_entry @@ -120,11 +119,11 @@ def search_term(term) # TODO might need refactoring def show_entries - entries_arr = LogEntry.find_all_by_issue_id(@db, @issue.id) - date_collections = entries_arr.group_by{|le| le.date.strftime("%Y-%m-%d")} + entries_arr = @issue.log_entries + date_collections = entries_arr.group_by{|le| le.created_at.strftime("%Y-%m-%d")} date_collections.each_key do |date_c| print @strmaker.green("#{date_c} - ") - print @strmaker.yellow(date_collections[date_c].first.date.strftime("%A")) + print @strmaker.yellow(date_collections[date_c].first.created_at.strftime("%A")) puts " [#{@strmaker.magenta(date_collections[date_c].count.to_s)}]" date_collections[date_c].each do |le| puts " #{le}"