Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fredwu/angel_nest
Browse files Browse the repository at this point in the history
  • Loading branch information
gitfly committed Jul 17, 2011
2 parents 622453d + cdc6f09 commit d60acb9
Show file tree
Hide file tree
Showing 23 changed files with 226 additions and 39 deletions.
15 changes: 14 additions & 1 deletion app/assets/stylesheets/style.css.scss
Expand Up @@ -202,7 +202,7 @@ form {
}

.input {
margin-bottom: 10px;
margin-bottom: $viewport_padding;
}

input.string,
Expand Down Expand Up @@ -635,6 +635,19 @@ form.multistage {
}
}

form.read_only {
input.string, input.numeric, textarea {
border: none;
background: none;
resize: none;
}

.attribute {
display: table;
margin-bottom: $viewport_padding;
}
}

/* ------------------------------
footer
------------------------------ */
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/application_controller.rb
Expand Up @@ -5,8 +5,9 @@ class ApplicationController < ActionController::Base

layout proc { |controller| controller.request.xhr? ? nil : 'application' }

before_filter :require_login, :unless => :devise_controller?
before_filter :ensure_ownership, :unless => :devise_controller?, :except => [:index, :show]
before_filter :require_login, :unless => :devise_controller?
before_filter :ensure_ownership, :unless => :devise_controller?, :except => [:index, :show]
after_filter :record_last_visited_page, :unless => :devise_controller?, :if => Proc.new { request.get? && !request.xhr? }

protected

Expand All @@ -24,6 +25,10 @@ def ensure_ownership
end
end

def record_last_visited_page
session[:user_return_to] = request.path
end

def deny_access
render :text => t('system.access_denied'), :status => 403
end
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -21,7 +21,9 @@ def show
end

def message_inboxes
@messages = case params[:type].try(:to_sym)
message_type = params[:type].try(:to_sym)

@messages = case message_type
when :inbox_messages then current_user.inbox_messages
when :sent_messages then current_user.sent_messages
when :archived_messages then current_user.archived_messages
Expand All @@ -30,6 +32,11 @@ def message_inboxes
when :archived_proposals then current_user.archived_proposals
else redirect_to my_message_inbox_path(:inbox_messages)
end

case message_type
when /_messages/ then render 'message_inboxes'
when /_proposals/ then render 'proposal_inboxes'
end
end

def add_micro_post
Expand Down
18 changes: 8 additions & 10 deletions app/models/user.rb
Expand Up @@ -83,6 +83,14 @@ def archived_proposals
incoming_messages.with_proposal.archived
end

def has_new_messages?
inbox_messages.unread.any?
end

def has_new_proposals?
inbox_proposals.unread.any?
end

def is_admin?
!!is_admin
end
Expand All @@ -103,10 +111,6 @@ def avatar(size = 80)
"http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?s=#{size}"
end

def has_new_messages?
incoming_messages.unread.any?
end

def send_private_message(target_user, content, extras = {})
messages.create!({
:content => content,
Expand Down Expand Up @@ -221,9 +225,3 @@ def email_nomarlisation
self.email = email.strip.downcase
end
end

class Array
def for_auto_suggest
map { |r| { :id => r.id, :name => r.name } }
end
end
1 change: 1 addition & 0 deletions app/views/layouts/application.html.slim
Expand Up @@ -25,6 +25,7 @@ body
h1= link_to t('site.name'), root_path
nav
ul
li= link_to_current t('label.home'), root_path
li= link_to_current t('label.startups'), startups_path
li= link_to_current t('label.entrepreneurs'), entrepreneurs_path
li= link_to_current t('label.investors'), investors_path
Expand Down
7 changes: 6 additions & 1 deletion app/views/layouts/userbars/_topnav.html.slim
Expand Up @@ -4,9 +4,14 @@ h3
| ! (
= link_to t('label.edit'), edit_registration_path(current_user)
' ) |
- if current_user.has_new_proposals?
= link_to "#{pluralize(current_user.inbox_proposals.unread.count, t('label.new_proposal'))}!", my_message_inbox_path(:inbox_proposals), :class => 'new'
- else
= link_to t('label.proposals_inbox'), my_message_inbox_path(:inbox_proposals)
' |
- if current_user.has_new_messages?
= link_to "#{pluralize(current_user.inbox_messages.unread.count, t('label.new_message'))}!", my_message_inbox_path(:inbox_messages), :class => 'new'
- else
= link_to "#{t('label.messages')} (#{current_user.inbox_messages.count})", my_message_inbox_path(:inbox_messages)
= link_to t('label.messages_inbox'), my_message_inbox_path(:inbox_messages)
' |
= link_to t('label.sign_out'), destroy_user_session_path
12 changes: 9 additions & 3 deletions app/views/messages/show_private_message.html.slim
@@ -1,10 +1,16 @@
.grid_3
= render 'users/message_inboxes'
- if @topic.is_with_proposal?
= render 'users/proposal_inboxes'
- else
= render 'users/message_inboxes'
.grid_9
- if @topic.is_with_proposal?
hr
h1= t('label.business_proposal')
.read_only= render 'proposals/form', :resource => @topic.proposal, :submit_path => '/'
ul
li= "#{t('label.submitted_by')}: #{link_to @topic.user.name, user_path(@topic.user)} (#{link_to @topic.proposal.startup.name, startup_path(@topic.proposal.startup)})".html_safe
li= "#{t('label.submitted_to')}: #{link_to @topic.target.name, user_path(@topic.target)}".html_safe
hr
.read_only= render 'proposals/read_only', :resource => @topic.proposal

h2= t('label.comments')
ul#messages
Expand Down
20 changes: 11 additions & 9 deletions app/views/proposals/_form.html.slim
@@ -1,27 +1,29 @@
ul#proposal_section_selector.multistage_selector
li= link_to t('label.investors'), '#investors'
- unless meta[:hide_investors]
li= link_to t('label.investors'), '#investors'
li= link_to t('label.product'), '#product'
li= link_to t('label.market'), '#market'
li= link_to t('label.competition'), '#competition'
li= link_to t('label.investment'), '#investment', :class => 'last'
.clear

= simple_form_for resource, :url => submit_path, :validate => true, :html => { :class => 'multistage' } do |f|
fieldset#investors
legend= t('label.investors')
.multi_add.input.string data-target="investors" data-start_text="#{t('text.enter_investor_names')}" data-selection_limit="#{Settings.recipient_limit.proposals}"
= label_tag :investors, t('label.investors')
= text_field_tag :investors, resource.investors.map(&:id).join(','), :class => 'string required', :'data-source' => resource.investors.for_auto_suggest.to_json
.grouped_buttons
= submit_tag t('label.next'), :class => 'navigation next'
- unless meta[:hide_investors]
fieldset#investors
legend= t('label.investors')
.multi_add.input.string data-target="investors" data-start_text="#{t('text.enter_investor_names')}" data-selection_limit="#{Settings.recipient_limit.proposals}"
= label_tag :investors, t('label.investors')
= text_field_tag :investors, resource.investors.map(&:id).join(','), :class => 'string required', :'data-source' => resource.investors.for_auto_suggest.to_json
.grouped_buttons
= submit_tag t('label.next'), :class => 'navigation next'
fieldset#product
legend= t('label.product')
= f.input :new_business_model
= f.input :new_product
= f.input :pitch
= f.input :introduction
.grouped_buttons
= submit_tag t('label.prev'), :class => 'navigation prev'
= submit_tag t('label.prev'), :class => 'navigation prev' unless meta[:hide_investors]
= submit_tag t('label.next'), :class => 'navigation next'
fieldset#market
legend= t('label.market')
Expand Down
69 changes: 69 additions & 0 deletions app/views/proposals/_read_only.html.slim
@@ -0,0 +1,69 @@
ul#proposal_section_selector.multistage_selector
li= link_to t('label.product'), '#product'
li= link_to t('label.market'), '#market'
li= link_to t('label.competition'), '#competition'
li= link_to t('label.investment'), '#investment', :class => 'last'
.clear

= simple_form_for resource, :url => '/', :html => { :class => 'multistage read_only' } do |f|
fieldset#product
legend= t('label.product')
= f.input :new_business_model if resource.new_business_model
= f.input :new_product if resource.new_product
= f.label :pitch
.attribute= resource.pitch
= f.label :introduction
.attribute= resource.introduction
.grouped_buttons
= submit_tag t('label.next'), :class => 'navigation next'
fieldset#market
legend= t('label.market')
h2= t('label.one_year_market')
= f.label :one_year_target_audience
.attribute= resource.one_year_target_audience
= f.input :one_year_per_capita_annual_spending
= f.input :one_year_number_of_users
= f.input :one_year_market_cap
= f.input :one_year_penetration_rate
= f.label :one_year_marketing_strategy
.attribute= resource.one_year_marketing_strategy
= f.input :one_year_gross_profit_margin
br
h2= t('label.five_year_market')
= f.label :five_year_target_audience
.attribute= resource.five_year_target_audience
= f.input :five_year_per_capita_annual_spending
= f.input :five_year_number_of_users
= f.input :five_year_market_cap
= f.input :five_year_penetration_rate
= f.label :five_year_marketing_strategy
.attribute= resource.five_year_marketing_strategy
= f.input :five_year_gross_profit_margin
.grouped_buttons
= submit_tag t('label.prev'), :class => 'navigation prev'
= submit_tag t('label.next'), :class => 'navigation next'
fieldset#competition
legend= t('label.competition')
= f.label :competitors_details
.attribute= resource.competitors_details
= f.label :competitive_edges
.attribute= resource.competitive_edges
= f.label :competing_strategy
.attribute= resource.competing_strategy
.grouped_buttons
= submit_tag t('label.prev'), :class => 'navigation prev'
= submit_tag t('label.next'), :class => 'navigation next'
fieldset#investment
legend= t('label.investment')
= f.input :investment_amount
= f.label :investment_currency
.attribute= resource.investment_currency
= f.input :equity_percentage
= f.label :spending_plan
.attribute= resource.spending_plan
= f.input :next_investment_round
.grouped_buttons
= submit_tag t('label.prev'), :class => 'navigation prev'
- unless resource.proposal_stage_identifier == 'submitted'
= submit_tag t('label.save_draft')
= submit_tag t('label.submit_proposal')
2 changes: 1 addition & 1 deletion app/views/proposals/edit.html.slim
@@ -1 +1 @@
= render 'form', :submit_path => startup_proposal_path(parent, resource)
= render 'form', :submit_path => startup_proposal_path(parent, resource), :meta => {}
2 changes: 1 addition & 1 deletion app/views/proposals/new.html.slim
@@ -1 +1 @@
= render 'form', :submit_path => startup_proposals_path(parent)
= render 'form', :submit_path => startup_proposals_path(parent), :meta => {}
7 changes: 0 additions & 7 deletions app/views/users/_message_inboxes.html.slim
Expand Up @@ -6,10 +6,3 @@ ul
li= link_to_current t('label.inbox_messages'), my_message_inbox_path(:inbox_messages)
li= link_to_current t('label.sent_messages') , my_message_inbox_path(:sent_messages)
li= link_to_current t('label.archived_messages') , my_message_inbox_path(:archived_messages)

hr
h3= t('label.startup_proposals')
ul
li= link_to_current t('label.inbox_proposals') , my_message_inbox_path(:inbox_proposals)
li= link_to_current t('label.sent_proposals') , my_message_inbox_path(:sent_proposals)
li= link_to_current t('label.archived_proposals') , my_message_inbox_path(:archived_proposals)
8 changes: 8 additions & 0 deletions app/views/users/_proposal_inboxes.html.slim
@@ -0,0 +1,8 @@
= render 'users/mini_profile', :user => current_user, :meta => {}

hr
h3= t('label.startup_proposals')
ul
li= link_to_current t('label.inbox_proposals') , my_message_inbox_path(:inbox_proposals)
li= link_to_current t('label.sent_proposals') , my_message_inbox_path(:sent_proposals)
li= link_to_current t('label.archived_proposals') , my_message_inbox_path(:archived_proposals)
2 changes: 1 addition & 1 deletion app/views/users/message_inboxes.html.slim
@@ -1,4 +1,4 @@
.grid_3
= render 'message_inboxes'
= render 'users/message_inboxes'
.grid_9
= render 'messages/index', :collection => @messages, :meta => { :linkable => true, :new_message? => true }
4 changes: 4 additions & 0 deletions app/views/users/proposal_inboxes.html.slim
@@ -0,0 +1,4 @@
.grid_3
= render 'users/proposal_inboxes'
.grid_9
= render 'messages/index', :collection => @messages, :meta => { :linkable => true }
3 changes: 3 additions & 0 deletions config/application.rb
Expand Up @@ -56,3 +56,6 @@ class Application < Rails::Application
end
end
end

require Rails.root + 'lib/monkey_patches/array'
require Rails.root + 'lib/monkey_patches/warden'
6 changes: 6 additions & 0 deletions config/locales/en.yml
Expand Up @@ -55,6 +55,7 @@ en:
time_ago: '%{time} ago'
time_ago_by: '%{time} ago by'
label:
home: Home
loading: Loading
create: Create
update: Update
Expand Down Expand Up @@ -85,6 +86,8 @@ en:
resend_unlock_instructions: Resend unlock instructions
edit_my_profile: Edit my profile
startup: Startup
submitted_by: Submitted by
submitted_to: Submitted to
startups: Startups
investor: Investor
investors: Investors
Expand Down Expand Up @@ -123,6 +126,7 @@ en:
five_year_market: Market in Five Years
messages: Messages
new_message: New message
new_proposal: New Proposal
private_messages: Private messages
inbox: Inbox
inbox_messages: Inbox messages
Expand All @@ -132,6 +136,8 @@ en:
sent_proposals: Sent proposals
archived_proposals: Archived proposals
recipients: Recipients
messages_inbox: Messages inbox
proposals_inbox: Proposals inbox
message:
proposal_saved: The proposal has been saved!
proposal_submitted: The proposal has been submitted to the investors!
Expand Down
5 changes: 5 additions & 0 deletions lib/monkey_patches/array.rb
@@ -0,0 +1,5 @@
class Array
def for_auto_suggest
map { |r| { :id => r.id, :name => r.name } }
end
end
6 changes: 6 additions & 0 deletions lib/monkey_patches/warden.rb
@@ -0,0 +1,6 @@
module Warden::Mixins::Common
# overwrites session reset so that we could keep things like 'last_visited_page'
def reset_session!
nil
end
end
4 changes: 2 additions & 2 deletions spec/controllers/users_controller_spec.rb
Expand Up @@ -32,11 +32,11 @@
it "shows inbox messages by default" do
get :message_inboxes

assigns(:messages).should == current_user.inbox_messages
response.should redirect_to(my_message_inbox_path(:inbox_messages))
end

it "shows inbox messages" do
get :message_inboxes, :type => :inbox
get :message_inboxes, :type => :inbox_messages

assigns(:messages).should == current_user.inbox_messages
end
Expand Down
1 change: 1 addition & 0 deletions spec/models/message_spec.rb
Expand Up @@ -57,6 +57,7 @@
subject.send_private_message(user, 'hey there!')

user.has_new_messages?.should == true
user.has_new_proposals?.should == false
end

context "private messages" do
Expand Down
1 change: 1 addition & 0 deletions spec/models/proposal_spec.rb
Expand Up @@ -60,6 +60,7 @@
startup.proposals.draft.count.should == 0
startup.proposals.submitted.count.should == 1
startup.founder.sent_proposals.count.should == 1
investor1.has_new_proposals?.should == true
investor1.proposals.count.should == 1
investor1.inbox_proposals.count.should == 1
startup.proposals.first.proposal_stage_identifier.should == 'submitted'
Expand Down

0 comments on commit d60acb9

Please sign in to comment.