diff options
| author | mo khan <mo@mokhan.ca> | 2016-06-25 23:14:45 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2016-06-25 23:14:45 -0600 |
| commit | 886f2b85bcf0da119e530ee41ce7a35de8d65804 (patch) | |
| tree | a5a4cf2213dff8527184deb500a3015ac4b09aa2 /app/assets/javascripts | |
| parent | 4a6be5c03daf44cd1904ef092f2fe62802f16f31 (diff) | |
stop timer after 10 mins and safely update model.
Diffstat (limited to 'app/assets/javascripts')
| -rw-r--r-- | app/assets/javascripts/models/timer.js.coffee | 3 | ||||
| -rw-r--r-- | app/assets/javascripts/views/workout_view.js.coffee | 41 |
2 files changed, 25 insertions, 19 deletions
diff --git a/app/assets/javascripts/models/timer.js.coffee b/app/assets/javascripts/models/timer.js.coffee index c38ab39..e555596 100644 --- a/app/assets/javascripts/models/timer.js.coffee +++ b/app/assets/javascripts/models/timer.js.coffee @@ -11,11 +11,14 @@ class Stronglifters.Timer refreshTimer: => @view.add('timer', 1000) @view.set('clock', moment.utc(@view.get('timer')).format('mm:ss')) + if @view.get('timer') > 600000 + @stop() stop: => if @running() clearTimeout @intervalId @intervalId = null + @view.set('clock', null) running: -> @intervalId? diff --git a/app/assets/javascripts/views/workout_view.js.coffee b/app/assets/javascripts/views/workout_view.js.coffee index a8f4f81..52b63fa 100644 --- a/app/assets/javascripts/views/workout_view.js.coffee +++ b/app/assets/javascripts/views/workout_view.js.coffee @@ -4,18 +4,22 @@ class Stronglifters.WorkoutView extends Ractive template: RactiveTemplates["templates/workout_view"] oninit: -> + @clock = new Stronglifters.Timer(@) @on 'updateProgress', (event) -> - model = new Stronglifters.Set(@get(event.keypath)) - @updateProgress(model) - prefix = (x, key) -> - x["#{event.keypath}.#{key}"] = model.changed[key] - x - @set(_.reduce(_.keys(model.changed), prefix, {})) + @withModel event.keypath, (model) => + @updateProgress(model) @observe 'workout.exercises.*.sets.*', (newValue, oldValue, keypath) -> - @refreshStatus(newValue, oldValue, keypath) - @set('message', "Let's do this!") - @clock = new Stronglifters.Timer(@) + @withModel keypath, (model) => + @refreshStatus(model, keypath) + + withModel: (keypath, callback) -> + model = new Stronglifters.Set(@get(keypath)) + callback(model) + prefix = (x, key) -> + x["#{keypath}.#{key}"] = model.changed[key] + x + @set(_.reduce(_.keys(model.changed), prefix, {})) updateProgress: (model) -> if !model.started() @@ -25,22 +29,21 @@ class Stronglifters.WorkoutView extends Ractive model.save() if model.successful() - @set('message', "If it was easy break for 1:30, otherwise rest for 3:00.") - @set('alertStatus', 'radius') + @displayMessage("If it was easy break for 1:30, otherwise rest for 3:00.", 'radius') else - @set('alertStatus', 'alert') - @set('message', "Take a 5:00 break.") + @displayMessage("Take a 5:00 break.", 'alert') @clock.start() - successful: (keypath) -> - @get("#{keypath}.target_repetitions") == @get("#{keypath}.actual_repetitions") - - refreshStatus: (newValue, oldValue, keypath) -> - if @get("#{keypath}.actual_repetitions") == null + refreshStatus: (model, keypath) -> + if !model.started() @set("#{keypath}.status", "secondary") return - if @successful(keypath) + if model.successful() @set("#{keypath}.status", "success") else @set("#{keypath}.status", "alert") + + displayMessage: (message, status) -> + @set('message', message) + @set('alertStatus', status) |
