questionnaire_engine 0.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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +234 -0
  5. data/Rakefile +30 -0
  6. data/app/models/survey/answer.rb +50 -0
  7. data/app/models/survey/attempt.rb +74 -0
  8. data/app/models/survey/option.rb +44 -0
  9. data/app/models/survey/options_type.rb +35 -0
  10. data/app/models/survey/predefined_value.rb +23 -0
  11. data/app/models/survey/question.rb +52 -0
  12. data/app/models/survey/questions_type.rb +27 -0
  13. data/app/models/survey/section.rb +47 -0
  14. data/app/models/survey/survey.rb +63 -0
  15. data/config/locales/en.yml +54 -0
  16. data/config/locales/pt-PT.yml +48 -0
  17. data/config/locales/pt.yml +48 -0
  18. data/lib/generators/survey/install_generator.rb +35 -0
  19. data/lib/generators/survey/survey_generator.rb +77 -0
  20. data/lib/generators/templates/active_admin.rb +85 -0
  21. data/lib/generators/templates/attempts_plain.rb +36 -0
  22. data/lib/generators/templates/attempts_views/_form.html.erb +61 -0
  23. data/lib/generators/templates/attempts_views/new.html.erb +10 -0
  24. data/lib/generators/templates/helper.rb +46 -0
  25. data/lib/generators/templates/migration.rb +56 -0
  26. data/lib/generators/templates/migration_add_head_number_to_options_table.rb +6 -0
  27. data/lib/generators/templates/migration_add_mandatory_to_questions_table.rb +6 -0
  28. data/lib/generators/templates/migration_add_types_to_questions_and_options.rb +13 -0
  29. data/lib/generators/templates/migration_create_predefined_values_table.rb +14 -0
  30. data/lib/generators/templates/migration_section.rb +22 -0
  31. data/lib/generators/templates/migration_update_survey_tables.rb +22 -0
  32. data/lib/generators/templates/rails_admin.rb +8 -0
  33. data/lib/generators/templates/survey_plain.rb +60 -0
  34. data/lib/generators/templates/survey_views/_form.html.erb +72 -0
  35. data/lib/generators/templates/survey_views/_option_fields.html.erb +26 -0
  36. data/lib/generators/templates/survey_views/_question_fields.html.erb +42 -0
  37. data/lib/generators/templates/survey_views/_section_fields.html.erb +29 -0
  38. data/lib/generators/templates/survey_views/edit.html.erb +2 -0
  39. data/lib/generators/templates/survey_views/index.html.erb +14 -0
  40. data/lib/generators/templates/survey_views/new.html.erb +2 -0
  41. data/lib/survey.rb +5 -0
  42. data/lib/survey/active_record.rb +15 -0
  43. data/lib/survey/engine.rb +6 -0
  44. data/lib/survey/version.rb +3 -0
  45. metadata +142 -0
