punchcard 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile.lock +11 -1
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/db/migrate/03_add_minutes_to_punches.rb +12 -0
- data/lib/public/js/app.js +2 -2
- data/lib/punchcard/person.rb +1 -1
- data/lib/punchcard/punch.rb +16 -4
- data/lib/punchcard.rb +1 -1
- data/punchcard.gemspec +6 -3
- data/test/test_database.rb +12 -8
- metadata +17 -4
- data/config.ru +0 -11
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
punchcard (0.2.
|
4
|
+
punchcard (0.2.5)
|
5
5
|
activerecord (~> 3.0.0)
|
6
6
|
bson_ext
|
7
7
|
gravtastic
|
@@ -27,13 +27,22 @@ GEM
|
|
27
27
|
builder (2.1.2)
|
28
28
|
ffi (1.0.1)
|
29
29
|
rake (>= 0.8.7)
|
30
|
+
gemcutter (0.6.1)
|
31
|
+
git (1.2.5)
|
30
32
|
gravtastic (3.1.0)
|
31
33
|
haml (3.0.24)
|
32
34
|
i18n (0.5.0)
|
35
|
+
jeweler (1.4.0)
|
36
|
+
gemcutter (>= 0.1.0)
|
37
|
+
git (>= 1.2.5)
|
38
|
+
rubyforge (>= 2.0.0)
|
39
|
+
json_pure (1.4.6)
|
33
40
|
rack (1.2.1)
|
34
41
|
rack-test (0.5.6)
|
35
42
|
rack (>= 1.0)
|
36
43
|
rake (0.8.7)
|
44
|
+
rubyforge (2.0.4)
|
45
|
+
json_pure (>= 1.1.7)
|
37
46
|
sass (3.1.0.alpha.200)
|
38
47
|
shoulda (2.10.3)
|
39
48
|
sinatra (1.1.0)
|
@@ -53,6 +62,7 @@ DEPENDENCIES
|
|
53
62
|
bson_ext
|
54
63
|
gravtastic
|
55
64
|
haml (>= 3.0.24)
|
65
|
+
jeweler
|
56
66
|
punchcard!
|
57
67
|
rack-test (>= 0.5.6)
|
58
68
|
sass (>= 3.0.0)
|
data/Rakefile
CHANGED
@@ -20,6 +20,7 @@ begin
|
|
20
20
|
gem.add_development_dependency "rack-test", ">= 0.5.6"
|
21
21
|
gem.add_development_dependency 'sqlite3', '>= 0'
|
22
22
|
gem.add_development_dependency 'timecop', '>= 0'
|
23
|
+
gem.add_development_dependency 'jeweler', '>= 0'
|
23
24
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
24
25
|
end
|
25
26
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/lib/public/js/app.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
function update_status() {
|
3
3
|
var in_office = [];
|
4
4
|
$.getJSON('/status.json', function(json) {
|
5
|
-
$.each(json, function(index, person) {
|
5
|
+
$.each(json.people, function(index, person) {
|
6
6
|
update_person(person);
|
7
7
|
});
|
8
8
|
});
|
@@ -35,7 +35,7 @@ function update_title() {
|
|
35
35
|
$(document).ready(function() {
|
36
36
|
$( "#personTemplate" ).template( "personTemplate" );
|
37
37
|
|
38
|
-
$('#people li').live('
|
38
|
+
$('#people li').live('click', function() {
|
39
39
|
user_id = $(this).attr('id');
|
40
40
|
$.post('/punch/' + user_id, function(data) {
|
41
41
|
//$('.result').html(data);
|
data/lib/punchcard/person.rb
CHANGED
@@ -18,7 +18,7 @@ class Person < ActiveRecord::Base
|
|
18
18
|
if punch = pending?
|
19
19
|
punch.punch_out!
|
20
20
|
else
|
21
|
-
if recently_finished = punches.finished.first and recently_finished.checked_out_at > 30.minutes.ago
|
21
|
+
if recently_finished = punches.finished.first and recently_finished.checked_out_at.utc > 30.minutes.ago.utc
|
22
22
|
recently_finished.reopen!
|
23
23
|
else
|
24
24
|
punches.create!
|
data/lib/punchcard/punch.rb
CHANGED
@@ -7,7 +7,8 @@ class Punch < ActiveRecord::Base
|
|
7
7
|
scope :finished, where("checked_in_at IS NOT NULL AND checked_out_at IS NOT NULL").order('checked_out_at DESC')
|
8
8
|
|
9
9
|
before_validation do |p|
|
10
|
-
p.checked_in_at ||= Time.now
|
10
|
+
p.checked_in_at ||= Time.now.utc
|
11
|
+
p.minutes = p.difference_in_minutes
|
11
12
|
end
|
12
13
|
|
13
14
|
validate do |p|
|
@@ -21,14 +22,25 @@ class Punch < ActiveRecord::Base
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
25
|
+
# Return database-saved minutes when already checked out, otherwise calculate based upon time now
|
26
|
+
def minutes
|
27
|
+
checked_out_at.present? ? self["minutes"] : difference_in_minutes
|
28
|
+
end
|
29
|
+
|
30
|
+
# Calculates the difference between checkin and checkout or time now when pending in minutes
|
31
|
+
def difference_in_minutes
|
32
|
+
base = checked_out_at.present? ? checked_out_at.utc : Time.now.utc
|
33
|
+
((base - checked_in_at.utc) / 60).round
|
34
|
+
end
|
35
|
+
|
24
36
|
# Punches this punch out when pending
|
25
37
|
def punch_out!
|
26
38
|
return false if checked_out_at.present?
|
27
39
|
# Make sure no one stays the night...
|
28
|
-
if self.checked_in_at.
|
29
|
-
self.checked_out_at = self.checked_in_at.end_of_day
|
40
|
+
if self.checked_in_at.utc < Time.now.utc.beginning_of_day
|
41
|
+
self.checked_out_at = self.checked_in_at.utc.end_of_day
|
30
42
|
else
|
31
|
-
self.checked_out_at = Time.now
|
43
|
+
self.checked_out_at = Time.now.utc
|
32
44
|
end
|
33
45
|
save!
|
34
46
|
self
|
data/lib/punchcard.rb
CHANGED
data/punchcard.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{punchcard}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Christoph Olszowka"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-10}
|
13
13
|
s.description = %q{Simple sinatra/activerecord based app for tracking time when people have been in the office}
|
14
14
|
s.email = %q{christoph at olszowka de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |s|
|
|
25
25
|
"README.rdoc",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
|
-
"config.ru",
|
29
28
|
"lib/db/migrate/01_create_people.rb",
|
30
29
|
"lib/db/migrate/02_create_punches.rb",
|
30
|
+
"lib/db/migrate/03_add_minutes_to_punches.rb",
|
31
31
|
"lib/public/cardbg.png",
|
32
32
|
"lib/public/css/blueprint.css",
|
33
33
|
"lib/public/js/app.js",
|
@@ -70,6 +70,7 @@ Gem::Specification.new do |s|
|
|
70
70
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.6"])
|
71
71
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
72
72
|
s.add_development_dependency(%q<timecop>, [">= 0"])
|
73
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
73
74
|
else
|
74
75
|
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
75
76
|
s.add_dependency(%q<bson_ext>, [">= 0"])
|
@@ -81,6 +82,7 @@ Gem::Specification.new do |s|
|
|
81
82
|
s.add_dependency(%q<rack-test>, [">= 0.5.6"])
|
82
83
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
83
84
|
s.add_dependency(%q<timecop>, [">= 0"])
|
85
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
84
86
|
end
|
85
87
|
else
|
86
88
|
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
@@ -93,6 +95,7 @@ Gem::Specification.new do |s|
|
|
93
95
|
s.add_dependency(%q<rack-test>, [">= 0.5.6"])
|
94
96
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
95
97
|
s.add_dependency(%q<timecop>, [">= 0"])
|
98
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
data/test/test_database.rb
CHANGED
@@ -25,9 +25,6 @@ class TestDatabase < Test::Unit::TestCase
|
|
25
25
|
setup do
|
26
26
|
Timecop.freeze(2.hours.ago) do
|
27
27
|
assert @person.punch!.instance_of?(Punch), "Should have been able to get punched and have returned a Punch"
|
28
|
-
punch = @person.pending?
|
29
|
-
punch.checked_in_at = 2.hours.ago
|
30
|
-
punch.save!
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
@@ -43,6 +40,10 @@ class TestDatabase < Test::Unit::TestCase
|
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
43
|
+
should "return an appropriate (virtual) amount of minutes while pending" do
|
44
|
+
assert_equal 120, @person.punches.first.minutes
|
45
|
+
end
|
46
|
+
|
46
47
|
context "and checked out 25 minutes ago" do
|
47
48
|
setup do
|
48
49
|
Timecop.freeze(25.minutes.ago) do
|
@@ -54,6 +55,10 @@ class TestDatabase < Test::Unit::TestCase
|
|
54
55
|
assert @person.punches.first.checked_out_at < 24.minutes.ago and @person.punches.first.checked_out_at > 26.minutes.ago
|
55
56
|
end
|
56
57
|
|
58
|
+
should "have set the proper amount of minutes" do
|
59
|
+
assert_equal 95, @person.punches.first.minutes
|
60
|
+
end
|
61
|
+
|
57
62
|
should "not be pending" do
|
58
63
|
assert_nil @person.pending?
|
59
64
|
end
|
@@ -123,10 +128,9 @@ class TestDatabase < Test::Unit::TestCase
|
|
123
128
|
|
124
129
|
context "that punched in yesterday" do
|
125
130
|
setup do
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
punch.save!
|
131
|
+
Timecop.freeze(1.day.ago) do
|
132
|
+
@person.punch!
|
133
|
+
end
|
130
134
|
end
|
131
135
|
|
132
136
|
context "and punches out today" do
|
@@ -136,7 +140,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
136
140
|
|
137
141
|
should "result in the punch out getting moved to the end of yesterday" do
|
138
142
|
checkout_time = @person.punches.finished.first.checked_out_at
|
139
|
-
assert_equal 1.day.ago.end_of_day.to_date, checkout_time.to_date
|
143
|
+
assert_equal 1.day.ago.end_of_day.utc.to_date, checkout_time.utc.to_date
|
140
144
|
assert_equal 23, checkout_time.hour
|
141
145
|
assert_equal 59, checkout_time.min
|
142
146
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 6
|
9
|
+
version: 0.2.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Christoph Olszowka
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-10 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -159,6 +159,19 @@ dependencies:
|
|
159
159
|
version: "0"
|
160
160
|
type: :development
|
161
161
|
version_requirements: *id010
|
162
|
+
- !ruby/object:Gem::Dependency
|
163
|
+
name: jeweler
|
164
|
+
prerelease: false
|
165
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
segments:
|
171
|
+
- 0
|
172
|
+
version: "0"
|
173
|
+
type: :development
|
174
|
+
version_requirements: *id011
|
162
175
|
description: Simple sinatra/activerecord based app for tracking time when people have been in the office
|
163
176
|
email: christoph at olszowka de
|
164
177
|
executables: []
|
@@ -177,9 +190,9 @@ files:
|
|
177
190
|
- README.rdoc
|
178
191
|
- Rakefile
|
179
192
|
- VERSION
|
180
|
-
- config.ru
|
181
193
|
- lib/db/migrate/01_create_people.rb
|
182
194
|
- lib/db/migrate/02_create_punches.rb
|
195
|
+
- lib/db/migrate/03_add_minutes_to_punches.rb
|
183
196
|
- lib/public/cardbg.png
|
184
197
|
- lib/public/css/blueprint.css
|
185
198
|
- lib/public/js/app.js
|
data/config.ru
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# Example config.ru for running from direct git clone
|
2
|
-
# See README to see how to launch from gem
|
3
|
-
require './lib/punchcard'
|
4
|
-
|
5
|
-
Punchcard.set :mongo_db, 'punchcard'
|
6
|
-
|
7
|
-
Punchcard.use Rack::Auth::Basic do |username, password|
|
8
|
-
[username, password] == ['admin', 'admin']
|
9
|
-
end
|
10
|
-
|
11
|
-
run Punchcard
|