[knowledge base] removed and added patch to move to notes

This commit is contained in:
Rushabh Mehta
2013-05-24 16:33:10 +05:30
parent 7e118cd875
commit 9c5f4fe165
48 changed files with 15 additions and 1289 deletions

View File

@@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@@ -1,44 +0,0 @@
.qv-body {
padding: 13px;
}
.qv-input {
font-size: 14px;
height: 2.5em;
width: 100%;
}
.qv-text {
font-size: 20px;
font-weight: bold;
}
.qv-ans-input {
height: 5em;
}
.qv-ans-text {
color: #444;
line-height: 1.7em;
}
.qv-question-wrapper {
}
.qv-add-answer {
width: 50%;
margin: 7px 0px;
padding: 7px;
background-color: #E2E2EE;
display: none;
}
.qv-add-answer textarea {
height: 17em;
font-size: 12px;
}
.qv-answer {
}

View File

@@ -1,11 +0,0 @@
<div class="appframe col col-lg-12">
<div class="layout-appframe"></div>
<div class="layout-main" style="min-height: 400px">
<div class="qv-question-wrapper">
</div>
<hr>
<div class="qv-answer-wrapper">
</div>
<div class="add-answer-area"></div>
</div>
</div>

View File

@@ -1,193 +0,0 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pscript['onload_question-view'] = function(wrapper) {
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.layout-appframe'));
wrapper.appframe.title('Question');
wrapper.appframe.add_home_breadcrumb();
wrapper.appframe.add_module_icon("Knowledge Base");
wrapper.appframe.add_breadcrumb("icon-file");
wrapper.add_answer_area = $('.add-answer-area').get(0);
}
pscript['refresh_question-view'] = function(wrapper) {
// href
var qid = window.location.hash.split('/')[1];
if(qid) {
pscript.question_view(qid);
}
}
pscript.question_view = function(qid, qtext) {
var w = wn.pages['question-view'];
new KBQuestionView(w, qid, qtext);
}
KBQuestionView = function(w, qid, qtext) {
var me = this;
this.make_question = function() {
$(w).find('.qv-question-wrapper').empty();
$(w.add_answer_area).empty();
new EditableText({
parent: $(w).find('.qv-question-wrapper').get(0),
dt: 'Question',
dn: qid,
fieldname: 'question',
text: qtext,
inp_class: 'qv-input',
disp_class: 'qv-text'
});
// show tags
}
// answer list
this.make_answer_list = function() {
$(w).find('.qv-answer-wrapper').empty();
this.ans_list = new KBAnswerList({
parent: $(w).find('.qv-answer-wrapper').get(0),
qid: qid
})
}
// check if users has answered
// (if no) then add a box to add a new answer
this.make_add_answer = function() {
$c_page('utilities', 'question_view', 'has_answered', qid, function(r, rt) {
if(r.message=='No') {
me.make_answer_box_link();
}
});
}
// add a link to open add answer
this.make_answer_box_link = function() {
wn.pages['question-view'].appframe.add_button('Add your answer', function() {
$(this).toggle(false);
me.make_answer_box();
}, 'icon-plus');
}
// answer box
// text area + add button
this.make_answer_box = function() {
$ds(w.add_answer_area);
$(w.add_answer_area, '<h3>Add your Answer</h3>\
<div class="help">In markdown format</div>');
this.input = $a(w.add_answer_area, 'textarea');
$(this.input).css({width: "90%", height: "200px"});
//wn.tinymce.add_simple(this.input);
this.btn = $btn($a(w.add_answer_area, 'div'), 'Post', function() {
var v = $(me.input).val();
if(!v) { msgprint('Write something!'); return; }
me.btn.set_working();
$c_page('utilities', 'question_view', 'add_answer',
JSON.stringify({qid: qid, "answer":v}),
function(r, rt) {
me.btn.done_working();
me.ans_list.list.run();
$dh(w.add_answer_area);
}
);
});
}
this.setup = function() {
if(qtext) {
this.make();
}
else {
$c_page('utilities', 'question_view', 'get_question', qid, function(r, rt) {
qtext = r.message;
me.make();
});
}
}
this.make = function() {
set_title(qtext);
this.make_question();
this.make_answer_list();
this.make_add_answer();
}
this.setup();
}
// kb answer list
KBAnswerList = function(args) {
var me = this;
$.extend(this, args);
this.make_list = function() {
wn.pages['question-view'].appframe.clear_buttons();
this.list = new wn.ui.Listing({
parent: me.parent,
appframe: wn.pages['question-view'].appframe,
as_dict: 1,
no_result_message: 'No answers yet, be the first one to answer!',
render_row: function(body, data) {
new KBAnswer(body, data, me)
},
get_query: function() {
return repl("SELECT t1.name, t1.owner, t1.answer, t1._users_voted, t2.first_name, "
+"t2.last_name, t1.modified from tabAnswer t1, tabProfile t2 "
+"where question='%(qid)s' and t1.owner = t2.name "
+"order by t1.modified desc", {qid: me.qid})
}
});
this.list.run();
}
this.make_list();
}
// kb answer
// answer
// by xxx | on xxx
KBAnswer = function(body, data, ans_list) {
body.className = 'qv-answer';
var edtxt = new EditableText({
parent: body,
dt: 'Answer',
dn: data.name,
fieldname: 'answer',
text: data.answer,
inp_class: 'qv-ans-input',
disp_class: 'qv-ans-text',
height: '300px',
width: '90%'
});
$(edtxt.wrapper).addClass('well');
var div = $a(body, 'div', '', {})
new KBItemToolbar({
parent: div,
det: data,
with_tags: 0,
doctype: 'Answer'
}, ans_list)
}
wn.require('app/js/kb_common.js');

