Skip to content

Commit 8b3a2e4

Browse files
committed
Reviews,chat box added
1 parent 48249ff commit 8b3a2e4

27 files changed

+310
-51
lines changed

Gemfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ gem 'turbolinks', '~> 5'
2626
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
2727
gem 'jbuilder', '~> 2.5'
2828
# Use Redis adapter to run Action Cable in production
29-
# gem 'redis', '~> 4.0'
29+
gem 'redis', '~> 4.0'
3030
# Use ActiveModel has_secure_password
3131
# gem 'bcrypt', '~> 3.1.7'
3232

@@ -63,4 +63,5 @@ gem 'devise', '~> 4.4'
6363
gem 'gravatar_image_tag','~> 1.2'
6464
gem 'carrierwave'
6565
gem 'mini_magick'
66-
gem "font-awesome-rails"
66+
gem "font-awesome-rails"
67+
gem "jquery-rails"

Gemfile.lock

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ GEM
114114
jbuilder (2.7.0)
115115
activesupport (>= 4.2.0)
116116
multi_json (>= 1.2)
117+
jquery-rails (4.3.3)
118+
rails-dom-testing (>= 1, < 3)
119+
railties (>= 4.2.0)
120+
thor (>= 0.14, < 2.0)
117121
listen (3.1.5)
118122
rb-fsevent (~> 0.9, >= 0.9.4)
119123
rb-inotify (~> 0.9, >= 0.9.7)
@@ -176,6 +180,7 @@ GEM
176180
rb-fsevent (0.10.3)
177181
rb-inotify (0.9.10)
178182
ffi (>= 0.5.0, < 2)
183+
redis (4.0.1)
179184
responders (2.4.0)
180185
actionpack (>= 4.2.0, < 5.3)
181186
railties (>= 4.2.0, < 5.3)
@@ -251,10 +256,12 @@ DEPENDENCIES
251256
guard (~> 2.14, >= 2.14.1)
252257
guard-livereload (~> 2.5, >= 2.5.2)
253258
jbuilder (~> 2.5)
259+
jquery-rails
254260
listen (>= 3.0.5, < 3.2)
255261
mini_magick
256262
puma (~> 3.7)
257263
rails (~> 5.1.6)
264+
redis (~> 4.0)
258265
sass-rails (~> 5.0)
259266
selenium-webdriver
260267
simple_form (~> 3.5)

app/assets/javascripts/application.js

+14
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,19 @@
1111
// about supported directives.
1212
//
1313
//= require rails-ujs
14+
1415
//= require turbolinks
1516
//= require_tree .
17+
18+
19+
function myFunction() {
20+
var x = document.getElementById("myDIV");
21+
if (x.style.display === "none") {
22+
x.style.display = "block";
23+
} else {
24+
x.style.display = "none";
25+
}
26+
}
27+
28+
29+
File renamed without changes.

app/assets/stylesheets/application.scss

+16
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,19 @@
115115
}
116116

117117

118+
.rating{
119+
margin: auto 0;
120+
}
121+
122+
.rating_star{
123+
background: url('/images/star.gif') 0 0;
124+
width:16px;
125+
heignt:16px;
126+
display:block;
127+
float:left;
128+
}
129+
130+
.on{
131+
background-position:0 16px;
132+
}
133+
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// Place all the styles related to the Cmt controller here.
1+
// Place all the styles related to the comments controller here.
22
// They will automatically be included in application.css.
33
// You can use Sass (SCSS) here: http://sass-lang.com/

app/controllers/cmt_controller.rb

-32
This file was deleted.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class CommentsController < ApplicationController
2+
3+
before_action :authenticate_user!, only: [:create, :destroy]
4+
5+
6+
7+
def create
8+
@seller = Seller.find(params[:seller_id])
9+
@comment = @seller.comments.create(params[:comment].permit(:name, :body))
10+
redirect_to seller_path(@seller)
11+
end
12+
13+
14+
def destroy
15+
@seller = Seller.find(params[:seller_id])
16+
@comment = @seller.comments.find(params[:id])
17+
@comment.destroy
18+
redirect_to seller_path(@seller)
19+
20+
end
21+
22+
23+
24+
25+
end

app/helpers/cmt_helper.rb

-2
This file was deleted.

app/helpers/comments_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module CommentsHelper
2+
end

app/models/cmt.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Cmt < ApplicationRecord
2-
belongs_to: user
3-
belongs_to: seller
2+
belongs_to :user
3+
belongs_to :seller
44

55
end

app/models/comment.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Comment < ApplicationRecord
2+
belongs_to :seller
3+
belongs_to :user
4+
end

app/models/seller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Seller < ApplicationRecord
55
has_many :cart_items
66
mount_uploader :image, ImageUploader #uploading image
77
serialize :image, JSON #for SQlite
8+
9+
has_many :comments, dependent: :destroy
810

911

1012
validates :category, :model, :brand, :price, presence: true

app/views/comments/_comment.html.erb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
<div style="margin-left: 15px;">
3+
4+
5+
6+
<strong><%= comment.body %><br></strong>
7+
<%= time_ago_in_words(comment.created_at) %> Ago<br>
8+
9+
10+
<% if user_signed_in? && @seller.user_id == current_user.id %>
11+
12+
<div style="margin-top: -17px; margin-left: 190px;">
13+
<%= link_to "delete" , [comment.seller,comment] , method: :delete, data: {confirm: "Are You Sure ?"} %>
14+
</div>
15+
16+
<%end%>
17+
18+
</div>
19+

app/views/comments/_form.html.erb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
4+
5+
<%= form_for ([@seller,@seller.comments.build]) do |f| %>
6+
7+
<p>
8+
9+
<%=f.text_area :body %>
10+
11+
12+
</p>
13+
14+
<p>
15+
<%=f.submit %>
16+
</p>
17+
18+
<% end %>
19+

app/views/layouts/application.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<%= stylesheet_link_tag 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' %>
1111

1212
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
13+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
1314
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
1415
</head>
1516

app/views/sellers/show.html.erb

+108-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,72 @@
1+
<style>
2+
3+
.comments{
4+
background: #E59866;
5+
opacity: 1;
6+
border-radius: 18px;
7+
padding-top: 5px;
8+
padding-bottom: 5px;
9+
margin-right: 500px;
10+
text-align:center;
11+
12+
}
13+
14+
15+
#myDIV {
16+
}
17+
#user-chat-box{
18+
position: fixed;
19+
bottom: 0;
20+
right: 15px;
21+
border: 1px solid grey;
22+
height: 350px;
23+
width: 300px;
24+
}
25+
#chat-messages-list{
26+
list-style: none;
27+
padding: 10px;
28+
height: 83%;
29+
background-color: white;
30+
overflow: auto;
31+
}
32+
.other-message{
33+
text-align: left;
34+
padding: 5px;
35+
}
36+
37+
38+
39+
40+
.self-message{
41+
text-align: right;
42+
padding: 5px;
43+
}
44+
45+
46+
47+
#chat-message-input-container{
48+
height: 30%;
49+
width: 100%;
50+
display: flex;
51+
flex-direction: row;
52+
}
53+
#msg{
54+
height: 50%;
55+
width: 70%;
56+
}
57+
#send{
58+
height: 50%;
59+
width: 30%;
60+
font-size: 25px;
61+
color: white;
62+
border: none;
63+
background:#1AABEE ;
64+
}
65+
66+
67+
</style>
68+
69+
170
<% content_for :body_class, 'bg-light' %>
271

372
<section class="section seller-show">
@@ -19,14 +88,39 @@
1988
<br>
2089

2190
<div class="control has-icons-left">
22-
<%= button_to 'Talk to Seller', '#', class: 'button is-info add-to-cart' %>
91+
<button onclick="myFunction()" class='button is-info add-to-cart' >Talk to Seller</button>
92+
93+
2394

2495
<span class="icon is-small is-left">
2596
<i class="fa fa-comments"></i>
2697
</span>
98+
<div id="myDIV">
99+
<% if user_signed_in? %>
100+
<div id="user-chat-box">
101+
<ul id="chat-messages-list">
102+
<li class="other-message">
103+
<span style="background-color:#F3AD87 ;">
104+
Other Message</span>
105+
</li>
106+
<li class="self-message">
107+
<span style=" background-color: #BBF5CF ;">
108+
Self Message
109+
</span>
110+
111+
</li>
112+
</ul>
113+
<div id="chat-message-input-container">
114+
<input id="msg" placeholder="Type message here">
115+
<button id="send"><i class="fa fa-paper-plane""></i></button>
116+
</div>
117+
</div>
118+
<% end %>
119+
</div>
27120
</div>
121+
</div>
28122

29-
</div>
123+
30124

31125

32126

@@ -104,18 +198,25 @@
104198

105199
<div class="column" style="border:1px solid #D7DBDD ">
106200
<li class="inline-block pr3 f3"><strong>Rating and Review: </strong></li>
201+
202+
<hr>
203+
<div style="background-color: #EAECEE; border-radius:20px; display:block;">
204+
<%= render @seller.comments %>
205+
107206

207+
</div>
108208

109-
110-
</div>
111-
<br>
112209
<br>
113-
<div class="column" style="border:1px solid #D7DBDD ">
114-
<li class="inline-block pr3 f3"><strong>Question And Answer: </strong></li>
210+
<strong><p class="comments">Add Review</p></strong><br>
211+
212+
<%= render "comments/form" %>
115213

116214

117215

118216
</div>
217+
<br>
218+
<br>
219+
119220

120221
</div>
121222
</ul>

config/routes.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
Rails.application.routes.draw do
22

3-
3+
resources :chats
44
resources :cart_items
55
resources :carts
6-
resources :sellers
6+
resources :sellers do
7+
resources :comments
8+
end
79
resources :searches
10+
811
devise_for :users , controllers: {
912
registrations: 'registrations'
1013
}
1114
root 'sellers#index' #store..earlier
1215

16+
mount ActionCable.server => "/cable"
17+
1318
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
1419
end

0 commit comments

Comments
 (0)