Skip to content

Commit

Permalink
Merge branch 'feature/add_late_time_notify' into 'master'
Browse files Browse the repository at this point in the history
Feature/add late time notify

See merge request !42
  • Loading branch information
Henry Tseng committed Aug 4, 2017
2 parents 4d67feb + 6f0cee9 commit d016426
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gem 'devise'
gem 'pundit'

gem 'settingslogic'
gem 'tamashii-common', '>= 0.1.5'
gem 'tamashii-common', '>= 0.1.6'
gem 'tamashii-manager', '>= 0.2.4'
gem 'active_model_serializers'

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ GEM
redis
tamashii-common
websocket-driver
tamashii-common (0.1.5)
tamashii-common (0.1.6)
tamashii-manager (0.2.4)
concurrent-ruby
nio4r
Expand Down Expand Up @@ -401,7 +401,7 @@ DEPENDENCIES
slim-rails
spring
spring-watcher-listen (~> 2.0.0)
tamashii-common (>= 0.1.5)
tamashii-common (>= 0.1.6)
tamashii-manager (>= 0.2.4)
timecop
turbolinks (~> 5)
Expand Down
2 changes: 1 addition & 1 deletion app/models/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def write(packet)
end

def on_accept
process_command :lcd_set_idle_text, "Tamashii Clockin\nSystem Ready"
process_command :lcd_set_idle_text, "Welcome to 5xRuby.tw! Tamashii Clockin System Ready\n#{Tamashii::AgentHint::TIME}"
end

# TODO: Use ruby auto generate below code
Expand Down
35 changes: 34 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,43 @@ def self.checkin_staff(user)
return false if user.nil?
result = user.checkin
return nil unless result
greeting = (user.check_records.today.count % 2).zero? ? 'Good Bye!' : 'Hello!'
greeting = generate_greeting(user)
{ auth: true, reason: 'checkin', message: "#{greeting}\n#{user.ascii_only_name}" }
end

def self.generate_greeting(user)
if (user.check_records.today.count % 2).zero?
# clock out
clock_out_greeting
else
# clock in
clock_in_greeting
end
end

def self.compute_late_time(time_now, time_limit)
seconds = time_now - time_limit
min = (seconds / 60.0).ceil
hour = min / 60
min %= 60
[hour, min]
end

def self.clock_in_greeting
time_limit = Time.zone.parse(Settings.clockin_time_limit)
time_now = Time.zone.now
if time_now > time_limit # Late
hour, min = compute_late_time(time_now, time_limit)
"Late for #{hour}h#{min}m!"
else # In time
'Hello'
end
end

def self.clock_out_greeting
'Good Bye!'
end

def ascii_only_name
if name.ascii_only?
name
Expand Down
2 changes: 1 addition & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ default: &default
channel: <%= ENV['FLOWDOCK_CHANNEL'] %>
slack:
token: <%= ENV['SLACK_TOKEN'] %>

clockin_time_limit: "10:00"

development:
<<: *default
Expand Down

0 comments on commit d016426

Please sign in to comment.