@@ -0,0 +1,22 @@
1
+ class UpdateSurveyTables < ActiveRecord::Migration
2
+ def change
3
+ #Survey Surveys table
4
+ add_column :survey_surveys, :locale_name, :string
5
+ add_column :survey_surveys, :locale_description, :text
6
+
7
+ #Survey Sections table
8
+ add_column :survey_sections, :locale_head_number, :string
9
+ add_column :survey_sections, :locale_name, :string
10
+ add_column :survey_sections, :locale_description, :text
11
+
12
+ #Survey Questions table
13
+ add_column :survey_questions, :head_number, :string
14
+ add_column :survey_questions, :description, :text
15
+ add_column :survey_questions, :locale_text, :string
16
+ add_column :survey_questions, :locale_head_number, :string
17
+ add_column :survey_questions, :locale_description, :text
18
+
19
+ #Survey Options table
20
+ add_column :survey_options, :locale_text, :string
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ RailsAdmin.config do |c|
2
+ c.excluded_models = [
3
+ Survey::Answer,
4
+ Survey::Option,
5
+ Survey::Attempt,
6
+ Survey::Question
7
+ ]
8
+ end
@@ -0,0 +1,60 @@
1
+ class <%= get_scope.capitalize %>::SurveysController < ApplicationController
2
+ before_filter :load_survey, :only => [:show, :edit, :update]
3
+
4
+ def index
5
+ @surveys = Survey::Survey.all
6
+ end
7
+
8
+ def new
9
+ @survey = Survey::Survey.new
10
+ end
11
+
12
+ def create
13
+ @survey = Survey::Survey.new(survey_params)
14
+ if @survey.valid? and @survey.save
15
+ default_redirect
16
+ else
17
+ render :action => :new
18
+ end
19
+ end
20
+
21
+ def edit
22
+ end
23
+
24
+ def show
25
+ end
26
+
27
+ def update
28
+ if @survey.update_attributes(survey_params)
29
+ default_redirect
30
+ else
31
+ render :action => :edit
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def default_redirect
38
+ redirect_to <%= get_scope %>_surveys_path, alert: I18n.t("surveys_controller.#{action_name}")
39
+ end
40
+
41
+ def load_survey
42
+ @survey = Survey::Survey.find(params[:id])
43
+ end
44
+
45
+ #######
46
+ private
47
+ #######
48
+
49
+ # Rails 4 Strong Params
50
+ def survey_params
51
+ if Rails::VERSION::MAJOR < 4
52
+ params[:survey_survey]
53
+ else
54
+ protected_attrs = ["created_at", "updated_at"]
55
+ params.require(:survey_survey).permit(Survey::Survey.new.attributes.keys - protected_attrs,
56
+ sections_attributes: Survey::Section.new.attributes.keys - protected_attrs,
57
+ questions_attributes: Survey::Question.new.attributes.keys - protected_attrs)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,72 @@
1
+ <%= form_for(@survey, :url => survey_scope(@survey)) do |f| %>
2
+
3
+ <% if f.object.errors.messages.any? %>
4
+ <ul>
5
+ <% f.object.errors.messages.each_pair do |field, msg| %>
6
+ <li>
7
+ <%= "#{field} - #{msg}" %>
8
+ </li>
9
+ <% end -%>
10
+ </ul>
11
+ <% end -%>
12
+
13
+ <div class="field">
14
+ <%= f.label :name %> <br />
15
+ <%= f.text_field :name %> <br />
16
+ </div>
17
+ <div class="field">
18
+ <%= f.label :locale_name %> <br />
19
+ <%= f.text_field :locale_name %> <br />
20
+ </div>
21
+ <div class="field">
22
+ <%= f.label :description %> <br />
23
+ <%= f.text_area :description, :size => "100x5" %> <br />
24
+ </div>
25
+ <div class="field">
26
+ <%= f.label :locale_description %> <br />
27
+ <%= f.text_area :locale_description %> <br />
28
+ </div>
29
+ <div class="field">
30
+ <%= f.label :attempts_number %> <br />
31
+ <%= f.text_field :attempts_number %> <br />
32
+ </div>
33
+ <div class="field">
34
+ <%= f.label :active %> <br />
35
+ <%= f.select :active, ["true", "false"] %>
36
+ </div>
37
+
38
+ <br/ >
39
+
40
+ <div class="field">
41
+ <ul>
42
+ <%= f.fields_for :sections do |builder| %>
43
+ <%= render "section_fields", :f => builder %>
44
+ <% end %>
45
+ </ul>
46
+ <br/ >
47
+ <%= link_to_add_field "Add a new Section", f, :sections %>
48
+ </div>
49
+
50
+ <br/ >
51
+
52
+ <div class="field">
53
+ <%= f.submit %>
54
+ </div>
55
+ <% end -%>
56
+
57
+ <script type="text/javascript">
58
+ // remove attachment field
59
+ function removeField(link) {
60
+ $(link).prev("input[type=hidden]").val("true");
61
+ tag = $(link).closest("li")
62
+ tag.hide("fade in").addClass("deleted");
63
+ }
64
+
65
+ // add attachment field
66
+ function addField(link, association, content) {
67
+ var new_id = new Date().getTime();
68
+ var regexp = new RegExp("new_" + association, "g");
69
+ var html = $(content.replace(regexp, new_id)).hide();
70
+ html.appendTo($(link).closest("div.field").find("ul").first()).slideDown("slow");
71
+ }
72
+ </script>
@@ -0,0 +1,26 @@
1
+ <li>
2
+ <h2>Option</h2>
3
+ <div class="field">
4
+ <%= f.label :head_number %> <br/ >
5
+ <%= f.text_field :head_number %>
6
+ </div>
7
+ <div class="field">
8
+ <%= f.label :text %> <br/ >
9
+ <%= f.text_field :text %>
10
+ </div>
11
+ <div class="field">
12
+ <%= f.label :locale_text %> <br/ >
13
+ <%= f.text_field :locale_text %>
14
+ </div>
15
+ <div class="field">
16
+ <%= f.label :options_type_id %> <br />
17
+ <%= f.select :options_type_id, Survey::OptionsType.options_types_title %>
18
+ </div>
19
+ <div class="field">
20
+ <%= f.check_box :correct %>
21
+ <%= f.label :correct %>
22
+ </div>
23
+ <div class="field">
24
+ <%= link_to_remove_field "Remove", f %>
25
+ </div>
26
+ </li>
@@ -0,0 +1,42 @@
1
+ <li>
2
+ <h2>Question</h2>
3
+ <div class="field">
4
+ <%= f.label :head_number %> <br />
5
+ <%= f.text_field :head_number %>
6
+ </div>
7
+ <div class="field">
8
+ <%= f.label :locale_head_number %> <br />
9
+ <%= f.text_field :locale_head_number %>
10
+ </div>
11
+ <div class="field">
12
+ <%= f.label :text %> <br />
13
+ <%= f.text_field :text %>
14
+ </div>
15
+ <div class="field">
16
+ <%= f.label :locale_text %> <br />
17
+ <%= f.text_field :locale_text %>
18
+ </div>
19
+ <div class="field">
20
+ <%= f.label :description %> <br />
21
+ <%= f.text_area :description %>
22
+ </div>
23
+ <div class="field">
24
+ <%= f.label :locale_description %> <br />
25
+ <%= f.text_area :locale_description %>
26
+ </div>
27
+ <div class="field">
28
+ <%= f.label :questions_type_id %> <br />
29
+ <%= f.select :questions_type_id, Survey::QuestionsType.questions_types_title %>
30
+ </div>
31
+
32
+ <div class="field">
33
+ <ul class="options">
34
+ <%= f.fields_for :options do |builder| %>
35
+ <%= render "option_fields", :f => builder %>
36
+ <% end -%>
37
+ </ul>
38
+ <%= link_to_add_field "Add a new Option", f, :options %>
39
+ <br/ >
40
+ <%= link_to_remove_field "Remove Question", f %>
41
+ </div>
42
+ </li>
@@ -0,0 +1,29 @@
1
+ <li>
2
+ <h2>Section</h2>
3
+ <%= f.hidden_field :id %>
4
+ <div class="field">
5
+ <%= f.label :head_number %> <br />
6
+ <%= f.text_field :locale_head_number %>
7
+ </div>
8
+ <div class="field">
9
+ <%= f.label :name %> <br />
10
+ <%= f.text_field :name %>
11
+ </div>
12
+ <div class="field">
13
+ <%= f.label :locale_name %> <br />
14
+ <%= f.text_field :locale_name %>
15
+ </div>
16
+ <div class="field">
17
+ <%= f.label :description %> <br />
18
+ <%= f.text_field :locale_description %>
19
+ </div>
20
+ <div class="field">
21
+ <ul>
22
+ <%= f.fields_for :questions do |builder| %>
23
+ <%= render "question_fields", :f => builder %>
24
+ <% end %>
25
+ </ul>
26
+ <br/ >
27
+ <%= link_to_add_field "Add a new Question", f, :questions %>
28
+ </div>
29
+ </li>
@@ -0,0 +1,2 @@
1
+ <h2>Edit Survey</h2>
2
+ <%= render 'form' %>
@@ -0,0 +1,14 @@
1
+ <div class="questionnaires_<%= action_name %>">
2
+ <h1>
3
+ Surveys Index
4
+ </h1>
5
+ <hr>
6
+ <%= link_to "New Survey", new_survey_path %>
7
+ <ul>
8
+ <% @surveys.each do |survey| %>
9
+ <li>
10
+ <%= link_to survey.name, edit_survey_path(survey) %>
11
+ </li>
12
+ <% end -%>
13
+ </ul>
14
+ </div>
@@ -0,0 +1,2 @@
1
+ <h2>New Survey</h2>
2
+ <%= render 'form' %>
data/lib/survey.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'survey/engine'
2
+ require 'survey/version'
3
+ require 'survey/active_record'
4
+
5
+ ActiveRecord::Base.send(:include, Survey::ActiveRecord)
@@ -0,0 +1,15 @@
1
+ module Survey
2
+ module ActiveRecord
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def has_surveys
7
+ has_many :survey_attempts, as: :participant, :class_name => ::Survey::Attempt
8
+
9
+ define_method("for_survey") do |survey|
10
+ self.survey_attempts.where(:survey_id => survey.id)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ module Survey
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Survey
2
+ VERSION = "0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: questionnaire_engine
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Dr-Click
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A rails gem to enable surveys in your application as easy as possible
70
+ email: ragab.mostafa@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - app/models/survey/survey.rb
76
+ - app/models/survey/question.rb
77
+ - app/models/survey/predefined_value.rb
78
+ - app/models/survey/option.rb
79
+ - app/models/survey/section.rb
80
+ - app/models/survey/answer.rb
81
+ - app/models/survey/options_type.rb
82
+ - app/models/survey/questions_type.rb
83
+ - app/models/survey/attempt.rb
84
+ - lib/survey.rb
85
+ - lib/generators/templates/active_admin.rb
86
+ - lib/generators/templates/migration.rb
87
+ - lib/generators/templates/migration_add_mandatory_to_questions_table.rb
88
+ - lib/generators/templates/migration_section.rb
89
+ - lib/generators/templates/helper.rb
90
+ - lib/generators/templates/attempts_views/new.html.erb
91
+ - lib/generators/templates/attempts_views/_form.html.erb
92
+ - lib/generators/templates/rails_admin.rb
93
+ - lib/generators/templates/migration_add_types_to_questions_and_options.rb
94
+ - lib/generators/templates/migration_create_predefined_values_table.rb
95
+ - lib/generators/templates/migration_add_head_number_to_options_table.rb
96
+ - lib/generators/templates/survey_plain.rb
97
+ - lib/generators/templates/survey_views/_section_fields.html.erb
98
+ - lib/generators/templates/survey_views/new.html.erb
99
+ - lib/generators/templates/survey_views/edit.html.erb
100
+ - lib/generators/templates/survey_views/_option_fields.html.erb
101
+ - lib/generators/templates/survey_views/index.html.erb
102
+ - lib/generators/templates/survey_views/_question_fields.html.erb
103
+ - lib/generators/templates/survey_views/_form.html.erb
104
+ - lib/generators/templates/migration_update_survey_tables.rb
105
+ - lib/generators/templates/attempts_plain.rb
106
+ - lib/generators/survey/install_generator.rb
107
+ - lib/generators/survey/survey_generator.rb
108
+ - lib/survey/engine.rb
109
+ - lib/survey/active_record.rb
110
+ - lib/survey/version.rb
111
+ - config/locales/pt.yml
112
+ - config/locales/en.yml
113
+ - config/locales/pt-PT.yml
114
+ - MIT-LICENSE
115
+ - Rakefile
116
+ - Gemfile
117
+ - README.md
118
+ homepage: https://github.com/dr-click/Questionnaire
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.1.11
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Questionnaire is a user oriented tool that brings surveys into Rails applications.
142
+ test_files: []