User page now uses the supermodel for user loading

This commit is contained in:
Ruben Vereecken 2014-08-08 19:26:24 +02:00
parent 47f00f9b5e
commit e6569539dc
7 changed files with 12 additions and 19 deletions

View file

@ -6,3 +6,4 @@ module.exports = class EarnedAchievementCollection extends CocoCollection
initialize: (userID) -> initialize: (userID) ->
@url = "/db/user/#{userID}/achievements" @url = "/db/user/#{userID}/achievements"
super()

View file

@ -195,7 +195,6 @@ module.exports = class LevelBus extends Bus
@saveSession() @saveSession()
onNewGoalStates: ({goalStates})-> onNewGoalStates: ({goalStates})->
console.debug arguments
state = @session.get 'state' state = @session.get 'state'
unless utils.kindaEqual state.goalStates, goalStates # Only save when goals really change unless utils.kindaEqual state.goalStates, goalStates # Only save when goals really change
state.goalStates = goalStates state.goalStates = goalStates

View file

@ -20,7 +20,6 @@ block append content
- var imgURL = achievement.getLockedImageURL(); - var imgURL = achievement.getLockedImageURL();
else else
- var imgURL = achievement.getImageURL(); - var imgURL = achievement.getImageURL();
- console.log(locked);
.col-lg-4.col-xs-12 .col-lg-4.col-xs-12
include ../achievement_notify include ../achievement_notify
else if activeLayout === 'table' else if activeLayout === 'table'
@ -38,7 +37,7 @@ block append content
tr tr
td= achievement.get('name') td= achievement.get('name')
td= achievement.get('description') td= achievement.get('description')
td= moment().format("MMMM Do YY", earnedAchievement.get('changed')) td= moment().format("MMMM Do YYYY", earnedAchievement.get('changed'))
if achievement.isRepeatable() if achievement.isRepeatable()
td= earnedAchievement.get('achievedAmount') td= earnedAchievement.get('achievedAmount')
else else

View file

@ -124,7 +124,7 @@ block append content
each achievement in earnedAchievements.models each achievement in earnedAchievements.models
tr tr
td= achievement.get('achievementName') td= achievement.get('achievementName')
td= moment().format("MMMM Do YY", achievement.get('changed')) td= moment().format("MMMM Do YYYY", achievement.get('changed'))
if achievement.get('achievedAmount') if achievement.get('achievedAmount')
td= achievement.get('achievedAmount') td= achievement.get('achievedAmount')
else else

View file

@ -34,7 +34,6 @@ module.exports = class NewModelModal extends ModalView
model model
onModelSubmitted: (e) -> onModelSubmitted: (e) ->
console.debug 'on model submitted'
e.preventDefault() e.preventDefault()
model = @makeNewModel() model = @makeNewModel()
res = model.save() res = model.save()

View file

@ -22,7 +22,6 @@ module.exports = class MainUserView extends UserView
getRenderData: -> getRenderData: ->
context = super() context = super()
if @levelSessions and @levelSessions.loaded if @levelSessions and @levelSessions.loaded
console.debug 'yep sessions loaded'
singlePlayerSessions = [] singlePlayerSessions = []
multiPlayerSessions = [] multiPlayerSessions = []
languageCounts = {} languageCounts = {}
@ -42,18 +41,14 @@ module.exports = class MainUserView extends UserView
context.multiPlayerSessions = multiPlayerSessions context.multiPlayerSessions = multiPlayerSessions
context.favoriteLanguage = favoriteLanguage context.favoriteLanguage = favoriteLanguage
if @earnedAchievements and @earnedAchievements.loaded if @earnedAchievements and @earnedAchievements.loaded
console.debug 'earned achievements loaded'
context.earnedAchievements = @earnedAchievements context.earnedAchievements = @earnedAchievements
context context
onLoaded: -> onLoaded: ->
console.debug @earnedAchievements if @user.loaded and not (@earnedAchievements or @levelSessions)
console.debug @earnedAchievements?.loaded
if @user.loaded and not @earnedAchievements
@supermodel.resetProgress() @supermodel.resetProgress()
#@levelSessions = new LevelSessionsCollection @user.getSlugOrID() @levelSessions = new LevelSessionsCollection @user.getSlugOrID()
@earnedAchievements = new EarnedAchievementCollection @user.getSlugOrID() @earnedAchievements = new EarnedAchievementCollection @user.getSlugOrID()
#@supermodel.loadCollection @levelSessions, 'levelSessions' @supermodel.loadCollection @levelSessions, 'levelSessions'
@supermodel.loadCollection @earnedAchievements, 'earnedAchievements' @supermodel.loadCollection @earnedAchievements, 'earnedAchievements'
super() super()

View file

@ -38,9 +38,9 @@ AchievablePlugin = (schema, options) ->
isRepeatable = achievement.get('proportionalTo')? isRepeatable = achievement.get('proportionalTo')?
alreadyAchieved = if isNew then false else LocalMongo.matchesQuery originalDocObj, query alreadyAchieved = if isNew then false else LocalMongo.matchesQuery originalDocObj, query
newlyAchieved = LocalMongo.matchesQuery(docObj, query) newlyAchieved = LocalMongo.matchesQuery(docObj, query)
log.debug 'isRepeatable: ' + isRepeatable #log.debug 'isRepeatable: ' + isRepeatable
log.debug 'alreadyAchieved: ' + alreadyAchieved #log.debug 'alreadyAchieved: ' + alreadyAchieved
log.debug 'newlyAchieved: ' + newlyAchieved #log.debug 'newlyAchieved: ' + newlyAchieved
userObjectID = doc.get(achievement.get('userField')) userObjectID = doc.get(achievement.get('userField'))
userID = if _.isObject userObjectID then userObjectID.toHexString() else userObjectID # Standardize! Use strings, not ObjectId's userID = if _.isObject userObjectID then userObjectID.toHexString() else userObjectID # Standardize! Use strings, not ObjectId's
@ -59,7 +59,7 @@ AchievablePlugin = (schema, options) ->
log.error err if err? log.error err if err?
if isRepeatable if isRepeatable
log.debug 'Upserting repeatable achievement called \'' + (achievement.get 'name') + '\' for ' + userID #log.debug 'Upserting repeatable achievement called \'' + (achievement.get 'name') + '\' for ' + userID
proportionalTo = achievement.get 'proportionalTo' proportionalTo = achievement.get 'proportionalTo'
originalAmount = if originalDocObj then util.getByPath(originalDocObj, proportionalTo) or 0 else 0 originalAmount = if originalDocObj then util.getByPath(originalDocObj, proportionalTo) or 0 else 0
newAmount = docObj[proportionalTo] newAmount = docObj[proportionalTo]
@ -74,11 +74,11 @@ AchievablePlugin = (schema, options) ->
return log.debug err if err? return log.debug err if err?
earnedPoints = earned.earnedPoints earnedPoints = earned.earnedPoints
log.debug earnedPoints #log.debug earnedPoints
wrapUp() wrapUp()
else # not alreadyAchieved else # not alreadyAchieved
log.debug 'Creating a new earned achievement called \'' + (achievement.get 'name') + '\' for ' + userID #log.debug 'Creating a new earned achievement called \'' + (achievement.get 'name') + '\' for ' + userID
earned.earnedPoints = worth earned.earnedPoints = worth
(new EarnedAchievement(earned)).save (err, doc) -> (new EarnedAchievement(earned)).save (err, doc) ->
return log.error err if err? return log.error err if err?