[fix] document refresh notification for same user in different tabs/sessions
This commit is contained in:
parent
46f9e75356
commit
65bc63f031
7 changed files with 18 additions and 8 deletions
|
|
@ -89,6 +89,7 @@ def init(site, sites_path=None):
|
|||
local.error_log = []
|
||||
local.message_log = []
|
||||
local.debug_log = []
|
||||
local.realtime_log = []
|
||||
local.flags = _dict({
|
||||
"ran_schedulers": [],
|
||||
"redirect_location": "",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import frappe
|
|||
import frappe.handler
|
||||
import frappe.auth
|
||||
import frappe.api
|
||||
import frappe.async
|
||||
import frappe.utils.response
|
||||
import frappe.website.render
|
||||
from frappe.utils import get_site_name, get_site_path
|
||||
|
|
@ -122,6 +123,10 @@ def application(request):
|
|||
if updated_in_db:
|
||||
frappe.db.commit()
|
||||
|
||||
# publish realtime
|
||||
for args in frappe.local.realtime_log:
|
||||
frappe.async.emit_via_redis(*args)
|
||||
|
||||
finally:
|
||||
if frappe.local.request.method in ("POST", "PUT") and frappe.db and rollback:
|
||||
frappe.db.rollback()
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ def is_file_old(file_path):
|
|||
return ((time.time() - os.stat(file_path).st_mtime) > TASK_LOG_MAX_AGE)
|
||||
|
||||
|
||||
def publish_realtime(event, message=None, room=None, user=None, doctype=None, docname=None):
|
||||
def publish_realtime(event, message=None, room=None, user=None, doctype=None, docname=None, now=False):
|
||||
"""Publish real-time updates
|
||||
|
||||
:param event: Event name, like `task_progress` etc.
|
||||
|
|
@ -140,7 +140,10 @@ def publish_realtime(event, message=None, room=None, user=None, doctype=None, do
|
|||
else:
|
||||
room = get_site_room()
|
||||
|
||||
emit_via_redis(event, message, room)
|
||||
if now:
|
||||
emit_via_redis(event, message, room)
|
||||
else:
|
||||
frappe.local.realtime_log.append([event, message, room])
|
||||
|
||||
def emit_via_redis(event, message, room):
|
||||
"""Publish real-time updates via redis
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ class Document(BaseDocument):
|
|||
|
||||
def notify_modified(self):
|
||||
"""Publish realtime that the current document is modified"""
|
||||
frappe.publish_realtime("doc_update", {"modified_by": frappe.session.user, "doctype": self.doctype, "name": self.name},
|
||||
frappe.publish_realtime("doc_update", {"modified": self.modified, "doctype": self.doctype, "name": self.name},
|
||||
doctype=self.doctype, docname=self.name)
|
||||
|
||||
if not self.meta.get("read_only") and not self.meta.get("issingle") and \
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ select.form-control {
|
|||
font-size: 12px;
|
||||
background-color: #fffce7;
|
||||
margin-bottom: 0px;
|
||||
margin: 0px -15px;
|
||||
}
|
||||
.delivery-status-indicator {
|
||||
display: inline-block;
|
||||
|
|
|
|||
|
|
@ -39,20 +39,20 @@ frappe.ui.form.save = function(frm, action, callback, btn) {
|
|||
|
||||
var cancel = function() {
|
||||
var args = {
|
||||
doctype: frm.doc.doctype,
|
||||
doctype: frm.doc.doctype,
|
||||
name: frm.doc.name
|
||||
};
|
||||
|
||||
|
||||
// update workflow state value if workflow exists
|
||||
var workflow_state_fieldname = frappe.workflow.get_state_fieldname(frm.doctype);
|
||||
if(workflow_state_fieldname) {
|
||||
$.extend(args, {
|
||||
workflow_state_fieldname: workflow_state_fieldname,
|
||||
workflow_state: frm.doc[workflow_state_fieldname]
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
_call({
|
||||
method: "frappe.desk.form.save.cancel",
|
||||
args: args,
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ $.extend(frappe.model, {
|
|||
if(doc) {
|
||||
// current document is dirty, show message if its not me
|
||||
if(cur_frm.doc.doctype===doc.doctype && cur_frm.doc.name===doc.name) {
|
||||
if(data.modified_by!==user) {
|
||||
if(!frappe.ui.form.is_saving && data.modified!=cur_frm.doc.modified) {
|
||||
doc.__needs_refresh = true;
|
||||
cur_frm.show_if_needs_refresh();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue