added helpers for each of the getting started steps; make step sections dull if completed

This commit is contained in:
danielgrippi 2011-08-03 11:57:50 -07:00
parent 303b23883d
commit b8b4ad3d84
13 changed files with 197 additions and 135 deletions

View file

@ -98,27 +98,9 @@ class UsersController < ApplicationController
@person = @user.person @person = @user.person
@profile = @user.profile @profile = @user.profile
@services = @user.services @services = @user.services
service = current_user.services.where(:type => "Services::Facebook").first @step = 0
@step = ((params[:step].to_i>0)&&(params[:step].to_i<4)) ? params[:step].to_i : 1 render "users/getting_started"
@step ||= 1
if @step == 2 && SERVICES['facebook']['app_id'] == ""
@step = 3
end
if @step == 3
@friends = service ? service.finder(:local => true) : []
@friends ||= []
end
if @step == 3 && @friends.length == 0
@user.update_attributes(:getting_started => false)
flash[:notice] = I18n.t('users.getting_started.could_not_find_anyone')
redirect_to root_path
else
render "users/getting_started"
end
end end
def getting_started_completed def getting_started_completed

View file

@ -3,8 +3,40 @@
# the COPYRIGHT file. # the COPYRIGHT file.
module UsersHelper module UsersHelper
def first_name_or_username (user)
set_name = user.person.profile.first_name # @return [Boolean] The user has filled out all profile fields
(set_name.nil? || set_name.empty?) ? user.username : user.person.profile.first_name def has_completed_profile?
profile = current_user.person.profile
[:full_name, :image_url,
:birthday, :gender,
:bio, :location,
:tag_string].map! do |attr|
return false if profile.send(attr).blank?
end
true
end
# @return [Boolean] The user has connected at least one service
def has_connected_services?
AppConfig[:connected_services].blank? || current_user.services.size > 0
end
# @return [Boolean] The user has at least 3 contacts
def has_few_contacts?
current_user.contacts.receiving.size > 2
end
# @return [Boolean] The user has followed at least 3 tags
def has_few_followed_tags?
current_user.followed_tags.size > 2
end
# @return [Boolean] The user has connected to cubbi.es
def has_connected_cubbies?
end
# @return [Boolean] The user has completed all steps in getting started
def has_completed_getting_started?
current_user.getting_started == false
end end
end end

View file

@ -12,10 +12,11 @@
%h3 %h3
= current_user.first_name = current_user.first_name
.section - unless has_completed_getting_started?
%ul.left_nav .section
%li %ul.left_nav
= link_to "Welcome", getting_started_path, :class => "home_selector" %li
= link_to "Welcome", getting_started_path, :class => "home_selector"
.section .section
= render 'aspects/aspect_listings' = render 'aspects/aspect_listings'

View file

@ -2,19 +2,17 @@
-# licensed under the Affero General Public License version 3 or later. See -# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file. -# the COPYRIGHT file.
- content_for :head do
= include_javascripts :home
.span-5.leftNavBar .span-5.leftNavBar
#home_user_badge #home_user_badge
= owner_image_link = owner_image_link
%h3 %h3
= current_user.first_name = current_user.first_name
.section - unless has_completed_getting_started?
%ul.left_nav .section
%li %ul.left_nav
= link_to "Welcome", getting_started_path, :class => "home_selector active" %li
= link_to "Welcome", getting_started_path, :class => "home_selector active"
.section .section
= render 'aspects/aspect_listings' = render 'aspects/aspect_listings'
@ -28,10 +26,10 @@
= "Welcome, #{current_user.first_name}!" = "Welcome, #{current_user.first_name}!"
%ul#getting_started %ul#getting_started
%li.profile %li.profile{:class => ("completed" if has_completed_profile?)}
.getting_started_number .getting_started_number
%h3 %h3
1 = @step += 1
.content .content
#getting_started_profile_photo #getting_started_profile_photo
= person_image_link(current_user.person, :size => :thumb_medium) = person_image_link(current_user.person, :size => :thumb_medium)
@ -47,22 +45,23 @@
#edit_profile_button_div #edit_profile_button_div
= link_to "Edit Profile", edit_profile_path, :class => "button" = link_to "Edit Profile", edit_profile_path, :class => "button"
%li.services - unless AppConfig[:configured_services].blank?
.getting_started_number %li.services{:class => ("completed" if has_connected_services?)}
%h3 .getting_started_number
2 %h3
.content = @step += 1
%h3 .content
= t('.connect_to_your_other_social_networks') %h3
#getting_started_service_icons = t('.connect_to_your_other_social_networks')
- AppConfig.configured_services.each do |service| #getting_started_service_icons
- unless current_user.services.any?{|x| x.provider == service} - AppConfig.configured_services.each do |service|
= link_to(image_tag("social_media_logos/#{service.downcase}-48x48.png", :title => service.titleize), "/auth/#{service}") - unless current_user.services.any?{|x| x.provider == service}
= link_to(image_tag("social_media_logos/#{service.downcase}-48x48.png", :title => service.titleize), "/auth/#{service}")
%li %li.connect_with_people{:class => ("completed" if has_few_contacts?)}
.getting_started_number .getting_started_number
%h3 %h3
3 = @step += 1
.content .content
%h3 %h3
= t(".connect_with_people") = t(".connect_with_people")
@ -108,17 +107,16 @@
#global_search #global_search
= form_tag(people_path, :method => 'get', :id => "global_search_form") do = form_tag(people_path, :method => 'get', :id => "global_search_form") do
= text_field_tag 'q', nil, :placeholder => "Search for people", :type => 'search', :results => 5 = text_field_tag 'q', nil, :placeholder => "Search for people", :type => 'search', :results => 5
.span-5.last .span-5.last{:style => "height:30px;"}
%p or
or = link_to t('.find_friends_from_facebook'), friend_finder_path('facebook'), :rel => 'facebox'
= link_to "find friends from Facebook", "#"
.clearfix .clearfix
%br %br
%li %li.follow_interests{:class => ("completed" if has_few_followed_tags?)}
.getting_started_number .getting_started_number
%h3 %h3
4 = @step += 1
.content .content
%h3 %h3
= t(".follow_your_interests") = t(".follow_your_interests")
@ -134,21 +132,21 @@
%h4 %h4
Featured tags Featured tags
%p %p
= link_to "#diaspora", "#" = link_to "#diaspora", tag_path('diaspora')
%br %br
= link_to "#kittens", "#" = link_to "#kittens", tag_path('kittens')
%br %br
= link_to "#puppies", "#" = link_to "#puppies", tag_path('puppies')
%br %br
= link_to "#maddog", "#" = link_to "#maddog", tag_path('maddog')
.clearfix .clearfix
%br %br
%br %br
%li %li.cubbies
.getting_started_number .getting_started_number
%h3 %h3
5 = @step += 1
.content .content
%h3 %h3
= t(".connect_to") = t(".connect_to")

View file

@ -1,22 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= form_tag profile_path, :method => :put, :multipart => true, :id => 'update_profile_form' do
%div{:style => "width:360px"}
= render 'profiles/edit_public', :profile => @profile, :aspect => @aspect, :person => @person
= hidden_field_tag :getting_started, @step
%h4
= t('search')
%p{:class=>"checkbox_select"}
= label_tag 'profile[searchable]', t('profiles.edit.allow_search')
= check_box_tag 'profile[searchable]', true, @profile.searchable
%br
%br
%br
.submit_block
= submit_tag "#{t('users.getting_started.save_and_continue')} →"

View file

@ -1,19 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
%br
%br
%br
%br
%br
%h3{:style => 'text-align: center;'}
= t('.find_your_friends_on_diaspora')
%br
%br
%br
= link_to image_tag('services/facebook_sign_in.png', :id => 'getting_started_logo', :width => 154, :height => 22), '/auth/facebook'
.submit_block
= link_to "#{t('.skip')} →", getting_started_path(:step => @step+1), :class => 'button'

View file

@ -1,21 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
- content_for :head do
= include_javascripts :aspects
%h3
= t('.people_already_on_diaspora')
%br
%br
#people_stream.stream
- for friend in @friends
= render :partial => 'people/person', :locals => {:person => friend.person, :contact => friend.contact}
%br
%br
.submit_block
= link_to "#{t('.finish')} →", getting_started_completed_path, :class => 'button'

View file

@ -1,4 +1,4 @@
unless AppConfig[:featured_users].count == Person.featured_users.count unless Rails.env == 'test' || AppConfig[:featured_users].count == Person.featured_users.count
puts "Fetching featured users from remote servers..." puts "Fetching featured users from remote servers..."
AppConfig[:featured_users].each do |x| AppConfig[:featured_users].each do |x|
Webfinger.new(x).fetch Webfinger.new(x).fetch

View file

@ -794,6 +794,8 @@ en:
follow_your_interests: "Follow your interests" follow_your_interests: "Follow your interests"
connect_to: "Connect to" connect_to: "Connect to"
find_friends_from_facebook: "find friends from Facebook"
profile_fields: profile_fields:
name: "Name" name: "Name"
birthday: "Birthday" birthday: "Birthday"

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="100px" height="74.489px" viewBox="0 0 100 74.489" enable-background="new 0 0 100 74.489" xml:space="preserve">
<path d="M91.236,1.479C73.359,18.953,55.482,36.427,37.605,53.9c-6.441-6.295-12.881-12.592-19.322-18.888
c-4.715-4.609-11.948,2.614-7.229,7.229c7.646,7.474,15.292,14.947,22.937,22.421c2.009,1.963,5.219,1.962,7.228,0
c4.65-4.546,9.302-9.092,13.951-13.637V69.81H4.679V19.318H55.17v12.52l4.679-4.678v-9.75c0-1.53-1.24-2.77-2.771-2.77H2.772
C1.241,14.64,0,15.88,0,17.41v54.307c0,1.531,1.241,2.771,2.772,2.771h54.306c1.53,0,2.771-1.24,2.771-2.771V46.452
C72.721,33.87,85.592,21.288,98.464,8.707C103.184,4.093,95.951-3.13,91.236,1.479z"/>
</svg>

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -3203,6 +3203,18 @@ ul#getting_started
input[type='search'] input[type='search']
:width 210px :width 210px
&.completed
@include opacity(0.4)
@include transition(opacity, 0.2s)
&:hover,
&:active
@include opacity(1)
.content h3
:text
:decoration line-through
.profile .profile
:min-height 170px :min-height 170px
@ -3282,9 +3294,9 @@ ul#getting_started
:padding :padding
:left 20px :left 20px
.completed &.completed
:background :background
:image url('/images/icons/check_yes_ok.png') !important :image url('/images/icons/check_yes_ok.png') !important
#featured_users_pane #featured_users_pane
:padding 10px 0 :padding 10px 0

View file

@ -16,7 +16,6 @@ Factory.define :profile do |p|
p.birthday Date.today p.birthday Date.today
end end
Factory.define :person do |p| Factory.define :person do |p|
p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@aol.com" } p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@aol.com" }
p.sequence(:url) { |n| AppConfig[:pod_url] } p.sequence(:url) { |n| AppConfig[:pod_url] }

View file

@ -4,18 +4,105 @@
require 'spec_helper' require 'spec_helper'
describe UsersHelper do describe UsersHelper do
describe '#first_name_or_username' do before do
@current_user = alice
end
def current_user
@current_user
end
describe "#has_completed_profile?" do
it 'returns true if the current user has filled out all 7 suggested fields (from getting started)' do
profile = @current_user.person.profile
profile.update_attributes!(
{:first_name => "alice", :last_name => "smith", :image_url => "abcd.jpg", :birthday => Date.new,
:gender => "cow", :location => "san fran", :tag_string => "#sup", :bio => "holler" })
has_completed_profile?.should be_true
end
it 'returns false if the current user has not filled out all 7 suggested fields (from getting started)' do
@current_user.update_attributes(:person => {:profile =>
{:first_name => nil, :last_name => nil, :birthday => nil, :gender => nil }})
has_completed_profile?.should be_false
end
end
describe "#has_connected_services?" do
before do before do
@user = alice AppConfig[:connected_services] = ['fake_service']
end end
it 'should display the first name if it is set' do it 'returns true if the current user has connected at least one service' do
first_name_or_username(@user).should == @user.person.profile.first_name @current_user.services << Factory.build(:service)
has_connected_services?.should be_true
end end
it 'should display the username if the first name is empty' do it 'returns true if the current user has zero connected services and the server has no services to connect' do
@user.person.profile.first_name = "" AppConfig[:connected_services] = []
first_name_or_username(@user).should == @user.username @current_user.services.delete_all
has_connected_services?.should be_true
end
it 'returns false if the current user has not connected any service' do
@current_user.services.delete_all
has_connected_services?.should be_false
end
end
describe "#has_few_contacts?" do
it 'returns true if the current_user has more than 2 contacts' do
3.times do |n|
@current_user.contacts << Contact.new(:person => Factory(:person), :receiving => true)
end
has_few_contacts?.should be_true
end
it 'returns false if the current_user has less than 2 contacts (inclusive)' do
@current_user.contacts.delete_all
has_few_contacts?.should be_false
end
end
describe "has_few_followed_tags?" do
it 'returns true if the current_user has more than 2 contacts' do
3.times do |n|
@current_user.followed_tags << ActsAsTaggableOn::Tag.new(:name => "poodles_#{n}")
end
has_few_followed_tags?.should be_true
end
it 'returns false if the current_user has less than 2 contacts (inclusive)' do
@current_user.followed_tags.delete_all
has_few_followed_tags?.should be_false
end
end
describe "#has_connected_cubbies?" do
before do
pending
end
it 'returns true if the current user has connected cubbies to their account' do
has_connected_cubbies?.should be_true
end
it 'returns false if the current user has not connected cubbies to their account' do
has_connected_cubbies?.should be_false
end
end
describe "#has_completed_getting_started?" do
it 'returns true if the current user has completed getting started' do
@current_user.getting_started = false
@current_user.save
has_completed_getting_started?.should be_true
end
it 'returns false if the current user has not completed getting started' do
@current_user.getting_started = true
@current_user.save
has_completed_getting_started?.should be_false
end end
end end
end end