mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Fixes for browsing profiles by username.
This commit is contained in:
parent
67b10474e8
commit
63a3aa9074
4 changed files with 49 additions and 25 deletions
|
@ -18,7 +18,7 @@ block content
|
|||
button.btn#toggle-editing
|
||||
i.icon-cog
|
||||
span(data-i18n="account_profile.edit_profile") Edit Profile
|
||||
if profile.active
|
||||
if profile && profile.active
|
||||
button.btn.btn-success#toggle-job-profile-active
|
||||
i.icon-eye-open
|
||||
span(data-i18n="account_profile.active") Looking for interview offers now
|
||||
|
@ -26,7 +26,7 @@ block content
|
|||
button.btn#toggle-job-profile-active
|
||||
i.icon-eye-close
|
||||
span(data-i18n="account_profile.inactive") Not looking for offers right now
|
||||
if profile.active || me.isAdmin()
|
||||
if profile && (profile.active || me.isAdmin())
|
||||
if !profileApproved
|
||||
button.btn.btn-success#toggle-job-profile-approved(disabled=!me.isAdmin())
|
||||
i.icon-eye-open
|
||||
|
@ -444,7 +444,7 @@ block content
|
|||
.public-profile-container
|
||||
h2(data-i18n="common.loading") Loading...
|
||||
|
||||
else
|
||||
else if user
|
||||
.public-profile-container
|
||||
h2
|
||||
span(data-i18n="account_profile.profile_for_prefix") Profile for
|
||||
|
@ -454,3 +454,12 @@ block content
|
|||
img.profile-photo(src=user.getPhotoURL(256))
|
||||
|
||||
p To see a private user profile, you may need to log in.
|
||||
|
||||
else
|
||||
.public-profile-container
|
||||
h2
|
||||
span(data-i18n="account_profile.profile_for_prefix") Profile for
|
||||
span= userID
|
||||
span(data-i18n="account_profile.profile_for_suffix")
|
||||
|
|
||||
span(data-i18n="loading_error.not_found")
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = class ProfileView extends View
|
|||
'click #toggle-editing': 'toggleEditing'
|
||||
'click #toggle-job-profile-active': 'toggleJobProfileActive'
|
||||
'click #toggle-job-profile-approved': 'toggleJobProfileApproved'
|
||||
'click save-notes-button': 'onJobProfileNotesChanged'
|
||||
'click #save-notes-button': 'onJobProfileNotesChanged'
|
||||
'click #contact-candidate': 'onContactCandidate'
|
||||
'click #enter-espionage-mode': 'enterEspionageMode'
|
||||
'click .editable-profile .profile-photo': 'onEditProfilePhoto'
|
||||
|
@ -27,8 +27,18 @@ module.exports = class ProfileView extends View
|
|||
|
||||
constructor: (options, @userID) ->
|
||||
@userID ?= me.id
|
||||
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
|
||||
super options
|
||||
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()
|
||||
|
||||
finishInit: ->
|
||||
return unless @userID
|
||||
@uploadFilePath = "db/user/#{@userID}"
|
||||
@highlightedContainers = []
|
||||
if @userID is me.id
|
||||
|
@ -43,28 +53,29 @@ module.exports = class ProfileView extends View
|
|||
|
||||
getRenderData: ->
|
||||
context = super()
|
||||
context.userID = @userID
|
||||
context.jobProfileSchema = me.schema().properties.jobProfile
|
||||
unless jobProfile = @user.get 'jobProfile'
|
||||
if @user and not jobProfile = @user.get 'jobProfile'
|
||||
jobProfile = {}
|
||||
for prop, schema of context.jobProfileSchema.properties
|
||||
jobProfile[prop] = _.clone schema.default if schema.default?
|
||||
for prop in context.jobProfileSchema.required
|
||||
jobProfile[prop] ?= {string: '', boolean: false, number: 0, integer: 0, array: []}[context.jobProfileSchema.properties[prop].type]
|
||||
@user.set 'jobProfile', jobProfile
|
||||
jobProfile.name ?= (@user.get('firstName') + ' ' + @user.get('lastName')).trim() if @user.get('firstName')
|
||||
jobProfile.name ?= (@user.get('firstName') + ' ' + @user.get('lastName')).trim() if @user?.get('firstName')
|
||||
context.profile = jobProfile
|
||||
context.user = @user
|
||||
context.myProfile = @user.id is context.me.id
|
||||
context.allowedToViewJobProfile = me.isAdmin() or "employer" in me.get('permissions') or (context.myProfile && !me.get('anonymous'))
|
||||
context.allowedToEditJobProfile = me.isAdmin() or (context.myProfile && !me.get('anonymous'))
|
||||
context.profileApproved = @user.get 'jobProfileApproved'
|
||||
context.myProfile = @user?.id is context.me.id
|
||||
context.allowedToViewJobProfile = @user and (me.isAdmin() or "employer" in me.get('permissions') or (context.myProfile && !me.get('anonymous')))
|
||||
context.allowedToEditJobProfile = @user and (me.isAdmin() or (context.myProfile && !me.get('anonymous')))
|
||||
context.profileApproved = @user?.get 'jobProfileApproved'
|
||||
context.progress = @progress ? @updateProgress()
|
||||
@editing ?= context.progress < 0.8
|
||||
context.editing = @editing
|
||||
context.marked = marked
|
||||
context.moment = moment
|
||||
context.iconForLink = @iconForLink
|
||||
if links = jobProfile.links
|
||||
if links = jobProfile?.links
|
||||
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
|
||||
|
@ -72,6 +83,7 @@ module.exports = class ProfileView extends View
|
|||
|
||||
afterRender: ->
|
||||
super()
|
||||
return unless @user
|
||||
unless @user.get('jobProfile')?.projects?.length or @editing
|
||||
@$el.find('.right-column').hide()
|
||||
@$el.find('.middle-column').addClass('double-column')
|
||||
|
@ -287,6 +299,7 @@ module.exports = class ProfileView extends View
|
|||
e.preventDefault()
|
||||
|
||||
updateProgress: (highlightNext) ->
|
||||
return unless @user
|
||||
completed = 0
|
||||
totalWeight = 0
|
||||
next = null
|
||||
|
|
|
@ -17,10 +17,12 @@ DEBUGGING = true
|
|||
|
||||
sendInitialRecruitingEmail = ->
|
||||
leaderboards = [
|
||||
{slug: 'brawlwood', team: 'humans', limit: 55, name: "Brawlwood", original: "52d97ecd32362bc86e004e87", majorVersion: 0}
|
||||
{slug: 'brawlwood', team: 'ogres', limit: 40, name: "Brawlwood", original: "52d97ecd32362bc86e004e87", majorVersion: 0}
|
||||
{slug: 'dungeon-arena', team: 'humans', limit: 200, name: "Dungeon Arena", original: "53173f76c269d400000543c2", majorVersion: 0}
|
||||
{slug: 'dungeon-arena', team: 'ogres', limit: 150, name: "Dungeon Arena", original: "53173f76c269d400000543c2", majorVersion: 0}
|
||||
#{slug: 'brawlwood', team: 'humans', limit: 55, name: "Brawlwood", original: "52d97ecd32362bc86e004e87", majorVersion: 0}
|
||||
#{slug: 'brawlwood', team: 'ogres', limit: 40, name: "Brawlwood", original: "52d97ecd32362bc86e004e87", majorVersion: 0}
|
||||
#{slug: 'dungeon-arena', team: 'humans', limit: 200, name: "Dungeon Arena", original: "53173f76c269d400000543c2", majorVersion: 0}
|
||||
#{slug: 'dungeon-arena', team: 'ogres', limit: 150, name: "Dungeon Arena", original: "53173f76c269d400000543c2", majorVersion: 0}
|
||||
{slug: 'greed', team: 'humans', limit: 320, name: "Greed", original: "53558b5a9914f5a90d7ccddb", majorVersion: 0}
|
||||
{slug: 'greed', team: 'ogres', limit: 300, name: "Greed", original: "53558b5a9914f5a90d7ccddb", majorVersion: 0}
|
||||
]
|
||||
async.waterfall [
|
||||
(callback) -> async.map leaderboards, grabSessions, callback
|
||||
|
@ -38,13 +40,12 @@ grabSessions = (levelInfo, callback) ->
|
|||
submitted: true
|
||||
sortParameters = totalScore: -1
|
||||
selectString = 'totalScore creator'
|
||||
query = LevelSession
|
||||
.find(queryParameters)
|
||||
.limit(levelInfo.limit)
|
||||
.sort(sortParameters)
|
||||
.select(selectString)
|
||||
.lean()
|
||||
query.exec (err, sessions) ->
|
||||
LevelSession.aggregate [
|
||||
{$match: queryParameters}
|
||||
{$project: {totalScore: 1, creator: 1}}
|
||||
{$sort: sortParameters}
|
||||
{$limit: levelInfo.limit}
|
||||
], (err, sessions) ->
|
||||
return callback err if err
|
||||
for session, rank in sessions
|
||||
session.levelInfo = levelInfo
|
||||
|
@ -80,7 +81,7 @@ emailUser = (user, callback) ->
|
|||
#return callback null, false if user.emails?.anyNotes?.enabled is false # TODO: later, uncomment to obey also "anyNotes" when that's untangled
|
||||
return callback null, false if user.emails?.recruitNotes?.enabled is false
|
||||
return callback null, false if user.email in alreadyEmailed
|
||||
return callback null, false if DEBUGGING and (totalEmailsSent > 1 or Math.random() > 0.1)
|
||||
return callback null, false if DEBUGGING and (totalEmailsSent > 1 or Math.random() > 0.05)
|
||||
++totalEmailsSent
|
||||
name = if user.firstName and user.lastName then "#{user.firstName}" else user.name
|
||||
name = "Wizard" if not name or name is "Anoner"
|
||||
|
@ -96,6 +97,7 @@ emailUser = (user, callback) ->
|
|||
level_name: user.session.levelInfo.name
|
||||
place: "##{user.session.rank}" # like "#31"
|
||||
level_race: team
|
||||
ladder_link: "http://codecombat.com/play/ladder/#{user.session.levelInfo.name.toLowerCase()}"
|
||||
sendwithus.api.send context, (err, result) ->
|
||||
return callback err if err
|
||||
callback null, user
|
||||
|
|
|
@ -130,7 +130,7 @@ UserHandler = class UserHandler extends Handler
|
|||
@getPropertiesFromMultipleDocuments res, User, properties, ids
|
||||
|
||||
nameToID: (req, res, name) ->
|
||||
User.findOne({nameLower:name.toLowerCase(),anonymous:false}).exec (err, otherUser) ->
|
||||
User.findOne({nameLower:unescape(name).toLowerCase(),anonymous:false}).exec (err, otherUser) ->
|
||||
res.send(if otherUser then otherUser._id else JSON.stringify(''))
|
||||
res.end()
|
||||
|
||||
|
|
Loading…
Reference in a new issue