mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
User page now uses the supermodel for user loading
This commit is contained in:
parent
47f00f9b5e
commit
e6569539dc
7 changed files with 12 additions and 19 deletions
|
@ -6,3 +6,4 @@ module.exports = class EarnedAchievementCollection extends CocoCollection
|
|||
|
||||
initialize: (userID) ->
|
||||
@url = "/db/user/#{userID}/achievements"
|
||||
super()
|
||||
|
|
|
@ -195,7 +195,6 @@ module.exports = class LevelBus extends Bus
|
|||
@saveSession()
|
||||
|
||||
onNewGoalStates: ({goalStates})->
|
||||
console.debug arguments
|
||||
state = @session.get 'state'
|
||||
unless utils.kindaEqual state.goalStates, goalStates # Only save when goals really change
|
||||
state.goalStates = goalStates
|
||||
|
|
|
@ -20,7 +20,6 @@ block append content
|
|||
- var imgURL = achievement.getLockedImageURL();
|
||||
else
|
||||
- var imgURL = achievement.getImageURL();
|
||||
- console.log(locked);
|
||||
.col-lg-4.col-xs-12
|
||||
include ../achievement_notify
|
||||
else if activeLayout === 'table'
|
||||
|
@ -38,7 +37,7 @@ block append content
|
|||
tr
|
||||
td= achievement.get('name')
|
||||
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()
|
||||
td= earnedAchievement.get('achievedAmount')
|
||||
else
|
||||
|
|
|
@ -124,7 +124,7 @@ block append content
|
|||
each achievement in earnedAchievements.models
|
||||
tr
|
||||
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')
|
||||
td= achievement.get('achievedAmount')
|
||||
else
|
||||
|
|
|
@ -34,7 +34,6 @@ module.exports = class NewModelModal extends ModalView
|
|||
model
|
||||
|
||||
onModelSubmitted: (e) ->
|
||||
console.debug 'on model submitted'
|
||||
e.preventDefault()
|
||||
model = @makeNewModel()
|
||||
res = model.save()
|
||||
|
|
|
@ -22,7 +22,6 @@ module.exports = class MainUserView extends UserView
|
|||
getRenderData: ->
|
||||
context = super()
|
||||
if @levelSessions and @levelSessions.loaded
|
||||
console.debug 'yep sessions loaded'
|
||||
singlePlayerSessions = []
|
||||
multiPlayerSessions = []
|
||||
languageCounts = {}
|
||||
|
@ -42,18 +41,14 @@ module.exports = class MainUserView extends UserView
|
|||
context.multiPlayerSessions = multiPlayerSessions
|
||||
context.favoriteLanguage = favoriteLanguage
|
||||
if @earnedAchievements and @earnedAchievements.loaded
|
||||
console.debug 'earned achievements loaded'
|
||||
context.earnedAchievements = @earnedAchievements
|
||||
context
|
||||
|
||||
onLoaded: ->
|
||||
console.debug @earnedAchievements
|
||||
console.debug @earnedAchievements?.loaded
|
||||
if @user.loaded and not @earnedAchievements
|
||||
if @user.loaded and not (@earnedAchievements or @levelSessions)
|
||||
@supermodel.resetProgress()
|
||||
#@levelSessions = new LevelSessionsCollection @user.getSlugOrID()
|
||||
@levelSessions = new LevelSessionsCollection @user.getSlugOrID()
|
||||
@earnedAchievements = new EarnedAchievementCollection @user.getSlugOrID()
|
||||
#@supermodel.loadCollection @levelSessions, 'levelSessions'
|
||||
@supermodel.loadCollection @levelSessions, 'levelSessions'
|
||||
@supermodel.loadCollection @earnedAchievements, 'earnedAchievements'
|
||||
|
||||
super()
|
||||
|
|
|
@ -38,9 +38,9 @@ AchievablePlugin = (schema, options) ->
|
|||
isRepeatable = achievement.get('proportionalTo')?
|
||||
alreadyAchieved = if isNew then false else LocalMongo.matchesQuery originalDocObj, query
|
||||
newlyAchieved = LocalMongo.matchesQuery(docObj, query)
|
||||
log.debug 'isRepeatable: ' + isRepeatable
|
||||
log.debug 'alreadyAchieved: ' + alreadyAchieved
|
||||
log.debug 'newlyAchieved: ' + newlyAchieved
|
||||
#log.debug 'isRepeatable: ' + isRepeatable
|
||||
#log.debug 'alreadyAchieved: ' + alreadyAchieved
|
||||
#log.debug 'newlyAchieved: ' + newlyAchieved
|
||||
|
||||
userObjectID = doc.get(achievement.get('userField'))
|
||||
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?
|
||||
|
||||
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'
|
||||
originalAmount = if originalDocObj then util.getByPath(originalDocObj, proportionalTo) or 0 else 0
|
||||
newAmount = docObj[proportionalTo]
|
||||
|
@ -74,11 +74,11 @@ AchievablePlugin = (schema, options) ->
|
|||
return log.debug err if err?
|
||||
|
||||
earnedPoints = earned.earnedPoints
|
||||
log.debug earnedPoints
|
||||
#log.debug earnedPoints
|
||||
wrapUp()
|
||||
|
||||
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
|
||||
(new EarnedAchievement(earned)).save (err, doc) ->
|
||||
return log.error err if err?
|
||||
|
|
Loading…
Reference in a new issue