[fix] Add communication into timeline in realtime

This commit is contained in:
Anand Doshi 2015-09-14 16:28:07 +05:30
parent 6983fa72f9
commit 39826f2d72
4 changed files with 28 additions and 8 deletions

View file

@ -174,6 +174,10 @@ def files_dirty():
return False
def compile_less():
from distutils.spawn import find_executable
if not find_executable("lessc"):
return
for path in app_paths:
less_path = os.path.join(path, "public", "less")
if os.path.exists(less_path):
@ -189,4 +193,4 @@ def compile_less():
print "compiling {0}".format(fpath)
css_path = os.path.join(path, "public", "css", fname.rsplit(".", 1)[0] + ".css")
os.system("which lessc && lessc {0} > {1}".format(fpath, css_path))
os.system("lessc {0} > {1}".format(fpath, css_path))

View file

@ -33,6 +33,16 @@ class Communication(Document):
else:
self.status = "Open"
def after_insert(self):
# send new comment to listening clients
comment = self.as_dict()
comment["comment"] = comment["content"]
comment["comment_by"] = comment["sender"]
comment["comment_type"] = comment["communication_medium"]
frappe.publish_realtime('new_comment', comment, doctype = self.reference_doctype,
docname = self.reference_name)
def on_update(self):
"""Update parent status as `Open` or `Replied`."""
self.update_parent()
@ -49,7 +59,7 @@ class Communication(Document):
to_status = "Open" if self.sent_or_received=="Received" else "Replied"
if to_status in status_field.options.splitlines():
frappe.db.set_value(parent.doctype, parent.name, "status", to_status)
parent.db_set("status", to_status)
parent.notify_update()

View file

@ -154,10 +154,11 @@ $.extend(frappe.model, {
},
new_comment: function(comment) {
if (frappe.model.docinfo[comment.comment_doctype]
&& frappe.model.docinfo[comment.comment_doctype][comment.comment_docname]) {
var comments = frappe.model.docinfo[comment.comment_doctype][comment.comment_docname].comments;
var reference_doctype = comment.comment_doctype || comment.reference_doctype;
var reference_name = comment.comment_docname || comment.reference_name;
if (frappe.model.docinfo[reference_doctype] && frappe.model.docinfo[reference_doctype][reference_name]) {
var comments = frappe.model.docinfo[reference_doctype][reference_name].comments;
var comment_exists = false;
for (var i=0, l=comments.length; i<l; i++) {
if (comments[i].name==comment.name) {
@ -165,12 +166,13 @@ $.extend(frappe.model, {
break;
}
}
if (!comment_exists) {
frappe.model.docinfo[comment.comment_doctype][comment.comment_docname].comments = comments.concat([comment]);
frappe.model.docinfo[reference_doctype][reference_name].comments = comments.concat([comment]);
}
}
if (cur_frm.doctype === comment.comment_doctype && cur_frm.docname === comment.comment_docname) {
cur_frm.comments.refresh();
if (cur_frm.doctype === reference_doctype && cur_frm.docname === reference_name) {
cur_frm.comments.refresh();
}
},

View file

@ -72,6 +72,10 @@ io.on('connection', function(socket){
})
.end(function(err, res) {
if(err) console.log(err);
if(!res) {
console.log("No response for doc_subscribe");
return;
}
if(res.status == 200) {
var room = get_doc_room(socket, doctype, docname);
// console.log('joining', room)