Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Three bug fixes #1

Open
wants to merge 66 commits into
base: rails3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
edcdaf6
Adding formtastic dependency to gemspec and edited README
ignu Mar 26, 2011
6b37e32
making the formtastic dependency permanent via rakefile
Apr 20, 2011
888b294
Added a conditional question group to the kitchen sink survey.
jdzak Mar 24, 2011
31c0a44
Updated method to get unanswered dependencies within ResultSet to al…
jdzak Mar 24, 2011
bac06e0
Saving response set completion time when a survey is finished.
jdzak Apr 7, 2011
2164bc1
merging jdzak: Fixed pick one and pick any not saving when an answer …
Apr 20, 2011
6dc21b3
Merged jdzak: Fixed problem with dropdowns inside of repeaters appear…
Apr 20, 2011
2a4fd7a
make tiny codes sane
May 4, 2011
5d992ae
bug fix from keviniano
May 4, 2011
420acc6
do not duplicate answers in the database when redoing parts of a survey
May 6, 2011
1f0c476
add api ids
May 9, 2011
d360cc4
rg is not an object, it's a fixnum
May 10, 2011
47cd0f4
need formtastic to create surveys
May 10, 2011
32989ed
Merge remote branch 'nubic/rails3' into rails3
May 10, 2011
fb292cc
Merge commit '420acc6342b3596b3927' into rails3
May 10, 2011
689703a
removed duplicate formtastic dependency
May 10, 2011
d2a72ef
Version bump to 0.16.2
May 10, 2011
36efee1
Check if there is an answer id
Apr 28, 2011
589da04
Include the methods every time so they don't have to be reloaded afte…
Apr 22, 2011
05c1e77
Changed to return the survey when parsed
Apr 22, 2011
f16a1d3
Version bump to 0.16.3
May 10, 2011
05f0282
added require for uuid -- was causing a 'uninitialized constant Surve…
May 10, 2011
6deed2b
Version bump to 0.16.4
May 10, 2011
56087c9
removed deprecation warning
May 10, 2011
25d5f64
replaced erb with haml templates
May 10, 2011
4f0e285
don't escape results
May 10, 2011
7ce9e49
display result only if it's an answer to the current question
May 10, 2011
1ccd1ef
Version bump to 0.16.5
May 10, 2011
e91b875
removed the last erb templates
May 10, 2011
76b76c8
show the results using a datatable from http://www.datatables.net/
May 10, 2011
b04b5ad
Version bump to 0.16.6
May 10, 2011
35ac033
made the results a little more pretty
May 11, 2011
c3fbc6e
Version bump to 0.16.7
May 11, 2011
25038af
handle saving string values correctly. Check for array first and then…
May 11, 2011
09b5593
show just one result, not a whole change history
May 11, 2011
941e840
whitespace changes
May 11, 2011
d7956b1
fixed a bug which meant that grid layout responses weren't being stor…
May 11, 2011
71525f9
Version bump to 0.16.8
May 11, 2011
1aef092
refactored code a little
May 12, 2011
02e985e
fixed an issue where the last date was sent instead of the currently …
May 12, 2011
fb8c12f
Version bump to 0.16.9
May 12, 2011
9dad351
replaced erb template with haml template for the extending surveyor g…
May 17, 2011
1b849fb
Version bump to 0.16.10
May 17, 2011
c890e24
removed a 's' from a regexp -- assume UTF-8 encoding and not Windows-31J
May 17, 2011
a24d83b
Merge branches 'rails3' and 'rails3' of git://github.com/gorenje/surv…
May 25, 2011
f1a6cc1
help text should not get its own number
May 25, 2011
b65e9b6
* remove previous answers if new answer is stored
Jun 3, 2011
027bac9
* remove previous answers if new answer is stored
Jun 3, 2011
8a46e5b
Version bump to 0.16.11
Jun 3, 2011
f62199f
Merge remote-tracking branch 'upstream/rails3' into rails3
Jun 7, 2011
f5de8fc
* activate and fix caching of sections
Jun 7, 2011
ab0370c
Version bump to 0.16.12
Jun 7, 2011
375f467
* enable an app that uses the surveyor to change the parse_and_build…
Jun 7, 2011
b6d1e9a
Merge pull request #2 from ewto/rails3
Jun 8, 2011
0244408
Version bump to 0.16.13
Jun 8, 2011
1acfd75
* bugfix for :pick => :any questions
Jun 10, 2011
935ae6f
Merge pull request #3 from ewto/rails3
Jun 10, 2011
a7a7ba2
Version bump to 0.16.14
Jun 10, 2011
1947036
* fix for issue described here https://github.com/gorenje/surveyor/c…
Jun 14, 2011
f4649ab
Merge pull request #4 from ewto/rails3
Jun 14, 2011
7bc4e30
Version bump to 0.16.15
Jun 14, 2011
d60ad8d
* ensure no_responses_for_section? used for the caching is working p…
Jun 14, 2011
c529676
Merge pull request #5 from ewto/rails3
Jun 14, 2011
b4b606b
Version bump to 0.16.16
Jun 14, 2011
6f4c83c
Merge branch 'rails3' of github.com:openplans/surveyor into rails3
Jun 15, 2011
de61510
fix check for answer exists? (patch from keviniano)
Jun 15, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -24,3 +24,5 @@ testbed/db/*
testbed/.bundle
testbed/*
surveys/fixtures/*.yml
.rvmrc
Gemfile.lock
5 changes: 5 additions & 0 deletions Gemfile
@@ -0,0 +1,5 @@
# -*- mode: ruby -*-
source "http://rubygems.org"

# Specify your gem's dependencies in newever.gemspec
gemspec
34 changes: 22 additions & 12 deletions README.md
Expand Up @@ -13,19 +13,19 @@ The Surveyor DSL defines questions, answers, question groups, survey sections, d
The Surveyor DSL supports a wide range of question types (too many to list here) and complex dependency logic. Here are the first few questions of the "kitchen sink" survey which should give you and idea of how it works. The full example with all the types of questions available if you follow the installation instructions below.

survey "Kitchen Sink survey" do

section "Basic questions" do
# A label is a question that accepts no answers
label "These questions are examples of the basic supported input types"

# A basic question with radio buttons
question_1 "What is your favorite color?", :pick => :one
answer "red"
answer "blue"
answer "green"
answer "yellow"
answer :other

# A basic question with checkboxes
# "question" and "answer" may be abbreviated as "q" and "a"
q_2 "Choose the colors you don't like", :pick => :any
Expand All @@ -34,8 +34,8 @@ The Surveyor DSL supports a wide range of question types (too many to list here)
a_3 "green"
a_4 "yellow"
a :omit
# A dependent question, with conditions and rule to logically join them

# A dependent question, with conditions and rule to logically join them
# the question's reference identifier is "2a", and the answer's reference_identifier is "1"
# question reference identifiers used in conditions need to be unique on a survey for the lookups to work
q_2a "Please explain why you don't like this color?"
Expand All @@ -45,24 +45,27 @@ The Surveyor DSL supports a wide range of question types (too many to list here)
condition_B :q_2, "==", :a_2
condition_C :q_2, "==", :a_3
condition_D :q_2, "==", :a_4

# ... other question, sections and such. See surveys/kitchen_sink_survey.rb for more.
end
end

end

The first question is "pick one" (radio buttons) with "other". The second question is "pick any" (checkboxes) with the option to "omit". It also features a dependency with a follow up question. Notice the dependency rule is defined as a string. We support complex dependency such as "A and (B or C) and D" or "A or ((B and C) or D)". The conditions are evaluated separately using the operators "==","!=","<>", ">=","<" the substituted by letter into to the dependency rule and evaluated.

# Installation

1. Add it to your bundler Gemfile:
1. Add surveyor to your Gemfile (add add haml too if you haven't already):

gem "surveyor"
gem "haml"

Then run:

`bundle install`

2. Generate assets, run migrations:

`script/rails generate surveyor:install`
`rake db:migrate`

Expand Down Expand Up @@ -91,7 +94,14 @@ and read surveys/EXTENDING\_SURVEYOR

# Requirements

Surveyor depends on Ruby (1.8.7 - 1.9.1), Rails 3 and HAML/SASS http://haml.hamptoncatlin.com/. It also depends on fastercsv for csv exports.
Surveyor depends on:

* Ruby (1.8.7 - 1.9.1)
* Rails 2.3
* HAML/SASS
* formtastic
* fastercsv for csv exports
* UUID

# Contributing, testing

Expand Down
7 changes: 6 additions & 1 deletion Rakefile
Expand Up @@ -11,7 +11,12 @@ begin
gem.authors = ["Brian Chamberlain", "Mark Yoon"]
gem.add_dependency 'haml'
gem.add_dependency 'fastercsv'
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
gem.add_dependency 'formtastic'
gem.add_dependency 'uuid'
gem.add_development_dependency "yard", ">= 0"
gem.add_development_dependency "rake"
gem.add_development_dependency "rspec"
gem.add_development_dependency "jeweler"
end
Jeweler::GemcutterTasks.new

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.16.1
0.16.16
4 changes: 2 additions & 2 deletions app/controllers/results_controller.rb
@@ -1,6 +1,6 @@
class ResultsController < ApplicationController
helper 'surveyor'
layout 'results'
layout 'results'
def index
@surveys = Survey.all
end
Expand All @@ -10,4 +10,4 @@ def show
@response_sets = @survey.response_sets
@questions = @survey.sections_with_questions.map(&:questions).flatten
end
end
end
31 changes: 15 additions & 16 deletions app/helpers/results_helper.rb
@@ -1,20 +1,19 @@
module ResultsHelper
def display_response(r_set,question)
sets = r_set.responses.select{|r| r.question.display_order == question.display_order}
if sets.size == 0
return "-"
elsif sets.size == 1
return (sets.first.string_value || sets.first.text_value || show_answer(sets.first))
else
txt = ""
sets.each do |set|
txt << show_answer(set) + "<br/>"
end
return txt
end
def display_response(r_set, question)
sets = r_set.responses.select do |r|
r.question == question && r.question.display_order == question.display_order
end

if sets.size == 0
"-"
elsif sets.size == 1
(sets.first.string_value || sets.first.text_value || show_answer(sets.first))
else
sets.map{|s| show_answer(s) }.join(", ")
end
end

def show_answer(set)
set.answer.text
set.answer.text
end
end
end
14 changes: 7 additions & 7 deletions app/helpers/surveyor_helper.rb
@@ -1,13 +1,13 @@
module SurveyorHelper
# Layout: stylsheets and javascripts
def surveyor_includes
surveyor_stylsheets + surveyor_javascripts
surveyor_stylsheets + surveyor_javascripts
end
def surveyor_stylsheets
stylesheet_link_tag 'surveyor/reset', 'surveyor/dateinput', 'surveyor'
stylesheet_link_tag 'surveyor/reset', 'surveyor/dateinput', 'surveyor/demo_table', 'surveyor'
end
def surveyor_javascripts
javascript_include_tag 'surveyor/jquery.tools.min', 'surveyor/jquery.surveyor'
javascript_include_tag 'surveyor/jquery.tools.min', 'surveyor/jquery.surveyor', 'surveyor/jquery.dataTables.min'
end
# Helper for displaying warning/notice/error flash messages
def flash_messages(types)
Expand All @@ -34,7 +34,7 @@ def next_section
# use copy in memory instead of making extra db calls
@sections.last == @section ? submit_tag(t('surveyor.click_here_to_finish').html_safe, :name => "finish") : submit_tag(t('surveyor.next_section').html_safe, :name => "section[#{@sections[@sections.index(@section)+1].id}]")
end

# Questions
def q_text(obj)
@n ||= 0
Expand All @@ -48,7 +48,7 @@ def q_text(obj)
# def question_help_helper(question)
# question.help_text.blank? ? "" : %Q(<span class="question-help">#{question.help_text}</span>)
# end

# Answers
def rc_to_attr(type_sym)
case type_sym.to_s
Expand All @@ -69,7 +69,7 @@ def generate_pick_none_input_html(response_class, default_value, css_class)
html[:value] = default_value if response_class.blank?
html
end

# Responses
def response_for(response_set, question, answer = nil, response_group = nil)
return nil unless response_set && question && question.id
Expand All @@ -79,5 +79,5 @@ def response_for(response_set, question, answer = nil, response_group = nil)
def response_idx(increment = true)
@rc ||= 0
(increment ? @rc += 1 : @rc).to_s
end
end
end
13 changes: 0 additions & 13 deletions app/views/layouts/results.html.erb

This file was deleted.

9 changes: 9 additions & 0 deletions app/views/layouts/results.html.haml
@@ -0,0 +1,9 @@
!!!
%html{:lang => "en", "xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
%head
%meta{:content => "text/html;charset=UTF-8", "http-equiv" => "content-type"}/
%title Survey: Result Sets
= surveyor_includes
%body
#flash= flash[:notice]
= yield
12 changes: 0 additions & 12 deletions app/views/layouts/surveyor_default.html.erb

This file was deleted.

9 changes: 9 additions & 0 deletions app/views/layouts/surveyor_default.html.haml
@@ -0,0 +1,9 @@
!!!
%html{:lang => "en", "xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
%head
%meta{:content => "text/html;charset=UTF-8", "http-equiv" => "content-type"}/
%title
Survey: #{controller.action_name}
= surveyor_includes
%body
= yield
4 changes: 3 additions & 1 deletion app/views/partials/_answer.html.haml
@@ -1,13 +1,15 @@
-# TODO: disabled
- rg ||= nil
- part_of_grid ||= false
- r = response_for(@response_set, q, a, rg)
- i = response_idx(q.pick != "one") # argument will be false (don't increment i) if we're on radio buttons
= f.semantic_fields_for i, r do |ff|
= ff.quiet_input :question_id unless q.pick == "one" # don't repeat question_id if we're on radio buttons
= ff.quiet_input :question_id unless q.pick == "one" && !part_of_grid # don't repeat question_id if we're on radio buttons
= ff.quiet_input :id unless q.pick == "one" or r.new_record?
= ff.quiet_input :response_group, :value => rg if q.pick != "one" && g && g.display_type == "repeater"
- case q.pick
- when "one"
= ff.quiet_input :id if r.id
= ff.input :answer_id, :as => :surveyor_radio, :collection => [[a.text, a.id]], :label => false, :input_html => {:class => a.css_class}, :response_class => a.response_class
- when "any"
= ff.input :answer_id, :as => :surveyor_check_boxes, :collection => [[a.text, a.id]], :label => false, :input_html => {:class => a.css_class}, :response_class => a.response_class
Expand Down
5 changes: 3 additions & 2 deletions app/views/partials/_question.html.haml
@@ -1,14 +1,15 @@
-# TODO: js for slider
- rg ||= nil
- renderer = q.renderer(g ||= nil)
= f.inputs q_text(q), :id => rg ? "q_#{q.id}_#{rg.id}" : "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}" do
= f.inputs q_text(q), :id => rg ? "q_#{q.id}_#{rg}" : "q_#{q.id}", :class => "q_#{renderer} #{q.css_class(@response_set)}" do
%span.help= q.help_text
- case renderer
- when :image, :label
- when :dropdown, :inline_dropdown, :slider
- when :dropdown, :inline_dropdown, :slider, :repeater_dropdown
- r = response_for(@response_set, q, nil, rg)
- i = response_idx
= f.semantic_fields_for i, r do |ff|
= ff.quiet_input :id if r.id
= ff.quiet_input :question_id
= ff.quiet_input :response_group, :value => rg if g && g.display_type == "repeater"
= ff.input :answer_id, :as => :select, :collection => q.answers.map{|a| [a.text, a.id]}, :label => false
Expand Down
8 changes: 4 additions & 4 deletions app/views/partials/_question_group.html.haml
@@ -1,12 +1,12 @@
- renderer = g.renderer
%span.help= g.help_text
= f.inputs q_text(g), :id => "g_#{g.id}", :class => "g_#{renderer} #{g.css_class(@response_set)}" do
%li.help= g.help_text
- case renderer
- when :grid
%li
%table
%col.pre
- qs.first.answers.each do |a|
- qs.first.answers.each do |a|
%col{:class => cycle("odd", "even")}
%col.post
%tbody
Expand All @@ -21,7 +21,7 @@
%th= q.split_text(:pre)
- response_idx if q.pick == "one" # increment the response index since the answer partial skips for q.pick == one
- q.answers.each do |a|
%td= render a.custom_renderer || '/partials/answer', :g => g, :q => q, :a => a, :f => f
%td= render a.custom_renderer || '/partials/answer', :g => g, :q => q, :a => a, :f => f, :part_of_grid => true
%th= q.split_text(:post)
- when :repeater
- (@response_set.count_group_responses(qs) + 1).times do |rg|
Expand All @@ -31,4 +31,4 @@
= submit_tag("+ add row", :name => "section[#{@section.id}][g_#{g.id}]", :class => "add_row")
- else # :inline
- qs.each do |q|
= render q.custom_renderer || "/partials/question", :g => g, :q => q, :f => f
= render q.custom_renderer || "/partials/question", :g => g, :q => q, :f => f
17 changes: 0 additions & 17 deletions app/views/results/index.html.erb

This file was deleted.

11 changes: 11 additions & 0 deletions app/views/results/index.html.haml
@@ -0,0 +1,11 @@
%h1 Listing Surveys
%table.list_table
%tr
%th ID
%th Name
%th Operation
- @surveys.each do |survey|
%tr
%td= h survey.id
%td= h survey.title
%td= link_to "show results list (#{survey.response_sets.count})", result_path(survey.access_code)
25 changes: 0 additions & 25 deletions app/views/results/show.html.erb

This file was deleted.