View File

@@ -1,47 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.utils import load_json, cstr, now
@webnotes.whitelist()
def update_item(arg):
args = load_json(arg)
webnotes.conn.sql("update `tab%s` set `%s`=%s, modified=%s where name=%s" \
% (args['dt'], args['fn'], '%s', '%s', '%s'), (args['text'], now(), args['dn']))
@webnotes.whitelist()
def has_answered(arg):
return webnotes.conn.sql("select name from tabAnswer where owner=%s and question=%s", (webnotes.user.name, arg)) and 'Yes' or 'No'
@webnotes.whitelist()
def get_question(arg):
return cstr(webnotes.conn.sql("select question from tabQuestion where name=%s", arg)[0][0])
@webnotes.whitelist()
def add_answer(arg):
arg = load_json(arg)
from webnotes.model.doc import Document
a = Document('Answer')
a.answer = arg['answer']
a.question = arg['qid']
a.points = 1
a.save(1)
webnotes.conn.set_value('Question', arg['qid'], 'modified', now())

View File

@@ -1,31 +0,0 @@
[
{
"creation": "2013-04-09 11:45:31",
"docstatus": 0,
"modified": "2013-04-09 11:47:24",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Page",
"module": "Utilities",
"name": "__common__",
"page_name": "Question View",
"standard": "Yes"
},
{
"doctype": "Page Role",
"name": "__common__",
"parent": "question-view",
"parentfield": "roles",
"parenttype": "Page",
"role": "All"
},
{
"doctype": "Page",
"name": "question-view"
},
{
"doctype": "Page Role"
}
]

View File

@@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@@ -1,31 +0,0 @@
div.kb-search-wrapper textarea {
height: 2.2em;
width: 80%;
font-size: 14px;
padding: 3px;
margin-bottom: 7px;
}
.kb-question-wrapper {
padding-bottom: 3px;
margin-bottom: 3px;
}
.kb-questions {
}
.un-answered {
color: #f33;
}
.kb-question-details {
margin: 11px 0px 11px 29px;
}
.kb-tag-filter-area {
padding: 7px;
background-color: #F2F2E8;
color: #222;
margin: 7px 0px;
display: none;
}

View File

@@ -1,19 +0,0 @@
<div class="appframe col col-lg-12">
<div class="layout-appframe"></div>
<div class="layout-main-section">
<div class="kb-search-wrapper">
<textarea></textarea>
<div>
<button class="btn btn-small search" onclick="">
<i class="icon-search"></i> Search</button>
<button class="btn btn-small ask">
<i class="icon-question-sign"></i> Ask</button>
</div>
</div>
</div>
<div class="layout-side-section">
<div class="questions-tags"></div>
<p class="help">A wiki or Q&A for your organization</p>
</div>
<div style="clear: both;"></div>
</div>

View File

