Commit 696973d
Changed files (2)
app
assets
javascripts
models
views
app/assets/javascripts/models/timer.js.coffee
@@ -1,7 +1,8 @@
class Stronglifters.Timer
constructor: (options) ->
@databag = options['databag']
- @format = options['format'] || 'mm:ss'
+ @format = options['format'] || (timer) ->
+ moment.utc(timer).format('mm:ss')
@interval = 1000
@key = options['key'] || 'clock'
@maxMilliseconds = options['maxMilliseconds'] || 600000
@@ -15,7 +16,8 @@ class Stronglifters.Timer
refreshTimer: =>
@databag.add('timer', @interval)
- @databag.set(@key, moment.utc(@databag.get('timer')).format(@format))
+ formattedValue = @format(@databag.get('timer'))
+ @databag.set(@key, formattedValue)
if @databag.get('timer') >= @maxMilliseconds
@stop()
@success()
app/assets/javascripts/views/workout_view.js.coffee
@@ -78,11 +78,12 @@ class Stronglifters.WorkoutView extends Ractive
targetMilliseconds = model.get('target_duration') * 1000
timer = new Stronglifters.Timer
databag: this
- format: 'ss'
+ format: (timer) ->
+ (moment.utc(timer).minutes() * 60) + moment.utc(timer).seconds()
key: "#{keypath}.actual_duration"
maxMilliseconds: targetMilliseconds
- success: ->
- console.log("SAVING")
+ success: =>
+ model.set('actual_duration', @get("#{keypath}.actual_duration"))
model.save()
@timers[keypath] = timer
timer.start()