[ADD] added filter for matrix and choice
bzr revid: pga@tinyerp.com-20140206134053-mjlfe7qdf07bk8me
This commit is contained in:
parent
3015f006fe
commit
34f14e357c
|
@ -294,21 +294,40 @@ class WebsiteSurvey(http.Controller):
|
|||
'prepare_result':self.prepare_result,
|
||||
'get_input_summary':self.get_input_summary,
|
||||
'get_graph_data':self.get_graph_data,
|
||||
'page_range':self.page_range
|
||||
'page_range':self.page_range,
|
||||
'current_filters':post and self.filter_input_ids(post)
|
||||
})
|
||||
def filter_input_ids(self,post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
input_line_obj = request.registry['survey.user_input_line']
|
||||
input_obj = request.registry['survey.user_input_line']
|
||||
domain_filter,choice = [],[]
|
||||
for ids in post:
|
||||
row_id,answer_id = ids.split(',')
|
||||
if row_id == '0':
|
||||
choice.append(int(answer_id))
|
||||
else:
|
||||
domain_filter.extend(['|',('value_suggested_row.id','=',int(row_id)),('value_suggested.id','=',int(answer_id))])
|
||||
if choice:
|
||||
domain_filter.insert(0,('value_suggested.id','in',choice))
|
||||
else:
|
||||
domain_filter = domain_filter[1:]
|
||||
line_ids = input_line_obj.search(cr, uid, domain_filter, context=context)
|
||||
filtered_input_ids = [input.user_input_id.id for input in input_obj.browse(cr, uid, line_ids, context=context)]
|
||||
return filtered_input_ids
|
||||
|
||||
def page_range(self, total_record, limit):
|
||||
'''Returns number of pages required for pagination'''
|
||||
total = math.ceil( total_record/float(limit) )
|
||||
return range(1, int( total+1 ))
|
||||
|
||||
def prepare_result(self, question):
|
||||
def prepare_result(self, question, current_filters=[]):
|
||||
'''Prepare statistical data for questions by counting number of vote per choice'''
|
||||
if question.type in ['simple_choice', 'multiple_choice'] :
|
||||
result_summary = {}
|
||||
[ result_summary.update({ label.id : {'text':label.value, 'count':0} }) for label in question.labels_ids ]
|
||||
[ result_summary.update({ label.id : {'text':label.value, 'count':0, 'answer_id':label.id} }) for label in question.labels_ids ]
|
||||
for input_line in question.user_input_line_ids:
|
||||
if result_summary.get(input_line.value_suggested.id) and not input_line.skipped:
|
||||
if result_summary.get(input_line.value_suggested.id) and (not(current_filters) or input_line.user_input_id.id in current_filters):
|
||||
result_summary[input_line.value_suggested.id]['count'] += 1
|
||||
result_summary = result_summary.values()
|
||||
if question.type == 'matrix':
|
||||
|
@ -318,7 +337,7 @@ class WebsiteSurvey(http.Controller):
|
|||
for cell in itertools.product(rows.keys(), answers.keys()):
|
||||
res[cell] = 0
|
||||
for input_line in question.user_input_line_ids:
|
||||
if not input_line.skipped:
|
||||
if not(current_filters) or input_line.user_input_id.id in current_filters:
|
||||
res[(input_line.value_suggested_row.id,input_line.value_suggested.id)] += 1
|
||||
result_summary= {'answers':answers,'rows':rows,'result':res}
|
||||
if question.type == 'numerical_box':
|
||||
|
@ -336,14 +355,15 @@ class WebsiteSurvey(http.Controller):
|
|||
return result_summary
|
||||
|
||||
@http.route(['/survey/results/graph/<model("survey.question"):question>'],type='http', auth='user', multilang=True, website=True)
|
||||
def get_graph_data(self, question):
|
||||
def get_graph_data(self, question, **post):
|
||||
'''Returns appropriate formated data required by graph library'''
|
||||
current_filters = eval(post.get('current_filters','[]'))
|
||||
result = []
|
||||
if question.type in ['simple_choice', 'multiple_choice']:
|
||||
result.append({'key':str(question.question),
|
||||
'values':self.prepare_result(question)})
|
||||
'values':self.prepare_result(question, current_filters)})
|
||||
if question.type == 'matrix':
|
||||
data = self.prepare_result(question)
|
||||
data = self.prepare_result(question, current_filters)
|
||||
for answer in data['answers']:
|
||||
values = []
|
||||
for res in data['result']:
|
||||
|
|
|
@ -18,3 +18,12 @@
|
|||
-moz-border-radius: 5px 5px 0 0;
|
||||
border-radius: 5px 5px 0 0;
|
||||
}
|
||||
|
||||
|
||||
.survey_answer i{
|
||||
padding:3px;
|
||||
cursor:pointer;
|
||||
}
|
||||
.survey_answer i.invisible{
|
||||
visibility: hidden!important;
|
||||
}
|
|
@ -101,10 +101,12 @@ $(document).ready(function () {
|
|||
$.each(survey_graphs, function(index, graph){
|
||||
var question_id = $(graph).attr("data-question_id");
|
||||
var graph_type = $(graph).attr("data-graph_type");
|
||||
var current_filters = $(graph).attr("data-current_filters");
|
||||
$.ajax({
|
||||
url: '/survey/results/graph/'+question_id,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data:{'current_filters':current_filters},
|
||||
success: function(response, status, xhr, wfe){
|
||||
if(graph_type == 'multi_bar'){
|
||||
nv.addGraph(function(){
|
||||
|
@ -122,5 +124,22 @@ $(document).ready(function () {
|
|||
});
|
||||
});
|
||||
|
||||
// Script for filter
|
||||
$('td.survey_answer').hover(function(){$(this).find('i.fa-filter').removeClass('invisible');},function(){$(this).find('i.fa-filter').addClass('invisible');});
|
||||
$('td.survey_answer i.fa-filter').click(function(){
|
||||
var cell=$(this);
|
||||
var question_id = cell.attr('data-question_id');
|
||||
var row_id = cell.attr('data-row_id') | 0;
|
||||
var answer_id = cell.attr('data-answer_id');
|
||||
if(document.URL.indexOf("?") == -1)
|
||||
{
|
||||
window.location.href = document.URL+'?' + encodeURI(row_id + ','+answer_id + '=' + question_id);
|
||||
}
|
||||
else{
|
||||
window.location.href = document.URL+'&' + encodeURI(row_id + ','+answer_id + '=' + question_id);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
console.debug("[survey] Survey Result JS loaded!");
|
||||
});
|
|
@ -116,7 +116,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active survey_graph" t-att-id="'graph_question_'+str(question.id)" t-att-data-question_id="question.id" data-graph_type= "bar">
|
||||
<div class="tab-pane active survey_graph" t-att-id="'graph_question_'+str(question.id)" t-att-data-question_id="question.id" data-graph_type= "bar" t-att-data-current_filters="current_filters">
|
||||
<!-- svg element for drawing bar chart -->
|
||||
<svg style="height:20em"></svg>
|
||||
</div>
|
||||
|
@ -129,13 +129,14 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="prepare_result(question)" t-as="user_input">
|
||||
<tr t-foreach="prepare_result(question, current_filters)" t-as="user_input">
|
||||
<td>
|
||||
<p t-esc="user_input['text']"></p>
|
||||
</td>
|
||||
<td>
|
||||
<td class="survey_answer">
|
||||
<span t-esc="round(user_input['count']*100.0/(input_summary['answered'] or 1),2)"></span> %
|
||||
<span t-esc="user_input['count']" class="label label-primary">Vote</span>
|
||||
<i class="fa fa-filter text-primary invisible survey_filter" t-att-data-question_id="question.id" t-att-data-answer_id="user_input['answer_id']"></i>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -147,7 +148,7 @@
|
|||
|
||||
<!-- Result for matrix -->
|
||||
<template id="result_matrix" name="Matrix Result">
|
||||
<t t-set="matrix_result" t-value="prepare_result(question)" />
|
||||
<t t-set="matrix_result" t-value="prepare_result(question, current_filters)" />
|
||||
<!-- Tabs -->
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active">
|
||||
|
@ -164,7 +165,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active with-3d-shadow with-transitions survey_graph" t-att-id="'graph_question_'+str(question.id)" t-att-data-question_id= "question.id" data-graph_type= "multi_bar">
|
||||
<div class="tab-pane active with-3d-shadow with-transitions survey_graph" t-att-id="'graph_question_'+str(question.id)" t-att-data-question_id= "question.id" data-graph_type= "multi_bar" t-att-data-current_filters="current_filters">
|
||||
<!-- svg element for drawing Multibar chart -->
|
||||
<svg style="height:20em"></svg>
|
||||
</div>
|
||||
|
@ -183,9 +184,9 @@
|
|||
<td>
|
||||
<span t-esc="matrix_result['rows'][row_id]"></span>
|
||||
</td>
|
||||
<td t-foreach="matrix_result['answers']" t-as="answer_id">
|
||||
<td class="survey_answer" t-foreach="matrix_result['answers']" t-as="answer_id">
|
||||
<span t-esc="round(matrix_result['result'][(row_id,answer_id)]*100.0/(input_summary['answered'] or 1),2)"></span> %
|
||||
<span class="label label-primary" t-esc="matrix_result['result'][(row_id,answer_id)]"></span>
|
||||
<span class="label label-primary" t-esc="matrix_result['result'][(row_id,answer_id)]"></span><i class="fa fa-filter text-primary invisible survey_filter" t-att-data-question_id="question.id" t-att-data-row_id="row_id" t-att-data-answer_id="answer_id"></i>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -196,7 +197,7 @@
|
|||
|
||||
<!-- Result for Numeric Data -->
|
||||
<template id="result_number" name="Number Result">
|
||||
<t t-set="number_result" t-value="prepare_result(question)" />
|
||||
<t t-set="number_result" t-value="prepare_result(question, current_filters)" />
|
||||
<span class="pull-right mt8">
|
||||
<span class="label label-default only_right_radius">Maximum </span> <span class="label label-success only_left_radius" t-esc="number_result['max']"></span>
|
||||
<span class="label label-default only_right_radius">Minimum </span> <span class="label label-danger only_left_radius" t-esc="number_result['min']"></span>
|
||||
|
|
Loading…
Reference in New Issue