mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-05 03:52:14 +00:00
many fixes to party system actions causing dom refresh
This commit is contained in:
parent
0e6d08e16b
commit
7764447355
4 changed files with 42 additions and 37 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
content = require('./content')
|
content = require('./content')
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.resetDom = (model) ->
|
||||||
|
window.DERBY.app.dom.clear()
|
||||||
|
window.DERBY.app.view.render(model)
|
||||||
|
model.fn '_tnl', '_user.stats.lvl', (lvl) -> (lvl*100)/5
|
||||||
|
|
||||||
###
|
###
|
||||||
Loads JavaScript files from (1) public/js/* and (2) external sources
|
Loads JavaScript files from (1) public/js/* and (2) external sources
|
||||||
We use this file (instead of <Scripts:> or <Tail:> inside .html) so we can utilize require() to concatinate for
|
We use this file (instead of <Scripts:> or <Tail:> inside .html) so we can utilize require() to concatinate for
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,6 @@ setupListReferences = (model) ->
|
||||||
taskTypes = ['habit', 'daily', 'todo', 'reward']
|
taskTypes = ['habit', 'daily', 'todo', 'reward']
|
||||||
_.each taskTypes, (type) -> model.refList "_#{type}List", "_user.tasks", "_user.idLists.#{type}"
|
_.each taskTypes, (type) -> model.refList "_#{type}List", "_user.tasks", "_user.idLists.#{type}"
|
||||||
|
|
||||||
setupModelFns = (model) ->
|
|
||||||
model.fn '_tnl', '_user.stats.lvl', (lvl) ->
|
|
||||||
# see https://github.com/lefnire/habitrpg/issues/4
|
|
||||||
# also update in scoring.coffee. TODO create a function accessible in both locations
|
|
||||||
(lvl*100)/5
|
|
||||||
|
|
||||||
# ========== ROUTES ==========
|
# ========== ROUTES ==========
|
||||||
|
|
||||||
|
|
@ -62,27 +57,18 @@ get '/', (page, model, next) ->
|
||||||
batch.commit()
|
batch.commit()
|
||||||
|
|
||||||
setupListReferences(model)
|
setupListReferences(model)
|
||||||
setupModelFns(model)
|
model.fn '_tnl', '_user.stats.lvl', (lvl) ->
|
||||||
|
# see https://github.com/lefnire/habitrpg/issues/4
|
||||||
|
# also update in scoring.coffee. TODO create a function accessible in both locations
|
||||||
|
(lvl*100)/5
|
||||||
|
|
||||||
if obj.party?.current?
|
if obj.party?.current?
|
||||||
party.partySubscribe model, obj.party.current, (p) ->
|
party.partySubscribe model, obj.party.current, (p) -> page.render()
|
||||||
|
|
||||||
# Here's a hack we need to get fixed (hopefully Lever will) - later model.queries override previous model.queries'
|
|
||||||
# returned fields. Aka, we need this here otherwise we only get the "public" fields for the current user, which
|
|
||||||
# are defined in model.query('users')party()
|
|
||||||
model.subscribe selfQ, (err, users) ->
|
|
||||||
model.ref '_user', users.at(0)
|
|
||||||
page.render()
|
|
||||||
else
|
else
|
||||||
page.render()
|
page.render()
|
||||||
|
|
||||||
# ========== CONTROLLER FUNCTIONS ==========
|
# ========== CONTROLLER FUNCTIONS ==========
|
||||||
|
|
||||||
resetDom = (model) ->
|
|
||||||
window.DERBY.app.dom.clear()
|
|
||||||
view.render(model)
|
|
||||||
setupModelFns(model)
|
|
||||||
|
|
||||||
ready (model) ->
|
ready (model) ->
|
||||||
user = model.at('_user')
|
user = model.at('_user')
|
||||||
scoring.setModel(model)
|
scoring.setModel(model)
|
||||||
|
|
@ -92,7 +78,7 @@ ready (model) ->
|
||||||
user.set('lastCron', +new Date) if (!lastCron? or lastCron == 'new')
|
user.set('lastCron', +new Date) if (!lastCron? or lastCron == 'new')
|
||||||
|
|
||||||
# Setup model in scoring functions
|
# Setup model in scoring functions
|
||||||
scoring.cron(resetDom)
|
scoring.cron()
|
||||||
|
|
||||||
# Load all the jQuery, Growl, Tour, etc
|
# Load all the jQuery, Growl, Tour, etc
|
||||||
browser.loadJavaScripts(model)
|
browser.loadJavaScripts(model)
|
||||||
|
|
@ -289,7 +275,7 @@ ready (model) ->
|
||||||
batch.set 'balance', 2 if user.get('balance') < 2 #only if they haven't manually bought tokens
|
batch.set 'balance', 2 if user.get('balance') < 2 #only if they haven't manually bought tokens
|
||||||
revive(batch, true)
|
revive(batch, true)
|
||||||
batch.commit()
|
batch.commit()
|
||||||
resetDom(model)
|
browser.resetDom(model)
|
||||||
|
|
||||||
exports.closeKickstarterNofitication = (e, el) -> user.set('flags.kickstarter', 'hide')
|
exports.closeKickstarterNofitication = (e, el) -> user.set('flags.kickstarter', 'hide')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
_ = require('underscore')
|
_ = require('underscore')
|
||||||
schema = require './schema'
|
schema = require './schema'
|
||||||
|
browser = require './browser'
|
||||||
|
|
||||||
_subscriptions =
|
_subscriptions =
|
||||||
party:
|
party:
|
||||||
|
|
@ -35,11 +36,16 @@ module.exports.partySubscribe = partySubscribe = (model, id, cb) ->
|
||||||
|
|
||||||
# FIXME this is the kicker right here. This isn't getting triggered, and it's the reason why we have to refresh
|
# FIXME this is the kicker right here. This isn't getting triggered, and it's the reason why we have to refresh
|
||||||
# after every event. Get this working
|
# after every event. Get this working
|
||||||
p.on '*', 'members', (ids) ->
|
# p.on '*', 'members', (ids) ->
|
||||||
console.log("members listener got called")
|
# console.log("members listener got called")
|
||||||
membersSubscribe model, ids
|
# membersSubscribe model, ids
|
||||||
|
ids = p.get('members')
|
||||||
membersSubscribe model, p.get('members'), (m) ->
|
if !_.isEmpty(ids)
|
||||||
|
membersSubscribe model, ids, (m) ->
|
||||||
|
browser.resetDom(model) if window?
|
||||||
|
cb(p) if cb?
|
||||||
|
else
|
||||||
|
browser.resetDom(model) if window?
|
||||||
cb(p) if cb?
|
cb(p) if cb?
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,7 +69,14 @@ module.exports.membersSubscribe = membersSubscribe = (model, ids, cb) ->
|
||||||
s.members.query.subscribe (err, m) ->
|
s.members.query.subscribe (err, m) ->
|
||||||
throw err if err
|
throw err if err
|
||||||
model.ref '_partyMembers', m
|
model.ref '_partyMembers', m
|
||||||
cb(m) if cb?
|
|
||||||
|
# Here's a hack we need to get fixed (hopefully Lever will) - later model.queries override previous model.queries'
|
||||||
|
# returned fields. Aka, we need this here otherwise we only get the "public" fields for the current user, which
|
||||||
|
# are defined in model.query('users')party()
|
||||||
|
selfQ = model.query('users').withId(model.get('_userId') or model.session.userId)
|
||||||
|
model.subscribe selfQ, (err, users) ->
|
||||||
|
model.ref '_user', users.at(0)
|
||||||
|
cb(m) if cb?
|
||||||
|
|
||||||
module.exports.app = (appExports, model) ->
|
module.exports.app = (appExports, model) ->
|
||||||
user = model.at('_user')
|
user = model.at('_user')
|
||||||
|
|
@ -75,7 +88,7 @@ module.exports.app = (appExports, model) ->
|
||||||
newParty = model.get("_newParty")
|
newParty = model.get("_newParty")
|
||||||
id = model.add 'parties', { name: newParty, leader: user.get('id'), members: [user.get('id')], invites:[] }
|
id = model.add 'parties', { name: newParty, leader: user.get('id'), members: [user.get('id')], invites:[] }
|
||||||
user.set 'party', {current: id, invitation: null, leader: true}
|
user.set 'party', {current: id, invitation: null, leader: true}
|
||||||
partySubscribe model, id
|
partySubscribe model, id, -> $('#party-modal').modal('show')
|
||||||
|
|
||||||
appExports.partyInvite = ->
|
appExports.partyInvite = ->
|
||||||
id = model.get('_newPartyMember').replace(/[\s"]/g, '')
|
id = model.get('_newPartyMember').replace(/[\s"]/g, '')
|
||||||
|
|
@ -100,8 +113,7 @@ module.exports.app = (appExports, model) ->
|
||||||
$('#party-modal').modal('hide')
|
$('#party-modal').modal('hide')
|
||||||
model.set '_newPartyMember', ''
|
model.set '_newPartyMember', ''
|
||||||
membersSubscribe model, p.get('members'), ->
|
membersSubscribe model, p.get('members'), ->
|
||||||
# TODO get subscriptions really working so we don't need to reload
|
#window.location.reload(true)
|
||||||
window.location.reload()
|
|
||||||
|
|
||||||
appExports.partyAccept = ->
|
appExports.partyAccept = ->
|
||||||
invitation = user.get('party.invitation')
|
invitation = user.get('party.invitation')
|
||||||
|
|
@ -110,12 +122,12 @@ module.exports.app = (appExports, model) ->
|
||||||
user.set 'party.invitation', null
|
user.set 'party.invitation', null
|
||||||
user.set 'party.current', p.get('id')
|
user.set 'party.current', p.get('id')
|
||||||
membersSubscribe model, p.get('members'), (m) ->
|
membersSubscribe model, p.get('members'), (m) ->
|
||||||
window.location.reload()
|
window.location.reload(true)
|
||||||
|
|
||||||
appExports.partyReject = ->
|
appExports.partyReject = ->
|
||||||
user.set 'party.invitation', null
|
user.set 'party.invitation', null
|
||||||
model.set '_party', null
|
model.set '_party', null
|
||||||
|
browser.resetDom(model)
|
||||||
# TODO splice parties.*.invites[key]
|
# TODO splice parties.*.invites[key]
|
||||||
# TODO notify sender
|
# TODO notify sender
|
||||||
|
|
||||||
|
|
@ -130,8 +142,9 @@ module.exports.app = (appExports, model) ->
|
||||||
# last member out, kill the party
|
# last member out, kill the party
|
||||||
model.del "parties.#{id}"
|
model.del "parties.#{id}"
|
||||||
#_subscriptions.party.query.unsubscribe()
|
#_subscriptions.party.query.unsubscribe()
|
||||||
model.set '_party', null
|
#model.set '_party', null
|
||||||
model.set '_partyMembers', null
|
#model.set '_partyMembers', null
|
||||||
setTimeout window.location.reload, 1
|
#browser.resetDom()
|
||||||
|
setTimeout (-> window.location.reload true), 1
|
||||||
|
|
||||||
#exports.partyDisband = ->
|
#exports.partyDisband = ->
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ score = (taskId, direction, times, batch, cron) ->
|
||||||
At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
|
At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
|
||||||
For incomplete Dailys, deduct experience
|
For incomplete Dailys, deduct experience
|
||||||
###
|
###
|
||||||
cron = (resetDom_cb) ->
|
cron = () ->
|
||||||
today = +new Date
|
today = +new Date
|
||||||
daysPassed = helpers.daysBetween(today, user.get('lastCron'))
|
daysPassed = helpers.daysBetween(today, user.get('lastCron'))
|
||||||
if daysPassed > 0
|
if daysPassed > 0
|
||||||
|
|
@ -245,7 +245,7 @@ cron = (resetDom_cb) ->
|
||||||
batch.setStats()
|
batch.setStats()
|
||||||
batch.set('history', obj.history)
|
batch.set('history', obj.history)
|
||||||
batch.commit()
|
batch.commit()
|
||||||
resetDom_cb(model)
|
require('./browser').reset(model)
|
||||||
setTimeout (-> user.set 'stats.hp', hpAfter), 1000 # animate hp loss
|
setTimeout (-> user.set 'stats.hp', hpAfter), 1000 # animate hp loss
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue