aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/questions_controller.rb3
-rw-r--r--app/models/answer.rb5
-rw-r--r--app/models/question.rb20
-rw-r--r--app/views/questions/doc_feedback_chart.dryml16
-rw-r--r--app/views/questions/show.dryml3
5 files changed, 47 insertions, 0 deletions
diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb
index ae35065..0e1ba3c 100644
--- a/app/controllers/questions_controller.rb
+++ b/app/controllers/questions_controller.rb
@@ -30,4 +30,7 @@ class QuestionsController < ApplicationController
def approve_questions
hobo_index Question.questions_to_approve
end
+
+ show_action :doc_feedback_chart
+
end
diff --git a/app/models/answer.rb b/app/models/answer.rb
index f013547..47544b3 100644
--- a/app/models/answer.rb
+++ b/app/models/answer.rb
@@ -47,6 +47,11 @@ class Answer < ActiveRecord::Base
named_scope :in_category, lambda { |category| {
:joins => :question, :conditions => { 'questions.question_category_id', category} } }
+ named_scope :with_feedback, lambda { |opt| {
+ :conditions => { :feedback => opt } } }
+
+ named_scope :with_some_feedback, :conditions => "answers.feedback IS NOT NULL AND answers.feedback <> ''"
+
validates_uniqueness_of :question_id, :scope => :reference, :if => :reference
validates_uniqueness_of :question_id, :scope => :owner_id, :unless => :reference
diff --git a/app/models/question.rb b/app/models/question.rb
index 084f826..294e03e 100644
--- a/app/models/question.rb
+++ b/app/models/question.rb
@@ -160,6 +160,26 @@ class Question < ActiveRecord::Base
after_create :notify_new_question
after_update :notify_approved_question
+ # Returns hash with:
+ # :values - string with coma-separated values
+ # :labels - string with coma-separated, quoted labels for values
+ def feedback_chart_data
+ classes = Answer.new.feedback.class.values - ['']
+ delta = 0.00001
+ result = {}
+ counts = classes.collect{ |opt| answers.with_feedback(opt).count }
+
+ result[:values] = counts.inject(nil) do |res, cur|
+ res.nil? ? (cur + delta).to_s : "#{res}, #{cur + delta}"
+ end
+
+ result[:labels] = classes.inject(nil) do |res, cur|
+ res.nil? ? "\"%%.%% - #{cur} (##)\"" : "#{res}, \"%%.%% - #{cur} (##)\""
+ end
+
+ result
+ end
+
protected
# Sends notification about new question (TODO: check for group).
def notify_new_question
diff --git a/app/views/questions/doc_feedback_chart.dryml b/app/views/questions/doc_feedback_chart.dryml
new file mode 100644
index 0000000..1a02c45
--- /dev/null
+++ b/app/views/questions/doc_feedback_chart.dryml
@@ -0,0 +1,16 @@
+<page>
+ <head:>
+ <javascript name='raphael'/>
+ <javascript name='g.raphael-min'/>
+ <javascript name='g.pie-min'/>
+ </head:>
+ <body:>
+ <script type="text/javascript" charset="utf-8">
+ var r = Raphael(0, 0, 600, 600);
+ <%=
+ dat = this.feedback_chart_data
+ "r.g.piechart(300, 300, 200, [#{dat[:values]}], {legend: [#{dat[:labels]}], legendpos: \"north\"});"
+ %>
+ </script>
+ </body:>
+</page>
diff --git a/app/views/questions/show.dryml b/app/views/questions/show.dryml
index 2e30578..8cb6629 100644
--- a/app/views/questions/show.dryml
+++ b/app/views/questions/show.dryml
@@ -26,5 +26,8 @@
<br/>
<a href="&answer_path(this.reference_answer)">View reference answer</a>.
</if>
+ <if test="&current_user.try.role.try.is_recruiter? && this.answers.with_some_feedback.count > 0">
+ <iframe src="<%= question_doc_feedback_chart_path(this.id) %>" width="600" height="600"/>
+ </if>
</content-body:>
</show-page>