Skip to content

Commit

Permalink
log_entries: new, show works.
Browse files Browse the repository at this point in the history
Time is using UTC I think...
  • Loading branch information
psyomn committed Sep 28, 2014
1 parent 0ecae59 commit 173b2a7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
15 changes: 8 additions & 7 deletions lib/wlog/commands/new_entry.rb
Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/wlog/domain/issue.rb
Expand Up @@ -11,6 +11,8 @@ module Wlog
# @author Simon Symeonidis
class Issue < ActiveRecord::Base

has_many :log_entries

StatusNew = 0
StatusStarted = 1
StatusFinished = 2
Expand Down
4 changes: 2 additions & 2 deletions lib/wlog/domain/log_entry.rb
Expand Up @@ -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}")
Expand Down
6 changes: 4 additions & 2 deletions lib/wlog/ui/cli_interface.rb
Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions lib/wlog/ui/issue_ui.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 173b2a7

Please sign in to comment.