updates to kb: unanswered questions show in desktop, questions query moved to server-side
diff --git a/erpnext/utilities/page/kb_common/kb_common.js b/erpnext/utilities/page/kb_common/kb_common.js
index d77a938..a135612 100644
--- a/erpnext/utilities/page/kb_common/kb_common.js
+++ b/erpnext/utilities/page/kb_common/kb_common.js
@@ -25,6 +25,7 @@
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();
@@ -43,6 +44,18 @@
}
}
+ 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.line1.innerHTML += ' | '
this.tags_area = $a(this.line1, 'span', 'kb-tags')
diff --git a/erpnext/utilities/page/questions/questions.css b/erpnext/utilities/page/questions/questions.css
index 52e8a38..779da55 100644
--- a/erpnext/utilities/page/questions/questions.css
+++ b/erpnext/utilities/page/questions/questions.css
@@ -14,6 +14,10 @@
.kb-questions {
}
+.un-answered {
+ color: #f33;
+}
+
.kb-question-details {
margin: 11px 0px 11px 29px;
}
diff --git a/erpnext/utilities/page/questions/questions.js b/erpnext/utilities/page/questions/questions.js
index 048ed54..22a70d8 100644
--- a/erpnext/utilities/page/questions/questions.js
+++ b/erpnext/utilities/page/questions/questions.js
@@ -115,24 +115,16 @@
no_results_message: 'No questions found. Ask a new question!',
appframe: wn.pages.questions.appframe,
as_dict: 1,
- get_query: function() {
-
- // filter by search string
- var v = me.search.value==$(me.search).attr('default_text') ? '' : me.search.value;
- cond = v ? (' and t1.question like "%'+v+'%"') : '';
-
- // filter by tags
- if(me.tag_filter_dict) {
- for(f in me.tag_filter_dict) {
- cond += ' and t1.`_user_tags` like "%' + f + '%"'
- }
+ method: 'utilities.page.questions.questions.get_questions',
+ get_args: function() {
+ var args = {};
+ if(me.search.value) {
+ args.search_text = me.search.value;
}
- 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})
+ if(me.tag_filter_dict) {
+ args.tag_filters = keys(me.tag_filter_dict);
+ }
+ return args
},
render_row: function(parent, data, listing) {
new KBQuestion(parent, data, me);
@@ -196,7 +188,11 @@
this.make = function() {
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() {
var q = this;
diff --git a/erpnext/utilities/page/questions/questions.py b/erpnext/utilities/page/questions/questions.py
index 52b80fe..bd9efc7 100644
--- a/erpnext/utilities/page/questions/questions.py
+++ b/erpnext/utilities/page/questions/questions.py
@@ -19,6 +19,29 @@
from webnotes.utils import load_json, cint, cstr
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
@webnotes.whitelist()
def add_question(arg):
@@ -39,20 +62,6 @@
'txt': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
'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()
def delete(arg):