chatty 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/chatty.js.coffee +219 -0
- data/app/assets/javascripts/chatty/application.js +13 -0
- data/app/assets/javascripts/chatty/chats.js +2 -0
- data/app/assets/stylesheets/chatty.css.scss +0 -0
- data/app/assets/stylesheets/chatty/application.css +13 -0
- data/app/assets/stylesheets/chatty/chats.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/chatty/admin_chats_controller.rb +26 -0
- data/app/controllers/chatty/application_controller.rb +3 -0
- data/app/controllers/chatty/chats_controller.rb +76 -0
- data/app/controllers/chatty/messages_controller.rb +48 -0
- data/app/helpers/chatty/application_helper.rb +8 -0
- data/app/helpers/chatty/chats_helper.rb +17 -0
- data/app/models/chatty/chat.rb +36 -0
- data/app/models/chatty/message.rb +24 -0
- data/app/views/chatty/chats/index.html.haml +22 -0
- data/app/views/chatty/chats/show.html.haml +9 -0
- data/app/views/chatty/messages/_form.html.haml +4 -0
- data/app/views/chatty/messages/new.html.haml +1 -0
- data/config/routes.rb +9 -0
- data/db/plugin_migrate/20140520083027_create_chatty_messages.rb +15 -0
- data/db/plugin_migrate/20140520083510_create_chatty_chats.rb +16 -0
- data/db/plugin_migrate/20140521072854_create_activities.rb +26 -0
- data/lib/chatty.rb +5 -0
- data/lib/chatty/engine.rb +11 -0
- data/lib/chatty/version.rb +3 -0
- data/lib/tasks/chatty_tasks.rake +0 -0
- metadata +311 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3aeb3e70f83afd3f86be21114ba93945fbb9530e
|
4
|
+
data.tar.gz: 25b6c8b4bad2d6877380cd64afcbca95624743c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8b2228f45d13f1dc3c56a50151f4e3ad06a2afdb291d01d10614fcc5a2441c863fa4d46b8361e3c05e724fe051e07d792c130b190a1b52223f36bf7055f4828
|
7
|
+
data.tar.gz: 84b9c366b554e62087f37e0295812f7279710f1425be2f3ad952a9d2b36be4c00bb5d151cf2778a13c826ade23027974c9247633c8e2d496bf4cddfd373f04ba
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Chatty'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
@@ -0,0 +1,219 @@
|
|
1
|
+
$ ->
|
2
|
+
# Adds the messages element and waits for the chat to be handled.
|
3
|
+
chatty_init = (chat) ->
|
4
|
+
chat.addClass("chatty_chat_" + chat.data("chat-id"))
|
5
|
+
|
6
|
+
messages = $("<div />", {
|
7
|
+
"class": "chatty_messages",
|
8
|
+
"text": chat.data("waiting-to-connect-message"),
|
9
|
+
"css": {
|
10
|
+
"display": "none"
|
11
|
+
}
|
12
|
+
})
|
13
|
+
chat.append(messages)
|
14
|
+
|
15
|
+
error = $("<div />", {
|
16
|
+
"class": "chatty_not_allowed_to_add_messages",
|
17
|
+
"text": chat.data("not-allowed-to-add-messages-message"),
|
18
|
+
"css": {
|
19
|
+
"display": "none"
|
20
|
+
}
|
21
|
+
})
|
22
|
+
chat.prepend(error)
|
23
|
+
|
24
|
+
error = $("<div />", {
|
25
|
+
"class": "chatty_not_signed_in_error",
|
26
|
+
"text": chat.data("need-to-be-signed-in-message"),
|
27
|
+
"css": {
|
28
|
+
"display": "none"
|
29
|
+
}
|
30
|
+
})
|
31
|
+
chat.prepend(error)
|
32
|
+
|
33
|
+
chatty_handled(chat, ->
|
34
|
+
chatty_init_messages(chat, ->
|
35
|
+
chatty_init_form(chat, ->
|
36
|
+
chatty_refresh_messages(chat)
|
37
|
+
chatty_check_new_messages(chat)
|
38
|
+
)
|
39
|
+
)
|
40
|
+
)
|
41
|
+
|
42
|
+
chatty_check_new_messages = (chat) ->
|
43
|
+
setTimeout((->
|
44
|
+
chatty_refresh_messages(chat)
|
45
|
+
|
46
|
+
# Handle changed chat state.
|
47
|
+
chatty_with_state(chat, (data) ->
|
48
|
+
if data.chat.state != "handled"
|
49
|
+
chatty_hide_form() unless chatty_form_hidden()
|
50
|
+
else
|
51
|
+
chatty_show_form() if chatty_form_hidden()
|
52
|
+
|
53
|
+
if data.chat.state == "closed"
|
54
|
+
chatty_show_not_allowed_to_add_messages() if chatty_not_allowed_to_add_messages_hidden()
|
55
|
+
else
|
56
|
+
chatty_hide_not_allowed_to_add_messages() unless chatty_not_allowed_to_add_messages_hidden()
|
57
|
+
)
|
58
|
+
|
59
|
+
chatty_check_new_messages(chat)
|
60
|
+
), 1000)
|
61
|
+
|
62
|
+
chatty_show_not_allowed_to_add_messages = (chat) ->
|
63
|
+
$(".chatty_not_allowed_to_add_messages", chat).slideDown("fast")
|
64
|
+
|
65
|
+
chatty_hide_not_allowed_to_add_messages = (chat) ->
|
66
|
+
$(".chatty_not_allowed_to_add_messages", chat).slideUp("fast")
|
67
|
+
|
68
|
+
chatty_not_allowed_to_add_messages_hidden = (chat) ->
|
69
|
+
$(".chatty_not_allowed_to_add_messages", chat).css("display") != "block"
|
70
|
+
|
71
|
+
chatty_hide_form = (chat) ->
|
72
|
+
$(".chatty_form", chat).slideUp("fast") unless chatty_form_hidden()
|
73
|
+
|
74
|
+
chatty_form_hidden = (chat) ->
|
75
|
+
$(".chatty_form", chat).css("display") != "block"
|
76
|
+
|
77
|
+
chatty_show_form = (chat) ->
|
78
|
+
$(".chatty_form", chat).slideDown("fast") if chatty_form_hidden()
|
79
|
+
|
80
|
+
chatty_with_state = (chat, callback) ->
|
81
|
+
$.ajax({type: "GET", url: "/chatty/chats/" + chat.data("chat-id"), cache: false, async: true, dataType: "json", success: (data) ->
|
82
|
+
callback(data)
|
83
|
+
})
|
84
|
+
|
85
|
+
# Waits for the chat to be handled, loads the messages and calls back.
|
86
|
+
chatty_handled = (chat, callback) ->
|
87
|
+
chatty_show_messages()
|
88
|
+
messages = $(".chatty_messages", chat)
|
89
|
+
|
90
|
+
$.ajax({type: "GET", url: "/chatty/chats/" + chat.data("chat-id"), cache: false, async: true, dataType: "json", success: (data) ->
|
91
|
+
chat.data("state", data.chat.state)
|
92
|
+
|
93
|
+
if data.chat.state == "new"
|
94
|
+
messages.text(chat.data("waiting-to-be-handled-message"))
|
95
|
+
else if data.chat.state == "closed"
|
96
|
+
chatty_show_not_allowed_to_add_messages()
|
97
|
+
|
98
|
+
if data.chat.state == "handled" || data.chat.state == "closed"
|
99
|
+
callback.call()
|
100
|
+
else
|
101
|
+
setTimeout((->
|
102
|
+
chatty_handled(chat, callback)
|
103
|
+
), 500)
|
104
|
+
})
|
105
|
+
|
106
|
+
# Inits all messages and begin new messages callback.
|
107
|
+
chatty_init_messages = (chat, callback) ->
|
108
|
+
chat.data("last-message-id", 0)
|
109
|
+
messages_container = $(".chatty_messages", chat)
|
110
|
+
messages_container.html("")
|
111
|
+
messages_container.slideDown("fast", ->
|
112
|
+
$.ajax({type: "GET", url: "/chatty/messages/?q[chat_id_eq]=" + chat.data("chat-id"), cache: false, async: true, dataType: "json", success: (data) ->
|
113
|
+
for message in data.messages
|
114
|
+
chatty_add_message(chat, message)
|
115
|
+
|
116
|
+
callback.call()
|
117
|
+
})
|
118
|
+
)
|
119
|
+
|
120
|
+
chatty_add_message = (chat, message) ->
|
121
|
+
msg_id = parseInt(message.id)
|
122
|
+
message_class = "chatty_message_" + msg_id
|
123
|
+
|
124
|
+
# Dont continue if message already exists!
|
125
|
+
return if $("." + message_class, chat).length > 0
|
126
|
+
|
127
|
+
last_id = parseInt(chat.data("last-message-id"))
|
128
|
+
chat.data("last-message-id", msg_id) if msg_id > last_id
|
129
|
+
messages_container = $(".chatty_messages", chat)
|
130
|
+
message_class = "chatty_message_" + msg_id
|
131
|
+
|
132
|
+
container = $("<div />", {
|
133
|
+
"class": "chatty_message " + message_class,
|
134
|
+
"data": {
|
135
|
+
"message_id": message.id
|
136
|
+
},
|
137
|
+
"css": {
|
138
|
+
"display": "none"
|
139
|
+
}
|
140
|
+
})
|
141
|
+
|
142
|
+
author_div = $("<div />", {
|
143
|
+
"class": "chatty_message_author",
|
144
|
+
"text": message.author_name
|
145
|
+
})
|
146
|
+
container.append(author_div)
|
147
|
+
|
148
|
+
message_div = $("<div />", {
|
149
|
+
"class": "chatty_message_message",
|
150
|
+
"text": message.message
|
151
|
+
})
|
152
|
+
container.append(message_div)
|
153
|
+
|
154
|
+
created_at_div = $("<div />", {
|
155
|
+
"class": "chatty_message_created_at",
|
156
|
+
"text": message.created_at
|
157
|
+
})
|
158
|
+
container.append(created_at_div)
|
159
|
+
|
160
|
+
messages_container.prepend(container)
|
161
|
+
container.slideDown("fast")
|
162
|
+
|
163
|
+
chatty_refresh_messages = (chat, callback) ->
|
164
|
+
last_message_id = chat.data("last-message-id")
|
165
|
+
|
166
|
+
$.ajax({type: "GET", url: "/chatty/messages/?q[id_gt]=" + chat.data("last-message-id") + "&q[chat_id_eq]=" + chat.data("chat-id"), cache: false, async: true, dataType: "json", success: (data) ->
|
167
|
+
for message in data.messages
|
168
|
+
chatty_add_message(chat, message)
|
169
|
+
})
|
170
|
+
|
171
|
+
chatty_show_not_signed_in_error = (chat) ->
|
172
|
+
$(".chatty_not_signed_in_error", chat).slideDown("fast")
|
173
|
+
|
174
|
+
chatty_show_cant_add_messages_error = (chat) ->
|
175
|
+
$(".chatty_not_allowed_to_add_messages", chat).slideDown("fast")
|
176
|
+
|
177
|
+
chatty_show_messages = (chat) ->
|
178
|
+
$(".chatty_messages", chat).slideDown("fast")
|
179
|
+
|
180
|
+
chatty_init_form = (chat, callback) ->
|
181
|
+
if !chat.data("signed-in")
|
182
|
+
chatty_show_not_signed_in_error()
|
183
|
+
callback.call()
|
184
|
+
else if !chat.data("can-add-messages")
|
185
|
+
chatty_show_cant_add_messages_error()
|
186
|
+
callback.call()
|
187
|
+
else if chat.data("state") == "closed"
|
188
|
+
callback.call()
|
189
|
+
else
|
190
|
+
$.ajax({type: "GET", url: "/chatty/messages/new?message[chat_id]=" + chat.data("chat-id"), cache: false, async: true, complete: (data) ->
|
191
|
+
form_container = $("<div />", {
|
192
|
+
"html": data.responseText,
|
193
|
+
"class": "chatty_form",
|
194
|
+
"css": {
|
195
|
+
"display": "none"
|
196
|
+
}
|
197
|
+
})
|
198
|
+
chat.prepend(form_container)
|
199
|
+
form_container.slideDown("fast")
|
200
|
+
|
201
|
+
$("form", form_container).bind("ajax:complete", (env, xhr, status) ->
|
202
|
+
textfield = $("textarea, input[type=text]", chat)
|
203
|
+
chatty_refresh_messages(chat)
|
204
|
+
res = $.parseJSON(xhr.responseText)
|
205
|
+
|
206
|
+
if !res.success
|
207
|
+
alert(res.errors)
|
208
|
+
else
|
209
|
+
textfield.val("")
|
210
|
+
|
211
|
+
textfield.focus()
|
212
|
+
)
|
213
|
+
|
214
|
+
callback.call()
|
215
|
+
})
|
216
|
+
|
217
|
+
$(".chatty_chat").each ->
|
218
|
+
chat = $(this)
|
219
|
+
chatty_init(chat)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Chatty::AdminChatsController < Chatty::ApplicationController
|
2
|
+
before_filter :set_chat, :only => [:handle, :show]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@ransack_params = params[:q] || {}
|
6
|
+
@ransack = Chatty::Chat.ransack(@ransack_params)
|
7
|
+
@chats = @ransack.result.order(:id).reverse_order
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle
|
14
|
+
@chat.handled = true
|
15
|
+
@chat.save!
|
16
|
+
@chat.create_activity :key => "chatty/chat.handled", :owner => current_user
|
17
|
+
|
18
|
+
redirect_to admin_chat_path(@chat)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def set_chat
|
24
|
+
@chat = Chatty::Chat.find(params[:id])
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require_dependency "chatty/application_controller"
|
2
|
+
|
3
|
+
class Chatty::ChatsController < Chatty::ApplicationController
|
4
|
+
before_action :set_chat, only: [:show, :edit, :update, :destroy, :messages, :handle, :close]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@ransack_params = params[:q] || {}
|
8
|
+
@ransack = Chatty::Chat.ransack(@ransack_params.clone)
|
9
|
+
@chats = @ransack.result.order(:id).reverse_order
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
respond_to do |format|
|
14
|
+
format.json { render(:json => {:chat => @chat.json}) }
|
15
|
+
format.html { render :show }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def new
|
20
|
+
@chat = Chatty::Chat.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@chat = Chatty::Chat.new(chat_params)
|
28
|
+
|
29
|
+
if @chat.save
|
30
|
+
redirect_to @chat, notice: 'Chat was successfully created.'
|
31
|
+
else
|
32
|
+
render action: 'new'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def update
|
37
|
+
if @chat.update(chat_params)
|
38
|
+
redirect_to @chat, notice: 'Chat was successfully updated.'
|
39
|
+
else
|
40
|
+
render action: 'edit'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
@chat.destroy
|
46
|
+
redirect_to chats_url, notice: 'Chat was successfully destroyed.'
|
47
|
+
end
|
48
|
+
|
49
|
+
def messages
|
50
|
+
@messages = @chat.messages
|
51
|
+
render :partial => "messages", :layout => false
|
52
|
+
end
|
53
|
+
|
54
|
+
def handle
|
55
|
+
@chat.handle
|
56
|
+
@chat.create_activity :key => "chatty/chat.handled", :owner => current_user
|
57
|
+
redirect_to chat_path(@chat)
|
58
|
+
end
|
59
|
+
|
60
|
+
def close
|
61
|
+
@chat.close
|
62
|
+
@chat.create_activity :key => "chatty/chat.closed", :owner => current_user
|
63
|
+
redirect_to chat_path(@chat)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def set_chat
|
69
|
+
@chat = Chatty::Chat.find(params[:id])
|
70
|
+
authorize! action_name.to_sym, @chat
|
71
|
+
end
|
72
|
+
|
73
|
+
def chat_params
|
74
|
+
params.require(:chat).permit(:user_type, :user_id, :resource_type, :resource_id)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Chatty::MessagesController < Chatty::ApplicationController
|
2
|
+
def new
|
3
|
+
spawn_message
|
4
|
+
render :new, :layout => false
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
spawn_message
|
9
|
+
|
10
|
+
if @message.save
|
11
|
+
render :json => {
|
12
|
+
:success => true
|
13
|
+
}
|
14
|
+
else
|
15
|
+
render :json => {
|
16
|
+
:success => false,
|
17
|
+
:errors => @message.errors.full_messages.join(". ")
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def index
|
23
|
+
@ransack_params = params[:q] || {}
|
24
|
+
@ransack = Chatty::Message.ransack(@ransack_params)
|
25
|
+
@messages = @ransack.result.order(:created_at, :id)
|
26
|
+
|
27
|
+
respond_to do |format|
|
28
|
+
format.json { render(:json => {:messages => @messages.map{ |message| message.json } }) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def spawn_message
|
35
|
+
if params[:message]
|
36
|
+
@message = Chatty::Message.new(message_params)
|
37
|
+
else
|
38
|
+
@message = Chatty::Message.new
|
39
|
+
end
|
40
|
+
|
41
|
+
@message.user = current_user
|
42
|
+
@message.chat_id = message_params[:chat_id]
|
43
|
+
end
|
44
|
+
|
45
|
+
def message_params
|
46
|
+
params.require(:message).permit(:chat_id, :message)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Chatty::ChatsHelper
|
2
|
+
def chatty_chat(chat)
|
3
|
+
content_tag(:div, nil, {
|
4
|
+
:class => "chatty_chat",
|
5
|
+
:data => {
|
6
|
+
:chat_id => chat.id,
|
7
|
+
:signed_in => signed_in?,
|
8
|
+
:can_add_messages => can?(:new, Chatty::Message),
|
9
|
+
:need_to_be_signed_in_message => _("You need to be signed in to write messages."),
|
10
|
+
:not_allowed_to_add_messages_message => _("You are not allowed to write messages."),
|
11
|
+
:waiting_to_connect_message => _("Waiting to connect..."),
|
12
|
+
:waiting_to_be_handled_message => _("Waiting to be handled..."),
|
13
|
+
:chat_is_closed_message => _("This chat is closed.")
|
14
|
+
}
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Chatty::Chat < ActiveRecord::Base
|
2
|
+
include PublicActivity::Model
|
3
|
+
tracked
|
4
|
+
|
5
|
+
belongs_to :resource, :polymorphic => true
|
6
|
+
belongs_to :user, :polymorphic => true
|
7
|
+
has_many :messages
|
8
|
+
|
9
|
+
validates_presence_of :user
|
10
|
+
accepts_nested_attributes_for :messages
|
11
|
+
|
12
|
+
state_machine :state, :initial => :new do
|
13
|
+
event :handle do
|
14
|
+
transition [:new, :closed] => :handled
|
15
|
+
end
|
16
|
+
|
17
|
+
event :close do
|
18
|
+
transition :handled => :closed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def json
|
23
|
+
return {
|
24
|
+
:id => id,
|
25
|
+
:state => state
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.translated_states
|
30
|
+
return {
|
31
|
+
_("New") => "new",
|
32
|
+
_("Handled") => "handled",
|
33
|
+
_("Closed") => "closed"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Chatty::Message < ActiveRecord::Base
|
2
|
+
belongs_to :chat
|
3
|
+
belongs_to :user, :polymorphic => true
|
4
|
+
|
5
|
+
validates_presence_of :chat, :user, :message
|
6
|
+
validate :validate_is_chat_open
|
7
|
+
|
8
|
+
def json
|
9
|
+
return {
|
10
|
+
:id => id,
|
11
|
+
:message => message,
|
12
|
+
:author_name => (user[:name].presence || user[:email].presence || user.id),
|
13
|
+
:created_at => created_at.strftime("%Y-%m-%d %H:%M:%S")
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def validate_is_chat_open
|
20
|
+
if chat.state != "handled"
|
21
|
+
errors.add(:chat_id, _("is not open for new messages in that state: %{chat_state}", :chat_state => chat.translated_state))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
%h1= _("Chats")
|
2
|
+
|
3
|
+
= simple_search_form_for @ransack, @ransack_params do |f|
|
4
|
+
= f.input :state_eq, :as => :select, :collection => Chatty::Chat.translated_states
|
5
|
+
= f.submit _("Search")
|
6
|
+
|
7
|
+
%table
|
8
|
+
%thead
|
9
|
+
%tr
|
10
|
+
%th= Chatty::Chat.human_attribute_name(:id)
|
11
|
+
%th= Chatty::Chat.human_attribute_name(:handled)
|
12
|
+
%th= Chatty::Chat.human_attribute_name(:created_at)
|
13
|
+
%tbody
|
14
|
+
- @chats.each do |chat|
|
15
|
+
%tr
|
16
|
+
%td= link_to chat.id, chat_path(chat)
|
17
|
+
%td= chat.handled? ? _("Yes") : _("No")
|
18
|
+
%td= l(chat.created_at, :format => :long)
|
19
|
+
- if @chats.none?
|
20
|
+
%tr
|
21
|
+
%td{:colspan => 3}
|
22
|
+
= _("No chats was found.")
|
@@ -0,0 +1,9 @@
|
|
1
|
+
%h1= _("Show chat")
|
2
|
+
|
3
|
+
= chatty_chat(@chat)
|
4
|
+
|
5
|
+
- if @chat.can_handle? && can?(:handle, @chat)
|
6
|
+
= link_to _("Handle"), handle_chat_path(@chat), :method => :post, :data => {:confirm => _("Are you sure?")}
|
7
|
+
|
8
|
+
- if @chat.can_close? && can?(:close, @chat)
|
9
|
+
= link_to _("Close"), close_chat_path(@chat), :method => :post, :data => {:confirm => _("Are you sure?")}
|
@@ -0,0 +1 @@
|
|
1
|
+
= render "form"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateChattyMessages < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :chatty_messages do |t|
|
4
|
+
t.integer :chat_id
|
5
|
+
t.string :user_type
|
6
|
+
t.integer :user_id
|
7
|
+
t.text :message
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :chatty_messages, :chat_id
|
13
|
+
add_index :chatty_messages, [:user_type, :user_id]
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateChattyChats < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :chatty_chats do |t|
|
4
|
+
t.string :user_type
|
5
|
+
t.integer :user_id
|
6
|
+
t.string :resource_type
|
7
|
+
t.integer :resource_id
|
8
|
+
t.string :state
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :chatty_chats, [:user_type, :user_id]
|
14
|
+
add_index :chatty_chats, [:resource_type, :resource_id]
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Migration responsible for creating a table with activities
|
2
|
+
class CreateActivities < ActiveRecord::Migration
|
3
|
+
# Create table
|
4
|
+
def self.up
|
5
|
+
unless table_exists? :activities
|
6
|
+
create_table :activities do |t|
|
7
|
+
t.belongs_to :trackable, :polymorphic => true
|
8
|
+
t.belongs_to :owner, :polymorphic => true
|
9
|
+
t.string :key
|
10
|
+
t.text :parameters
|
11
|
+
t.belongs_to :recipient, :polymorphic => true
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :activities, [:trackable_id, :trackable_type]
|
17
|
+
add_index :activities, [:owner_id, :owner_type]
|
18
|
+
add_index :activities, [:recipient_id, :recipient_type]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Drop table
|
23
|
+
def self.down
|
24
|
+
drop_table :activities if table_exists? :activities
|
25
|
+
end
|
26
|
+
end
|
data/lib/chatty.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,311 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chatty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kasper Johansen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: string-cases
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: haml-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simple_form_ransack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: public_activity
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: plugin_migrator
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: devise
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: ransack
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: gettext_simple_rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.0.12
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.0.12
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simple_form
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sass-rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: state_machine
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: cancan
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: sqlite3
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: rspec-rails
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - '>='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: factory_girl_rails
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - '>='
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - '>='
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: forgery
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - '>='
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - '>='
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
251
|
+
description: Making it easy to set it up a live chat on your website.
|
252
|
+
email:
|
253
|
+
- k@spernj.org
|
254
|
+
executables: []
|
255
|
+
extensions: []
|
256
|
+
extra_rdoc_files: []
|
257
|
+
files:
|
258
|
+
- app/models/chatty/message.rb
|
259
|
+
- app/models/chatty/chat.rb
|
260
|
+
- app/helpers/chatty/application_helper.rb
|
261
|
+
- app/helpers/chatty/chats_helper.rb
|
262
|
+
- app/assets/javascripts/chatty.js.coffee
|
263
|
+
- app/assets/javascripts/chatty/chats.js
|
264
|
+
- app/assets/javascripts/chatty/application.js
|
265
|
+
- app/assets/stylesheets/scaffold.css
|
266
|
+
- app/assets/stylesheets/chatty.css.scss
|
267
|
+
- app/assets/stylesheets/chatty/chats.css
|
268
|
+
- app/assets/stylesheets/chatty/application.css
|
269
|
+
- app/controllers/chatty/admin_chats_controller.rb
|
270
|
+
- app/controllers/chatty/messages_controller.rb
|
271
|
+
- app/controllers/chatty/application_controller.rb
|
272
|
+
- app/controllers/chatty/chats_controller.rb
|
273
|
+
- app/views/chatty/chats/show.html.haml
|
274
|
+
- app/views/chatty/chats/index.html.haml
|
275
|
+
- app/views/chatty/messages/_form.html.haml
|
276
|
+
- app/views/chatty/messages/new.html.haml
|
277
|
+
- config/routes.rb
|
278
|
+
- db/plugin_migrate/20140521072854_create_activities.rb
|
279
|
+
- db/plugin_migrate/20140520083027_create_chatty_messages.rb
|
280
|
+
- db/plugin_migrate/20140520083510_create_chatty_chats.rb
|
281
|
+
- lib/tasks/chatty_tasks.rake
|
282
|
+
- lib/chatty.rb
|
283
|
+
- lib/chatty/engine.rb
|
284
|
+
- lib/chatty/version.rb
|
285
|
+
- MIT-LICENSE
|
286
|
+
- Rakefile
|
287
|
+
- README.rdoc
|
288
|
+
homepage: https://www.github.com/kaspernj/chatty
|
289
|
+
licenses: []
|
290
|
+
metadata: {}
|
291
|
+
post_install_message:
|
292
|
+
rdoc_options: []
|
293
|
+
require_paths:
|
294
|
+
- lib
|
295
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
296
|
+
requirements:
|
297
|
+
- - '>='
|
298
|
+
- !ruby/object:Gem::Version
|
299
|
+
version: '0'
|
300
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
301
|
+
requirements:
|
302
|
+
- - '>='
|
303
|
+
- !ruby/object:Gem::Version
|
304
|
+
version: '0'
|
305
|
+
requirements: []
|
306
|
+
rubyforge_project:
|
307
|
+
rubygems_version: 2.0.7
|
308
|
+
signing_key:
|
309
|
+
specification_version: 4
|
310
|
+
summary: Chatty is a chat extention for Rails
|
311
|
+
test_files: []
|