Skip to content
Browse files

got it all working pretty well :)

  • Loading branch information...
1 parent 20dd237 commit 211bf3fd252ce9f5dc82d6c9024f02f85abe4f1a @remi committed Oct 9, 2008
Showing with 70 additions and 15 deletions.
  1. +57 −0 gui.rb
  2. +9 −0 lib/timetray/project.rb
  3. +4 −2 lib/timetray/task.rb
  4. +0 −13 timetray-test.rb
View
57 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
View
9 lib/timetray/project.rb
@@ -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
View
6 lib/timetray/task.rb
@@ -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
View
13 timetray-test.rb
@@ -1,13 +0,0 @@
-#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/lib/timetray'
-
-SimpleTray.icon_directory = File.join File.dirname(__FILE__), 'icons'
-SimpleTray.app 'TODO' do
-
- click_me do
- name = prompt 'Enter Name'
- msgbox "Your name is #{name}"
- end
- ____
- exit
-end

0 comments on commit 211bf3f

Please sign in to comment.
Something went wrong with that request. Please try again.