Skip to content

Commit

Permalink
got it all working pretty well :)
Browse files Browse the repository at this point in the history
  • Loading branch information
remi committed Oct 9, 2008
1 parent 20dd237 commit 211bf3f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
57 changes: 57 additions & 0 deletions gui.rb
@@ -0,0 +1,57 @@
#! /usr/bin/env ruby
require File.dirname(__FILE__) + '/lib/timetray'

# ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:' # memory for now, for testing
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => DB_PATH
unless File.file?DB_PATH
CreateTimeTrayDB.verbose = false
CreateTimeTrayDB.migrate :up
end

SimpleTray.icon_directory = File.join File.dirname(__FILE__), 'icons'
SimpleTray.app 'TODO' do

TimeTray.current_tasks.each do |task|
menu "#{task.name} (#{time_ago_in_words task.current_log.started_at})" do
stop { task.stop! }
end
end
item('No Current Tasks'){} if TimeTray.current_tasks.empty?
____

TimeTray.projects.each do |project|
menu project.name do
for task in project.tasks
menu "#{ task }#{ (task.logs.empty?) ? '' : " (#{task.logs.count})" }" do
item (task.active? ? 'Stop' : 'Start') do
if task.active?
task.stop!
else
task.start!
end
end
unless task.logs.empty?
____
task.logs.each do |log|
if log.active?
item("started #{time_ago_in_words(log.started_at)} ago"){}
else
item(relative_time_span([log.started_at, log.stopped_at])){}
end
end
end
end
end
____ unless project.tasks.empty?
new_task { project.tasks.create :name => prompt("New Task Name") }
end
end

____ unless TimeTray.projects.empty?
item 'New Project' do
Project.create :name => prompt('New Project Name')
end

____
exit
end
9 changes: 9 additions & 0 deletions lib/timetray/project.rb
Expand Up @@ -13,4 +13,13 @@ def current_tasks
tasks.reload
tasks.select &:active?
end

def duration
tasks.inject(0) {|total,task| total += task.duration }
end
alias total_time duration

def to_s
name
end
end
6 changes: 4 additions & 2 deletions lib/timetray/task.rb
Expand Up @@ -19,9 +19,11 @@ def duration
end
alias total_time duration

protected

def current_log
logs.select {|l| l.active? }.first # grab first one that's active
end

def to_s
name
end
end
13 changes: 0 additions & 13 deletions timetray-test.rb

This file was deleted.

0 comments on commit 211bf3f

Please sign in to comment.