updates to kb: unanswered questions show in desktop, questions query moved to server-side
This commit is contained in:
parent
e343393d73
commit
c7dbe293c3
@ -126,6 +126,7 @@ erpnext.desktop.show_pending_notifications = function() {
|
|||||||
add_circle('todo', 'things_todo', 'Things To Do');
|
add_circle('todo', 'things_todo', 'Things To Do');
|
||||||
add_circle('calendar', 'todays_events', 'Todays Events');
|
add_circle('calendar', 'todays_events', 'Todays Events');
|
||||||
add_circle('project', 'open_tasks', 'Open Tasks');
|
add_circle('project', 'open_tasks', 'Open Tasks');
|
||||||
|
add_circle('kb', 'unanswered_questions', 'Unanswered Questions');
|
||||||
|
|
||||||
erpnext.update_messages();
|
erpnext.update_messages();
|
||||||
|
|
||||||
|
@ -136,6 +136,7 @@ erpnext.update_messages = function(reset) {
|
|||||||
show_in_circle('things_todo', r.message.things_todo);
|
show_in_circle('things_todo', r.message.things_todo);
|
||||||
show_in_circle('todays_events', r.message.todays_events);
|
show_in_circle('todays_events', r.message.todays_events);
|
||||||
show_in_circle('open_tasks', r.message.open_tasks);
|
show_in_circle('open_tasks', r.message.open_tasks);
|
||||||
|
show_in_circle('unanswered_questions', r.message.unanswered_questions);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
clearInterval(wn.updates.id);
|
clearInterval(wn.updates.id);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
def get_unread_messages():
|
def get_unread_messages():
|
||||||
@ -11,9 +12,7 @@ def get_unread_messages():
|
|||||||
""", webnotes.user.name, as_list=1)
|
""", webnotes.user.name, as_list=1)
|
||||||
|
|
||||||
def get_open_support_tickets():
|
def get_open_support_tickets():
|
||||||
"""
|
"""Returns a count of open support tickets"""
|
||||||
Returns a count of open support tickets
|
|
||||||
"""
|
|
||||||
from webnotes.utils import cint
|
from webnotes.utils import cint
|
||||||
open_support_tickets = webnotes.conn.sql("""\
|
open_support_tickets = webnotes.conn.sql("""\
|
||||||
SELECT COUNT(*) FROM `tabSupport Ticket`
|
SELECT COUNT(*) FROM `tabSupport Ticket`
|
||||||
@ -21,18 +20,14 @@ def get_open_support_tickets():
|
|||||||
return open_support_tickets and cint(open_support_tickets[0][0]) or 0
|
return open_support_tickets and cint(open_support_tickets[0][0]) or 0
|
||||||
|
|
||||||
def get_open_tasks():
|
def get_open_tasks():
|
||||||
"""
|
"""Returns a count of open tasks"""
|
||||||
Returns a count of open tasks
|
|
||||||
"""
|
|
||||||
from webnotes.utils import cint
|
from webnotes.utils import cint
|
||||||
return webnotes.conn.sql("""\
|
return webnotes.conn.sql("""\
|
||||||
SELECT COUNT(*) FROM `tabTask`
|
SELECT COUNT(*) FROM `tabTask`
|
||||||
WHERE status = 'Open'""")[0][0]
|
WHERE status = 'Open'""")[0][0]
|
||||||
|
|
||||||
def get_things_todo():
|
def get_things_todo():
|
||||||
"""
|
"""Returns a count of incomplete todos"""
|
||||||
Returns a count of incomplete todos
|
|
||||||
"""
|
|
||||||
from webnotes.utils import cint
|
from webnotes.utils import cint
|
||||||
incomplete_todos = webnotes.conn.sql("""\
|
incomplete_todos = webnotes.conn.sql("""\
|
||||||
SELECT COUNT(*) FROM `tabToDo`
|
SELECT COUNT(*) FROM `tabToDo`
|
||||||
@ -41,9 +36,7 @@ def get_things_todo():
|
|||||||
return incomplete_todos and cint(incomplete_todos[0][0]) or 0
|
return incomplete_todos and cint(incomplete_todos[0][0]) or 0
|
||||||
|
|
||||||
def get_todays_events():
|
def get_todays_events():
|
||||||
"""
|
"""Returns a count of todays events in calendar"""
|
||||||
Returns a count of todays events in calendar
|
|
||||||
"""
|
|
||||||
from webnotes.utils import nowdate, cint
|
from webnotes.utils import nowdate, cint
|
||||||
todays_events = webnotes.conn.sql("""\
|
todays_events = webnotes.conn.sql("""\
|
||||||
SELECT COUNT(*) FROM `tabEvent`
|
SELECT COUNT(*) FROM `tabEvent`
|
||||||
@ -53,6 +46,11 @@ def get_todays_events():
|
|||||||
webnotes.session.get('user'), nowdate()))
|
webnotes.session.get('user'), nowdate()))
|
||||||
return todays_events and cint(todays_events[0][0]) or 0
|
return todays_events and cint(todays_events[0][0]) or 0
|
||||||
|
|
||||||
|
def get_unanswered_questions():
|
||||||
|
return len(filter(lambda d: d[0]==0,
|
||||||
|
webnotes.conn.sql("""select (select count(*) from tabAnswer
|
||||||
|
where tabAnswer.question = tabQuestion.name) as answers from tabQuestion""")))
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_global_status_messages(arg=None):
|
def get_global_status_messages(arg=None):
|
||||||
return {
|
return {
|
||||||
@ -60,5 +58,6 @@ def get_global_status_messages(arg=None):
|
|||||||
'open_support_tickets': get_open_support_tickets(),
|
'open_support_tickets': get_open_support_tickets(),
|
||||||
'things_todo': get_things_todo(),
|
'things_todo': get_things_todo(),
|
||||||
'todays_events': get_todays_events(),
|
'todays_events': get_todays_events(),
|
||||||
'open_tasks': get_open_tasks()
|
'open_tasks': get_open_tasks(),
|
||||||
|
'unanswered_questions': get_unanswered_questions()
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ KBItemToolbar = function(args, kb) {
|
|||||||
this.wrapper = $a(this.parent, 'div', '', {});
|
this.wrapper = $a(this.parent, 'div', '', {});
|
||||||
this.line1 = $a(this.wrapper, 'div', '', {color: '#888', fontSize:'11px', margin:'7px 0px'});
|
this.line1 = $a(this.wrapper, 'div', '', {color: '#888', fontSize:'11px', margin:'7px 0px'});
|
||||||
this.make_timestamp();
|
this.make_timestamp();
|
||||||
|
this.make_answers();
|
||||||
if(this.with_tags)
|
if(this.with_tags)
|
||||||
this.make_tags();
|
this.make_tags();
|
||||||
this.setup_del();
|
this.setup_del();
|
||||||
@ -43,6 +44,18 @@ KBItemToolbar = function(args, kb) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.make_answers = function() {
|
||||||
|
if(this.doctype=='Question') {
|
||||||
|
if(this.det.answers==0) {
|
||||||
|
this.line1.innerHTML += ' | no answers';
|
||||||
|
} else if(this.det.answers==1) {
|
||||||
|
this.line1.innerHTML += ' | 1 answer';
|
||||||
|
} else {
|
||||||
|
this.line1.innerHTML += ' | '+this.det.answers+' answers';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.make_tags = function() {
|
this.make_tags = function() {
|
||||||
this.line1.innerHTML += ' | '
|
this.line1.innerHTML += ' | '
|
||||||
this.tags_area = $a(this.line1, 'span', 'kb-tags')
|
this.tags_area = $a(this.line1, 'span', 'kb-tags')
|
||||||
|
@ -14,6 +14,10 @@ div.kb-search-wrapper textarea {
|
|||||||
.kb-questions {
|
.kb-questions {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.un-answered {
|
||||||
|
color: #f33;
|
||||||
|
}
|
||||||
|
|
||||||
.kb-question-details {
|
.kb-question-details {
|
||||||
margin: 11px 0px 11px 29px;
|
margin: 11px 0px 11px 29px;
|
||||||
}
|
}
|
||||||
|
@ -115,24 +115,16 @@ function KnowledgeBase(w) {
|
|||||||
no_results_message: 'No questions found. Ask a new question!',
|
no_results_message: 'No questions found. Ask a new question!',
|
||||||
appframe: wn.pages.questions.appframe,
|
appframe: wn.pages.questions.appframe,
|
||||||
as_dict: 1,
|
as_dict: 1,
|
||||||
get_query: function() {
|
method: 'utilities.page.questions.questions.get_questions',
|
||||||
|
get_args: function() {
|
||||||
// filter by search string
|
var args = {};
|
||||||
var v = me.search.value==$(me.search).attr('default_text') ? '' : me.search.value;
|
if(me.search.value) {
|
||||||
cond = v ? (' and t1.question like "%'+v+'%"') : '';
|
args.search_text = me.search.value;
|
||||||
|
}
|
||||||
// filter by tags
|
|
||||||
if(me.tag_filter_dict) {
|
if(me.tag_filter_dict) {
|
||||||
for(f in me.tag_filter_dict) {
|
args.tag_filters = keys(me.tag_filter_dict);
|
||||||
cond += ' and t1.`_user_tags` like "%' + f + '%"'
|
|
||||||
}
|
}
|
||||||
}
|
return args
|
||||||
return repl('select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags, '
|
|
||||||
+'t1._users_voted, t2.first_name, t2.last_name '
|
|
||||||
+'from tabQuestion t1, tabProfile t2 '
|
|
||||||
+'where t1.docstatus!=2 '
|
|
||||||
+'and t1.owner = t2.name'
|
|
||||||
+'%(cond)s order by t1.modified desc', {user:user, cond: cond})
|
|
||||||
},
|
},
|
||||||
render_row: function(parent, data, listing) {
|
render_row: function(parent, data, listing) {
|
||||||
new KBQuestion(parent, data, me);
|
new KBQuestion(parent, data, me);
|
||||||
@ -196,7 +188,11 @@ KBQuestion = function(parent, det, kb) {
|
|||||||
|
|
||||||
this.make = function() {
|
this.make = function() {
|
||||||
this.wrapper = $a(parent, 'div', 'kb-question-wrapper');
|
this.wrapper = $a(parent, 'div', 'kb-question-wrapper');
|
||||||
this.q_area = $a($a(this.wrapper, 'div'), 'h3', 'kb-questions link_type', {display:'inline', textDecoration:'none'}, det.question);
|
this.q_area = $a($a(this.wrapper, 'div'), 'h3',
|
||||||
|
'kb-questions link_type', {display:'inline', textDecoration:'none'}, det.question);
|
||||||
|
if(det.answers==0) {
|
||||||
|
$(this.q_area).addClass('un-answered')
|
||||||
|
}
|
||||||
|
|
||||||
this.q_area.onclick = function() {
|
this.q_area.onclick = function() {
|
||||||
var q = this;
|
var q = this;
|
||||||
|
@ -19,6 +19,29 @@ import webnotes
|
|||||||
from webnotes.utils import load_json, cint, cstr
|
from webnotes.utils import load_json, cint, cstr
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@webnotes.whitelist()
|
||||||
|
def get_questions():
|
||||||
|
"""get list of questions"""
|
||||||
|
import json
|
||||||
|
conds = ''
|
||||||
|
|
||||||
|
if 'search_text' in webnotes.form_dict:
|
||||||
|
conds = ' and t1.question like "%'+ webnotes.form_dict['search_text'] + '%"'
|
||||||
|
|
||||||
|
if 'tag_filters' in webnotes.form_dict:
|
||||||
|
tag_filters = json.loads(webnotes.form_dict['tag_filters'])
|
||||||
|
for t in tag_filters:
|
||||||
|
conds += ' and t1._user_tags like "%'+ t +'%"'
|
||||||
|
|
||||||
|
return webnotes.conn.sql("""select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags,
|
||||||
|
t2.first_name, t2.last_name, (select count(*) from tabAnswer where
|
||||||
|
tabAnswer.question = t1.name) as answers
|
||||||
|
from tabQuestion t1, tabProfile t2
|
||||||
|
where t1.docstatus!=2
|
||||||
|
and t1.owner = t2.name
|
||||||
|
%(conds)s
|
||||||
|
order by t1.modified desc""" % {"conds":conds}, as_dict=1)
|
||||||
|
|
||||||
# add a new question
|
# add a new question
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def add_question(arg):
|
def add_question(arg):
|
||||||
@ -40,20 +63,6 @@ def add_question(arg):
|
|||||||
'notify': 1
|
'notify': 1
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@webnotes.whitelist()
|
|
||||||
def vote(arg):
|
|
||||||
args = load_json(arg)
|
|
||||||
|
|
||||||
res = webnotes.conn.sql("select points, _users_voted from `tab%s` where name=%s" % (args['dt'], '%s'), args['dn'])[0]
|
|
||||||
p = cint(res[0])
|
|
||||||
p = args['vote']=='up' and p+1 or p-1
|
|
||||||
|
|
||||||
# update
|
|
||||||
webnotes.conn.sql("update `tab%s` set points=%s, _users_voted=%s where name=%s" % (args['dt'], '%s', '%s', '%s'), \
|
|
||||||
(p, cstr(res[1]) + ',' + webnotes.user.name, args['dn']))
|
|
||||||
|
|
||||||
return p
|
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def delete(arg):
|
def delete(arg):
|
||||||
"""
|
"""
|
||||||
|
@ -2258,7 +2258,7 @@ $('body').append('<a class="erpnext-logo" title="Powered by ERPNext" \
|
|||||||
href="http://erpnext.com" target="_blank"></a>')}
|
href="http://erpnext.com" target="_blank"></a>')}
|
||||||
erpnext.update_messages=function(reset){if(inList(['Guest'],user)||!wn.session_alive){return;}
|
erpnext.update_messages=function(reset){if(inList(['Guest'],user)||!wn.session_alive){return;}
|
||||||
if(!reset){var set_messages=function(r){if(!r.exc){erpnext.toolbar.set_new_comments(r.message.unread_messages);var show_in_circle=function(parent_id,msg){var parent=$('#'+parent_id);if(parent){if(msg){parent.find('span:first').text(msg);parent.toggle(true);}else{parent.toggle(false);}}}
|
if(!reset){var set_messages=function(r){if(!r.exc){erpnext.toolbar.set_new_comments(r.message.unread_messages);var show_in_circle=function(parent_id,msg){var parent=$('#'+parent_id);if(parent){if(msg){parent.find('span:first').text(msg);parent.toggle(true);}else{parent.toggle(false);}}}
|
||||||
show_in_circle('unread_messages',r.message.unread_messages.length);show_in_circle('open_support_tickets',r.message.open_support_tickets);show_in_circle('things_todo',r.message.things_todo);show_in_circle('todays_events',r.message.todays_events);show_in_circle('open_tasks',r.message.open_tasks);}else{clearInterval(wn.updates.id);}}
|
show_in_circle('unread_messages',r.message.unread_messages.length);show_in_circle('open_support_tickets',r.message.open_support_tickets);show_in_circle('things_todo',r.message.things_todo);show_in_circle('todays_events',r.message.todays_events);show_in_circle('open_tasks',r.message.open_tasks);show_in_circle('unanswered_questions',r.message.unanswered_questions);}else{clearInterval(wn.updates.id);}}
|
||||||
wn.call({method:'startup.startup.get_global_status_messages',callback:set_messages});}else{erpnext.toolbar.set_new_comments(0);$('#unread_messages').toggle(false);}}
|
wn.call({method:'startup.startup.get_global_status_messages',callback:set_messages});}else{erpnext.toolbar.set_new_comments(0);$('#unread_messages').toggle(false);}}
|
||||||
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
|
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
|
||||||
wn.updates.id=setInterval(erpnext.update_messages,60000);}
|
wn.updates.id=setInterval(erpnext.update_messages,60000);}
|
||||||
|
@ -726,7 +726,7 @@ $('body').append('<a class="erpnext-logo" title="Powered by ERPNext" \
|
|||||||
href="http://erpnext.com" target="_blank"></a>')}
|
href="http://erpnext.com" target="_blank"></a>')}
|
||||||
erpnext.update_messages=function(reset){if(inList(['Guest'],user)||!wn.session_alive){return;}
|
erpnext.update_messages=function(reset){if(inList(['Guest'],user)||!wn.session_alive){return;}
|
||||||
if(!reset){var set_messages=function(r){if(!r.exc){erpnext.toolbar.set_new_comments(r.message.unread_messages);var show_in_circle=function(parent_id,msg){var parent=$('#'+parent_id);if(parent){if(msg){parent.find('span:first').text(msg);parent.toggle(true);}else{parent.toggle(false);}}}
|
if(!reset){var set_messages=function(r){if(!r.exc){erpnext.toolbar.set_new_comments(r.message.unread_messages);var show_in_circle=function(parent_id,msg){var parent=$('#'+parent_id);if(parent){if(msg){parent.find('span:first').text(msg);parent.toggle(true);}else{parent.toggle(false);}}}
|
||||||
show_in_circle('unread_messages',r.message.unread_messages.length);show_in_circle('open_support_tickets',r.message.open_support_tickets);show_in_circle('things_todo',r.message.things_todo);show_in_circle('todays_events',r.message.todays_events);show_in_circle('open_tasks',r.message.open_tasks);}else{clearInterval(wn.updates.id);}}
|
show_in_circle('unread_messages',r.message.unread_messages.length);show_in_circle('open_support_tickets',r.message.open_support_tickets);show_in_circle('things_todo',r.message.things_todo);show_in_circle('todays_events',r.message.todays_events);show_in_circle('open_tasks',r.message.open_tasks);show_in_circle('unanswered_questions',r.message.unanswered_questions);}else{clearInterval(wn.updates.id);}}
|
||||||
wn.call({method:'startup.startup.get_global_status_messages',callback:set_messages});}else{erpnext.toolbar.set_new_comments(0);$('#unread_messages').toggle(false);}}
|
wn.call({method:'startup.startup.get_global_status_messages',callback:set_messages});}else{erpnext.toolbar.set_new_comments(0);$('#unread_messages').toggle(false);}}
|
||||||
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
|
erpnext.startup.set_periodic_updates=function(){wn.updates={};if(wn.updates.id){clearInterval(wn.updates.id);}
|
||||||
wn.updates.id=setInterval(erpnext.update_messages,60000);}
|
wn.updates.id=setInterval(erpnext.update_messages,60000);}
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
/*
|
/*
|
||||||
* erpnext/utilities/page/kb_common/kb_common.js
|
* erpnext/utilities/page/kb_common/kb_common.js
|
||||||
*/
|
*/
|
||||||
KBItemToolbar=function(args,kb){$.extend(this,args);var me=this;this.make=function(){this.wrapper=$a(this.parent,'div','',{});this.line1=$a(this.wrapper,'div','',{color:'#888',fontSize:'11px',margin:'7px 0px'});this.make_timestamp();if(this.with_tags)
|
KBItemToolbar=function(args,kb){$.extend(this,args);var me=this;this.make=function(){this.wrapper=$a(this.parent,'div','',{});this.line1=$a(this.wrapper,'div','',{color:'#888',fontSize:'11px',margin:'7px 0px'});this.make_timestamp();this.make_answers();if(this.with_tags)
|
||||||
this.make_tags();this.setup_del();}
|
this.make_tags();this.setup_del();}
|
||||||
this.make_timestamp=function(){this.line1.innerHTML=repl('By %(name)s | %(when)s',{name:wn.utils.full_name(this.det.first_name,this.det.last_name),when:wn.datetime.comment_when(this.det.modified)});if(has_common(user_roles,['Administrator','System Manager'])){this.line1.innerHTML+=' | <a style="cursor:pointer;"\
|
this.make_timestamp=function(){this.line1.innerHTML=repl('By %(name)s | %(when)s',{name:wn.utils.full_name(this.det.first_name,this.det.last_name),when:wn.datetime.comment_when(this.det.modified)});if(has_common(user_roles,['Administrator','System Manager'])){this.line1.innerHTML+=' | <a style="cursor:pointer;"\
|
||||||
class="del-link">delete</a>';}}
|
class="del-link">delete</a>';}}
|
||||||
|
this.make_answers=function(){if(this.doctype=='Question')
|
||||||
|
this.line1.innerHTML+=' | '+this.det.answers+' answers'}
|
||||||
this.make_tags=function(){this.line1.innerHTML+=' | '
|
this.make_tags=function(){this.line1.innerHTML+=' | '
|
||||||
this.tags_area=$a(this.line1,'span','kb-tags')
|
this.tags_area=$a(this.line1,'span','kb-tags')
|
||||||
this.tags=new TagList(this.tags_area,this.det._user_tags&&(this.det._user_tags.split(',')),this.doctype,this.det.name,0,kb.set_tag_filter)}
|
this.tags=new TagList(this.tags_area,this.det._user_tags&&(this.det._user_tags.split(',')),this.doctype,this.det.name,0,kb.set_tag_filter)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user