Skip to content

Commit

Permalink
Add new mentoring functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
reidab committed Mar 20, 2012
1 parent a5d9f43 commit f148310
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 5 deletions.
91 changes: 91 additions & 0 deletions app/controllers/mentoring_controller.rb
@@ -0,0 +1,91 @@
class MentoringController < ApplicationController
before_filter :authenticate_user!, :only => [:profile_edit, :matches]

def test
end

def search
# if @mentor_tags.present?
# @people = Person.tagged_with(@mentor_tags, :on => :mentor_topic_tags, :any => true)
# elsif @mentor_tags.present?
# @people = Person.tagged_with(@mentee_tags, :on => :mentee_topic_tags, :any => true)
# end

# render :text => params.inspect + "\n\n" + @people.inspect
end

def profile
session[:mentoring_profile] = load_mentoring_params
redirect_to mentoring_profile_welcome_path
end

def profile_welcome
@mentoring = get_mentoring_data
@matched_user = User.find_by_email(@mentoring[:contact][:email])
unless current_user.present?
@signin_data = SignInData.new(:email => @mentoring[:contact][:email], :provider => 'auto')
session[:user_return_to] = mentoring_profile_edit_path
end
end

def profile_edit
@mentoring = get_mentoring_data
@name = current_user.name || [@mentoring[:firstname], @mentoring[:lastname]].join(' ')
@person = current_user.person || current_user.authentications.first.to_person || Person.new

@person.name ||= @name
@person.interested_mentor = @mentoring[:mentor_areas].present?
@person.interested_mentee = @mentoring[:mentee_areas].present?

@person.mentor_topic_models += @mentoring[:mentor_areas].map{|area| MentorshipTopic.find_or_create_by_slug(area) }
@person.mentee_topic_models += @mentoring[:mentee_areas].map{|area| MentorshipTopic.find_or_create_by_slug(area) }
end

def matches
if current_person
if params[:kind] == 'mentors'
mentor_rankings = Hash.new(0)
current_person.mentee_topic_models.each do |topic|
topic.mentors.each do |mentor|
mentor_rankings[mentor] += 1
end
end
@potential_mentors = mentor_rankings.keys.sort_by{|mentor| mentor_rankings[mentor]}.reverse
elsif params[:kind] == 'mentees'
mentee_rankings = Hash.new(0)
current_person.mentor_topic_models.each do |topic|
topic.mentees.each do |mentee|
mentee_rankings[mentee] += 1
end
end
@potential_mentees = mentee_rankings.keys.sort_by{|mentee| mentee_rankings[mentee]}.reverse
else
raise ActiveRecord::RecordNotFound
end
end
end

# Sign the user out, but preserve their mentoring session data
def sign_out_preserve_mentoring
if current_user.present?
mentoring = get_mentoring_data
sign_out current_user
session[:mentoring_profile] = mentoring
end
redirect_to mentoring_profile_welcome_path
end

private

def get_mentoring_data
session[:mentoring_profile].presence || load_mentoring_params
end

def load_mentoring_params
{}.tap do |mentoring|
mentoring[:mentor_areas] = params[:mentor_area_details].present? ? params[:mentor_area_details].split(',') : []
mentoring[:mentee_areas] = params[:mentee_area_details].present? ? params[:mentee_area_details].split(',') : []
mentoring[:contact] = params.extract!(:firstname, :lastname, :companyname, :email, :phone)
end
end
end
10 changes: 10 additions & 0 deletions app/models/mentorship_topic.rb
@@ -0,0 +1,10 @@
class MentorshipTopic < ActiveRecord::Base
has_many :person_mentor_topics
has_many :person_mentee_topics
has_many :mentors, :through => :person_mentor_topics, :source => :person
has_many :mentees, :through => :person_mentee_topics, :source => :person

def humanize
name || slug
end
end
5 changes: 5 additions & 0 deletions app/models/person.rb
Expand Up @@ -19,6 +19,11 @@ class Person < ActiveRecord::Base

customizable_slug_from :name

has_many :person_mentor_topics
has_many :person_mentee_topics
has_many :mentor_topic_models, :through => :person_mentor_topics, :source => :mentorship_topic
has_many :mentee_topic_models, :through => :person_mentee_topics, :source => :mentorship_topic

belongs_to :user
accepts_nested_attributes_for :user, :update_only => true

Expand Down
4 changes: 4 additions & 0 deletions app/models/person_mentee_topic.rb
@@ -0,0 +1,4 @@
class PersonMenteeTopic < ActiveRecord::Base
belongs_to :person
belongs_to :mentorship_topic
end
4 changes: 4 additions & 0 deletions app/models/person_mentor_topic.rb
@@ -0,0 +1,4 @@
class PersonMentorTopic < ActiveRecord::Base
belongs_to :person
belongs_to :mentorship_topic
end
18 changes: 18 additions & 0 deletions app/stylesheets/desktop.sass
Expand Up @@ -207,6 +207,15 @@ body
#add_yourself
+grid(10,16)
+alpha
#mentoring_profile_edit
#add_yourself
+grid(16,16)
.person_info, .mentorship_info
+grid(8,16)
.person_info
+alpha
.mentorship_info
+omega
#user_home
#profile
+grid(10,16)
Expand All @@ -217,6 +226,15 @@ body
#view_options
.show
padding-left: 20px
#profile_welcome
h1
padding-bottom: .5em
.intro
+grid(6,16)
+alpha
.user_welcome
+grid(7,16)


div#creepy-baby-sloth
margin: 2em auto 0 auto
Expand Down
5 changes: 3 additions & 2 deletions app/views/authentications/_login_form.html.haml
@@ -1,8 +1,9 @@
- button_text ||= nil
.sign_in_form
= semantic_form_for((@signin_data || SignInData.new), :url => user_sessions_path) do |f|
= f.input :email, :label => t('field.email_address.label'), :input_html => {:size => nil, :autocorrect => "off", :autocapitalize => "off"}
= f.input :provider, :label=>t('field.provider.label') , :collection => Authentication.provider_options, :include_blank => false
= f.commit_button t('button.sign_in')
= f.input :provider, :label=>t('field.provider.label_sign_in') , :collection => Authentication.provider_options, :include_blank => false
= f.commit_button button_text || t('button.sign_in')
- if allow_login_as_specific_user?
%p.development_only.login_as_sample_user
DEV:
Expand Down
23 changes: 23 additions & 0 deletions app/views/mentoring/matches.html.haml
@@ -0,0 +1,23 @@
#mentoring_matches
- if params[:kind] == 'mentors'
.mentors
%h2 Potential Mentors
%p
You're looking for mentorship in the following topics:
= current_person.mentor_topic_models.map{|t| t.humanize }.join(', ')
- if @potential_mentors.present?
%p Here are some mentors that match
= render :partial => 'people/list', :object => @potential_mentors
- else
%p We couldn't find any mentors that matched. Check back later, as new mentors may join.
- elsif params[:kind] == 'mentees'
.mentees
%h2 Potential Mentees
%p
You're looking to mentor people in the following topics:
= current_person.mentor_topic_models.map{|t| t.humanize }.join(', ')
- if @potential_mentees.present?
%p Here are some interested mentees that match
= render :partial => 'people/list', :object => @potential_mentees
- else
%p We couldn't find any mentees that matched. Check back later, as new mentees may join.
44 changes: 44 additions & 0 deletions app/views/mentoring/profile_edit.html.haml
@@ -0,0 +1,44 @@
#welcome
%h1= t('user.welcome.hi', :name => @name.split(' ').first)
#mentoring_profile_edit
#add_yourself
- if @person.new_record?
%h2= t('user.welcome.add_yourself', :organization => SETTINGS['organization']['name'])
%p= t('user.welcome.provider', :provider => provider_name(current_user.authentications.first.provider))
- else
%h2= t('user.welcome.review_details')
%p= t('user.welcome.already_in_directory')

-# TODO: re-combine this with people/_form
- context ||= @person.new_record? ? :add_self : :review
= semantic_form_for(@person, :html => {:multipart => true}) do |f|
= display_errors_for @person
.person_info
= f.inputs :name => "Personal Information" do
= f.input :name
= render 'site/custom_slug_field', :form => f
- unless @person.new_record?
= f.semantic_fields_for :user do |u|
= u.input :email
= f.input :location
= f.input :url
= f.input :bio
= f.input :tag_list, :as => :text, :input_html => {:class => 'tags'}
= f.input :technology_list, :as => :text, :input_html => {:class => 'tags'}
= import_image_from_url_tags_for f, @person, :photo
- if mentoring_enabled?
.mentorship_info
= f.inputs :name => t('people.field.mentoring.title') do
= f.input :interested_mentor
= f.input :mentor_topic_models, :label_method => :humanize, :label => "I am interested in mentoring these topics", :hint => "Choosing from these structured topics will increase your chance of finding mentees."
= f.input :mentor_topics, :label => "Other topics I'd like to mentor", :as => :string
= f.input :interested_mentee
= f.input :mentee_topic_models, :label_method => :humanize, :label => "I am interested in being mentored in these topics", :hint => "Choosing from these structured topics will increase your chance of finding mentees."
= f.input :mentee_topics, :label => "Other topics I'd like mentorship in", :as => :string
= f.input :reviewed, :input_html => {:value => true}, :as => :hidden
- if current_user.admin?
= f.input :user, :include_blank => "-- #{t('field.user.blankoption')} --", :label_method => :label_for_admin
= hidden_field_tag :form_context, context
%hr
= f.buttons do
= f.commit_button "Save and Continue"
32 changes: 32 additions & 0 deletions app/views/mentoring/profile_welcome.html.haml
@@ -0,0 +1,32 @@
#profile_welcome
%h1 Let&apos;s finish setting up your mentoring profile.
.intro
%h2 Welcome to ePDX!
%p
ePDX is the community-edited guide to Portland's awesome tech community and where your mentoring profile will live.
You can sign in anytime to search for mentorship connections and edit your profile.
%p
While you're here, be sure to check out the rest of the site for a look at the many people, companies, and groups that make up the world of Portland tech.

.user_welcome
- if current_user
%p You're currently signed in to ePDX as:
.signed_in_user
- if current_user.avatar_url
%img.avatar{:src => normalize_url(current_user.avatar_url), :align => 'left'}
.name
%strong= current_user.name
%p
If this isn't you, you can
= link_to t('sign_out'), mentoring_sign_out_path
- elsif @matched_user.present?
.matched-user
%h3 Welcome back!
%p Based on your email address, it looks like you've already got an ePDX account.
.sign_in_form
= semantic_form_for(SignInData.new(:email => @matched_user.email, :provider => 'auto'), :url => user_sessions_path) do |f|
= f.input :email, :as => :hidden
= f.input :provider, :as => :hidden
= f.commit_button t('button.sign_in') + " to continue"
- else
= render :partial => 'authentications/login_form', :locals => {:button_text => "Continue"}
37 changes: 37 additions & 0 deletions app/views/mentoring/test.html.haml
@@ -0,0 +1,37 @@
= form_tag mentoring_search_path, :method => :post do
= hidden_field_tag :firstname, "Reid"
= hidden_field_tag :lastname, "Beels"
= hidden_field_tag :companyname, "Pixeldye"
= hidden_field_tag :email, "mail@reidbeels.com"
= hidden_field_tag :phone, ""

= hidden_field_tag :mentor_type, ""
= hidden_field_tag :mentor_areas, "startup,strategy,raisingmoney,productdev"
= hidden_field_tag :mentor_area_details, "startup_protection,startup_team,strategy_market,strategy_validation,strategy_size,funding_model,funding_decision,funding_amount,productdev_requirements,productdev_roadmap"
= hidden_field_tag :mentee_area_other, "OTHER MARKETING,OTHER SALES,OTHER OPS,OTHER EXIT"

= hidden_field_tag :mentee_type, ""
= hidden_field_tag :mentee_area_details, "marketing_plan,marketing_budget,marketing_target-market,sales_sales-plan,sales_sales-budget,sales_comp-levels,operations_requirements,operations_office-space,exit_strategy,exit_valuation"
= hidden_field_tag :mentee_areas, "marketing,sales,bizoperations,exitstrategy"
= hidden_field_tag :mentor_area_other, "OTHER STARTUP,OTHER STRATEGY,OTHER FUNDRAISING,OTHER PRODUCT"

= submit_tag "POST search request"

= form_tag mentoring_profile_path, :method => :post do
= hidden_field_tag :firstname, "Reid"
= hidden_field_tag :lastname, "Beels"
= hidden_field_tag :companyname, "Pixeldye"
= hidden_field_tag :email, "mail3@reidbeels.com"
= hidden_field_tag :phone, ""

= hidden_field_tag :mentor_type, ""
= hidden_field_tag :mentor_areas, "startup,strategy,raisingmoney,productdev"
= hidden_field_tag :mentor_area_details, "startup_protection,startup_team,strategy_market,strategy_validation,strategy_size,funding_model,funding_decision,funding_amount,productdev_requirements,productdev_roadmap"
= hidden_field_tag :mentee_area_other, "OTHER MARKETING,OTHER SALES,OTHER OPS,OTHER EXIT"

= hidden_field_tag :mentee_type, ""
= hidden_field_tag :mentee_area_details, "marketing_plan,marketing_budget,marketing_target-market,sales_sales-plan,sales_sales-budget,sales_comp-levels,operations_requirements,operations_office-space,exit_strategy,exit_valuation"
= hidden_field_tag :mentee_areas, "marketing,sales,bizoperations,exitstrategy"
= hidden_field_tag :mentor_area_other, "OTHER STARTUP,OTHER STRATEGY,OTHER FUNDRAISING,OTHER PRODUCT"

= submit_tag "POST profile request"
4 changes: 2 additions & 2 deletions app/views/people/show.html.haml
Expand Up @@ -49,12 +49,12 @@
- if @person.interested_mentor
.section.mentor
%h2= t('people.field.mentor_topics.title')
%p= @person.mentor_topics
%p= (@person.mentor_topic_models.map{|t| t.humanize} << @person.mentor_topics.presence).compact.join(", ")

- if @person.interested_mentee
.section.mentee
%h2= t('people.field.mentee_topics.title')
%p= @person.mentee_topics
%p= (@person.mentee_topic_models.map{|t| t.humanize} << @person.mentee_topics.presence).compact.join(", ")

.record_actions
- if display_record_controls?(@person)
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -228,6 +228,7 @@ en:
title: "Projects" # people#show
provider:
label: Add an account
label_sign_in: Sign in using…
add: Add it!
prompt: "Pick a service…"
random:
Expand Down
8 changes: 8 additions & 0 deletions config/routes.rb
Expand Up @@ -5,6 +5,14 @@
get '/s(/:query)' => 'site#search', :as => :short_search
get '/opensearch(.:format)' => 'site#opensearch', :as => :opensearch

get '/mentoring/test/' => 'mentoring#test'
post '/mentoring/search' => 'mentoring#search', :as => :mentoring_search
post '/mentoring/profile' => 'mentoring#profile', :as => :mentoring_profile
get '/mentoring/profile/welcome' => 'mentoring#profile_welcome', :as => :mentoring_profile_welcome
get '/mentoring/profile/edit' => 'mentoring#profile_edit', :as => :mentoring_profile_edit
get '/mentoring/sign_out' => 'mentoring#sign_out_preserve_mentoring', :as => :mentoring_sign_out
get '/mentoring/matches/:kind' => 'mentoring#matches', :as => :mentoring_matches

resources :authentications
resources :companies do
member do
Expand Down
19 changes: 19 additions & 0 deletions db/migrate/20120320053424_create_mentorship_topics.rb
@@ -0,0 +1,19 @@
class CreateMentorshipTopics < ActiveRecord::Migration
def change
create_table :mentorship_topics do |t|
t.string :name
t.string :slug
t.timestamps
end

create_table :person_mentor_topics do |t|
t.belongs_to :person
t.belongs_to :mentorship_topic
end

create_table :person_mentee_topics do |t|
t.belongs_to :person
t.belongs_to :mentorship_topic
end
end
end

0 comments on commit f148310

Please sign in to comment.