@@ -1,221 +0,0 @@
// ERPNext - web based ERP (http://erpnext.com)
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pscript.onload_questions = function(wrapper) {
body = $(wrapper).find('.layout-main-section').get(0);
wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.layout-appframe'));
wrapper.appframe.add_home_breadcrumb();
wrapper.appframe.add_breadcrumb(wn.modules["Knowledge Base"].icon);
wrapper.appframe.title('Knowledge Base');
// kb
var kb = new KnowledgeBase(body);
wn.model.with_doctype("Question", function() {
this.sidebar_stats = new wn.views.SidebarStats({
doctype: "Question",
stats: ["_user_tags"],
parent: $(wrapper).find('.questions-tags'),
set_filter: function(fieldname, label) {
kb.set_filter(fieldname, label);
//me.set_filter(fieldname, label);
}
});
})
}
// knowledge base object
// has a box for search or ask a question
// and list of top rated search results
//
function KnowledgeBase(w) {
var me = this;
this.sort_by = 'modified';
this.tag_filter_dict = {};
this.make_search_bar = function() {
this.search = $(w).find('.kb-search-wrapper textarea').get(0);
$(w).find('.btn.search').click(function() {
me.run();
})
$(w).find('.btn.ask').click(function() {
me.ask();
})
}
// ask a new question
this.ask = function() {
if(this.search.value==$(this.search).attr('default_text')) {
msgprint('Please enter some text'); return;
}
this.add_question([]);
}
// suggest a few users who can answer
this.suggest = function() {
this.dialog = new wn.ui.Dialog({
title: 'Suggest a users',
width: 400,
fields: [
{fieldtype:'HTML', options:'Optional: Suggest a few users who can help you answer this question<br>'},
{fieldtype:'Link', fieldname:'profile1', label:'1st User',options:'Profile'},
{fieldtype:'Link', fieldname:'profile2', label:'2nd User',options:'Profile'},
{fieldtype:'Link', fieldname:'profile3', label:'3rd User',options:'Profile'},
{fieldtype:'Button', fieldname:'ask', label:'Add the Question'}
]
});
this.dialog.fields_dict.ask.input.onclick = function() {
me.dialog.hide();
me.add_question(values(me.dialog.get_values()));
}
this.dialog.show();
}
// add a new question to the database
this.add_question = function(suggest_list) {
$c_page('utilities', 'questions', 'add_question', {
question: this.search.value,
suggest: suggest_list
}, function(r,rt) {
$(me.search).val('').blur();
me.run();
})
}
// where tags that filter will be displayed
this.make_tag_filter_area = function() {
this.tag_filters = $a(w, 'div', 'kb-tag-filter-area');
$a(this.tag_filters,'span','',{marginRight:'4px',color:'#442'}, '<i>Showing for:</i>');
this.tag_area = $a(this.tag_filters, 'span');
}
// make a list of questions
this.make_list = function() {
this.make_tag_filter_area();
this.list_area = $a(w, 'div', '', {marginRight:'13px'})
this.no_result = $a(w, 'div','help_box',{display:'none'},'No questions asked yet! Be the first one to ask')
this.list = new wn.ui.Listing({
parent: this.list_area,
no_results_message: 'No questions found. Ask a new question!',
appframe: wn.pages.questions.appframe,
as_dict: 1,
method: 'utilities.page.questions.questions.get_questions',
get_args: function() {
var args = {};
if(me.search.value) {
args.search_text = me.search.value;
}
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);
}
});
this.list.run();
}
this.set_filter = function(fieldname, label) {
this.set_tag_filter({label:label});
}
// add a tag filter to the search in the
// main page
this.set_tag_filter = function(tag) {
// check if exists
if(in_list(keys(me.tag_filter_dict), tag.label)) return;
// create a tag in filters
var filter_tag = new SingleTag({
parent: me.tag_area,
label: tag.label,
dt: 'Question',
color: tag.color
});
// remove tag from filters
filter_tag.remove = function(tag_remove) {
$(tag_remove.body).fadeOut();
delete me.tag_filter_dict[tag_remove.label];
// hide everything?
if(!keys(me.tag_filter_dict).length) {
$(me.tag_filters).slideUp(); // hide
}
// run
me.run();
}
// add to dict
me.tag_filter_dict[tag.label] = filter_tag;
$ds(me.tag_filters);
// run
me.run();
}
this.run = function() {
this.list.run();
}
this.make_search_bar();
this.make_list();
}
// single kb question
// "question
// points | tag list"
KBQuestion = function(parent, det, kb) {
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);
if(det.answers==0) {
$(this.q_area).addClass('un-answered')
}
this.q_area.onclick = function() {
var q = this;
window.location.href = '#!question-view/' + q.id;
//loadpage('question-view', function() { pscript.question_view(q.id, q.txt) })
}
this.q_area.id = det.name; this.q_area.txt = det.question;
new KBItemToolbar({
parent: this.wrapper,
det: det,
with_tags: 1,
doctype: 'Question'
}, kb)
}
this.make()
}
wn.require('app/js/kb_common.js');

View File

@@ -1,74 +0,0 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.utils import load_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,
(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):
args = load_json(arg)
from webnotes.model.doc import Document
d = Document('Question')
d.question = args['question']
d.points = 1
d.save(1)
if args['suggest']:
from core.page.messages import messages
for s in args['suggest']:
if s:
messages.post(json.dumps({
'contact': s,
'txt': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
'notify': 1
}))
@webnotes.whitelist()
def delete(arg):
"""
delete a question or answer (called from kb toolbar)
"""
args = load_json(arg)
from webnotes.model import delete_doc
delete_doc(args['dt'], args['dn'])

View File

@@ -1,31 +0,0 @@
[
{
"creation": "2013-04-09 11:50:08",
"docstatus": 0,
"modified": "2013-04-09 11:52:08",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Page",
"module": "Utilities",
"name": "__common__",
"page_name": "Questions",
"standard": "Yes"
},
{
"doctype": "Page Role",
"name": "__common__",
"parent": "questions",
"parentfield": "roles",
"parenttype": "Page",
"role": "All"
},
{
"doctype": "Page",
"name": "questions"
},
{
"doctype": "Page Role"
}
]