[rename] messages -> chat
This commit is contained in:
parent
99a36256ab
commit
1dbd6c83ea
18 changed files with 77 additions and 63 deletions
|
|
@ -22,7 +22,7 @@ def get_data():
|
|||
},
|
||||
{
|
||||
"type": "page",
|
||||
"label": _("Messages"),
|
||||
"label": _("Chat"),
|
||||
"name": "messages",
|
||||
"description": _("Chat messages and other notifications."),
|
||||
"data_doctype": "Communication"
|
||||
|
|
|
|||
0
frappe/desk/page/chat/__init__.py
Normal file
0
frappe/desk/page/chat/__init__.py
Normal file
|
|
@ -1,32 +1,27 @@
|
|||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// MIT License. See license.txt
|
||||
|
||||
// TODO
|
||||
// new message popup
|
||||
|
||||
frappe.provide('frappe.desk.pages.messages');
|
||||
|
||||
frappe.pages.messages.on_page_load = function(parent) {
|
||||
frappe.pages.chat.on_page_load = function(parent) {
|
||||
var page = frappe.ui.make_app_page({
|
||||
parent: parent,
|
||||
});
|
||||
|
||||
page.set_title('<span class="hidden-xs">' + __("Messages") + '</span>'
|
||||
page.set_title('<span class="hidden-xs">' + __("Chat") + '</span>'
|
||||
+ '<span class="hidden-sm hidden-md hidden-lg message-to"></span>');
|
||||
|
||||
$(".navbar-center").html(__("Messages"));
|
||||
$(".navbar-center").html(__("Chat"));
|
||||
|
||||
frappe.desk.pages.messages = new frappe.desk.pages.Messages(parent);
|
||||
frappe.pages.chat.chat = new frappe.Chat(parent);
|
||||
}
|
||||
|
||||
frappe.pages.messages.on_page_show = function() {
|
||||
frappe.pages.chat.on_page_show = function() {
|
||||
// clear title prefix
|
||||
frappe.utils.set_title_prefix("");
|
||||
|
||||
frappe.breadcrumbs.add("Desk");
|
||||
}
|
||||
|
||||
frappe.desk.pages.Messages = Class.extend({
|
||||
frappe.Chat = Class.extend({
|
||||
init: function(wrapper, page) {
|
||||
this.wrapper = wrapper;
|
||||
this.page = wrapper.page;
|
||||
|
|
@ -46,7 +41,7 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
var me = this;
|
||||
frappe.realtime.on('new_message', function(comment) {
|
||||
if(comment.modified_by !== user || comment.communication_type === 'Bot') {
|
||||
if(frappe.get_route()[0] === 'messages') {
|
||||
if(frappe.get_route()[0] === 'chat') {
|
||||
var current_contact = $(cur_page.page).find('[data-contact]').data('contact');
|
||||
var on_broadcast_page = current_contact === user;
|
||||
if ((current_contact == comment.owner)
|
||||
|
|
@ -56,7 +51,7 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
setTimeout(function() { me.prepend_comment(comment); }, 1000);
|
||||
}
|
||||
} else {
|
||||
frappe.utils.notify(__("Message from {0}", [comment.sender_full_name]), comment.content);
|
||||
frappe.utils.notify(__("Message from {0}", [frappe.user_info(comment.owner).fullname]), comment.content);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -64,23 +59,23 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
|
||||
prepend_comment: function(comment) {
|
||||
var $row = $('<div class="list-row"/>');
|
||||
frappe.desk.pages.messages.list.data.unshift(comment);
|
||||
frappe.desk.pages.messages.list.render_row($row, comment);
|
||||
frappe.desk.pages.messages.list.$w.prepend($row);
|
||||
frappe.pages.chat.chat.list.data.unshift(comment);
|
||||
frappe.pages.chat.chat.list.render_row($row, comment);
|
||||
frappe.pages.chat.chat.list.$w.prepend($row);
|
||||
},
|
||||
|
||||
make_sidebar: function() {
|
||||
var me = this;
|
||||
return frappe.call({
|
||||
module:'frappe.desk',
|
||||
page:'messages',
|
||||
page:'chat',
|
||||
method:'get_active_users',
|
||||
callback: function(r,rt) {
|
||||
// sort
|
||||
r.message.sort(function(a, b) { return cint(b.has_session) - cint(a.has_session); });
|
||||
|
||||
// render
|
||||
me.page.sidebar.html(frappe.render_template("messages_sidebar", {data: r.message}));
|
||||
me.page.sidebar.html(frappe.render_template("chat_sidebar", {data: r.message}));
|
||||
|
||||
// bind click
|
||||
me.page.sidebar.find("a").on("click", function() {
|
||||
|
|
@ -105,7 +100,7 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
make_messages: function(contact) {
|
||||
var me = this;
|
||||
|
||||
this.page.main.html($(frappe.render_template("messages_main", { "contact": contact })));
|
||||
this.page.main.html($(frappe.render_template("chat_main", { "contact": contact })));
|
||||
|
||||
var text_area = this.page.main.find(".messages-textarea").on("focusout", function() {
|
||||
// on touchscreen devices, scroll to top
|
||||
|
|
@ -127,7 +122,7 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
if(txt) {
|
||||
return frappe.call({
|
||||
module: 'frappe.desk',
|
||||
page:'messages',
|
||||
page:'chat',
|
||||
method:'post',
|
||||
args: {
|
||||
txt: txt,
|
||||
|
|
@ -164,7 +159,7 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
this.list = new frappe.ui.Listing({
|
||||
parent: this.page.main.find(".message-list"),
|
||||
page: this.page,
|
||||
method: 'frappe.desk.page.messages.messages.get_list',
|
||||
method: 'frappe.desk.page.chat.chat.get_list',
|
||||
args: {
|
||||
contact: contact
|
||||
},
|
||||
|
|
@ -172,7 +167,7 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
freeze: false,
|
||||
render_row: function(wrapper, data) {
|
||||
me.prepare(data);
|
||||
var row = $(frappe.render_template("messages_row", {
|
||||
var row = $(frappe.render_template("chat_row", {
|
||||
data: data
|
||||
})).appendTo(wrapper);
|
||||
row.find(".avatar, .indicator").tooltip();
|
||||
|
|
@ -184,7 +179,7 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
delete: function(ele) {
|
||||
$(ele).parent().css('opacity', 0.6);
|
||||
return frappe.call({
|
||||
method: 'frappe.desk.page.messages.messages.delete',
|
||||
method: 'frappe.desk.page.chat.chat.delete',
|
||||
args: {name : $(ele).attr('data-name')},
|
||||
callback: function() {
|
||||
$(ele).parents(".list-row:first").toggle(false);
|
||||
|
|
@ -220,6 +215,10 @@ frappe.desk.pages.Messages = Class.extend({
|
|||
data.is_mine = true;
|
||||
}
|
||||
|
||||
if(data.owner==data.reference_name && data.communication_type === "Bot") {
|
||||
data.owner = 'bot';
|
||||
}
|
||||
|
||||
data.content = frappe.markdown(data.content);
|
||||
}
|
||||
|
||||
23
frappe/desk/page/chat/chat.json
Normal file
23
frappe/desk/page/chat/chat.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"content": null,
|
||||
"creation": "2012-06-14 18:44:56",
|
||||
"docstatus": 0,
|
||||
"doctype": "Page",
|
||||
"icon": "",
|
||||
"idx": 1,
|
||||
"modified": "2016-03-31 02:02:13.503910",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Desk",
|
||||
"name": "chat",
|
||||
"owner": "Administrator",
|
||||
"page_name": "messages",
|
||||
"roles": [
|
||||
{
|
||||
"role": "All"
|
||||
}
|
||||
],
|
||||
"script": null,
|
||||
"standard": "Yes",
|
||||
"style": null,
|
||||
"title": "Chat"
|
||||
}
|
||||
|
|
@ -41,6 +41,7 @@ def get_list(arg=None):
|
|||
return frappe.db.sql("""select * from `tabCommunication`
|
||||
where
|
||||
communication_type in ('Chat', 'Notification')
|
||||
and comment_type != 'Bot'
|
||||
and reference_doctype ='User'
|
||||
and (owner=%(contact)s
|
||||
or reference_name=%(user)s
|
||||
|
|
@ -78,7 +79,8 @@ def get_active_users():
|
|||
# in case of administrator
|
||||
data.append({"name": frappe.session.user, "has_session": 100})
|
||||
|
||||
data.append({"name": "Bot", "has_session": 100})
|
||||
if 'System Manager' in frappe.get_roles():
|
||||
data.append({"name": "Bot", "has_session": 100})
|
||||
|
||||
return data
|
||||
|
||||
|
|
@ -9,16 +9,12 @@
|
|||
style="width: 20px; height: 16px; display: inline-block;"></span>
|
||||
{% } %}
|
||||
<div class="pull-left hidden-xs">
|
||||
{% if (data.communication_type==="Bot") { %}
|
||||
<span class="octicon octicon-zap bot-icon"></span>
|
||||
{% } else { %}
|
||||
<span class="avatar avatar-small" title="{%= frappe.user.full_name(data.owner) %} ">
|
||||
<img class="media-object {{ data.is_system_message ? "grayscale" : "" }}"
|
||||
src="{%= frappe.user.image(data.owner) %}">
|
||||
</span>
|
||||
{% } %}
|
||||
</div>
|
||||
<div class="media-body {{ data.is_system_message ? "text-muted" : "" }} message-bubble {{ data.is_mine ? "my-message" : "" }}">
|
||||
<div class="media-body {{ data.is_system_message ? "system-message" : "" }} message-bubble {{ data.is_mine ? "my-message" : "" }}">
|
||||
{%= data.content %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -26,7 +22,7 @@
|
|||
<div class="col-sm-3 text-right message-row-right">
|
||||
<div class="text-muted">
|
||||
<span class="hidden-sm hidden-md hidden-lg">
|
||||
{%= data.communication_type==="Bot" ? "Bot" : frappe.user.full_name(data.owner) %},
|
||||
{%= frappe.user.full_name(data.owner) %},
|
||||
</span>
|
||||
{%= comment_when(data.modified) %}
|
||||
</div>
|
||||
|
|
@ -1 +0,0 @@
|
|||
Chat-like interface with list of messages, updates by various users, transactions.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"creation": "2012-06-14 18:44:56.000000",
|
||||
"docstatus": 0,
|
||||
"doctype": "Page",
|
||||
"icon": "icon-envelope",
|
||||
"idx": 1,
|
||||
"modified": "2013-07-11 14:43:32.000001",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Desk",
|
||||
"name": "messages",
|
||||
"owner": "Administrator",
|
||||
"page_name": "messages",
|
||||
"roles": [
|
||||
{
|
||||
"role": "All"
|
||||
}
|
||||
],
|
||||
"standard": "Yes",
|
||||
"title": "Messages"
|
||||
}
|
||||
|
|
@ -24,11 +24,13 @@ def notify_link_count(doctype, name):
|
|||
def update_link_count():
|
||||
'''increment link count in the `idx` column for the given document'''
|
||||
link_count = frappe.cache().get_value('_link_count')
|
||||
|
||||
# reset the count
|
||||
frappe.cache().delete_value('_link_count')
|
||||
|
||||
if link_count:
|
||||
for key, count in link_count.iteritems():
|
||||
if key[0] not in ignore_doctypes:
|
||||
frappe.db.sql('update `tab{0}` set idx = idx + {1} where name=%s'.format(key[0], count),
|
||||
key[1])
|
||||
|
||||
# reset the count
|
||||
frappe.cache().delete_value('_link_count')
|
||||
|
|
|
|||
BIN
frappe/public/images/ui/bot.png
Normal file
BIN
frappe/public/images/ui/bot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
|
|
@ -259,6 +259,14 @@ frappe.Application = Class.extend({
|
|||
}
|
||||
return false;
|
||||
})
|
||||
.keydown("meta+b ctrl+b", function(e) {
|
||||
e.preventDefault();
|
||||
var route = frappe.get_route();
|
||||
if(route[0]==='Form' || route[0]==='List') {
|
||||
new_doc(route[1]);
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.keydown("esc", function(e) {
|
||||
// close open grid row
|
||||
var open_row = $(".grid-row-open");
|
||||
|
|
|
|||
|
|
@ -7,6 +7,14 @@ frappe.user_info = function(uid) {
|
|||
if(!uid)
|
||||
uid = user;
|
||||
|
||||
if(uid.toLowerCase()==="bot") {
|
||||
return {
|
||||
fullname: __("Bot"),
|
||||
image: "/assets/frappe/images/ui/bot.png",
|
||||
abbr: "B"
|
||||
}
|
||||
}
|
||||
|
||||
if(!(frappe.boot.user_info && frappe.boot.user_info[uid])) {
|
||||
var user_info = {fullname: toTitle(uid.split("@")[0]) || "Unknown"};
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -329,12 +329,16 @@ _f.Frm.prototype.show_web_link = function() {
|
|||
if(!doc.__islocal && doc.__onload && doc.__onload.is_website_generator) {
|
||||
me.web_link && me.web_link.remove();
|
||||
if(doc.__onload.published) {
|
||||
me.web_link = me.sidebar.add_user_action("See on Website",
|
||||
function() {}).attr("href", "/" + doc.__onload.website_route).attr("target", "_blank");
|
||||
me.add_web_link("/" + doc.__onload.website_route)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_f.Frm.prototype.add_web_link = function(path) {
|
||||
this.web_link = this.sidebar.add_user_action("See on Website",
|
||||
function() {}).attr("href", path).attr("target", "_blank");
|
||||
}
|
||||
|
||||
_f.Frm.prototype.check_doc_perm = function() {
|
||||
// get perm
|
||||
var dt = this.parent_doctype?this.parent_doctype : this.doctype;
|
||||
|
|
|
|||
|
|
@ -210,10 +210,6 @@ class TestDocument(unittest.TestCase):
|
|||
|
||||
self.assertEquals(old_count + 1, new_count)
|
||||
|
||||
# hack - for travis so that it does not batch idx updates (?)
|
||||
import time
|
||||
time.sleep(1)
|
||||
|
||||
before_update = frappe.db.get_value(doctype, name, 'idx')
|
||||
|
||||
update_link_count()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue