From 7ec3910e36ab3544d3e19ab688848cfb36dfa291 Mon Sep 17 00:00:00 2001 From: Michael Schmatz Date: Sun, 8 Jun 2014 17:38:02 -0700 Subject: [PATCH] Make LinkedIn import more robust --- app/templates/account/profile.jade | 12 +++--- app/views/account/profile_view.coffee | 60 +++++++++++++++++++-------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/app/templates/account/profile.jade b/app/templates/account/profile.jade index fe31e5a87..9a8e21c45 100644 --- a/app/templates/account/profile.jade +++ b/app/templates/account/profile.jade @@ -3,11 +3,7 @@ extends /templates/base block content if allowedToEditJobProfile .profile-control-bar - if linkedInAuthorized - button.btn#importLinkedIn - span Import LinkedIn - else - script(type="in/Login" id="linkedInAuthButton" data-onAuth="contractCallback") + if editing .progress.profile-completion-progress .progress-bar.progress-bar-success(style="width: #{100 * progress}%") @@ -23,6 +19,12 @@ block content button.btn#toggle-editing i.icon-cog 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 button.btn.btn-success#toggle-job-profile-active i.icon-eye-open diff --git a/app/views/account/profile_view.coffee b/app/views/account/profile_view.coffee index be0de3b5c..ba4808781 100644 --- a/app/views/account/profile_view.coffee +++ b/app/views/account/profile_view.coffee @@ -69,35 +69,43 @@ module.exports = class ProfileView extends View 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, -> - console.log "DONE" - + jobProfileSchema: -> @user.schema().properties.jobProfile.properties + processLinkedInProfileData: (p, cb) -> #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" - currentJobProfile.name = p["formattedName"] + nameMaxLength = jobProfileSchema.name.maxLength + currentJobProfile.name = p["formattedName"].slice(0,nameMaxLength) if p["skills"]?["values"].length skillNames = [] + skillMaxLength = jobProfileSchema.skills.items.maxLength for skill in p.skills.values - skillNames.push skill.skill.name - - console.log "Skills: #{skillNames}" + skillNames.push skill.skill.name.slice(0,skillMaxLength) currentJobProfile.skills = skillNames if p["headline"] - console.log "jobProfile.shortDescription: #{p["headline"]}" - currentJobProfile.shortDescription = p["headline"] + shortDescriptionMaxLength = jobProfileSchema.shortDescription.maxLength + currentJobProfile.shortDescription = p["headline"].slice(0,shortDescriptionMaxLength) if p["summary"] - console.log "jobProfile.longDescription: #{p.summary}" - currentJobProfile.longDescription = p.summary + longDescriptionMaxLength = jobProfileSchema.longDescription.maxLength + currentJobProfile.longDescription = p.summary.slice(0,longDescriptionMaxLength) if p["positions"]?["values"]?.length newWorks = [] + workSchema = jobProfileSchema.work.items.properties for position in p["positions"]["values"] workObj = {} - workObj.description = position.summary?.slice(0,139) - if position.startDate?.year + descriptionMaxLength = workSchema.description.maxLength + + workObj.description = position.summary?.slice(0,descriptionMaxLength) + workObj.description ?= "" + if position.startDate?.year? workObj.duration = "#{position.startDate.year} - " if (not position.endDate?.year) or (position.endDate?.year and position.endDate?.year > (new Date().getFullYear())) workObj.duration += "present" @@ -105,18 +113,26 @@ module.exports = class ProfileView extends View workObj.duration += position.endDate.year else workObj.duration = "" + durationMaxLength = workSchema.duration.maxLength + workObj.duration = workObj.duration.slice(0,durationMaxLength) + employerMaxLength = workSchema.employer.maxLength workObj.employer = position.company?.name ? "" + workObj.employer = workObj.employer.slice(0,employerMaxLength) workObj.role = position.title ? "" + roleMaxLength = workSchema.role.maxLength + workObj.role = workObj.role.slice(0,roleMaxLength) newWorks.push workObj currentJobProfile.work = newWorks if p["educations"]?["values"]?.length newEducation = [] + eduSchema = jobProfileSchema.education.items.properties for education in p["educations"]["values"] educationObject = {} 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} - " if (not education.endDate?.year) or (education.endDate?.year and education.endDate?.year > (new Date().getFullYear())) educationObject.duration += "present" @@ -124,14 +140,21 @@ module.exports = class ProfileView extends View educationObject.degree = "Studying" else educationObject.duration += education.endDate.year - + else + educationObject.duration = "" + educationObject.duration = educationObject.duration.slice(0,eduSchema.duration.maxLength) educationObject.school = education.schoolName ? "" + educationObject.school = educationObject.school.slice(0,eduSchema.school.maxLength) educationObject.description = "" - console.log "Educated at:#{education.schoolName}" newEducation.push educationObject currentJobProfile.education = newEducation - me.set('jobProfile',currentJobProfile) - @render() + validationErrors = @user.validate() + 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: -> context = super() @@ -186,6 +209,7 @@ module.exports = class ProfileView extends View toggleEditing: -> @editing = not @editing @render() + IN.parse() toggleJobProfileApproved: -> return unless me.isAdmin()