doop 0.0.3.1 → 0.0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/assets/images/nino-icon.png +0 -0
- data/app/assets/images/passport-icon.png +0 -0
- data/app/assets/images/time-icon.png +0 -0
- data/app/helpers/doop_helper.rb +14 -7
- data/doop.gemspec +4 -2
- data/lib/doop-rspec.rb +82 -0
- data/lib/doop.rb +3 -1
- data/lib/doop/version.rb +1 -1
- data/lib/doop_controller.rb +14 -9
- data/lib/generators/doopgovuk/doopgovuk_generator.rb +3 -0
- data/lib/generators/doopgovuk/templates/app/assets/javascripts/demo.js.coffee +7 -0
- data/lib/generators/doopgovuk/templates/app/assets/javascripts/demo/application.js +2 -0
- data/lib/generators/doopgovuk/templates/app/assets/stylesheets/demo.css.scss +50 -8
- data/lib/generators/doopgovuk/templates/app/assets/stylesheets/demo/application.css +3 -0
- data/lib/generators/doopgovuk/templates/app/controllers/demo_controller.rb +202 -68
- data/lib/generators/doopgovuk/templates/app/views/demo/_about_you.html.erb +84 -0
- data/lib/generators/doopgovuk/templates/app/views/demo/_before_you_begin.html.erb +56 -0
- data/lib/generators/doopgovuk/templates/app/views/demo/_children.html.erb +64 -0
- data/lib/generators/doopgovuk/templates/app/views/demo/_declaration.html.erb +32 -0
- data/lib/generators/doopgovuk/templates/app/views/demo/_preamble.html.erb +36 -27
- data/lib/generators/doopgovuk/templates/app/views/demo/harness.html.erb +1 -1
- data/lib/generators/doopgovuk/templates/app/views/demo/index.html.erb +6 -0
- data/lib/generators/doopgovuk/templates/app/views/demo/index.js.erb +1 -1
- data/lib/generators/doopgovuk/templates/app/views/doop/_change_answer_tooltip.html.erb +1 -1
- data/lib/generators/doopgovuk/templates/app/views/doop/_debug.html.erb +4 -0
- data/lib/generators/doopgovuk/templates/app/views/doop/_error.html.erb +1 -3
- data/lib/generators/doopgovuk/templates/app/views/doop/_navbar.html.erb +4 -3
- data/lib/generators/doopgovuk/templates/app/views/doop/_question.html.erb +11 -7
- data/lib/generators/doopgovuk/templates/app/views/doop/_question_form.html.erb +5 -6
- data/lib/generators/doopgovuk/templates/app/views/doop/_textfield.html.erb +14 -0
- data/lib/generators/doopgovuk/templates/app/views/doop/_tooltip.html.erb +1 -1
- data/lib/generators/doopgovuk/templates/spec/features/demo_spec.rb +121 -48
- data/lib/generators/doopgovuk/templates/spec/rails_helper.rb +4 -73
- data/spec/doop_spec.rb +47 -0
- metadata +22 -12
- data/lib/generators/doopgovuk/templates/app/views/demo/_summary.html.erb +0 -10
- data/lib/generators/doopgovuk/templates/app/views/demo/_your_details.html.erb +0 -55
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YThjZGUzODA4ZDUzMzM2YWYyMTI5NDk0Yjc1NDUwZWZhYmYzMGYyMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yjc2YTZjMDU0ZWQ1NjU0ZWI1ODVhZTQ5MDQyOThiMzI5ZGFmOTZhZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTYwNGJjYzkxOTAzYjQzMGI0OGE5MzdiZTI1ZjQzMmNmN2YxYzUyMmNmOWFi
|
10
|
+
M2Y3MGVlNGM4ZWNlM2Q3MWQzZThmOTU1NzA5MWU2MjA3NDAyZTZiZjAzN2U4
|
11
|
+
ZDcyYTBiZDJlNWE5NjI1ZmY2MDM2MjEyMDNmNTJmMjQ1NDI2YWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTAxMDk5MzBkMTM4NjBkNmFlOGZlYzI0MjhlMDNhNTBiYjc0OWM1ZGM5NTQ2
|
14
|
+
ZjQ5Y2U5ZTI4ZTg5ZWRmNjQ5NmQ3NTI0ZGViZTAwNTRmNWY5ZWFhNjkzOGJm
|
15
|
+
YzYyNzc5ZWM4Yzg0YWY0ODEwYTA3NGVmOTVkZWQyM2Q4ODg3NDU=
|
Binary file
|
Binary file
|
Binary file
|
data/app/helpers/doop_helper.rb
CHANGED
@@ -23,7 +23,7 @@ module DoopHelper
|
|
23
23
|
root = doop[path]
|
24
24
|
s = ""
|
25
25
|
if question_visible? path
|
26
|
-
s = render( "doop/question", :content => block, :root => root, :path => path, :answer => root["_answer"], :title => opts[:title], :indent => opts[:indent] )
|
26
|
+
s = render( "doop/question", :content => block, :root => root, :path => path, :answer => root["_answer"], :title => opts[:title], :indent => opts[:indent], :id => question_id(path) )
|
27
27
|
end
|
28
28
|
s
|
29
29
|
end
|
@@ -53,23 +53,30 @@ module DoopHelper
|
|
53
53
|
if options.include? :last_answered
|
54
54
|
path = options[:last_answered]
|
55
55
|
if doop.last_answered == path
|
56
|
-
block.call doop[path]["_answer"]
|
56
|
+
block.call doop[path]["_answer"], question_id(path)
|
57
57
|
end
|
58
58
|
elsif options.include? :changed
|
59
59
|
path = options[:changed]
|
60
60
|
if doop.is_being_changed(path)
|
61
|
-
block.call doop[path]["_answer"]
|
61
|
+
block.call doop[path]["_answer"], question_id(path)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def tooltip &block
|
67
|
-
render( "doop/tooltip", :content => block )
|
66
|
+
def tooltip id, &block
|
67
|
+
render( "doop/tooltip", :content => block, :id => id )
|
68
68
|
end
|
69
69
|
|
70
|
-
def change_answer_tooltip &block
|
71
|
-
render( "doop/change_answer_tooltip", :content => block )
|
70
|
+
def change_answer_tooltip id, &block
|
71
|
+
render( "doop/change_answer_tooltip", :content => block, :id => id )
|
72
72
|
end
|
73
73
|
|
74
|
+
def question_id path
|
75
|
+
path.split("/").last
|
76
|
+
end
|
77
|
+
|
78
|
+
def doop_textfield name, answer, res, options = {}
|
79
|
+
s = render "doop/textfield", :answer => answer, :name => name, :res => res, :label => options[:label]
|
80
|
+
end
|
74
81
|
|
75
82
|
end
|
data/doop.gemspec
CHANGED
@@ -8,7 +8,9 @@ require 'fileutils'
|
|
8
8
|
if !Dir['doop_demo/*'].empty?
|
9
9
|
dest = "lib/generators/doopgovuk/templates"
|
10
10
|
FileUtils.cp "doop_demo/app/assets/stylesheets/demo.css.scss", "#{dest}/app/assets/stylesheets/demo.css.scss"
|
11
|
+
FileUtils.cp "doop_demo/app/assets/stylesheets/demo/application.css", "#{dest}/app/assets/stylesheets/demo/application.css"
|
11
12
|
FileUtils.cp "doop_demo/app/assets/javascripts/demo.js.coffee", "#{dest}/app/assets/javascripts/demo.js.coffee"
|
13
|
+
FileUtils.cp "doop_demo/app/assets/javascripts/demo/application.js", "#{dest}/app/assets/javascripts/demo/application.js"
|
12
14
|
FileUtils.cp "doop_demo/app/controllers/demo_controller.rb", "#{dest}/app/controllers/demo_controller.rb"
|
13
15
|
FileUtils.cp "doop_demo/app/views/layouts/application.html.erb", "#{dest}/app/views/layouts/application.html.erb"
|
14
16
|
FileUtils.cp_r "doop_demo/app/views/doop", "#{dest}/app/views"
|
@@ -33,8 +35,8 @@ Gem::Specification.new do |spec|
|
|
33
35
|
|
34
36
|
spec.add_development_dependency "bundler", "~> 1.7"
|
35
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
-
spec.add_development_dependency "rspec"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
37
39
|
|
38
|
-
spec.add_runtime_dependency "rails"
|
40
|
+
spec.add_runtime_dependency "rails", "~> 4.1"
|
39
41
|
end
|
40
42
|
|
data/lib/doop-rspec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
RSpec::Matchers.define :be_asked do
|
3
|
+
match do |q_title|
|
4
|
+
page.find_by_id( "#{q_title}-open" )
|
5
|
+
end
|
6
|
+
|
7
|
+
failure_message do |q_title|
|
8
|
+
"Expected question with id #{q_title} to be asked"
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec::Matchers.define :be_enabled do
|
14
|
+
match do |q_title|
|
15
|
+
page.find_by_id( q_title )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec::Matchers.define :be_disabled do
|
20
|
+
match do |q_title|
|
21
|
+
expect(page).to have_no_selector( "##{q_title}" )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec::Matchers.define :be_visible do
|
26
|
+
match do |id|
|
27
|
+
page.find_by_id( id )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def question text
|
32
|
+
text
|
33
|
+
end
|
34
|
+
|
35
|
+
def change_question q_title, &block
|
36
|
+
@q_title = q_title
|
37
|
+
page.find_by_id( "#{q_title}-change" ).click
|
38
|
+
expect( question q_title ).to be_asked
|
39
|
+
yield block
|
40
|
+
end
|
41
|
+
|
42
|
+
def answer_question q_title, &block
|
43
|
+
@q_title = q_title
|
44
|
+
expect( question q_title ).to be_asked
|
45
|
+
yield block
|
46
|
+
page.find_by_id( "#{q_title}-closed" )
|
47
|
+
end
|
48
|
+
|
49
|
+
def rollup_text
|
50
|
+
page.find_by_id( "#{@q_title}-change" ).text
|
51
|
+
end
|
52
|
+
|
53
|
+
def change_answer_tooltip_for q_id
|
54
|
+
"#{q_id}-change-answer-tooltip"
|
55
|
+
end
|
56
|
+
|
57
|
+
def tooltip
|
58
|
+
"#{@q_title}-tooltip"
|
59
|
+
end
|
60
|
+
|
61
|
+
def change_answer_tooltip
|
62
|
+
"#{@q_title}-change-answer-tooltip"
|
63
|
+
end
|
64
|
+
|
65
|
+
def wait_for_page p_title
|
66
|
+
page.find_by_id( "#{p_title}-page" )
|
67
|
+
end
|
68
|
+
|
69
|
+
def page_title
|
70
|
+
page.find_by_id( "page_title").text
|
71
|
+
end
|
72
|
+
|
73
|
+
def b_fill_in options = {}
|
74
|
+
options.keys.each do |key|
|
75
|
+
page.fill_in( "b_#{key}", :with => options[key] )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def change_page page_name
|
80
|
+
page.find_by_id( "#{page_name}-nav" ).click
|
81
|
+
wait_for_page page_name
|
82
|
+
end
|
data/lib/doop.rb
CHANGED
@@ -117,6 +117,7 @@ module Doop
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def each_path_elem(path)
|
120
|
+
return if path == nil
|
120
121
|
p = ""
|
121
122
|
path.split("/").select{|r| !r.empty?}.each do |n|
|
122
123
|
p += "/" + n
|
@@ -163,7 +164,7 @@ module Doop
|
|
163
164
|
next
|
164
165
|
end
|
165
166
|
|
166
|
-
q = path if path.start_with?(q) && root["_answered"] == false
|
167
|
+
q = path if path.start_with?("#{q}/") && root["_answered"] == false
|
167
168
|
end
|
168
169
|
|
169
170
|
each_path_elem( q ) { |n| self[n]["_open"] = true }
|
@@ -257,6 +258,7 @@ module Doop
|
|
257
258
|
# open all parent questions
|
258
259
|
each_path_elem_reverse(path) do |p|
|
259
260
|
self[p + "/_open"] = true
|
261
|
+
self[p + "/_answered"] = false if p != path
|
260
262
|
end
|
261
263
|
end
|
262
264
|
|
data/lib/doop/version.rb
CHANGED
data/lib/doop_controller.rb
CHANGED
@@ -12,7 +12,6 @@ module Doop
|
|
12
12
|
def initialize application_controller, &block
|
13
13
|
@controller = application_controller
|
14
14
|
@block = block
|
15
|
-
@debug_on_block = nil
|
16
15
|
@current_page_block = method( :default_current_page )
|
17
16
|
@all_pages_block = method( :default_all_pages )
|
18
17
|
end
|
@@ -25,9 +24,9 @@ module Doop
|
|
25
24
|
back_val = @controller.params["back_a_page"]
|
26
25
|
nav_path = @controller.params["nav_path"]
|
27
26
|
change_answer_path = @controller.params["change_answer_path"]
|
28
|
-
return back if back_val != nil
|
29
|
-
return change_page nav_path if nav_path != nil
|
30
|
-
return change change_answer_path if change_answer_path != nil
|
27
|
+
return back if back_val != nil
|
28
|
+
return change_page nav_path if nav_path != nil
|
29
|
+
return change change_answer_path if change_answer_path != nil
|
31
30
|
|
32
31
|
render_page in_doop { |doop| doop.answer( @controller.params ) }
|
33
32
|
end
|
@@ -80,11 +79,21 @@ module Doop
|
|
80
79
|
end
|
81
80
|
|
82
81
|
def render_page res = {}
|
82
|
+
|
83
|
+
redirect_url = res[:redirect]
|
84
|
+
|
85
|
+
if ! redirect_url.nil?
|
86
|
+
@controller.respond_to do |format|
|
87
|
+
format.js { @controller.render :js => "window.location.href='#{redirect_url}'" }
|
88
|
+
format.html { redirect_to redirect_url }
|
89
|
+
end
|
90
|
+
return
|
91
|
+
end
|
92
|
+
|
83
93
|
res[:page] = get_page
|
84
94
|
res[:page_path] = get_page_path
|
85
95
|
res[:page_title] = @doop[res[:page_path]]["_nav_name"]
|
86
96
|
res[:all_pages] = get_all_pages
|
87
|
-
res[:debug_on] = @debug_on_block != nil ? @debug_on_block.call : false
|
88
97
|
@controller.render "index", :locals => { :res => res, :doop => @doop }
|
89
98
|
end
|
90
99
|
|
@@ -136,10 +145,6 @@ module Doop
|
|
136
145
|
@all_pages_block.call
|
137
146
|
end
|
138
147
|
|
139
|
-
def debug_on &block
|
140
|
-
@debug_on_block = block
|
141
|
-
end
|
142
|
-
|
143
148
|
def load_yaml &block
|
144
149
|
@load_yaml_block = block
|
145
150
|
end
|
@@ -5,7 +5,9 @@ class DoopgovukGenerator < Rails::Generators::Base
|
|
5
5
|
|
6
6
|
def generate_layout
|
7
7
|
copy_file "app/assets/stylesheets/demo.css.scss", "app/assets/stylesheets/#{name}.css.scss"
|
8
|
+
copy_file "app/assets/stylesheets/demo/application.css", "app/assets/stylesheets/#{name}/application.css"
|
8
9
|
copy_file "app/assets/javascripts/demo.js.coffee", "app/assets/javascripts/#{name}.js.coffee"
|
10
|
+
copy_file "app/assets/javascripts/demo/application.js", "app/assets/javascripts/#{name}/application.js"
|
9
11
|
template "app/controllers/demo_controller.rb", "app/controllers/#{name}_controller.rb"
|
10
12
|
copy_file "app/views/layouts/application.html.erb", "app/views/layouts/application.html.erb"
|
11
13
|
directory "app/views/doop"
|
@@ -25,6 +27,7 @@ class DoopgovukGenerator < Rails::Generators::Base
|
|
25
27
|
|
26
28
|
gem 'govuk_frontend_toolkit'
|
27
29
|
gem 'govuk_template'
|
30
|
+
gem 'jquery-ui-rails'
|
28
31
|
|
29
32
|
gem_group :development do
|
30
33
|
gem 'rspec-rails'
|
@@ -6,4 +6,11 @@ $( () ->
|
|
6
6
|
history.pushState('back', null, null);
|
7
7
|
$( "#back_a_page" ).val( "pressed" )
|
8
8
|
$( "#back_a_page" ).click()
|
9
|
+
|
10
|
+
$('#doop_debug').dialog( { autoOpen: false, height: 400, width: 400, position: { my: 'right top', at: 'right top' } })
|
11
|
+
$("body").keydown (e) ->
|
12
|
+
if e.ctrlKey && e.keyCode == 89
|
13
|
+
$('#doop_debug').dialog( "open")
|
14
|
+
|
15
|
+
|
9
16
|
)
|
@@ -48,6 +48,10 @@ $question-fg-color: #014c73;
|
|
48
48
|
margin: 0.75em 0.75em 0.75em 0.75em;
|
49
49
|
}
|
50
50
|
|
51
|
+
li {
|
52
|
+
margin: 0.75em 0.75em 0.75em 0.75em;
|
53
|
+
}
|
54
|
+
|
51
55
|
.info_img {
|
52
56
|
float: right;
|
53
57
|
margin: 10px 10px 10px 10px;
|
@@ -75,16 +79,14 @@ $question-fg-color: #014c73;
|
|
75
79
|
.title {
|
76
80
|
padding: 0 0 0 0;
|
77
81
|
display: table-cell;
|
78
|
-
width: 80%;
|
79
82
|
vertical-align: middle;
|
80
83
|
}
|
81
84
|
|
82
85
|
.answer {
|
83
86
|
display: table-cell;
|
84
|
-
max-width: 20%;
|
85
87
|
text-align: right;
|
86
88
|
vertical-align: middle;
|
87
|
-
.button {
|
89
|
+
.button-change-answer {
|
88
90
|
@include button($question-fg-color);
|
89
91
|
margin: 0 0 0 0;
|
90
92
|
}
|
@@ -144,15 +146,13 @@ button {
|
|
144
146
|
}
|
145
147
|
|
146
148
|
.error {
|
147
|
-
margin: 0 0 10px 0;
|
148
|
-
span {
|
149
149
|
color: red;
|
150
150
|
border: 1px solid #B01117;
|
151
151
|
background-color: #FFF3CF;
|
152
|
-
padding:
|
152
|
+
padding: 2px 5px 2px 5px;
|
153
153
|
border-radius: 5px;
|
154
|
-
|
155
|
-
|
154
|
+
margin: 10px 0 10px 0;
|
155
|
+
width: auto;
|
156
156
|
}
|
157
157
|
|
158
158
|
.navbar {
|
@@ -234,6 +234,18 @@ button {
|
|
234
234
|
|
235
235
|
}
|
236
236
|
|
237
|
+
.summary_box {
|
238
|
+
display: block;
|
239
|
+
margin: 15px 0 15px 0;
|
240
|
+
max-width: 100%;
|
241
|
+
min-height: 60px;
|
242
|
+
border: solid #d1e4f2 5px;
|
243
|
+
box-shadow: 0 0 7px #ccc;
|
244
|
+
padding: 0.75em 0.75em 0.75em 0.75em;
|
245
|
+
background: #e1effa;
|
246
|
+
border-radius: 0.15em;
|
247
|
+
}
|
248
|
+
|
237
249
|
.change_answer_tooltip {
|
238
250
|
border: 1px solid #F8C830;
|
239
251
|
background-color: #FFF4B5;
|
@@ -244,4 +256,34 @@ button {
|
|
244
256
|
}
|
245
257
|
|
246
258
|
|
259
|
+
.before_you_begin {
|
260
|
+
|
261
|
+
ul {
|
262
|
+
padding: 0;
|
263
|
+
margin: 0;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
li {
|
268
|
+
padding: 32px 0 32px 88px;
|
269
|
+
border-bottom: 1px solid #ccc;
|
270
|
+
list-style-type: none;
|
271
|
+
}
|
272
|
+
|
273
|
+
li.nino {
|
274
|
+
background: url(image_path('nino-icon.png')) left center no-repeat;
|
275
|
+
}
|
276
|
+
|
277
|
+
li.passport {
|
278
|
+
background: url(image_path('passport-icon.png')) left center no-repeat;
|
279
|
+
}
|
280
|
+
li.time {
|
281
|
+
background: url(image_path('time-icon.png')) left center no-repeat;
|
282
|
+
}
|
283
|
+
|
284
|
+
}
|
285
|
+
|
286
|
+
select {
|
287
|
+
@include core-16();
|
288
|
+
}
|
247
289
|
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
3
|
require 'doop'
|
3
4
|
require 'yaml'
|
5
|
+
require 'date'
|
4
6
|
|
5
7
|
class DemoController < ApplicationController
|
6
8
|
|
@@ -13,7 +15,7 @@ class DemoController < ApplicationController
|
|
13
15
|
load_yaml do
|
14
16
|
data = params["doop_data"]
|
15
17
|
if data != nil
|
16
|
-
if Rails.env.development? || Rails.env.test?
|
18
|
+
if Rails.env.development? || Rails.env.test? || params.include?("harness")
|
17
19
|
next data
|
18
20
|
else
|
19
21
|
next ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base).decrypt_and_verify data if !Rails.env.development?
|
@@ -22,45 +24,72 @@ class DemoController < ApplicationController
|
|
22
24
|
|
23
25
|
<<-EOS
|
24
26
|
page: {
|
27
|
+
before_you_begin: {
|
28
|
+
_page: "before_you_begin",
|
29
|
+
_nav_name: "Before you begin",
|
30
|
+
},
|
25
31
|
preamble: {
|
26
32
|
_page: "preamble",
|
27
|
-
_nav_name: "
|
33
|
+
_nav_name: "Preamble",
|
28
34
|
|
29
|
-
|
30
|
-
_question: "
|
31
|
-
_answer: "No"
|
32
|
-
},
|
33
|
-
enrolled_before: {
|
34
|
-
_question: "Have you enrolled for this service before ?"
|
35
|
-
},
|
36
|
-
year_last_applied: {
|
37
|
-
_question: "What year did you last apply?"
|
35
|
+
income_more_than_50000: {
|
36
|
+
_question: "Does you or your partner have an individual income of more than £50,000 a year ?"
|
38
37
|
},
|
39
|
-
|
40
|
-
_question: "
|
38
|
+
do_you_still_want_to_apply: {
|
39
|
+
_question: "Do you still want to apply for child benefit?"
|
41
40
|
}
|
42
41
|
},
|
43
|
-
|
44
|
-
_page: "
|
45
|
-
_nav_name: "
|
42
|
+
about_you: {
|
43
|
+
_page: "about_you",
|
44
|
+
_nav_name: "About You",
|
46
45
|
|
47
46
|
your_name: {
|
48
47
|
_question: "What is your name?",
|
49
|
-
_answer: {}
|
48
|
+
_answer: {}
|
49
|
+
},
|
50
|
+
known_by_other_name: {
|
51
|
+
_question: "Have you ever been known by another surname ?"
|
52
|
+
},
|
53
|
+
previous_name: {
|
54
|
+
_question: "What name were you previously known by ?"
|
55
|
+
},
|
56
|
+
dob: {
|
57
|
+
_question: "Your date of birth"
|
58
|
+
},
|
59
|
+
your_address: {
|
60
|
+
_question: "Your address",
|
61
|
+
_answer: {}
|
62
|
+
},
|
63
|
+
lived_at_address_for_more_than_12_months: {
|
64
|
+
_question: "Have you lived at this address for more than 12 months ?"
|
65
|
+
},
|
66
|
+
last_address: {
|
67
|
+
_question: "What was your last address ?",
|
68
|
+
_answer: {}
|
50
69
|
},
|
51
|
-
|
52
|
-
_question: "What
|
53
|
-
|
70
|
+
your_phone_numbers: {
|
71
|
+
_question: "What numbers can we contact you on ?",
|
72
|
+
_answer: {}
|
73
|
+
},
|
74
|
+
have_nino: {
|
75
|
+
_question: "Do you have a national insurance number ?"
|
76
|
+
},
|
77
|
+
nino: {
|
78
|
+
_question: "What is your national insurance number ?"
|
54
79
|
}
|
55
80
|
|
56
81
|
},
|
57
|
-
|
58
|
-
_page: "
|
59
|
-
_nav_name: "
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
}
|
82
|
+
children: {
|
83
|
+
_page: "children",
|
84
|
+
_nav_name: "Children",
|
85
|
+
how_many_birth_certs: {
|
86
|
+
_question: "How many birth certificates are you sending us?"
|
87
|
+
},
|
88
|
+
#{child_yaml}
|
89
|
+
},
|
90
|
+
declaration: {
|
91
|
+
_page: "declaration",
|
92
|
+
_nav_name: "Declaration",
|
64
93
|
}
|
65
94
|
|
66
95
|
}
|
@@ -68,6 +97,26 @@ class DemoController < ApplicationController
|
|
68
97
|
|
69
98
|
end
|
70
99
|
|
100
|
+
def child_yaml
|
101
|
+
<<-EOS
|
102
|
+
child__1: {
|
103
|
+
name: {
|
104
|
+
_question: "Child's name",
|
105
|
+
_answer: {}
|
106
|
+
},
|
107
|
+
gender: {
|
108
|
+
_question: "Is this child male or female ?"
|
109
|
+
},
|
110
|
+
dob: {
|
111
|
+
_question: "Child's date of birth"
|
112
|
+
},
|
113
|
+
own_child: {
|
114
|
+
_question: "Is this child your own child ?"
|
115
|
+
}
|
116
|
+
}
|
117
|
+
EOS
|
118
|
+
end
|
119
|
+
|
71
120
|
save_yaml do |yaml|
|
72
121
|
if Rails.env.development? || Rails.env.test?
|
73
122
|
request["doop_data"] = yaml
|
@@ -78,85 +127,170 @@ class DemoController < ApplicationController
|
|
78
127
|
end
|
79
128
|
end
|
80
129
|
|
81
|
-
|
82
|
-
|
130
|
+
|
131
|
+
# PREAMBLE callbacks
|
132
|
+
|
133
|
+
on_answer "/page/preamble/income_more_than_50000" do |question,path, params, answer|
|
134
|
+
answer_with( question, { "_summary" => answer } )
|
135
|
+
enable( "/page/preamble/do_you_still_want_to_apply", answer == 'Yes' )
|
136
|
+
end
|
137
|
+
|
138
|
+
on_answer "/page/preamble/do_you_still_want_to_apply" do |question,path, params, answer|
|
139
|
+
answer_with( question, { "_summary" => "Yes" } )
|
83
140
|
end
|
84
141
|
|
85
|
-
# On answer call backs
|
86
142
|
|
87
|
-
|
143
|
+
|
144
|
+
# ABOUT YOU callbacks
|
145
|
+
|
146
|
+
on_answer "/page/about_you/your_name" do |question,path, params, answer|
|
147
|
+
res = validate( answer, ["title", "firstname", "surname"] )
|
148
|
+
next res if !res.empty?
|
149
|
+
|
150
|
+
name = "#{answer['title']} #{answer['firstname']} #{answer['middlenames']} #{answer['surname']}".squish
|
151
|
+
formatted_name = name.split( " ").map{ |n| n.capitalize }.join( " ")
|
152
|
+
answer_with( question, { "_summary" => formatted_name } )
|
153
|
+
end
|
154
|
+
|
155
|
+
on_answer "/page/about_you/known_by_other_name" do |question,path, params, answer|
|
88
156
|
answer_with( question, { "_summary" => answer } )
|
157
|
+
enable( "/page/about_you/previous_name", answer == 'Yes' )
|
89
158
|
end
|
90
159
|
|
91
|
-
on_answer "/page/
|
160
|
+
on_answer "/page/about_you/previous_name" do |question,path, params, answer|
|
161
|
+
res = validate( answer )
|
162
|
+
next res if !res.empty?
|
92
163
|
answer_with( question, { "_summary" => answer } )
|
93
|
-
enable( "/page/preamble/year_last_applied", answer == "Yes" )
|
94
164
|
end
|
95
165
|
|
96
|
-
on_answer "/page/
|
166
|
+
on_answer "/page/about_you/dob" do |question,path, params, answer|
|
167
|
+
d = format_date answer
|
168
|
+
next { :answer_error => "Date of birth must be formated as dd/mm/yyyy" } if d.nil?
|
169
|
+
answer_with( question, { "_summary" => d } )
|
170
|
+
end
|
171
|
+
|
172
|
+
on_answer "/page/about_you/your_address" do |question,path, params, answer|
|
173
|
+
res = validate( answer, ["address1", "address2", "address3", "postcode"] )
|
174
|
+
next res if !res.empty?
|
175
|
+
|
176
|
+
a = "#{answer['address1']}, #{answer['postcode']}"
|
177
|
+
answer_with( question, { "_summary" => a } )
|
178
|
+
end
|
179
|
+
|
180
|
+
on_answer "/page/about_you/lived_at_address_for_more_than_12_months" do |question, path, params, answer|
|
97
181
|
answer_with( question, { "_summary" => answer } )
|
182
|
+
enable( "/page/about_you/last_address", answer == 'No' )
|
98
183
|
end
|
99
184
|
|
100
|
-
on_answer "/page/
|
101
|
-
|
102
|
-
|
103
|
-
end
|
185
|
+
on_answer "/page/about_you/last_address" do |question,path, params, answer|
|
186
|
+
res = validate( answer, ["address1", "address2", "address3", "postcode"] )
|
187
|
+
next res if !res.empty?
|
104
188
|
|
105
|
-
|
189
|
+
a = "#{answer['address1']}, #{answer['postcode']}"
|
190
|
+
answer_with( question, { "_summary" => a } )
|
106
191
|
end
|
107
192
|
|
108
|
-
on_answer
|
193
|
+
on_answer "/page/about_you/your_phone_numbers" do |question,path, params, answer|
|
194
|
+
res = validate( answer, ["daytime", "evening"] )
|
195
|
+
next res if !res.empty?
|
109
196
|
answer_with( question, { "_summary" => "Provided" } )
|
110
197
|
end
|
111
198
|
|
112
|
-
on_answer
|
113
|
-
|
114
|
-
|
115
|
-
answer_with( question, { "_summary" => "#{firstname} #{surname}" } )
|
199
|
+
on_answer "/page/about_you/have_nino" do |question, path, params, answer|
|
200
|
+
answer_with( question, { "_summary" => answer } )
|
201
|
+
enable( "/page/about_you/nino", answer == 'Yes' )
|
116
202
|
end
|
117
203
|
|
118
|
-
on_answer
|
204
|
+
on_answer "/page/about_you/nino" do |question, path, params, answer|
|
205
|
+
res = validate( answer )
|
206
|
+
next res if !res.empty?
|
207
|
+
answer_with( question, { "_summary" => answer } )
|
208
|
+
end
|
119
209
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
210
|
+
on_answer "/page/children/how_many_birth_certs" do |question,path, params, answer|
|
211
|
+
res = validate( answer )
|
212
|
+
next res if !res.empty?
|
213
|
+
next { :answer_error => "Must be a number" } if !is_number answer
|
124
214
|
|
125
|
-
address1 = answer["address1"]
|
126
|
-
address2 = answer["address2"]
|
127
|
-
address3 = answer["address3"]
|
128
|
-
postcode = answer["postcode"]
|
129
|
-
summary = [address1, address2, address3, postcode].select{ |n| !n.empty? }.join( ", ")
|
130
|
-
answer_with( question, { "_summary" => summary } )
|
131
215
|
|
216
|
+
answer_with( question, { "_summary" => answer } )
|
132
217
|
end
|
133
218
|
|
134
|
-
on_answer
|
135
|
-
|
136
|
-
|
137
|
-
add( "/page/your_details/address_history/address__99", address )
|
138
|
-
renumber( "/page/your_details/address_history" )
|
139
|
-
next
|
140
|
-
end
|
219
|
+
on_answer "/page/children/child__(\\d+)/name" do |question,path, params, answer|
|
220
|
+
res = validate( answer, ["firstname", "surname"] )
|
221
|
+
next res if !res.empty?
|
141
222
|
|
142
|
-
|
223
|
+
name = "#{answer['firstname']} #{answer['middlenames']} #{answer['surname']}".squish
|
224
|
+
formatted_name = name.split( " ").map{ |n| n.capitalize }.join( " ")
|
225
|
+
answer_with( question, { "_summary" => formatted_name } )
|
143
226
|
end
|
144
227
|
|
145
|
-
on_answer
|
146
|
-
answer_with( question, { "_summary" =>
|
228
|
+
on_answer "/page/children/child__(\\d+)/gender" do |question,path, params, answer|
|
229
|
+
answer_with( question, { "_summary" => answer } )
|
230
|
+
end
|
231
|
+
|
232
|
+
on_answer "/page/children/child__(\\d+)/dob" do |question,path, params, answer|
|
233
|
+
d = format_date answer
|
234
|
+
next { :answer_error => "Date of birth must be formated as dd/mm/yyyy" } if d.nil?
|
235
|
+
answer_with( question, { "_summary" => d } )
|
236
|
+
end
|
237
|
+
|
238
|
+
on_answer "/page/children/child__(\\d+)/own_child" do |question,path, params, answer|
|
239
|
+
answer_with( question, { "_summary" => answer } )
|
147
240
|
end
|
148
241
|
|
149
|
-
on_answer
|
242
|
+
on_answer "/page/children/child__(\\d+)" do |question,path, params, answer|
|
243
|
+
if params.include?("remove_child")
|
244
|
+
remove path
|
245
|
+
renumber "/page/children"
|
246
|
+
next
|
247
|
+
end
|
248
|
+
name = doop["#{path}/name/_answer"]
|
249
|
+
answer_with( question, { "_summary" => doop["#{path}/name/_summary"] } )
|
250
|
+
end
|
251
|
+
|
252
|
+
on_answer "/page/children" do |question, path, params, answer|
|
253
|
+
if params.include?("add_child")
|
254
|
+
add( "/page/children/child__99", YAML.load( child_yaml )["child__1"] )
|
255
|
+
renumber( "/page/children" )
|
256
|
+
next
|
257
|
+
end
|
150
258
|
answer_with( question, { "_summary" => "Provided" } )
|
151
259
|
end
|
152
260
|
|
153
|
-
on_answer
|
154
|
-
|
261
|
+
on_answer "/page/declaration" do |question, path, params, answer |
|
262
|
+
{ :redirect => "https://github.com/coder36/doop" }
|
155
263
|
end
|
156
264
|
|
157
265
|
end
|
158
266
|
end
|
159
267
|
|
268
|
+
end
|
269
|
+
|
160
270
|
|
271
|
+
def format_date d
|
272
|
+
begin
|
273
|
+
return nil if d.length != 10
|
274
|
+
Date.strptime( d, "%d/%m/%Y" ).strftime( "%-d %B %Y" )
|
275
|
+
rescue
|
276
|
+
nil
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def validate answer,fields=nil
|
281
|
+
res = {}
|
282
|
+
|
283
|
+
if fields == nil
|
284
|
+
res["answer_error".to_sym] = "Can not be empty" if answer.squish.empty?
|
285
|
+
return res
|
286
|
+
end
|
287
|
+
|
288
|
+
fields.each do |f|
|
289
|
+
res["#{f}_error".to_sym] = "Can not be empty" if answer[f].squish.empty?
|
290
|
+
end
|
291
|
+
res
|
161
292
|
end
|
162
293
|
|
294
|
+
def is_number num
|
295
|
+
num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
|
296
|
+
end
|