metadata_presenter 2.14.0 → 2.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42603519130d7f5029066830adc145fe8800465f38493f5acfe37943623210b9
4
- data.tar.gz: 9cb6b248e8246c2b0145f6d746043680494fd7292a36d2e18dff619cf55af8dc
3
+ metadata.gz: b7184f97740de68d7fb003316d4d2bc5a822ccdfa13749c858b638b64b7f59e6
4
+ data.tar.gz: 6d540b23868160de18de5c3ef87c5a9ef2f7ecc279ed72e4e2c9ab5bb3c0369d
5
5
  SHA512:
6
- metadata.gz: 354e08330a417e94180c4686e058eac97155e2b62440faabdf1e10b17d469d2e7b93a0fd155d5d3eeb71549f2fc6725c78e048ac442c5a5b6dfeaae3f81c09e9
7
- data.tar.gz: 22011caef879554eb407f7bbda3726b5255178eb51b15e095c3409ec84f97df6ed565382f51651801f0ee9686b895ffc1db92ee9f4e715baa957e4378b88eee9
6
+ metadata.gz: 10c4c37e567f4b1c58546627c480ceda59a1c65bdafeacf65014c044a380a03a7f22f40180674054f5614adc742fd95aca4624b6d8a1af3ac2158b96a0ebbac0
7
+ data.tar.gz: 3eb7004878552017ce8c9e180675330d824461234ad410f11384b788eeb5ab46a480526020a7edf4efd6ece8d1f7588d0cfd2ed3561fe9270d2c936717072b4b
@@ -9,6 +9,10 @@ module MetadataPresenter
9
9
 
10
10
  def number
11
11
  if service.flow_object(uuid).branch?
12
+ # Even though we are associating the column number to a specific flow object
13
+ # in the Coordinates model we do not use column_number + 1 as we are
14
+ # updating the position for the Spacers that exist for a branch which
15
+ # are always in the same column as the branch object itself.
12
16
  coordinates.set_branch_spacers_column(uuid, column_number)
13
17
  end
14
18
 
@@ -39,7 +39,7 @@ module MetadataPresenter
39
39
  end
40
40
 
41
41
  def set_branch_spacers_column(branch_uuid, column)
42
- branch_spacers[branch_uuid].each do |position|
42
+ branch_spacers[branch_uuid].each do |_, position|
43
43
  position[:column] = column
44
44
  end
45
45
  end
@@ -50,7 +50,7 @@ module MetadataPresenter
50
50
  # to draw an arrow therefore we increment the row number from the branches
51
51
  # calculated starting row
52
52
  def set_branch_spacers_row(branch_uuid, starting_row)
53
- branch_spacers[branch_uuid].each.with_index(starting_row) do |position, row|
53
+ branch_spacers[branch_uuid].each.with_index(starting_row) do |(_, position), row|
54
54
  position[:row] = row
55
55
  end
56
56
  end
@@ -64,12 +64,14 @@ module MetadataPresenter
64
64
  service.flow.keys.index_with { |_uuid| { row: nil, column: nil } }
65
65
  end
66
66
 
67
- # This also takes into account the 'or' expressions which
67
+ # This also takes into account the 'OR' expressions which
68
68
  # need an additional line for an arrow.
69
69
  def setup_branch_spacers
70
70
  service.branches.each.with_object({}) do |branch, hash|
71
71
  destinations = exiting_destinations_from_branch(branch)
72
- hash[branch.uuid] = destinations.map { { row: nil, column: nil } }
72
+ hash[branch.uuid] = destinations.index_with do |_uuid|
73
+ { row: nil, column: nil }
74
+ end
73
75
  end
74
76
  end
75
77
  end
@@ -28,7 +28,7 @@ module MetadataPresenter
28
28
 
29
29
  return ROW_ZERO if place_on_row_zero?
30
30
 
31
- existing_row || [current_row, potential_row].compact.max
31
+ existing_row || [current_row, potential_row, branch_spacer_row].compact.max
32
32
  end
33
33
  end
34
34
 
@@ -36,27 +36,60 @@ module MetadataPresenter
36
36
  @existing_row ||= coordinates.uuid_row(uuid)
37
37
  end
38
38
 
39
+ # This looks for any branches in the current column and checks that there is
40
+ # enough space for the any branch conditionals before returning a row number.
39
41
  def potential_row
40
42
  return if branches_in_column.empty?
41
43
 
42
- row_numbers = branches_in_column.map do |uuid, _|
43
- coordinates.branch_spacers[uuid].map { |position| position[:row] }
44
+ row_numbers = branches_in_column.map do |branch_uuid, _|
45
+ coordinates.branch_spacers[branch_uuid].map { |_, position| position[:row] }
44
46
  end
45
47
  row_numbers.flatten.max + 1
46
48
  end
47
49
 
50
+ # This looks at the previous column and finds any branches that link to the
51
+ # current object. If any are found it checks for rows numbers that relate
52
+ # to the current objects UUID in the branch spacers hash and defaults to
53
+ # returning the highest row number.
54
+ def branch_spacer_row
55
+ return if spacers_for_current_object.empty?
56
+
57
+ spacers_for_current_object.map { |position| position[:row] }.max
58
+ end
59
+
48
60
  def first_row?
49
61
  @first_row ||= route.row.zero?
50
62
  end
51
63
 
52
64
  def branches_in_column
53
- @branches_in_column ||= coordinates.positions_in_column(uuid_column).select do |key, position|
65
+ @branches_in_column ||= branches(uuid_column)
66
+ end
67
+
68
+ def branches_in_previous_column
69
+ @branches_in_previous_column ||= branches(uuid_column - 1)
70
+ end
71
+
72
+ def branches(column_number)
73
+ coordinates.positions_in_column(column_number).select do |key, position|
54
74
  next if uuid == key || position[:row].blank?
55
75
 
56
76
  service.flow_object(key).branch?
57
77
  end
58
78
  end
59
79
 
80
+ def spacers_for_current_object
81
+ @spacers_for_current_object ||= begin
82
+ spacer_positions = branches_in_previous_column.select do |key, _|
83
+ coordinates.branch_spacers[key]
84
+ end
85
+
86
+ current_object_spacers = spacer_positions.map do |branch_uuid, _|
87
+ coordinates.branch_spacers[branch_uuid][uuid]
88
+ end
89
+ current_object_spacers.compact
90
+ end
91
+ end
92
+
60
93
  def uuid_column
61
94
  @uuid_column ||= coordinates.uuid_column(uuid)
62
95
  end
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.14.0'.freeze
2
+ VERSION = '2.14.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.14.0
4
+ version: 2.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms