surveillance 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +42 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/surveillance.js +6 -0
- data/app/assets/javascripts/surveillance/admin.coffee +4 -0
- data/app/assets/javascripts/surveillance/admin/matrix-questions.coffee +18 -0
- data/app/assets/javascripts/surveillance/application.js +17 -0
- data/app/assets/javascripts/surveillance/collections/branch_rule_collection.coffee +2 -0
- data/app/assets/javascripts/surveillance/form.coffee +7 -0
- data/app/assets/javascripts/surveillance/manifest.coffee +7 -0
- data/app/assets/javascripts/surveillance/models/branch_rule.coffee +21 -0
- data/app/assets/javascripts/surveillance/models/question.coffee +19 -0
- data/app/assets/javascripts/surveillance/models/questions/choosable_question.coffee +15 -0
- data/app/assets/javascripts/surveillance/models/questions/matrix.coffee +19 -0
- data/app/assets/javascripts/surveillance/models/questions/matrix_question.coffee +7 -0
- data/app/assets/javascripts/surveillance/models/questions/number.coffee +17 -0
- data/app/assets/javascripts/surveillance/vendor/backbone.min.js +1 -0
- data/app/assets/javascripts/surveillance/vendor/bootstrap.js +2118 -0
- data/app/assets/javascripts/surveillance/vendor/jquery-ui-sortable.js +2256 -0
- data/app/assets/javascripts/surveillance/vendor/jquery.scrollto.js +210 -0
- data/app/assets/javascripts/surveillance/vendor/underscore.min.js +5 -0
- data/app/assets/javascripts/surveillance/views/attempt_view.coffee +74 -0
- data/app/assets/javascripts/surveillance/views/question_view.coffee +53 -0
- data/app/assets/javascripts/surveillance/views/questions/choice_view.coffee +52 -0
- data/app/assets/javascripts/surveillance/views/questions/matrix_question_view.coffee +26 -0
- data/app/assets/javascripts/surveillance/views/questions/matrix_view.coffee +21 -0
- data/app/assets/javascripts/surveillance/views/questions/number_view.coffee +19 -0
- data/app/assets/javascripts/surveillance/views/questions/order.coffee +9 -0
- data/app/assets/javascripts/surveillance/views/questions/select_matrix_view.coffee +31 -0
- data/app/assets/javascripts/surveillance/views/section_view.coffee +54 -0
- data/app/assets/stylesheets/surveillance/admin.sass +1 -0
- data/app/assets/stylesheets/surveillance/application.css +14 -0
- data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.svg +229 -0
- data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/stylesheets/surveillance/overrides.sass +2 -0
- data/app/assets/stylesheets/surveillance/vendor/bootstrap.css +6175 -0
- data/app/controllers/concerns/surveillance/attempts_management_concern.rb +51 -0
- data/app/controllers/concerns/surveillance/base_controller_concern.rb +37 -0
- data/app/controllers/surveillance/admin/attempts_controller.rb +38 -0
- data/app/controllers/surveillance/admin/base_controller.rb +15 -0
- data/app/controllers/surveillance/admin/exports_controller.rb +24 -0
- data/app/controllers/surveillance/admin/options_controller.rb +44 -0
- data/app/controllers/surveillance/admin/questions_controller.rb +59 -0
- data/app/controllers/surveillance/admin/sections_controller.rb +46 -0
- data/app/controllers/surveillance/admin/surveys_controller.rb +43 -0
- data/app/controllers/surveillance/application_controller.rb +7 -0
- data/app/controllers/surveillance/response/attempts_controller.rb +50 -0
- data/app/controllers/surveillance/response/base_controller.rb +38 -0
- data/app/controllers/surveillance/response/partial_attempts_controller.rb +15 -0
- data/app/controllers/surveillance/surveys_controller.rb +6 -0
- data/app/helpers/surveillance/admin/exports_helper.rb +37 -0
- data/app/helpers/surveillance/application_helper.rb +84 -0
- data/app/models/surveillance/answer.rb +56 -0
- data/app/models/surveillance/answer_content.rb +7 -0
- data/app/models/surveillance/attempt.rb +146 -0
- data/app/models/surveillance/branch_rule.rb +52 -0
- data/app/models/surveillance/field_setting.rb +6 -0
- data/app/models/surveillance/option.rb +18 -0
- data/app/models/surveillance/question.rb +50 -0
- data/app/models/surveillance/section.rb +16 -0
- data/app/models/surveillance/survey.rb +38 -0
- data/app/views/layouts/surveillance/application.html.haml +11 -0
- data/app/views/surveillance/admin/attempts/index.html.haml +47 -0
- data/app/views/surveillance/admin/attempts/list.html.haml +11 -0
- data/app/views/surveillance/admin/attempts/overview.html.haml +6 -0
- data/app/views/surveillance/admin/attempts/show.html.haml +62 -0
- data/app/views/surveillance/admin/exports/show.rxls +39 -0
- data/app/views/surveillance/admin/options/_field.html.haml +11 -0
- data/app/views/surveillance/admin/options/_form.html.haml +8 -0
- data/app/views/surveillance/admin/options/_list.html.haml +10 -0
- data/app/views/surveillance/admin/options/_option.html.haml +13 -0
- data/app/views/surveillance/admin/options/edit.html.haml +7 -0
- data/app/views/surveillance/admin/options/new.html.haml +7 -0
- data/app/views/surveillance/admin/questions/_form.html.haml +35 -0
- data/app/views/surveillance/admin/questions/_list.html.haml +17 -0
- data/app/views/surveillance/admin/questions/_question.html.haml +27 -0
- data/app/views/surveillance/admin/questions/edit.html.haml +7 -0
- data/app/views/surveillance/admin/questions/new.html.haml +4 -0
- data/app/views/surveillance/admin/sections/_form.html.haml +16 -0
- data/app/views/surveillance/admin/sections/_list.html.haml +13 -0
- data/app/views/surveillance/admin/sections/_section.html.haml +16 -0
- data/app/views/surveillance/admin/sections/edit.html.haml +7 -0
- data/app/views/surveillance/admin/sections/new.html.haml +4 -0
- data/app/views/surveillance/admin/surveys/_form.html.haml +22 -0
- data/app/views/surveillance/admin/surveys/_list.html.haml +13 -0
- data/app/views/surveillance/admin/surveys/_survey.html.haml +32 -0
- data/app/views/surveillance/admin/surveys/edit.html.haml +7 -0
- data/app/views/surveillance/admin/surveys/index.html.haml +1 -0
- data/app/views/surveillance/admin/surveys/new.html.haml +4 -0
- data/app/views/surveillance/field/date/_form.html.haml +5 -0
- data/app/views/surveillance/field/date/_overview.html.haml +2 -0
- data/app/views/surveillance/field/date/_show.html.haml +10 -0
- data/app/views/surveillance/field/matrix/_form.html.haml +40 -0
- data/app/views/surveillance/field/matrix/_overview.html.haml +19 -0
- data/app/views/surveillance/field/matrix/_questions_fields.html.haml +11 -0
- data/app/views/surveillance/field/matrix/_settings.html.haml +18 -0
- data/app/views/surveillance/field/matrix/_show.html.haml +22 -0
- data/app/views/surveillance/field/multiple_choices/_form.html.haml +18 -0
- data/app/views/surveillance/field/multiple_choices/_settings.html.haml +21 -0
- data/app/views/surveillance/field/multiple_choices/_show.html.haml +21 -0
- data/app/views/surveillance/field/multiple_choices_matrix/_form.html.haml +33 -0
- data/app/views/surveillance/field/multiple_choices_matrix/_show.html.haml +1 -0
- data/app/views/surveillance/field/number/_form.html.haml +5 -0
- data/app/views/surveillance/field/number/_overview.html.haml +2 -0
- data/app/views/surveillance/field/number/_settings.html.haml +2 -0
- data/app/views/surveillance/field/number/_show.html.haml +10 -0
- data/app/views/surveillance/field/order/_form.html.haml +17 -0
- data/app/views/surveillance/field/order/_overview.html.haml +22 -0
- data/app/views/surveillance/field/order/_settings.html.haml +11 -0
- data/app/views/surveillance/field/order/_show.html.haml +8 -0
- data/app/views/surveillance/field/select_matrix/_form.html.haml +17 -0
- data/app/views/surveillance/field/shared/_rules_form.html.haml +30 -0
- data/app/views/surveillance/field/shared/settings/_boolean.html.haml +9 -0
- data/app/views/surveillance/field/shared/settings/_number.html.haml +5 -0
- data/app/views/surveillance/field/single_choice/_form.html.haml +16 -0
- data/app/views/surveillance/field/single_choice/_overview.html.haml +14 -0
- data/app/views/surveillance/field/single_choice/_settings.html.haml +2 -0
- data/app/views/surveillance/field/single_choice/_show.html.haml +21 -0
- data/app/views/surveillance/field/single_select/_form.html.haml +4 -0
- data/app/views/surveillance/field/single_select/_overview.html.haml +14 -0
- data/app/views/surveillance/field/single_select/_show.html.haml +13 -0
- data/app/views/surveillance/field/text/_form.html.haml +5 -0
- data/app/views/surveillance/field/text/_overview.html.haml +2 -0
- data/app/views/surveillance/field/text/_show.html.haml +10 -0
- data/app/views/surveillance/field/text_area/_form.html.haml +5 -0
- data/app/views/surveillance/field/text_area/_overview.html.haml +1 -0
- data/app/views/surveillance/field/text_area/_show.html.haml +10 -0
- data/app/views/surveillance/response/attempts/complete.html.haml +11 -0
- data/app/views/surveillance/response/attempts/edit.html.haml +15 -0
- data/app/views/surveillance/sections/_section.html.haml +24 -0
- data/app/views/surveillance/surveys/_survey.html.haml +4 -0
- data/app/views/surveillance/surveys/index.html.haml +8 -0
- data/app/views/surveillance/surveys/show.html.haml +15 -0
- data/config/locales/surveillance.fr.yml +165 -0
- data/config/routes.rb +30 -0
- data/db/migrate/20130626115136_create_surveillance_surveys.rb +13 -0
- data/db/migrate/20130626115805_create_surveillance_sections.rb +12 -0
- data/db/migrate/20130626130351_create_surveillance_questions.rb +14 -0
- data/db/migrate/20130702111125_create_surveillance_options.rb +11 -0
- data/db/migrate/20130703113456_create_surveillance_attempts.rb +11 -0
- data/db/migrate/20130703115649_create_surveillance_answers.rb +11 -0
- data/db/migrate/20130703115723_create_surveillance_answer_contents.rb +10 -0
- data/db/migrate/20130710151627_create_surveillance_field_settings.rb +11 -0
- data/db/migrate/20130711100032_create_surveillance_answers_options_join_table.rb +7 -0
- data/db/migrate/20130729143002_create_surveillance_branch_rules.rb +14 -0
- data/db/migrate/20140212153506_add_state_to_surveillance_attempts.rb +6 -0
- data/db/migrate/20140213101147_add_access_token_to_surveillance_attempts.rb +5 -0
- data/db/migrate/20140213133036_add_partial_to_surveillance_questions.rb +5 -0
- data/lib/generators/surveillance/install/install_generator.rb +34 -0
- data/lib/generators/surveillance/install/templates/initializer.rb +51 -0
- data/lib/surveillance.rb +61 -0
- data/lib/surveillance/branch_action.rb +5 -0
- data/lib/surveillance/branch_condition.rb +5 -0
- data/lib/surveillance/engine.rb +13 -0
- data/lib/surveillance/field.rb +58 -0
- data/lib/surveillance/field/base.rb +149 -0
- data/lib/surveillance/field/date.rb +17 -0
- data/lib/surveillance/field/matrix.rb +66 -0
- data/lib/surveillance/field/matrix_question.rb +13 -0
- data/lib/surveillance/field/multiple_choices.rb +29 -0
- data/lib/surveillance/field/multiple_choices_matrix.rb +13 -0
- data/lib/surveillance/field/number.rb +34 -0
- data/lib/surveillance/field/order.rb +40 -0
- data/lib/surveillance/field/order_question.rb +22 -0
- data/lib/surveillance/field/other_choice.rb +28 -0
- data/lib/surveillance/field/select_matrix.rb +13 -0
- data/lib/surveillance/field/single_choice.rb +36 -0
- data/lib/surveillance/field/single_select.rb +31 -0
- data/lib/surveillance/field/text.rb +13 -0
- data/lib/surveillance/field/text_area.rb +6 -0
- data/lib/surveillance/partials_collection.rb +7 -0
- data/lib/surveillance/setting.rb +24 -0
- data/lib/surveillance/settings_collection.rb +17 -0
- data/lib/surveillance/validators.rb +7 -0
- data/lib/surveillance/validators/answer_validator.rb +9 -0
- data/lib/surveillance/version.rb +3 -0
- data/lib/tasks/surveillance_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/locales/rails.fr.yml +226 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140113224541_create_surveillance_surveys.surveillance.rb +14 -0
- data/spec/dummy/db/migrate/20140113224542_create_surveillance_sections.surveillance.rb +13 -0
- data/spec/dummy/db/migrate/20140113224543_create_surveillance_questions.surveillance.rb +15 -0
- data/spec/dummy/db/migrate/20140113224544_create_surveillance_options.surveillance.rb +12 -0
- data/spec/dummy/db/migrate/20140113224545_create_surveillance_attempts.surveillance.rb +12 -0
- data/spec/dummy/db/migrate/20140113224546_create_surveillance_answers.surveillance.rb +12 -0
- data/spec/dummy/db/migrate/20140113224547_create_surveillance_answer_contents.surveillance.rb +11 -0
- data/spec/dummy/db/migrate/20140113224548_create_surveillance_field_settings.surveillance.rb +12 -0
- data/spec/dummy/db/migrate/20140113224549_create_surveillance_answers_options_join_table.surveillance.rb +8 -0
- data/spec/dummy/db/migrate/20140113224550_create_surveillance_branch_rules.surveillance.rb +15 -0
- data/spec/dummy/db/schema.rb +103 -0
- data/spec/dummy/log/development.log +38066 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0018421aaf29044fbd13363bbdfd8f44 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/017d7a30ec05c0fb0265fb5167c73ee9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/034b76adeb89d6ca63cd9eea649331f5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/05de8fbfacab66a0efe4f9790b2ac723 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0811effcff3b9107d49398bdba7488e5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0d45beae32861dc508fc2db09b9d95b3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0d4961f3da5a0d5234736a6abbf42226 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0f491ed240e1a27bbc05e5213afd48bb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/10e2a0dbdbb68c055e8b7ccd6f2906d8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1173cdef6c662a55ef590489fe26e8fe +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1b3e93127523ec0f3c93bcd91d4390dc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1bb56fbf17ccbb14dcbaa4d6d639e620 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2bd0ba6a1598c9fa67081d8f906db6f8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3fbe053f103de46cc1b320f059b99c1f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4144b095447efb810a548b99e41df9eb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/421d097cb8d88f975d8ccf75c9e5e306 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/474bc1c9055df6cc1cdff58817a6cb41 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4829d251eeb22cdbd05b27b6ba809538 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4f584ca3f0c8ec62906e6f03bc5963c2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/55d647d88e01b91b2a146e7db0481c09 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/62db8b5885b79c5dc0667fab0fbf46bb +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7080a4d265fe784c9704db71f81da832 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7220af243fd39e3dffd233252e4a8c17 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7cd0e5bfe12b86ed494d02e8e5b62bbf +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/7e37a8ae2a50653b388d57c573d12548 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8113790dad1da8858c82cfc3eb14ef87 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/83997102fc04f275cd6cd8c1ddb55835 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8a7b047a16adbc640e03eaabe4a4fe93 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/90b48fb4bfa22ddcd063734065d27086 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/935886b24c90d344752d2a80e3657801 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/9606a6d70af63ce3fea26ded0a69d5c2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/97db73fdf0bbab24fb92892c61ec7a9b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a23bb60554e715c228ae3cdfb5d81807 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ad17e102b9f9288a9e919b0b0a2ab05b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c26ae1f6640b52c232bd392a6e2f7110 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c6cb3deca0f08bd9569d00fca09272da +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d39b4eebbd0042342e10497a34fd6378 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d5ee573b2abdcdc245a830bde2dd76f3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d6487e59842ff206d84f6de5e3a7400c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dafa124ddd0e828d7c5c0a5c4db455ba +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e5bbd03518f9abc3e9bc1373c74fd3f1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ed5aa255edff522c2e36e6f0151ff747 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ee263a426f6530013f86aa860448fa91 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/efa0c4d855d425fdf4b63ab26c45e94c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f2881259fd5bad1c0a5b1ab5dff97c47 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f34108e540cff2fbc32036da452ca6ae +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7e7e00ef8efc13c6a2628e453344440 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f9a44009076e46b0f35af5e7031a1871 +0 -0
- data/spec/spec_helper.rb +87 -0
- metadata +598 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSurveillanceSurveys < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :surveillance_surveys do |t|
|
4
|
+
t.string :title
|
5
|
+
t.text :description
|
6
|
+
t.text :last_page_description
|
7
|
+
t.date :end_date
|
8
|
+
t.boolean :published, default: false
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSurveillanceQuestions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :surveillance_questions do |t|
|
4
|
+
t.text :title
|
5
|
+
t.text :description
|
6
|
+
t.belongs_to :parent, polymorphic: true
|
7
|
+
t.string :field_type
|
8
|
+
t.boolean :mandatory, default: true
|
9
|
+
t.integer :position, default: 0
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSurveillanceBranchRules < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :surveillance_branch_rules do |t|
|
4
|
+
t.integer :question_id
|
5
|
+
t.integer :sub_question_id
|
6
|
+
t.integer :option_id
|
7
|
+
t.integer :section_id
|
8
|
+
t.string :condition
|
9
|
+
t.string :action
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Surveillance
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
# Copied files come from templates folder
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
# Generator desc
|
7
|
+
desc "Surveillance installation generator"
|
8
|
+
|
9
|
+
def welcome
|
10
|
+
say "Installing surveillance files ..."
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_initializer_file
|
14
|
+
say "Copying Surveillance initializer template"
|
15
|
+
copy_file "initializer.rb", "config/initializers/surveillance.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_migrations
|
19
|
+
say "Installing migrations, don't forget to `rake db:migrate`"
|
20
|
+
rake "surveillance:install:migrations"
|
21
|
+
end
|
22
|
+
|
23
|
+
def mount_engine
|
24
|
+
mount_path = ask(
|
25
|
+
"Where would you like to mount the Surveillance engine ? [/surveillance]"
|
26
|
+
).presence || '/surveillance'
|
27
|
+
|
28
|
+
gsub_file "config/routes.rb", /mount Surveillance::Engine.*\'/, ''
|
29
|
+
|
30
|
+
path = mount_path.match(/^\//) ? mount_path : "/#{ mount_path }"
|
31
|
+
route "mount Surveillance::Engine => '#{ path }'"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Surveillance.config do |config|
|
2
|
+
# Choose a controller class method to be called before admin controllers
|
3
|
+
# actions to authenticate admins
|
4
|
+
# Setting it to nil, will let everybody access the admin panel
|
5
|
+
#
|
6
|
+
# Default : nil
|
7
|
+
#
|
8
|
+
# config.admin_authorization_method = :authenticate_user!
|
9
|
+
|
10
|
+
# Define a layout to be used in Surveillance views
|
11
|
+
# Setting it to nil will let the default layout
|
12
|
+
#
|
13
|
+
# Default : nil
|
14
|
+
#
|
15
|
+
# config.views_layout = "survey"
|
16
|
+
|
17
|
+
# Change Admin base controller
|
18
|
+
#
|
19
|
+
# config.admin_base_controller = 'AdminController'
|
20
|
+
|
21
|
+
# Register field partials to allow overriding field rendering from admin
|
22
|
+
#
|
23
|
+
# Don't forget to add the registered partial view in :
|
24
|
+
# "app/views/surveillance/field/customer/<partial_path>"
|
25
|
+
#
|
26
|
+
# config.partials.register "Partial Name", "partial_path"
|
27
|
+
|
28
|
+
# Register a callback to be called when an attempt has already be registered
|
29
|
+
# for an anonymous user.
|
30
|
+
# The callback will be executed in the context of the controller, allowing you
|
31
|
+
# to use controller methods
|
32
|
+
# Setting it to nil will keep the default behaviour of adding a flash[:error]
|
33
|
+
# message and redirecting to the surveys list
|
34
|
+
#
|
35
|
+
# Default : nil
|
36
|
+
#
|
37
|
+
# config.attempt_already_registered_callback = ->(attempt) {
|
38
|
+
# flash[:error] = "You already completed this survey"
|
39
|
+
# redirect_to(root_path)
|
40
|
+
# }
|
41
|
+
|
42
|
+
# Surveys root path used when redirecting from a survey
|
43
|
+
# Executed in the context of the controller / view where it is called
|
44
|
+
# Note that the controller is inside the Surveillance Engine, you need
|
45
|
+
# to call the root on the `main_app` object if you need to redirect to
|
46
|
+
# your app
|
47
|
+
#
|
48
|
+
# Default : nil
|
49
|
+
#
|
50
|
+
# config.surveys_root_path = -> { main_app.root_path }
|
51
|
+
end
|
data/lib/surveillance.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "decent_exposure"
|
2
|
+
require "haml-rails"
|
3
|
+
require "jquery-rails"
|
4
|
+
require "simple_form"
|
5
|
+
require "spreadsheet_on_rails"
|
6
|
+
require 'aasm'
|
7
|
+
|
8
|
+
require "surveillance/engine"
|
9
|
+
|
10
|
+
module Surveillance
|
11
|
+
extend ActiveSupport::Autoload
|
12
|
+
|
13
|
+
autoload :Field, "surveillance/field"
|
14
|
+
autoload :PartialsCollection, "surveillance/partials_collection"
|
15
|
+
autoload :SettingsCollection, "surveillance/settings_collection"
|
16
|
+
autoload :Setting, "surveillance/setting"
|
17
|
+
autoload :Validators, "surveillance/validators"
|
18
|
+
|
19
|
+
# Defines an autorization method to be called before actions in admin
|
20
|
+
# controllers to authenticate admin users
|
21
|
+
#
|
22
|
+
mattr_accessor :admin_authorization_method
|
23
|
+
@@admin_authorization_method = nil
|
24
|
+
|
25
|
+
mattr_accessor :admin_base_controller
|
26
|
+
@@admin_base_controller = 'Surveillance::ApplicationController'
|
27
|
+
|
28
|
+
mattr_accessor :views_layout
|
29
|
+
@@views_layout = nil
|
30
|
+
|
31
|
+
mattr_accessor :partials
|
32
|
+
@@partials = Surveillance::PartialsCollection.new
|
33
|
+
|
34
|
+
mattr_accessor :attempt_already_registered_callback
|
35
|
+
@@attempt_already_registered_callback = nil
|
36
|
+
|
37
|
+
mattr_accessor :surveys_root_path
|
38
|
+
@@surveys_root_path = nil
|
39
|
+
|
40
|
+
class << self
|
41
|
+
def table_name_prefix
|
42
|
+
'surveillance_'
|
43
|
+
end
|
44
|
+
|
45
|
+
def options_for ary, key
|
46
|
+
ary.map do |item|
|
47
|
+
str = item.to_s
|
48
|
+
[I18n.t("surveillance.#{ key }.#{ str }"), str]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def config &block
|
53
|
+
yield self
|
54
|
+
end
|
55
|
+
|
56
|
+
def unique_token
|
57
|
+
(Time.now.to_f * (100 ** 10)).to_i.to_s(36) +
|
58
|
+
(rand * 10 ** 10).to_i.to_s(36)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Surveillance
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Surveillance
|
4
|
+
|
5
|
+
config.to_prepare do
|
6
|
+
path = Rails.root.join('lib', 'decorators', 'surveillance', '**', '*.rb')
|
7
|
+
|
8
|
+
Dir[path].each do |file|
|
9
|
+
load file
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Surveillance
|
2
|
+
module Field
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
autoload :Base, "surveillance/field/base"
|
7
|
+
autoload :Text, "surveillance/field/text"
|
8
|
+
autoload :TextArea, "surveillance/field/text_area"
|
9
|
+
autoload :Number, "surveillance/field/number"
|
10
|
+
autoload :Date, "surveillance/field/date"
|
11
|
+
autoload :SingleChoice, "surveillance/field/single_choice"
|
12
|
+
autoload :MultipleChoices, "surveillance/field/multiple_choices"
|
13
|
+
autoload :SingleSelect, "surveillance/field/single_select"
|
14
|
+
autoload :Matrix, "surveillance/field/matrix"
|
15
|
+
autoload :MultipleChoicesMatrix, "surveillance/field/multiple_choices_matrix"
|
16
|
+
autoload :SelectMatrix, "surveillance/field/select_matrix"
|
17
|
+
autoload :MatrixChoice, "surveillance/field/matrix_choice"
|
18
|
+
autoload :MatrixQuestion, "surveillance/field/matrix_question"
|
19
|
+
autoload :Order, "surveillance/field/order"
|
20
|
+
autoload :OrderQuestion, "surveillance/field/order_question"
|
21
|
+
|
22
|
+
autoload :OtherChoice, "surveillance/field/other_choice"
|
23
|
+
|
24
|
+
mattr_accessor :available_field_types
|
25
|
+
@@available_field_types = %w(
|
26
|
+
text text_area number date single_choice multiple_choices single_select
|
27
|
+
matrix multiple_choices_matrix select_matrix order
|
28
|
+
)
|
29
|
+
|
30
|
+
def field(options = {})
|
31
|
+
attempt = options.fetch(:attempt, nil)
|
32
|
+
answer = options.fetch(:answer, nil)
|
33
|
+
rebuild = options.fetch(:rebuild, false)
|
34
|
+
|
35
|
+
return @field if !rebuild && @field
|
36
|
+
@field = (field_class).new(self, attempt: attempt, answer: answer)
|
37
|
+
end
|
38
|
+
|
39
|
+
def field_class
|
40
|
+
Field.const_get(field_type.camelize)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.field_types_enum
|
44
|
+
Surveillance.options_for(@@available_field_types, "field_types")
|
45
|
+
end
|
46
|
+
|
47
|
+
included do
|
48
|
+
validates_presence_of :field_type
|
49
|
+
|
50
|
+
after_initialize do
|
51
|
+
self.field_type ||= "text"
|
52
|
+
end
|
53
|
+
|
54
|
+
before_validation :before_validation_callback
|
55
|
+
delegate :before_validation_callback, to: :field
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module Surveillance
|
2
|
+
module Field
|
3
|
+
class Base
|
4
|
+
include ActionView::Helpers::FormOptionsHelper
|
5
|
+
|
6
|
+
attr_accessor :question
|
7
|
+
attr_writer :answer, :attempt
|
8
|
+
|
9
|
+
def initialize question, options = {}
|
10
|
+
self.question = question
|
11
|
+
self.attempt = options.fetch(:attempt, nil)
|
12
|
+
self.answer = options.fetch(:answer, nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
def attempt
|
16
|
+
@attempt || (@answer && @answer.attempt)
|
17
|
+
end
|
18
|
+
|
19
|
+
def answer
|
20
|
+
@answer ||= attempt && attempt.answer_to(question)
|
21
|
+
end
|
22
|
+
|
23
|
+
def answer_or_initialize
|
24
|
+
answer || Surveillance::Answer.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def answer_or_initialize_for attempt
|
28
|
+
self.attempt = attempt
|
29
|
+
answer = answer_or_initialize
|
30
|
+
answer.question = question
|
31
|
+
answer
|
32
|
+
end
|
33
|
+
|
34
|
+
def choosable?
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
def mandatory_content?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def matrix?
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_sub_questions?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
def view_name
|
51
|
+
"question"
|
52
|
+
end
|
53
|
+
|
54
|
+
def setting_value key
|
55
|
+
setting = question.settings.find { |s| s.key == key.to_s }
|
56
|
+
setting && setting.value
|
57
|
+
end
|
58
|
+
|
59
|
+
def settings
|
60
|
+
@settings ||= self.class.settings.freeze
|
61
|
+
end
|
62
|
+
|
63
|
+
def settings?
|
64
|
+
settings.length > 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def answer_string
|
68
|
+
answer.content ? answer.content.value : ""
|
69
|
+
end
|
70
|
+
|
71
|
+
# Defines following partial view path methods :
|
72
|
+
%w(show settings overview export).each do |view|
|
73
|
+
define_method(:"#{ view }_path") do
|
74
|
+
"#{ self.class.name.underscore }/#{ view }"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def form_path
|
79
|
+
if question.partial.presence
|
80
|
+
"surveillance/field/custom/#{ question.partial }"
|
81
|
+
else
|
82
|
+
"#{ self.class.name.underscore }/form"
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def rules_form_path
|
88
|
+
"surveillance/field/shared/rules_form"
|
89
|
+
end
|
90
|
+
|
91
|
+
def validate_answer answer
|
92
|
+
self.answer = answer
|
93
|
+
|
94
|
+
if question.mandatory && empty?
|
95
|
+
answer.errors[:present] << I18n.t("errors.messages.empty")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def empty?
|
100
|
+
!present?
|
101
|
+
end
|
102
|
+
|
103
|
+
def present?
|
104
|
+
raise NoMethodError, "Each field type must override present? to " +
|
105
|
+
"implement custom presence logic. " +
|
106
|
+
"Raised from #{ self.class.name }"
|
107
|
+
end
|
108
|
+
|
109
|
+
def available_branch_conditions
|
110
|
+
conditions = %w(answers doesnt_answer)
|
111
|
+
conditions += %w(answers_option doesnt_answer_option) if choosable?
|
112
|
+
conditions
|
113
|
+
end
|
114
|
+
|
115
|
+
def available_branch_actions
|
116
|
+
%w(goto_section finalize_survey)
|
117
|
+
end
|
118
|
+
|
119
|
+
def options_list
|
120
|
+
@options_list ||= question.options.each_with_index.map do |option, index|
|
121
|
+
["#{ index } - #{ option.title }", option.id]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Override this method to define custom before_validation callbacks to
|
126
|
+
# be executed on the referer question model
|
127
|
+
#
|
128
|
+
def before_validation_callback
|
129
|
+
end
|
130
|
+
|
131
|
+
class << self
|
132
|
+
attr_writer :settings
|
133
|
+
|
134
|
+
def setting key, options = {}
|
135
|
+
settings[key] = Surveillance::Setting.new(self, options.merge(key: key))
|
136
|
+
end
|
137
|
+
|
138
|
+
def settings
|
139
|
+
@settings ||= Surveillance::SettingsCollection.new
|
140
|
+
end
|
141
|
+
|
142
|
+
def inherited subclass
|
143
|
+
# Ensure settings are inherited
|
144
|
+
subclass.settings.reverse_merge! settings
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|