Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/javascripts/conversations.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
92 changes: 92 additions & 0 deletions app/assets/stylesheets/conversations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.left-message {
background-color: #e1e1e1;
text-align: left;
}

.right-message {
background-color: #b6e74d;
position: relative;
text-align: right;
}

.speech-bubble {
border-radius: 25px;
padding: 20px;
width: 50%;
height: 50%;
word-wrap: break-word;
margin-bottom: 2%;
}


.no-message-header {
color: red;
}

//Index Page

.testimonial {
margin-bottom: 10px;
margin-top: 20px;
}

.testimonial-section {
width: 100%;
height: auto;
padding: 15px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
position: relative;
border: 1px solid rgb(119,119,119);
background-color: white;
}

.testimonial-section:after {
top: 100%;
left: 50px;
border: solid transparent;
content: " ";
position: absolute;
border-top-color: rgb(119,119,119);
border-width: 15px;
margin-left: -15px;
}

.testimonial-desc {
margin-top: 20px;
text-align:left;
padding-left: 15px;
}

.testimonial-writer {
display: inline-block;
vertical-align: top;
padding-left: 10px;
}

.testimonial-writer-name {
font-weight: bold;
}

.testimonial-writer-designation {
font-size: 85%;
}

.testimonial-writer-company {
font-size: 85%;
}

.testimonial.testimonial-success .testimonial-section {
border-color: #5CB85C;
color: #449d44;
background-color: rgba(92, 184, 92, 0.1);
}

.testimonial.testimonial-success .testimonial-section:after {
border-top-color: #5CB85C;
}

.testimonial.testimonial-success .testimonial-writer-name {
color: #5CB85C;
}
64 changes: 64 additions & 0 deletions app/controllers/conversations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class ConversationsController < ApplicationController

def index
if current_company
@conversations = current_company.conversations
else
@conversations = current_customer.conversations
end
end

def create
@quote = Quote.find(params[:quote_id])
if current_customer && @quote.customer_request.customer == current_customer
conversation = Conversation.new(quote_id: @quote.id, company_id: @quote.company.id, customer_id: current_customer.id)
elsif current_company && @quote.company == current_company
conversation = Conversation.new(quote_id: @quote.id, company_id: current_company.id, customer_id: @quote.customer_request.customer.id)
end

if conversation && conversation.save
redirect_to "/conversations/#{conversation.id}"
else
render :show
end
end

def show
@messages = Conversation.find(params[:id]).messages.includes(:company, :customer).order('created_at')
@conversation = Conversation.find(params[:id])

if current_company
@me = current_company
@them = @conversation.customer
else
@me = current_customer
@them = @conversation.company
end

if @messages.count == 0
render 'show.html.erb'
elsif @messages[0].conversation.company == current_company || @messages[0].conversation.customer == current_customer
render 'show.html.erb'
else
redirect_to '/'
end
end

def message
@conversation = Conversation.find(params[:id])
if params[:customer_id]
@message = Message.create(body: params[:body], conversation_id: @conversation.id, customer_id: params[:customer_id])
MessageMailer.new_message(@conversation).deliver_now
redirect_to "/conversations/#{@conversation.id}"
elsif params[:company_id]
@message = Message.create(body: params[:body], conversation_id: @conversation.id, company_id: params[:company_id])
MessageMailer.new_message(@conversation).deliver_now
redirect_to "/conversations/#{@conversation.id}"
else
flash[:notice] = "You need to be signed in to create a message."
redirect_to '/'
end
end


end
2 changes: 2 additions & 0 deletions app/helpers/conversations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ConversationsHelper
end
11 changes: 11 additions & 0 deletions app/mailers/message_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class MessageMailer < ApplicationMailer
default from: 'noreply@veteranswork.com'

def new_message(conversation)
@conversation = conversation
@customer_email_address = @conversation.customer.email
@company_email_address = @conversation.company.email
mail(to: @customer_email_address, subject: 'New Message - Veterans Work', body: "To see your message, visit the conversation page /conversations/#{@conversation.id}")
mail(to: @company_email_address, subject: 'New Message - Veterans Work', body: "To see your message, visit the conversation page /conversations/#{@conversation.id}")
end
end
1 change: 1 addition & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Company < ApplicationRecord
has_many :quotes
has_many :contracts, through: :quotes
has_many :orders
has_many :conversations

has_attached_file :avatar,
styles: { medium: '300x300>', thumb: '100x100>' },
Expand Down
17 changes: 17 additions & 0 deletions app/models/conversation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: conversations
#
# id :integer not null, primary key
# customer_id :integer
# company_id :integer
# quote_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#

class Conversation < ApplicationRecord
belongs_to :company
belongs_to :customer
has_many :messages
end
1 change: 1 addition & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Customer < ApplicationRecord
has_many :customer_requests, dependent: :delete_all
has_many :quotes, through: :customer_requests
has_many :contracts, through: :customer_requests
has_many :conversations


def open_quotes
Expand Down
18 changes: 18 additions & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# == Schema Information
#
# Table name: messages
#
# id :integer not null, primary key
# body :text
# conversation_id :integer
# company_id :integer
# customer_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#

