mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-05 12:02:13 +00:00
try offloading everythign to the client
This commit is contained in:
parent
81e673b81a
commit
c7f2f81985
1 changed files with 47 additions and 42 deletions
|
|
@ -32,6 +32,7 @@ get '/', (page, model, next) ->
|
||||||
|
|
||||||
userPath = "users.#{model.session.userId}"
|
userPath = "users.#{model.session.userId}"
|
||||||
model.subscribe userPath, (err, user) ->
|
model.subscribe userPath, (err, user) ->
|
||||||
|
model.ref '_user', user
|
||||||
userObj = user.get()
|
userObj = user.get()
|
||||||
return page.redirect '/500.html' unless userObj? #this should never happen, but it is. Looking into it
|
return page.redirect '/500.html' unless userObj? #this should never happen, but it is. Looking into it
|
||||||
|
|
||||||
|
|
@ -48,19 +49,6 @@ get '/', (page, model, next) ->
|
||||||
potion: content.items.potion
|
potion: content.items.potion
|
||||||
reroll: content.items.reroll
|
reroll: content.items.reroll
|
||||||
|
|
||||||
# FIXME temporary hack to remove duplicates and empty (grey) tasks. Need to figure out why they're being produced
|
|
||||||
taskIds = _.pluck(userObj.tasks, 'id')
|
|
||||||
_.each ['habitIds','dailyIds','todoIds', 'completedIds', 'rewardIds'], (path) ->
|
|
||||||
unique = _.uniq userObj[path] #remove duplicates
|
|
||||||
#remove empty grey tasks
|
|
||||||
preened = _.filter(unique, (val) -> _.contains(taskIds, val))
|
|
||||||
user.set(path, preened) if _.size(preened) != _.size(userObj[path]) # There were indeed duplicates or empties
|
|
||||||
|
|
||||||
# ========== Notifiations ==========
|
|
||||||
unless userObj.notifications?.kickstarter
|
|
||||||
user.set('notifications.kickstarter', 'show')
|
|
||||||
|
|
||||||
model.ref '_user', user
|
|
||||||
model.set '_view', _view
|
model.set '_view', _view
|
||||||
|
|
||||||
setupListReferences(model)
|
setupListReferences(model)
|
||||||
|
|
@ -75,9 +63,54 @@ get '/', (page, model, next) ->
|
||||||
|
|
||||||
# ========== CONTROLLER FUNCTIONS ==========
|
# ========== CONTROLLER FUNCTIONS ==========
|
||||||
|
|
||||||
|
cron = (model) ->
|
||||||
|
user = model.at('_user')
|
||||||
|
userObj = user.get()
|
||||||
|
|
||||||
|
## User Cleanup
|
||||||
|
# FIXME temporary hack to remove duplicates and empty (grey) tasks. Need to figure out why they're being produced
|
||||||
|
taskIds = _.pluck(userObj.tasks, 'id')
|
||||||
|
_.each ['habitIds','dailyIds','todoIds', 'completedIds', 'rewardIds'], (path) ->
|
||||||
|
unique = _.uniq userObj[path] #remove duplicates
|
||||||
|
#remove empty grey tasks
|
||||||
|
preened = _.filter(unique, (val) -> _.contains(taskIds, val))
|
||||||
|
userObj[path] = preened if _.size(preened) != _.size(userObj[path]) # There were indeed duplicates or empties
|
||||||
|
|
||||||
|
## Notifiations
|
||||||
|
unless userObj.notifications?.kickstarter
|
||||||
|
user.set('notifications.kickstarter', 'show')
|
||||||
|
|
||||||
|
## Cron
|
||||||
|
# hp-shimmy so we can animate the hp-loss
|
||||||
|
before = {hp:userObj.stats.hp, lastCron:userObj.lastCron}
|
||||||
|
scoring.cron(userObj)
|
||||||
|
after = {hp:userObj.stats.hp, lastCron:userObj.lastCron}
|
||||||
|
userObj.stats.hp = before.hp
|
||||||
|
|
||||||
|
model.set "users.#{userObj.id}", userObj, ->
|
||||||
|
# Don't do anything if same day or new user
|
||||||
|
return if before.lastCron == after.lastCron or !before.lastCron?
|
||||||
|
|
||||||
|
setTimeout ->
|
||||||
|
#setupListReferences(model)
|
||||||
|
view.render(model)
|
||||||
|
user.set 'stats.hp', after.hp
|
||||||
|
#setTimeout (-> user.set('stats.hp', after.hp)), 0 # animated
|
||||||
|
# window.location.reload()
|
||||||
|
# browser.setupSortable(model)
|
||||||
|
# browser.setupTooltips(model)
|
||||||
|
# browser.setupTour(model)
|
||||||
|
, 1000
|
||||||
|
|
||||||
ready (model) ->
|
ready (model) ->
|
||||||
user = model.at('_user')
|
user = model.at('_user')
|
||||||
|
|
||||||
|
# Setup model in scoring functions
|
||||||
|
scoring.setModel(model)
|
||||||
|
|
||||||
|
# First things first. Preen the user object, check if dailies, etc
|
||||||
|
cron(model)
|
||||||
|
|
||||||
# Load all the jQuery, Growl, Tour, etc
|
# Load all the jQuery, Growl, Tour, etc
|
||||||
browser.loadJavaScripts(model)
|
browser.loadJavaScripts(model)
|
||||||
browser.setupSortable(model)
|
browser.setupSortable(model)
|
||||||
|
|
@ -85,9 +118,6 @@ ready (model) ->
|
||||||
browser.setupTour(model)
|
browser.setupTour(model)
|
||||||
browser.setupGrowlNotifications(model) unless model.get('_view.mobileDevice')
|
browser.setupGrowlNotifications(model) unless model.get('_view.mobileDevice')
|
||||||
|
|
||||||
# Setup model in scoring functions
|
|
||||||
scoring.setModel(model)
|
|
||||||
|
|
||||||
require('../server/private').app(exports, model)
|
require('../server/private').app(exports, model)
|
||||||
|
|
||||||
user.on 'set', 'tasks.*.completed', (i, completed, previous, isLocal, passed) ->
|
user.on 'set', 'tasks.*.completed', (i, completed, previous, isLocal, passed) ->
|
||||||
|
|
@ -274,28 +304,3 @@ ready (model) ->
|
||||||
|
|
||||||
exports.closeKickstarterNofitication = (e, el) ->
|
exports.closeKickstarterNofitication = (e, el) ->
|
||||||
user.set('notifications.kickstarter', 'hide')
|
user.set('notifications.kickstarter', 'hide')
|
||||||
|
|
||||||
# ========== CRON ==========
|
|
||||||
|
|
||||||
setTimeout ->
|
|
||||||
userObj = user.get()
|
|
||||||
|
|
||||||
# hp-shimmy so we can animate the hp-loss
|
|
||||||
before = {hp:userObj.stats.hp, lastCron:userObj.lastCron}
|
|
||||||
scoring.cron(userObj)
|
|
||||||
after = {hp:userObj.stats.hp, lastCron:userObj.lastCron}
|
|
||||||
#userObj.stats.hp = before.hp
|
|
||||||
|
|
||||||
# Don't do anything if same day or new user
|
|
||||||
return if before.lastCron == after.lastCron or !before.lastCron?
|
|
||||||
|
|
||||||
#set necessary references
|
|
||||||
model.set "users.#{userObj.id}", userObj, ->
|
|
||||||
#setupListReferences(model)
|
|
||||||
#view.resetModel(model)
|
|
||||||
#setTimeout (-> user.set('stats.hp', after.hp)), 0 # animated
|
|
||||||
window.location.reload()
|
|
||||||
# browser.setupSortable(model)
|
|
||||||
# browser.setupTooltips(model)
|
|
||||||
# browser.setupTour(model)
|
|
||||||
, 1000
|
|
||||||
Loading…
Reference in a new issue