Make LinkedIn import more robust
This commit is contained in:
parent
4072c1b969
commit
7ec3910e36
2 changed files with 49 additions and 23 deletions
app
|
@ -3,11 +3,7 @@ extends /templates/base
|
||||||
block content
|
block content
|
||||||
if allowedToEditJobProfile
|
if allowedToEditJobProfile
|
||||||
.profile-control-bar
|
.profile-control-bar
|
||||||
if linkedInAuthorized
|
|
||||||
button.btn#importLinkedIn
|
|
||||||
span Import LinkedIn
|
|
||||||
else
|
|
||||||
script(type="in/Login" id="linkedInAuthButton" data-onAuth="contractCallback")
|
|
||||||
if editing
|
if editing
|
||||||
.progress.profile-completion-progress
|
.progress.profile-completion-progress
|
||||||
.progress-bar.progress-bar-success(style="width: #{100 * progress}%")
|
.progress-bar.progress-bar-success(style="width: #{100 * progress}%")
|
||||||
|
@ -23,6 +19,12 @@ block content
|
||||||
button.btn#toggle-editing
|
button.btn#toggle-editing
|
||||||
i.icon-cog
|
i.icon-cog
|
||||||
span(data-i18n="account_profile.edit_profile") Edit Profile
|
span(data-i18n="account_profile.edit_profile") Edit Profile
|
||||||
|
if linkedInAuthorized
|
||||||
|
button.btn.btn-success#importLinkedIn
|
||||||
|
i.icon-arrow-down
|
||||||
|
span Import LinkedIn
|
||||||
|
else
|
||||||
|
script(type="in/Login" id="linkedInAuthButton" data-onAuth="contractCallback")
|
||||||
if profile.active
|
if profile.active
|
||||||
button.btn.btn-success#toggle-job-profile-active
|
button.btn.btn-success#toggle-job-profile-active
|
||||||
i.icon-eye-open
|
i.icon-eye-open
|
||||||
|
|
|
@ -69,35 +69,43 @@ module.exports = class ProfileView extends View
|
||||||
else
|
else
|
||||||
@waitingForLinkedIn = true
|
@waitingForLinkedIn = true
|
||||||
importLinkedIn: =>
|
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) =>
|
application.linkedinHandler.getProfileData (err, profileData) =>
|
||||||
console.log profileData
|
console.log profileData
|
||||||
@processLinkedInProfileData profileData, ->
|
@processLinkedInProfileData profileData, ->
|
||||||
console.log "DONE"
|
jobProfileSchema: -> @user.schema().properties.jobProfile.properties
|
||||||
|
|
||||||
processLinkedInProfileData: (p, cb) ->
|
processLinkedInProfileData: (p, cb) ->
|
||||||
#handle formatted-name
|
#handle formatted-name
|
||||||
currentJobProfile = me.get('jobProfile')
|
currentJobProfile = @user.get('jobProfile')
|
||||||
|
jobProfileSchema = @user.schema().properties.jobProfile.properties
|
||||||
|
|
||||||
if p["formattedName"]? and p["formattedName"] isnt "private"
|
if p["formattedName"]? and p["formattedName"] isnt "private"
|
||||||
currentJobProfile.name = p["formattedName"]
|
nameMaxLength = jobProfileSchema.name.maxLength
|
||||||
|
currentJobProfile.name = p["formattedName"].slice(0,nameMaxLength)
|
||||||
if p["skills"]?["values"].length
|
if p["skills"]?["values"].length
|
||||||
skillNames = []
|
skillNames = []
|
||||||
|
skillMaxLength = jobProfileSchema.skills.items.maxLength
|
||||||
for skill in p.skills.values
|
for skill in p.skills.values
|
||||||
skillNames.push skill.skill.name
|
skillNames.push skill.skill.name.slice(0,skillMaxLength)
|
||||||
|
|
||||||
console.log "Skills: #{skillNames}"
|
|
||||||
currentJobProfile.skills = skillNames
|
currentJobProfile.skills = skillNames
|
||||||
if p["headline"]
|
if p["headline"]
|
||||||
console.log "jobProfile.shortDescription: #{p["headline"]}"
|
shortDescriptionMaxLength = jobProfileSchema.shortDescription.maxLength
|
||||||
currentJobProfile.shortDescription = p["headline"]
|
currentJobProfile.shortDescription = p["headline"].slice(0,shortDescriptionMaxLength)
|
||||||
if p["summary"]
|
if p["summary"]
|
||||||
console.log "jobProfile.longDescription: #{p.summary}"
|
longDescriptionMaxLength = jobProfileSchema.longDescription.maxLength
|
||||||
currentJobProfile.longDescription = p.summary
|
currentJobProfile.longDescription = p.summary.slice(0,longDescriptionMaxLength)
|
||||||
if p["positions"]?["values"]?.length
|
if p["positions"]?["values"]?.length
|
||||||
newWorks = []
|
newWorks = []
|
||||||
|
workSchema = jobProfileSchema.work.items.properties
|
||||||
for position in p["positions"]["values"]
|
for position in p["positions"]["values"]
|
||||||
workObj = {}
|
workObj = {}
|
||||||
workObj.description = position.summary?.slice(0,139)
|
descriptionMaxLength = workSchema.description.maxLength
|
||||||
if position.startDate?.year
|
|
||||||
|
workObj.description = position.summary?.slice(0,descriptionMaxLength)
|
||||||
|
workObj.description ?= ""
|
||||||
|
if position.startDate?.year?
|
||||||
workObj.duration = "#{position.startDate.year} - "
|
workObj.duration = "#{position.startDate.year} - "
|
||||||
if (not position.endDate?.year) or (position.endDate?.year and position.endDate?.year > (new Date().getFullYear()))
|
if (not position.endDate?.year) or (position.endDate?.year and position.endDate?.year > (new Date().getFullYear()))
|
||||||
workObj.duration += "present"
|
workObj.duration += "present"
|
||||||
|
@ -105,18 +113,26 @@ module.exports = class ProfileView extends View
|
||||||
workObj.duration += position.endDate.year
|
workObj.duration += position.endDate.year
|
||||||
else
|
else
|
||||||
workObj.duration = ""
|
workObj.duration = ""
|
||||||
|
durationMaxLength = workSchema.duration.maxLength
|
||||||
|
workObj.duration = workObj.duration.slice(0,durationMaxLength)
|
||||||
|
employerMaxLength = workSchema.employer.maxLength
|
||||||
workObj.employer = position.company?.name ? ""
|
workObj.employer = position.company?.name ? ""
|
||||||
|
workObj.employer = workObj.employer.slice(0,employerMaxLength)
|
||||||
workObj.role = position.title ? ""
|
workObj.role = position.title ? ""
|
||||||
|
roleMaxLength = workSchema.role.maxLength
|
||||||
|
workObj.role = workObj.role.slice(0,roleMaxLength)
|
||||||
newWorks.push workObj
|
newWorks.push workObj
|
||||||
currentJobProfile.work = newWorks
|
currentJobProfile.work = newWorks
|
||||||
|
|
||||||
|
|
||||||
if p["educations"]?["values"]?.length
|
if p["educations"]?["values"]?.length
|
||||||
newEducation = []
|
newEducation = []
|
||||||
|
eduSchema = jobProfileSchema.education.items.properties
|
||||||
for education in p["educations"]["values"]
|
for education in p["educations"]["values"]
|
||||||
educationObject = {}
|
educationObject = {}
|
||||||
educationObject.degree = education.degree ? "Studied"
|
educationObject.degree = education.degree ? "Studied"
|
||||||
if education.startDate?.year
|
educationObject.degree = educationObject.degree.slice(0,eduSchema.degree.maxLength)
|
||||||
|
if education.startDate?.year?
|
||||||
educationObject.duration = "#{education.startDate.year} - "
|
educationObject.duration = "#{education.startDate.year} - "
|
||||||
if (not education.endDate?.year) or (education.endDate?.year and education.endDate?.year > (new Date().getFullYear()))
|
if (not education.endDate?.year) or (education.endDate?.year and education.endDate?.year > (new Date().getFullYear()))
|
||||||
educationObject.duration += "present"
|
educationObject.duration += "present"
|
||||||
|
@ -124,14 +140,21 @@ module.exports = class ProfileView extends View
|
||||||
educationObject.degree = "Studying"
|
educationObject.degree = "Studying"
|
||||||
else
|
else
|
||||||
educationObject.duration += education.endDate.year
|
educationObject.duration += education.endDate.year
|
||||||
|
else
|
||||||
|
educationObject.duration = ""
|
||||||
|
educationObject.duration = educationObject.duration.slice(0,eduSchema.duration.maxLength)
|
||||||
educationObject.school = education.schoolName ? ""
|
educationObject.school = education.schoolName ? ""
|
||||||
|
educationObject.school = educationObject.school.slice(0,eduSchema.school.maxLength)
|
||||||
educationObject.description = ""
|
educationObject.description = ""
|
||||||
console.log "Educated at:#{education.schoolName}"
|
|
||||||
newEducation.push educationObject
|
newEducation.push educationObject
|
||||||
currentJobProfile.education = newEducation
|
currentJobProfile.education = newEducation
|
||||||
me.set('jobProfile',currentJobProfile)
|
validationErrors = @user.validate()
|
||||||
@render()
|
if validationErrors
|
||||||
|
return alert("Please notify team@codecombat.com! There were validation errors from the import: #{JSON.stringify validationErrors}")
|
||||||
|
else
|
||||||
|
@user.set('jobProfile',currentJobProfile)
|
||||||
|
@user.save()
|
||||||
|
@render()
|
||||||
|
|
||||||
getRenderData: ->
|
getRenderData: ->
|
||||||
context = super()
|
context = super()
|
||||||
|
@ -186,6 +209,7 @@ module.exports = class ProfileView extends View
|
||||||
toggleEditing: ->
|
toggleEditing: ->
|
||||||
@editing = not @editing
|
@editing = not @editing
|
||||||
@render()
|
@render()
|
||||||
|
IN.parse()
|
||||||
|
|
||||||
toggleJobProfileApproved: ->
|
toggleJobProfileApproved: ->
|
||||||
return unless me.isAdmin()
|
return unless me.isAdmin()
|
||||||
|
|
Reference in a new issue