2014-07-15 10:15:21 -04:00
|
|
|
UserView = require 'views/kinds/UserView'
|
2014-07-29 10:50:07 -04:00
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
|
|
|
LevelSession = require 'models/LevelSession'
|
2014-07-15 10:15:21 -04:00
|
|
|
template = require 'templates/user/home'
|
|
|
|
{me} = require 'lib/auth'
|
2014-08-07 16:03:00 -04:00
|
|
|
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
|
2014-07-15 10:15:21 -04:00
|
|
|
|
2014-07-29 10:50:07 -04:00
|
|
|
class LevelSessionsCollection extends CocoCollection
|
|
|
|
model: LevelSession
|
|
|
|
|
|
|
|
constructor: (userID) ->
|
2014-08-07 16:03:00 -04:00
|
|
|
@url = "/db/user/#{userID}/level.sessions?project=state.complete,levelID,levelName,changed,team,submittedCodeLanguage,totalScore&order=-1"
|
2014-07-29 10:50:07 -04:00
|
|
|
super()
|
|
|
|
|
2014-07-21 13:49:16 -04:00
|
|
|
module.exports = class MainUserView extends UserView
|
2014-07-15 10:15:21 -04:00
|
|
|
id: 'user-home-view'
|
|
|
|
template: template
|
|
|
|
|
2014-07-21 13:49:16 -04:00
|
|
|
constructor: (userID, options) ->
|
2014-07-15 10:15:21 -04:00
|
|
|
super options
|
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
2014-08-07 16:03:00 -04:00
|
|
|
if @levelSessions and @levelSessions.loaded
|
|
|
|
console.debug 'yep sessions loaded'
|
2014-07-29 10:50:07 -04:00
|
|
|
singlePlayerSessions = []
|
|
|
|
multiPlayerSessions = []
|
|
|
|
languageCounts = {}
|
|
|
|
for levelSession in @levelSessions.models
|
2014-08-03 17:58:51 -04:00
|
|
|
if levelSession.isMultiplayer()
|
2014-07-29 10:50:07 -04:00
|
|
|
multiPlayerSessions.push levelSession
|
|
|
|
else
|
|
|
|
singlePlayerSessions.push levelSession
|
|
|
|
languageCounts[levelSession.get 'submittedCodeLanguage'] = (languageCounts[levelSession.get 'submittedCodeLanguage'] or 0) + 1
|
|
|
|
mostUsedCount = 0
|
|
|
|
favoriteLanguage = null
|
|
|
|
for language, count of languageCounts
|
|
|
|
if count > mostUsedCount
|
|
|
|
mostUsedCount = count
|
2014-07-29 14:11:45 -04:00
|
|
|
favoriteLanguage = language
|
2014-07-29 10:50:07 -04:00
|
|
|
context.singlePlayerSessions = singlePlayerSessions
|
|
|
|
context.multiPlayerSessions = multiPlayerSessions
|
2014-07-29 14:11:45 -04:00
|
|
|
context.favoriteLanguage = favoriteLanguage
|
2014-08-07 16:03:00 -04:00
|
|
|
if @earnedAchievements and @earnedAchievements.loaded
|
|
|
|
console.debug 'earned achievements loaded'
|
|
|
|
context.earnedAchievements = @earnedAchievements
|
2014-07-15 10:15:21 -04:00
|
|
|
context
|
|
|
|
|
2014-07-29 10:50:07 -04:00
|
|
|
onLoaded: ->
|
2014-08-07 16:03:00 -04:00
|
|
|
console.debug @earnedAchievements
|
|
|
|
console.debug @earnedAchievements?.loaded
|
|
|
|
if @user.loaded and not @earnedAchievements
|
|
|
|
@supermodel.resetProgress()
|
|
|
|
#@levelSessions = new LevelSessionsCollection @user.getSlugOrID()
|
|
|
|
@earnedAchievements = new EarnedAchievementCollection @user.getSlugOrID()
|
|
|
|
#@supermodel.loadCollection @levelSessions, 'levelSessions'
|
|
|
|
@supermodel.loadCollection @earnedAchievements, 'earnedAchievements'
|
|
|
|
|
2014-07-29 10:50:07 -04:00
|
|
|
super()
|