metadata_presenter 2.12.0 → 2.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 120ed63601d40a759fe3176e0555341c7cc7220cc1bac5a87cf58d5989d670fa
4
- data.tar.gz: 84e748f9388d3208ade3db02f37f662e8ab4e7fca1aef8488411dd05dabe6a93
3
+ metadata.gz: 8a349beb4173c1f6361b321a95e36a407c5f5361153403cae2fbd15ffb7b8840
4
+ data.tar.gz: 8e06745f55b04f1074a5da27b77e4f9cb720b95bfb328672c14cca059e4a3003
5
5
  SHA512:
6
- metadata.gz: 2bd170ba65c91f723ada48baff42bd90228cbf22f5aaa56eb158203b3f497037635bdeaf8e17f760556ad6bf55fb6ed922727c2bae9914e6f9e81cad54d708da
7
- data.tar.gz: 8045ff1fe8a8366bedc081a4864687e7da1f56119ca71285f03bb3457787c9644513e8f54195b5fc6feb8cdbb3fc6d899bbf86b683109f910235e81a01288a05
6
+ metadata.gz: 01f7f93e1b0d7a058ff856cb27ce07ec816b060e2b2299cec55be298aa046809a9e9ba82f9f770205b4fe647a8d3e046e1a0b10afad0a78fc5190e52aa28fc5f
7
+ data.tar.gz: 5cb518f2fb78f26ae06d447d0d1a7a7f2b84de9b4f24057079464bdcd77945c36430c4718c49d1bc2a04ec48ab1cfb422fbfc02c952a516ca83d7cae3e29a2ff
@@ -7,19 +7,15 @@ module MetadataPresenter
7
7
  end
8
8
 
9
9
  def number
10
- use_new_column? ? new_column : existing_column
10
+ [existing_column, new_column].compact.max
11
11
  end
12
12
 
13
13
  private
14
14
 
15
15
  attr_reader :uuid, :coordinates, :new_column
16
16
 
17
- def use_new_column?
18
- existing_column.nil? || new_column > existing_column
19
- end
20
-
21
17
  def existing_column
22
- @existing_column ||= @coordinates.uuid_column(uuid)
18
+ @coordinates.uuid_column(uuid)
23
19
  end
24
20
  end
25
21
  end
@@ -35,14 +35,6 @@ module MetadataPresenter
35
35
  positions[uuid]
36
36
  end
37
37
 
38
- def occupied?(column, row, new_object_uuid)
39
- positions.any? do |uuid, position|
40
- position[:column] == column &&
41
- position[:row] == row &&
42
- new_object_uuid != uuid
43
- end
44
- end
45
-
46
38
  def positions_in_column(column_number)
47
39
  positions.select { |_, position| position[:column] == column_number }
48
40
  end
@@ -185,7 +185,10 @@ module MetadataPresenter
185
185
  position = coordinates.position(uuid)
186
186
  next if detached?(position)
187
187
 
188
- @ordered[position[:column]][position[:row]] = get_flow_object(uuid)
188
+ column = position[:column]
189
+ row = position[:row]
190
+ insert_spacer(column, row) if occupied?(column, row, uuid)
191
+ @ordered[column][row] = get_flow_object(uuid)
189
192
  end
190
193
  end
191
194
 
@@ -193,6 +196,11 @@ module MetadataPresenter
193
196
  position[:row].nil? || position[:column].nil?
194
197
  end
195
198
 
199
+ def occupied?(column, row, uuid)
200
+ object = @ordered[column][row]
201
+ object.is_a?(MetadataPresenter::Flow) && object.uuid != uuid
202
+ end
203
+
196
204
  def get_flow_object(uuid)
197
205
  # main_flow is always empty if the Grid is _actually_ building the main flow
198
206
  return MetadataPresenter::Pointer.new(uuid: uuid) if main_flow.include?(uuid)
@@ -245,14 +253,16 @@ module MetadataPresenter
245
253
  previous_uuid = ''
246
254
  next_column = coordinates.uuid_column(branch.uuid) + 1
247
255
  exiting_destinations_from_branch(branch).each_with_index do |uuid, row|
248
- if uuid == previous_uuid
249
- @ordered[next_column].insert(row, MetadataPresenter::Spacer.new)
250
- end
256
+ insert_spacer(next_column, row) if uuid == previous_uuid
251
257
  previous_uuid = uuid
252
258
  end
253
259
  end
254
260
  end
255
261
 
262
+ def insert_spacer(column, row)
263
+ @ordered[column].insert(row, MetadataPresenter::Spacer.new)
264
+ end
265
+
256
266
  # Any destinations exiting the branch that have not already been traversed.
257
267
  # This removes any branch destinations that already exist on other rows. If
258
268
  # that is the case then the arrow will flow towards whatever row that object