class Message < ApplicationRecord
belongs_to :conversation
belongs_to :company
belongs_to :customer
end
31 changes: 31 additions & 0 deletions app/views/conversations/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="container">
<h1 class="text-center">My Conversations</h1>
<% @conversations.each do |conversation| %>
<div class="row">
<div class="col-sm-6">
<div id="tb-testimonial" class="testimonial testimonial-default">
<div class="testimonial-section">
<% if conversation.messages.count > 0 %>
<h2><%= conversation.messages.last.body %></h2>
<% else %>
<h2 class="no-message-header">You don't have any messages for this conversation</h2>
<% end %>
</div>
<div class="testimonial-desc">
<div class="testimonial-writer">
<% if current_company %>
<div class="testimonial-writer-name"><%= conversation.customer.email %></div>
<div class="testimonial-writer-designation"><%= conversation.created_at.localtime.strftime("%m/%d/%Y - %H:%M %Z") %></div>
<a href="/conversations/<%=conversation.id%>" class="testimonial-writer-company btn btn-success">Go To Conversation</a>
<% else %>
<div class="testimonial-writer-name"><%= conversation.company.email %></div>
<div class="testimonial-writer-designation"><%= conversation.created_at.localtime.strftime("%m/%d/%Y - %H:%M %Z") %></div>
<a href="/conversations/<%=conversation.id%>" class="testimonial-writer-company btn btn-success">Go To Conversation</a>
<% end %>
</div>
</div>
</div>
</div>
</div>
<% end %>
</div>
34 changes: 34 additions & 0 deletions app/views/conversations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="col-xs-12">
<h2>Conversation With <%= @them.email %></h2>
<div class="well">
<% @messages.each do |message| %>
<div class="row">
<% if current_company && message.company == current_company || current_customer && message.customer == current_customer %>
<div class="col-xs-6 col-xs-offset-6 right-message speech-bubble">
<p>Sent By: Me</p>
<p><%= message.created_at.localtime.strftime("%m/%d/%Y - %H:%M %Z")%></p>
<p><%= message.body %></p>
</div>
<% else %>
<div class="col-xs-6 left-message speech-bubble">
<p>Sent By: <%= @them.email %></p>
<p><%= message.created_at.localtime.strftime("%m/%d/%Y - %H:%M %Z")%></p>
<p><%= message.body %></p>
</div>
<% end %>
</div>
<% end %>
</div>
</div>

<div class="col-xs-12 text-center">
<%= form_tag "/conversations/#{@conversation.id}/messages", method: :post do %>
<%= text_area_tag :body, "", required:true, class: "form-control", placeholder: "Send Message" %>
<% if current_customer %>
<%= hidden_field_tag 'customer_id', current_customer.id %>
<% else %>
<%= hidden_field_tag 'company_id', current_company.id %>
<% end %>
<button type="submit" class="btn btn-theme-bg">Submit</button>
<% end %>
</div>
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
<li><a href="/customers/edit">Edit My Profile</a></li>
<li><a href="/quotes">View Quotes</a></li>
<li><a href="/contracts">View Contracts</a></li>
<li><a href="/my_conversations">My Conversations</a></li>
<% elsif current_company %>
<li><a href="/companies/<%=current_company.id%>">Profile</a></li>
<li><a href="/companies/edit">Edit My Profile</a></li>
<li><a href="/contracts">View Contracts</a></li>
<li><a href="/my_conversations">My Conversations</a></li>
<% elsif current_admin %>
<li><a href="/admins/">Home Page</a></li>
<li><a href="/credits/">Credits</a></li>
Expand Down
7 changes: 6 additions & 1 deletion app/views/quotes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@
<%= f.submit "Accept", class: "btn btn-md btn-success" %>
<% end %>
<button type="button" class="btn btn-danger btn-md top-margin-button" data-toggle="modal" data-target="#myModal">Decline Quote</button><br>
<a class="btn btn-theme-bg" href="/quotes" role="button"><span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>Back</a>
<a class="btn btn-theme-bg" href="/quotes" role="button"><span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>Back</a><br>
<form action="/conversations" method="post">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
<input type="hidden" name="quote_id" value="<%= @quote.id %>">
<button class="btn btn-md">Start A Conversation</button>
</form>
<% end %>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
get '/how' => 'pages#how'
get '/admin_panel' => 'pages#admin_panel'

post '/conversations' => 'conversations#create'
get '/conversations/:id' => 'conversations#show'
post '/conversations/:id/messages' => 'conversations#message'
get '/my_conversations' => 'conversations#index'

resources :admins
resources :customer_requests
resources :companies
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20171010010705_create_conversations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateConversations < ActiveRecord::Migration[5.1]
def change
create_table :conversations do |t|
t.integer :customer_id
t.integer :company_id
t.integer :quote_id

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20171010011032_create_messages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateMessages < ActiveRecord::Migration[5.1]
def change
create_table :messages do |t|
t.text :body
t.integer :conversation_id
t.integer :company_id
t.integer :customer_id

t.timestamps
end
end
end
Loading