mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Improvements to profile views. Added links to players' code.
This commit is contained in:
parent
8a728cbb64
commit
77920b5416
12 changed files with 53 additions and 26 deletions
|
@ -22,13 +22,13 @@ module.exports = class LevelBus extends Bus
|
|||
'tome:spell-changed': 'onSpellChanged'
|
||||
'tome:spell-created': 'onSpellCreated'
|
||||
'application:idle-changed': 'onIdleChanged'
|
||||
|
||||
|
||||
constructor: ->
|
||||
super(arguments...)
|
||||
@changedSessionProperties = {}
|
||||
@saveSession = _.debounce(@saveSession, 1000, {maxWait: 5000})
|
||||
@playerIsIdle = false
|
||||
|
||||
|
||||
init: ->
|
||||
super()
|
||||
@fireScriptsRef = @fireRef?.child('scripts')
|
||||
|
@ -36,7 +36,7 @@ module.exports = class LevelBus extends Bus
|
|||
setSession: (@session) ->
|
||||
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
|
||||
@timerIntervalID = setInterval(@incrementSessionPlaytime, 1000)
|
||||
|
||||
|
||||
onIdleChanged: (e) ->
|
||||
@playerIsIdle = e.idle
|
||||
|
||||
|
@ -44,7 +44,7 @@ module.exports = class LevelBus extends Bus
|
|||
if @playerIsIdle then return
|
||||
@changedSessionProperties.playtime = true
|
||||
@session.set("playtime",@session.get("playtime") + 1)
|
||||
|
||||
|
||||
onPoint: ->
|
||||
return true unless @session?.get('multiplayer')
|
||||
super()
|
||||
|
@ -224,7 +224,7 @@ module.exports = class LevelBus extends Bus
|
|||
|
||||
saveSession: ->
|
||||
return if _.isEmpty @changedSessionProperties
|
||||
# don't let peaking admins mess with the session accidentally
|
||||
# don't let peeking admins mess with the session accidentally
|
||||
return unless @session.get('multiplayer') or @session.get('creator') is me.id
|
||||
Backbone.Mediator.publish 'level:session-will-save', session: @session
|
||||
patch = {}
|
||||
|
|
|
@ -294,6 +294,7 @@
|
|||
project_picture_help: "Upload a 230x115px or larger image showing off the project."
|
||||
project_link: "Link"
|
||||
project_link_help: "Link to the project."
|
||||
player_code: "Player Code"
|
||||
|
||||
employers:
|
||||
want_to_hire_our_players: "Want to hire expert CodeCombat players?"
|
||||
|
@ -867,6 +868,7 @@
|
|||
source_document: "Source Document"
|
||||
document: "Document" # note to diplomats: not a physical document, a document in MongoDB, ie a record in a database
|
||||
sprite_sheet: "Sprite Sheet"
|
||||
candidate_sessions: "Candidate Sessions"
|
||||
|
||||
delta:
|
||||
added: "Added"
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif
|
||||
color: #555
|
||||
|
||||
ul.links, ul.projects
|
||||
ul.links, ul.projects, ul.sessions
|
||||
margin: 0
|
||||
padding: 0
|
||||
|
||||
|
@ -140,7 +140,7 @@
|
|||
background-color: rgb(177, 55, 25)
|
||||
padding: 15px
|
||||
font-size: 20px
|
||||
|
||||
|
||||
.middle-column
|
||||
width: $middle-width - 2 * $middle-padding
|
||||
padding-left: $middle-padding
|
||||
|
|
|
@ -170,6 +170,19 @@ block content
|
|||
span(data-i18n="account_profile.contact") Contact
|
||||
| #{profile.name.split(' ')[0]}
|
||||
|
||||
if !editing && sessions.length
|
||||
h3(data-i18n="account_profile.player_code") Player Code
|
||||
ul.sessions
|
||||
each session in sessions
|
||||
li
|
||||
- var sessionLink = "/play/level/" + session.levelID + "?team=" + (session.team || 'humans') + "&session=" + session._id;
|
||||
a(href=sessionLink)
|
||||
span= session.levelName
|
||||
if session.team
|
||||
span #{session.team}
|
||||
if session.codeLanguage != 'javascript'
|
||||
span - #{{coffeescript: 'CoffeeScript', python: 'Python', lua: 'Lua', io: 'Io', clojure: 'Clojure'}[session.codeLanguage]}
|
||||
|
||||
.middle-column.full-height-column
|
||||
.sub-column
|
||||
#name-container.editable-section
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
View = require 'views/kinds/RootView'
|
||||
template = require 'templates/account/profile'
|
||||
User = require 'models/User'
|
||||
LevelSession = require 'models/LevelSession'
|
||||
CocoCollection = require 'collections/CocoCollection'
|
||||
{me} = require 'lib/auth'
|
||||
JobProfileContactView = require 'views/modal/job_profile_contact_modal'
|
||||
JobProfileView = require 'views/account/job_profile_view'
|
||||
forms = require 'lib/forms'
|
||||
|
||||
class LevelSessionsCollection extends CocoCollection
|
||||
url: -> "/db/user/#{@userID}/level.sessions/employer"
|
||||
model: LevelSession
|
||||
constructor: (@userID) ->
|
||||
super()
|
||||
|
||||
module.exports = class ProfileView extends View
|
||||
id: "profile-view"
|
||||
template: template
|
||||
|
@ -42,9 +50,7 @@ module.exports = class ProfileView extends View
|
|||
if User.isObjectID @userID
|
||||
@finishInit()
|
||||
else
|
||||
console.log "getting", @userID
|
||||
$.ajax "/db/user/#{@userID}/nameToID", success: (@userID) =>
|
||||
console.log " got", @userID
|
||||
@finishInit() unless @destroyed
|
||||
@render()
|
||||
|
||||
|
@ -63,6 +69,7 @@ module.exports = class ProfileView extends View
|
|||
$.post "/db/user/#{@userID}/track/viewed_by_employer" unless me.isAdmin()
|
||||
else
|
||||
@user = User.getByID(@userID)
|
||||
@sessions = @supermodel.loadCollection(new LevelSessionsCollection(@userID), 'candidate_sessions').model
|
||||
|
||||
onLinkedInLoaded: =>
|
||||
@linkedinLoaded = true
|
||||
|
@ -80,11 +87,11 @@ module.exports = class ProfileView extends View
|
|||
@renderLinkedInButton()
|
||||
else
|
||||
@waitingForLinkedIn = true
|
||||
|
||||
importLinkedIn: =>
|
||||
overwriteConfirm = confirm("Importing LinkedIn data will overwrite your current work experience, skills, name, descriptions, and education. Continue?")
|
||||
unless overwriteConfirm then return
|
||||
application.linkedinHandler.getProfileData (err, profileData) =>
|
||||
console.log profileData
|
||||
@processLinkedInProfileData profileData
|
||||
jobProfileSchema: -> @user.schema().properties.jobProfile.properties
|
||||
|
||||
|
@ -217,6 +224,8 @@ module.exports = class ProfileView extends View
|
|||
links = ($.extend(true, {}, link) for link in links)
|
||||
link.icon = @iconForLink link for link in links
|
||||
context.profileLinks = _.sortBy links, (link) -> not link.icon # icons first
|
||||
context.sessions = (s.attributes for s in @sessions.models when (s.get('submitted') or s.get('level-id') is 'gridmancer'))
|
||||
context.sessions.sort (a, b) -> (b.playtime ? 0) - (a.playtime ? 0)
|
||||
context
|
||||
|
||||
afterRender: ->
|
||||
|
@ -303,7 +312,7 @@ module.exports = class ProfileView extends View
|
|||
errors = @user.validate()
|
||||
return @showErrors errors if errors
|
||||
jobProfile = @user.get('jobProfile')
|
||||
jobProfile.updated = (new Date()).toISOString()
|
||||
jobProfile.updated = (new Date()).toISOString() if @user is me
|
||||
@user.set 'jobProfile', jobProfile
|
||||
return unless res = @user.save()
|
||||
res.error =>
|
||||
|
|
|
@ -52,6 +52,7 @@ module.exports = class EmployersView extends View
|
|||
@listenToOnce @candidates, 'all', @renderCandidatesAndSetupScrolling
|
||||
|
||||
renderCandidatesAndSetupScrolling: =>
|
||||
|
||||
@render()
|
||||
$(".nano").nanoScroller()
|
||||
if window.history?.state?.lastViewedCandidateID
|
||||
|
|
|
@ -10,14 +10,6 @@ ModelModal = require 'views/modal/model_modal'
|
|||
|
||||
HIGHEST_SCORE = 1000000
|
||||
|
||||
class LevelSessionsCollection extends CocoCollection
|
||||
url: ''
|
||||
model: LevelSession
|
||||
|
||||
constructor: (levelID) ->
|
||||
super()
|
||||
@url = "/db/level/#{levelID}/all_sessions"
|
||||
|
||||
module.exports = class LadderTabView extends CocoView
|
||||
id: 'ladder-tab-view'
|
||||
template: require 'templates/play/ladder/ladder_tab'
|
||||
|
|
|
@ -43,7 +43,7 @@ module.exports = class LadderView extends RootView
|
|||
|
||||
onLoaded: ->
|
||||
@teams = teamDataFromLevel @level
|
||||
@render()
|
||||
super()
|
||||
|
||||
getRenderData: ->
|
||||
ctx = super()
|
||||
|
|
|
@ -24,7 +24,7 @@ module.exports = class Spell
|
|||
@permissions = read: p.permissions?.read ? [], readwrite: p.permissions?.readwrite ? [] # teams
|
||||
teamSpells = @session.get('teamSpells')
|
||||
team = @session.get('team') ? 'humans'
|
||||
@useTranspiledCode = @permissions.readwrite.length and ((teamSpells and not _.contains(teamSpells[team], @spellKey)) or (@session.get('creator') isnt me.id) or @spectateView)
|
||||
@useTranspiledCode = @permissions.readwrite.length and ((teamSpells and not _.contains(teamSpells[team], @spellKey)) or (@session.get('creator') isnt me.id and not (me.isAdmin() or 'employer' in me.get('permissions'))) or @spectateView)
|
||||
#console.log @spellKey, "using transpiled code?", @useTranspiledCode
|
||||
@source = @originalSource = p.source
|
||||
@parameters = p.parameters
|
||||
|
|
|
@ -14,14 +14,14 @@ class LevelSessionHandler extends Handler
|
|||
getByRelationship: (req, res, args...) ->
|
||||
return @getActiveSessions req, res if args.length is 2 and args[1] is 'active'
|
||||
super(arguments...)
|
||||
|
||||
|
||||
formatEntity: (req, document) ->
|
||||
documentObject = super(req, document)
|
||||
if req.user.isAdmin() or req.user.id is document.creator
|
||||
if req.user.isAdmin() or req.user.id is document.creator or ('employer' in req.user.get('permissions'))
|
||||
return documentObject
|
||||
else
|
||||
return _.omit documentObject, ['submittedCode','code']
|
||||
|
||||
|
||||
getActiveSessions: (req, res) ->
|
||||
return @sendUnauthorizedError(res) unless req.user.isAdmin()
|
||||
start = new Date()
|
||||
|
@ -34,6 +34,7 @@ class LevelSessionHandler extends Handler
|
|||
|
||||
hasAccessToDocument: (req, document, method=null) ->
|
||||
return true if req.method is 'GET' and document.get('totalScore')
|
||||
return true if ('employer' in req.user.get('permissions')) and (method ? req.method).toLowerCase() is 'get'
|
||||
super(arguments...)
|
||||
|
||||
module.exports = new LevelSessionHandler()
|
||||
|
|
|
@ -62,7 +62,6 @@ module.exports.setup = (app) ->
|
|||
req.logIn(user, (err) ->
|
||||
return next(err) if (err)
|
||||
activity = req.user.trackActivity 'login', 1
|
||||
console.log "updating", activity
|
||||
user.update {activity: activity}, (err) ->
|
||||
return next(err) if (err)
|
||||
res.send(UserHandler.formatEntity(req, req.user))
|
||||
|
|
|
@ -189,6 +189,7 @@ UserHandler = class UserHandler extends Handler
|
|||
return @avatar(req, res, args[0]) if args[1] is 'avatar'
|
||||
return @getNamesByIDs(req, res) if args[1] is 'names'
|
||||
return @nameToID(req, res, args[0]) if args[1] is 'nameToID'
|
||||
return @getLevelSessionsForEmployer(req, res, args[0]) if args[1] is 'level.sessions' and args[2] is 'employer'
|
||||
return @getLevelSessions(req, res, args[0]) if args[1] is 'level.sessions'
|
||||
return @getCandidates(req, res) if args[1] is 'candidates'
|
||||
return @getEmployers(req, res) if args[1] is 'employers'
|
||||
|
@ -227,9 +228,18 @@ UserHandler = class UserHandler extends Handler
|
|||
res.redirect photoURL
|
||||
res.end()
|
||||
|
||||
getLevelSessionsForEmployer: (req, res, userID) ->
|
||||
return @sendUnauthorizedError(res) unless req.user._id+'' is userID or req.user.isAdmin() or ('employer' in req.user.get('permissions'))
|
||||
query = creator: userID, levelID: {$in: ['gridmancer', 'greed', 'dungeon-arena', 'brawlwood', 'gold-rush']}
|
||||
projection = 'levelName levelID team playtime codeLanguage submitted' # code totalScore
|
||||
LevelSession.find(query).select(projection).exec (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
documents = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
|
||||
@sendSuccess(res, documents)
|
||||
|
||||
getLevelSessions: (req, res, userID) ->
|
||||
return @sendUnauthorizedError(res) unless req.user._id+'' is userID or req.user.isAdmin()
|
||||
query = {'creator': userID}
|
||||
query = creator: userID
|
||||
projection = null
|
||||
if req.query.project
|
||||
projection = {}
|
||||
|
|
Loading…
Reference in a new issue