qwester 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -34
- data/app/models/qwester/presentation.rb +33 -2
- data/app/models/qwester/presentation_questionnaire.rb +2 -0
- data/app/models/qwester/questionnaire.rb +8 -22
- data/db/migrate/20130502082540_add_position_to_qwester_presentation_questionnaires.rb +5 -0
- data/lib/active_admin/admin/presentations.rb +23 -0
- data/lib/qwester/version.rb +3 -1
- data/lib/tasks/qwester_tasks.rake +12 -2
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130502082731_add_position_to_qwester_presentation_questionnaires.qwester.rb +6 -0
- data/test/dummy/db/schema.rb +2 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +1748 -0
- data/test/dummy/log/test.log +45696 -0
- data/test/dummy/test/fixtures/qwester/presentation_questionnaires.yml +2 -0
- data/test/dummy/test/test_helper.rb +4 -0
- data/test/unit/qwester/presentation_questionnaire_test.rb +35 -0
- data/test/unit/qwester/presentation_test.rb +8 -0
- metadata +9 -2
data/README.rdoc
CHANGED
@@ -255,37 +255,4 @@ initializer:
|
|
255
255
|
|
256
256
|
Qwester.active_admin_menu = 'none'
|
257
257
|
|
258
|
-
See test/dummy/config/initializers/qwester.rb for an example
|
259
|
-
|
260
|
-
You will also need to add the following to your config/routes so that you can
|
261
|
-
reorder items:
|
262
|
-
|
263
|
-
namespace :admin do
|
264
|
-
resources :questionnaires do
|
265
|
-
resources :questions, :only => [:move_up, :move_down] do
|
266
|
-
member do
|
267
|
-
get :move_up
|
268
|
-
get :move_down
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
resources :questions do
|
274
|
-
resources :answers, :only => [:move_up, :move_down, :remove] do
|
275
|
-
member do
|
276
|
-
get :move_up
|
277
|
-
get :move_down
|
278
|
-
get :remove
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
resources :rule_sets do
|
284
|
-
resources :answers, :only => [:add, :delete] do
|
285
|
-
member do
|
286
|
-
put :add
|
287
|
-
put :delete
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
258
|
+
See test/dummy/config/initializers/qwester.rb for an example
|
@@ -2,11 +2,16 @@ module Qwester
|
|
2
2
|
class Presentation < ActiveRecord::Base
|
3
3
|
attr_accessible :description, :name, :title, :questionnaire_ids, :default
|
4
4
|
|
5
|
-
has_many
|
5
|
+
has_many(
|
6
|
+
:presentation_questionnaires,
|
7
|
+
:order => 'position'
|
8
|
+
)
|
6
9
|
|
7
10
|
has_many(
|
8
11
|
:questionnaires,
|
9
|
-
:through => :presentation_questionnaires
|
12
|
+
:through => :presentation_questionnaires,
|
13
|
+
:uniq => true,
|
14
|
+
:order => 'position'
|
10
15
|
)
|
11
16
|
accepts_nested_attributes_for :questionnaires
|
12
17
|
|
@@ -41,5 +46,31 @@ module Qwester
|
|
41
46
|
self.title = self.name.humanize unless self.title.present?
|
42
47
|
end
|
43
48
|
|
49
|
+
def method_missing(symbol, *args, &block)
|
50
|
+
if symbol.to_sym == :position || acts_as_list_method?(symbol)
|
51
|
+
pass_acts_as_list_method_to(presentation_questionnaires, symbol, args.first)
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Allows acts_as_list methods to be used within the questionnaire.
|
58
|
+
#
|
59
|
+
# Usage:
|
60
|
+
#
|
61
|
+
# questionnaire.move_to_top(question)
|
62
|
+
# questionnaire.last?(question)
|
63
|
+
#
|
64
|
+
def pass_acts_as_list_method_to(presentation_questionnaires, symbol, questionnaire)
|
65
|
+
raise "A Questionnaire is needed to identify the PresentationQuesti" unless questionnaire.kind_of? Questionnaire
|
66
|
+
presentation_questionnaire = presentation_questionnaires.where(:questionnaire_id => questionnaire.id).first
|
67
|
+
presentation_questionnaire.send(symbol) if presentation_questionnaire
|
68
|
+
end
|
69
|
+
|
70
|
+
def acts_as_list_method?(symbol)
|
71
|
+
methods = ActiveRecord::Acts::List::InstanceMethods.instance_methods + ActiveRecord::Acts::List::InstanceMethods.private_instance_methods
|
72
|
+
methods.include?(symbol.to_sym)
|
73
|
+
end
|
74
|
+
|
44
75
|
end
|
45
76
|
end
|
@@ -46,35 +46,22 @@ module Qwester
|
|
46
46
|
|
47
47
|
private
|
48
48
|
def method_missing(symbol, *args, &block)
|
49
|
-
if acts_as_list_method?(symbol)
|
50
|
-
|
51
|
-
else
|
49
|
+
if symbol.to_sym == :position || acts_as_list_method?(symbol)
|
50
|
+
pass_acts_as_list_method_to_questionnaires_question(symbol, args.first)
|
51
|
+
else
|
52
52
|
super
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
# Allows acts_as_list methods to be used within the questionnaire.
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# However, as questions are used on multiple questionnaires and they
|
62
|
-
# need to be independently sortable within each questionnaire, it is the
|
63
|
-
# through table model QuestionnairesQuestion that acts_as_list. To change
|
64
|
-
# position the change must be made in the context of the questionnaire.
|
65
|
-
# pass_method_to_questionnaires_question in combination with method_missing,
|
66
|
-
# allows you to pass to a questionnaire the acts_as_list method together with
|
67
|
-
# the question it needs to effect. The equivalent move_higher call then becomes:
|
68
|
-
#
|
69
|
-
# questionnaire.move_higher(questionnaire.questions.last)
|
70
|
-
#
|
71
|
-
# You can also do:
|
72
|
-
#
|
57
|
+
#
|
58
|
+
# Usage:
|
59
|
+
#
|
73
60
|
# questionnaire.move_to_top(question)
|
74
61
|
# questionnaire.last?(question)
|
75
62
|
#
|
76
|
-
def
|
77
|
-
raise "A Question is needed to identify QuestionnairesQuestion" unless question.kind_of? Question
|
63
|
+
def pass_acts_as_list_method_to_questionnaires_question(symbol, question)
|
64
|
+
raise "A Question is needed to identify the QuestionnairesQuestion" unless question.kind_of? Question
|
78
65
|
questionnaires_question = questionnaires_questions.where(:question_id => question.id).first
|
79
66
|
questionnaires_question.send(symbol) if questionnaires_question
|
80
67
|
end
|
@@ -83,6 +70,5 @@ module Qwester
|
|
83
70
|
ActiveRecord::Acts::List::InstanceMethods.instance_methods.include?(symbol.to_sym)
|
84
71
|
end
|
85
72
|
|
86
|
-
|
87
73
|
end
|
88
74
|
end
|
@@ -28,6 +28,15 @@ module Qwester
|
|
28
28
|
div(:style => 'display:inline-block;margin-right:20px;') do
|
29
29
|
para image_tag(questionnaire.button_image.url(:thumbnail))
|
30
30
|
para questionnaire.title
|
31
|
+
move_up_link = " "
|
32
|
+
move_down_link = " "
|
33
|
+
unless qwester_presentation.first?(questionnaire)
|
34
|
+
move_up_link = link_to('<', move_up_admin_qwester_presentation_path(qwester_presentation, :questionnaire_id => questionnaire.id))
|
35
|
+
end
|
36
|
+
unless qwester_presentation.last?(questionnaire)
|
37
|
+
move_down_link = link_to('>', move_down_admin_qwester_presentation_path(qwester_presentation, :questionnaire_id => questionnaire.id))
|
38
|
+
end
|
39
|
+
para [move_up_link, 'move', move_down_link].join(' ').html_safe
|
31
40
|
end
|
32
41
|
end
|
33
42
|
para "Default: Will be inital presentation of quesitonnaires" if qwester_presentation.default?
|
@@ -48,5 +57,19 @@ module Qwester
|
|
48
57
|
f.buttons
|
49
58
|
end
|
50
59
|
|
60
|
+
member_action :move_up do
|
61
|
+
presentation = Presentation.find(params[:id])
|
62
|
+
questionnaire = Questionnaire.find(params[:questionnaire_id])
|
63
|
+
presentation.move_higher(questionnaire)
|
64
|
+
redirect_to admin_qwester_presentation_path(presentation)
|
65
|
+
end
|
66
|
+
|
67
|
+
member_action :move_down do
|
68
|
+
presentation = Presentation.find(params[:id])
|
69
|
+
questionnaire = Questionnaire.find(params[:questionnaire_id])
|
70
|
+
presentation.move_lower(questionnaire)
|
71
|
+
redirect_to admin_qwester_presentation_path(presentation)
|
72
|
+
end
|
73
|
+
|
51
74
|
end
|
52
75
|
end
|
data/lib/qwester/version.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Qwester
|
2
|
-
VERSION = "0.2.
|
2
|
+
VERSION = "0.2.1"
|
3
3
|
end
|
4
4
|
|
5
5
|
# History
|
6
6
|
# =======
|
7
7
|
#
|
8
|
+
# 0.2.1 - Allows questionnaires to be positioned within a presentation
|
9
|
+
#
|
8
10
|
# 0.2.0 - Adds weighting to answers
|
9
11
|
# Weighting can be used to give some answers greater weight in comparisons.
|
10
12
|
# Weighting can be aliased.
|
@@ -1,8 +1,8 @@
|
|
1
1
|
namespace :qwester do
|
2
2
|
|
3
|
-
# Usage: rake data:
|
3
|
+
# Usage: rake data:reset_questionnaire_positions RAILS_ENV=production
|
4
4
|
desc "Goes through each of the acts_as_list objects and resets the positions based on order they were added to the database"
|
5
|
-
task :
|
5
|
+
task :reset_questionnaire_positions => :environment do
|
6
6
|
|
7
7
|
Qwester::Questionnaire.all.each do |questionnaire|
|
8
8
|
first_id = questionnaire.questionnaires_questions.minimum(:id)
|
@@ -22,4 +22,14 @@ namespace :qwester do
|
|
22
22
|
after = Qwester::AnswerStore.count
|
23
23
|
puts "#{before - after} answer stores removed, with #{after} remaining."
|
24
24
|
end
|
25
|
+
|
26
|
+
desc "Reset positions of questionnaires within presentations"
|
27
|
+
task :reset_presentation_questionnaires_positions => :environment do
|
28
|
+
Qwester::Presentation.all.each do |presentation|
|
29
|
+
presentation.presentation_questionnaires.each_with_index do |presentation_questionnaire, index|
|
30
|
+
presentation_questionnaire.update_attribute(:position, index + 1)
|
31
|
+
end
|
32
|
+
puts "Presentation '#{presentation.name}' questionnaires postitioned #{presentation.presentation_questionnaires.collect(&:position)}"
|
33
|
+
end
|
34
|
+
end
|
25
35
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
|
-
Dummy::Application.config.session_store
|
3
|
+
Dummy::Application.config.session_store(:cookie_store, key: '_dummy_session')
|
4
4
|
|
5
5
|
# Use the database for sessions instead of the cookie-based default,
|
6
6
|
# which shouldn't be used to store highly confidential information
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
7
|
ActiveSupport.on_load(:action_controller) do
|
8
|
-
wrap_parameters
|
8
|
+
wrap_parameters(format: [:json])
|
9
9
|
end
|
10
10
|
|
11
11
|
# Disable root element in JSON by default.
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20130502082731) do
|
15
15
|
|
16
16
|
create_table "active_admin_comments", :force => true do |t|
|
17
17
|
t.string "resource_id", :null => false
|
@@ -97,6 +97,7 @@ ActiveRecord::Schema.define(:version => 20130402085424) do
|
|
97
97
|
t.integer "presentation_id"
|
98
98
|
t.datetime "created_at", :null => false
|
99
99
|
t.datetime "updated_at", :null => false
|
100
|
+
t.integer "position"
|
100
101
|
end
|
101
102
|
|
102
103
|
create_table "qwester_presentations", :force => true do |t|
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|