rtt 0.0.0.47 → 0.0.0.48

Sign up to get free protection for your applications and to get access to all the features.
data/db/rtt.sqlite3 DELETED
Binary file
data/lib/rtt/client.rb DELETED
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env ruby
2
- module Rtt
3
- class Client
4
- include DataMapper::Resource
5
-
6
- DEFAULT_NAME = 'default'
7
- DEFAULT_DESCRIPTION = 'Default Client'
8
-
9
- property :id, Serial
10
- property :name, String, :required => true, :unique => true, :default => DEFAULT_NAME
11
- property :description, String, :default => DEFAULT_DESCRIPTION
12
- property :active, Boolean, :default => false
13
- has n, :projects #, :through => Resource
14
-
15
- before :create do |client|
16
- client.active = true if Client.all.length == 0
17
- true
18
- end
19
-
20
- def self.default
21
- first_or_create :active => true
22
- end
23
-
24
- def self.current_active?
25
- first :active => true
26
- end
27
-
28
- def activate
29
- deactivate_all
30
- self.active = true
31
- self.save
32
- self
33
- end
34
-
35
- def deactivate_all
36
- Client.all.each do |client|
37
- client.active = false
38
- client.save
39
- end
40
- end
41
- end
42
- end
data/lib/rtt/project.rb DELETED
@@ -1,54 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- module Rtt
3
- class Project
4
- include DataMapper::Resource
5
-
6
- DEFAULT_NAME = 'default'
7
- DEFAULT_DESCRIPTION = 'Default Project'
8
-
9
- property :id, Serial
10
- property :name, String, :required => true, :unique => true, :default => DEFAULT_NAME
11
- property :description, String, :default => DEFAULT_DESCRIPTION
12
- property :active, Boolean, :default => false
13
- property :rate, Float
14
-
15
- has n, :tasks #, :through => Resource
16
- has n, :users, :through => :tasks
17
- belongs_to :client
18
-
19
- before :valid?, :set_default_client
20
-
21
- before :create do |project|
22
- project.active = true if Project.all.length == 0
23
- true
24
- end
25
-
26
- def self.default
27
- first_or_create :active => true
28
- end
29
-
30
- def self.current_active?
31
- first :active => true
32
- end
33
-
34
- def activate
35
- deactivate_all
36
- self.active = true
37
- self.save
38
- self
39
- end
40
-
41
- def deactivate_all
42
- Project.all.each do |project|
43
- if project.id != self.id
44
- project.active = false
45
- project.save
46
- end
47
- end
48
- end
49
-
50
- def set_default_client
51
- self.client = Client.default if self.client.nil?
52
- end
53
- end
54
- end
data/lib/rtt/task.rb DELETED
@@ -1,144 +0,0 @@
1
- #!/usr/bin/env ruby
2
- module Rtt
3
- class Task
4
- include DataMapper::Resource
5
-
6
- DEFAULT_NAME = 'Default task'
7
-
8
- property :id, Serial
9
- property :name, Text, :required => true, :default => DEFAULT_NAME
10
- property :date, Date
11
- property :start_at, DateTime
12
- property :end_at, DateTime
13
- property :active, Boolean, :default => false
14
- property :accumulated_spent_time, Float, :default => 0
15
- property :rate, Float, :default => 0
16
-
17
- belongs_to :project
18
- has 1, :client, :through => :project
19
- belongs_to :user
20
-
21
- before :valid?, :set_default_project
22
- before :valid?, :set_default_user
23
-
24
- def self.task(task_name)
25
- base_attributes = { :name => task_name, :user => Rtt.current_user, :date => Date.today, :rate => (Rtt.current_project.rate if Rtt.current_project.present?) }
26
- if task_name.nil?
27
- existing_task = Task.first :active => true
28
- if existing_task
29
- existing_task
30
- else
31
- base_attributes.merge!(:name => DEFAULT_NAME) if task_name.blank?
32
- Task.create(base_attributes)
33
- end
34
- elsif (existing_task = Task.first base_attributes.merge({:start_at.gte => Date.today.beginning_of_day})).present?
35
- existing_task
36
- else
37
- Task.create(base_attributes)
38
- end
39
- end
40
-
41
- def start
42
- self.start_at = DateTime.now
43
- self.active = true
44
- save
45
- self
46
- end
47
-
48
- def add_current_spent_time_to_accumulated_spent_time
49
- self.accumulated_spent_time = self.accumulated_spent_time + self.time_difference_since_start_at
50
- end
51
-
52
- def clone_task(task)
53
- task = Task.new
54
- task.attributes = self.attributes
55
- task.id = nil
56
- task
57
- end
58
-
59
- def duration
60
- return '-' if end_at.blank?
61
- convert_to_hour_and_minutes(accumulated_spent_time)
62
- end
63
-
64
- def duration=(d)
65
- return unless !!/^(\d{1,2})[hH]{1,2}(\d{1,2})[mM]{1,2}$/.match(d)
66
- self.start_at = DateTime.parse('00:00:01', self.date)
67
- self.end_at = DateTime.parse('00:00:01', self.date).advance(:hours => $1.to_i, :minutes => $2.to_i, :seconds => 1)
68
- self.accumulated_spent_time = self.time_difference_since_start_at
69
- end
70
-
71
- def set_default_project
72
- self.project = Project.default if self.project.nil?
73
- end
74
-
75
- def set_default_user
76
- self.user = User.default if self.user.nil?
77
- end
78
-
79
- def stop
80
- split_task if span_multiple_days?
81
- finish
82
- self
83
- end
84
-
85
- def pause
86
- split_task if span_multiple_days?
87
- finish(DateTime.now, true)
88
- self
89
- end
90
-
91
- def time_difference_since_start_at
92
- end_date_or_now = self.end_at ? self.end_at : DateTime.now
93
- end_date_or_now - self.start_at
94
- end
95
-
96
- private
97
-
98
- def convert_to_hour_and_minutes(dif)
99
- hours, mins = time_diff_in_hours_and_minutes(dif)
100
- "#{hours}h#{mins}m"
101
- end
102
-
103
- def finish(end_at = DateTime.now, activation = false)
104
- self.end_at = end_at
105
- self.date = end_at.to_date
106
- self.add_current_spent_time_to_accumulated_spent_time
107
- self.active = activation
108
- self.save
109
- end
110
-
111
- def save_in_between_days_split(date)
112
- task = clone_task(self)
113
- task.start_at = date.beginning_of_day
114
- end_at = date.end_of_day.to_datetime
115
- task.send(:finish, end_at)
116
- task.save
117
- end
118
-
119
- def save_last_task_split(date)
120
- task = clone_task(self)
121
- end_at = date.end_of_day.to_datetime
122
- task.send(:finish, end_at)
123
- task.save
124
- end
125
-
126
- def span_multiple_days?
127
- self.start_at.day != Date.today.day
128
- end
129
-
130
- def split_task
131
- date = Date.today - 1
132
- while (date > self.start_at)
133
- save_in_between_days_split(date)
134
- date -= 1
135
- end
136
- save_last_task_split(date)
137
- self.start_at = Date.today.beginning_of_day.to_datetime
138
- end
139
-
140
- def time_diff_in_hours_and_minutes(dif)
141
- Date::day_fraction_to_time(dif)
142
- end
143
- end
144
- end
data/lib/rtt/user.rb DELETED
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env ruby
2
- module Rtt
3
- class User
4
- include DataMapper::Resource
5
-
6
- BLANK_FIELD = ''
7
- DEFAULT_NICK = 'Default user'
8
-
9
- property :id, Serial
10
- property :nickname, String, :required => true, :unique => true, :default => DEFAULT_NICK
11
- property :first_name, String, :default => BLANK_FIELD
12
- property :last_name, String, :default => BLANK_FIELD
13
- property :company, String, :default => BLANK_FIELD
14
- property :address, String, :default => BLANK_FIELD
15
- property :city, String, :default => BLANK_FIELD
16
- property :country, String, :default => BLANK_FIELD
17
- property :email, String, :default => BLANK_FIELD
18
- property :phone, String, :default => BLANK_FIELD
19
- property :zip, String, :default => BLANK_FIELD
20
- property :site, String, :default => BLANK_FIELD
21
- property :active, Boolean, :default => false
22
-
23
- has n, :tasks #, :through => Resource
24
- has n, :projects, :through => :tasks
25
-
26
- def self.default
27
- first_or_create :active => true
28
- end
29
-
30
- def self.find_or_create_active
31
- last_user = User.last
32
- if last_user.present?
33
- last_user.active = true
34
- last_user.save
35
- last_user
36
- else
37
- self.default
38
- end
39
- end
40
-
41
- def activate
42
- self.active = true
43
- self.save
44
- self
45
- end
46
-
47
- def deactivate
48
- self.active = false
49
- self.save
50
- self
51
- end
52
-
53
- def full_name
54
- "#{first_name.present? ? first_name : ''} #{last_name.present? ? last_name : ''}".strip
55
- end
56
-
57
- def full_name_and_nickname
58
- "#{full_name.present? ? full_name : ''} #{full_name.present? ? "(#{nickname})" : nickname }".strip
59
- end
60
-
61
- def location
62
- "#{self.city}#{self.city.present? && self.country.present? ? ', ' : ''}#{self.country}".strip
63
- end
64
- end
65
- end
data/log/rtt.sqlite3 DELETED
File without changes
@@ -1,3 +0,0 @@
1
- require 'rubygems'
2
- require 'spec'
3
- require 'lib/rtt'