@@ -17,11 +17,7 @@ module MetadataPresenter
17
17
 
18
18
  return ROW_ZERO if place_on_row_zero?
19
19
 
20
- if object_above.branch? && uuid != object_above.uuid
21
- coordinates.uuid_row(object_above.uuid) + number_of_destinations
22
- else
23
- existing_row.nil? ? current_row : [current_row, existing_row].max
24
- end
20
+ [current_row, existing_row, potential_row].compact.max
25
21
  end
26
22
 
27
23
  private
@@ -32,13 +28,32 @@ module MetadataPresenter
32
28
  @existing_row ||= coordinates.uuid_row(uuid)
33
29
  end
34
30
 
31
+ def potential_row
32
+ return unless object_above.branch? && uuid != object_above.uuid
33
+
34
+ coordinates.uuid_row(object_above.uuid) + number_of_destinations
35
+ end
36
+
35
37
  def first_row?
36
38
  @first_row ||= route.row.zero?
37
39
  end
38
40
 
39
41
  def object_above
40
42
  @object_above ||=
41
- service.flow_object(coordinates.uuid_at_position(uuid_column, row_above))
43
+ service.flow_object(
44
+ coordinates.uuid_at_position(uuid_column, row_number_for_object_above)
45
+ )
46
+ end
47
+
48
+ def row_number_for_object_above
49
+ column_objects.map { |_, p| p[:row] if p[:row] < current_row }.compact.max.to_i
50
+ end
51
+
52
+ def column_objects
53
+ objects_in_column = coordinates.positions_in_column(uuid_column).reject do |u, p|
54
+ u == uuid || p[:row].nil?
55
+ end
56
+ objects_in_column.sort_by { |_, p| p[:row] }
42
57
  end
43
58
 
44
59
  # Takes into account the 'or' type of conditionals which requires an
@@ -51,10 +66,6 @@ module MetadataPresenter
51
66
  @uuid_column ||= coordinates.uuid_column(uuid)
52
67
  end
53
68
 
54
- def row_above
55
- @row_above ||= route.row - 1
56
- end
57
-
58
69
  # If an object has already been positioned on row 0 then leave it there.
59
70
  # If the object is a checkanswers or confirmation type then always place it
60
71
  # on row 0.
@@ -78,12 +78,6 @@
78
78
  "default": ""
79
79
  }
80
80
  },
81
- "f475d6fd-0ea4-45d5-985e-e1a7c7a5b992": {
82
- "_type": "flow.page",
83
- "next": {
84
- "default": "be130ac1-f33d-4845-807d-89b23b90d205"
85
- }
86
- },
87
81
  "be130ac1-f33d-4845-807d-89b23b90d205": {
88
82
  "_type": "flow.page",
89
83
  "next": {
@@ -399,62 +393,6 @@
399
393
  }
400
394
  ]
401
395
  },
402
- {
403
- "_id": "page.j",
404
- "url": "page-j",
405
- "body": "Page J body",
406
- "lede": "",
407
- "_type": "page.singlequestion",
408
- "_uuid": "f475d6fd-0ea4-45d5-985e-e1a7c7a5b992",
409
- "heading": "Page J",
410
- "components": [
411
- {
412
- "_id": "page-j_radios_1",
413
- "hint": "",
414
- "name": "page-j_radios_1",
415
- "_type": "radios",
416
- "_uuid": "c2f4ad91-d7ad-4aa9-b7e9-be287a7248d3",
417
- "items": [
418
- {
419
- "_id": "page-j_radios_1_item_1",
420
- "hint": "",
421
- "name": "page-j_radios_1",
422
- "_type": "radio",
423
- "_uuid": "2e7e602d-e1af-4757-a126-75363fad80f3",
424
- "label": "Item 1",
425
- "value": "value-1",
426
- "errors": {},
427
- "legend": "Item 1",
428
- "collection": "components",
429
- "validation": {
430
- "required": true
431
- }
432
- },
433
- {
434
- "_id": "page-j_radios_1_item_2",
435
- "hint": "",
436
- "name": "page-j_radios_1",
437
- "_type": "radio",
438
- "_uuid": "4548747d-81c0-49a5-b4f1-32291b7c3415",
439
- "label": "Item 2",
440
- "value": "value-2",
441
- "errors": {},
442
- "legend": "Item 2",
443
- "collection": "components",
444
- "validation": {
445
- "required": true
446
- }
447
- }
448
- ],
449
- "errors": {},
450
- "legend": "Page J",
451
- "collection": "components",
452
- "validation": {
453
- "required": true
454
- }
455
- }
456
- ]
457
- },
458
396
  {
459
397
  "_id": "page.k",
460
398
  "url": "page-k",
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.12.0'.freeze
2
+ VERSION = '2.12.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 2.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms