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-07-29 10:50:07 -04:00
|
|
|
class LevelSessionsCollection extends CocoCollection
|
|
|
|
model: LevelSession
|
|
|
|
|
|
|
|
constructor: (userID) ->
|
2014-07-29 14:11:45 -04:00
|
|
|
@url = "/db/user/#{userID}/level.sessions?project=state.complete,levelID,levelName,changed,team,submittedCodeLanguage&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-07-29 10:50:07 -04:00
|
|
|
if @user
|
|
|
|
singlePlayerSessions = []
|
|
|
|
multiPlayerSessions = []
|
|
|
|
languageCounts = {}
|
|
|
|
for levelSession in @levelSessions.models
|
|
|
|
if levelSession.isMultiPlayer()
|
|
|
|
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-07-15 10:15:21 -04:00
|
|
|
context
|
|
|
|
|
2014-07-29 10:50:07 -04:00
|
|
|
onUserLoaded: (user) ->
|
|
|
|
@levelSessions = @supermodel.loadCollection(new LevelSessionsCollection(@userID), 'levelSessions').model
|
|
|
|
super user
|
|
|
|
|
|
|
|
onLoaded: ->
|
|
|
|
super()
|