metadata_presenter 2.7.1 → 2.10.0

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: 1fdd31511c6eb1cc78b19a16d64843881679854e2481c86fd878ce66017b4c3a
4
- data.tar.gz: 8e42b7bea3d117b46e049714f44b2ae3140bffeef11dbac9eda34b65a74e4083
3
+ metadata.gz: e03698bc80c7779212a57aaa9bbca97b5567025b950a6a6b7170fb635745e3e0
4
+ data.tar.gz: 7c3eca3a9da18aa6001791d2c5def0abacbf95b8b9baeb2be8920df804734bdd
5
5
  SHA512:
6
- metadata.gz: 1a3f106ada407c1789b53cd6d414fc958eccac06e183a073778aadf8e1708b99876496e5191189f51cf5a2d313a63ef820059bf826ef74c367aa56077e32068e
7
- data.tar.gz: b50bb6c4d5652a8a0dfb1b3b3aaee2a52181f4bac04816f51bde201869e37c0a3fc79e1d0496491294f3ccf9ee78a582a92578abc098583dec65ec1aaeb74a36
6
+ metadata.gz: a6dedb4d4413eab6222933b8096bf45c6fef7db7d51853e1a46ecaf51f4b718362bbe00776f5adfc3b3687dcf10fb6660b289d9dc930768dadfa5dc1bfbda1b9
7
+ data.tar.gz: c822f36b904e46fd6075979dd3acca19ed1e91ddcf73a5adf93ca4ad261e2da5e5507866fe890641c116ecb4695e25b16281fd5aa54304b7328b50b5a4d55b34
@@ -1,10 +1,23 @@
1
1
  module MetadataPresenter
2
2
  class Spacer < OpenStruct
3
+ def type
4
+ 'flow.spacer'
5
+ end
6
+ end
7
+
8
+ class Pointer < OpenStruct
9
+ def type
10
+ 'flow.pointer'
11
+ end
3
12
  end
4
13
 
5
14
  class Grid
6
- def initialize(service)
15
+ attr_reader :start_from
16
+
17
+ def initialize(service, start_from: nil, main_flow: [])
7
18
  @service = service
19
+ @start_from = start_from
20
+ @main_flow = main_flow
8
21
  @ordered = []
9
22
  @routes = []
10
23
  @traversed = []
@@ -21,9 +34,10 @@ module MetadataPresenter
21
34
  add_rows
22
35
  add_by_coordinates
23
36
  insert_expression_spacers
37
+ trim_pointers unless main_flow.empty?
24
38
  trim_spacers
25
39
 
26
- @ordered
40
+ @ordered = @ordered.reject(&:empty?)
27
41
  end
28
42
 
29
43
  def ordered_flow
@@ -32,12 +46,20 @@ module MetadataPresenter
32
46
  end
33
47
 
34
48
  def ordered_pages
35
- ordered_flow.reject(&:branch?)
49
+ @ordered_pages ||= ordered_flow.reject(&:branch?)
50
+ end
51
+
52
+ def flow_uuids
53
+ ordered_flow.map(&:uuid)
54
+ end
55
+
56
+ def page_uuids
57
+ ordered_pages.map(&:uuid)
36
58
  end
37
59
 
38
60
  private
39
61
 
40
- attr_reader :service
62
+ attr_reader :service, :main_flow
41
63
  attr_accessor :ordered, :traversed, :routes, :coordinates
42
64
 
43
65
  def setup_coordinates
@@ -48,21 +70,30 @@ module MetadataPresenter
48
70
  @route_from_start ||=
49
71
  MetadataPresenter::Route.new(
50
72
  service: service,
51
- traverse_from: service.start_page.uuid
73
+ traverse_from: start_from || service.start_page.uuid
52
74
  )
53
75
  end
54
76
 
55
77
  def make_grid
56
78
  traverse_all_routes
57
79
 
58
- rows = @routes.map(&:row).max
59
- columns = @routes.map { |r| r.column + r.flow_uuids.count }.max
60
- columns.times.map { rows.times.map { MetadataPresenter::Spacer.new } }
80
+ max_potential_columns.times.map do
81
+ max_potential_rows.times.map { MetadataPresenter::Spacer.new }
82
+ end
83
+ end
84
+
85
+ def max_potential_rows
86
+ @max_potential_rows ||= @routes.map(&:row).max + 1
87
+ end
88
+
89
+ def max_potential_columns
90
+ @routes.map { |r| r.column + r.flow_uuids.count }.max + 1
61
91
  end
62
92
 
63
93
  def traverse_all_routes
64
- # Always traverse the route that begins from the start page first and get
65
- # the potential routes from any branching points that exist.
94
+ # Always traverse the route from the start_from uuid. Defaulting to the
95
+ # start page of the form unless otherwise specified.
96
+ # Get all the potential routes from any branching points that exist.
66
97
  route_from_start.traverse
67
98
  @routes.append(route_from_start)
68
99
  traversed_routes = route_from_start.routes
@@ -103,13 +134,12 @@ module MetadataPresenter
103
134
 
104
135
  def add_rows
105
136
  @routes.each do |route|
106
- route.flow_uuids.each do |uuid|
107
- next if @traversed.include?(uuid)
137
+ next if @traversed.include?(route.traverse_from)
108
138
 
139
+ route.flow_uuids.each do |uuid|
109
140
  @coordinates[uuid][:row] = route.row if @coordinates[uuid][:row].nil?
110
-
111
141
  update_route_rows(route, uuid)
112
- @traversed.push(uuid)
142
+ @traversed.push(uuid) unless @traversed.include?(uuid)
113
143
  end
114
144
  end
115
145
  end
@@ -132,23 +162,58 @@ module MetadataPresenter
132
162
 
133
163
  def add_by_coordinates
134
164
  @coordinates.each do |uuid, position|
135
- # If row and column are nil then the object is detached
136
- next if position[:row].nil? || position[:column].nil?
165
+ next if detached?(position)
166
+
167
+ @ordered[position[:column]][position[:row]] = get_flow_object(uuid)
168
+ end
169
+ end
170
+
171
+ def detached?(position)
172
+ position[:row].nil? || position[:column].nil?
173
+ end
174
+
175
+ def get_flow_object(uuid)
176
+ # main_flow is always empty if the Grid is _actually_ building the main flow
177
+ return MetadataPresenter::Pointer.new(uuid: uuid) if main_flow.include?(uuid)
178
+
179
+ service.flow_object(uuid)
180
+ end
181
+
182
+ # A row should end at the first Pointer object it finds.
183
+ # Therefore replace any Pointers after the first one with Spacers.
184
+ def trim_pointers
185
+ max_potential_rows.times do |row|
186
+ first_index_of = first_pointer(row)
187
+ next unless first_index_of
137
188
 
138
- flow_object = service.flow_object(uuid)
139
- @ordered[position[:column]][position[:row]] = flow_object
189
+ next_column = first_index_of + 1
190
+ @ordered.drop(next_column).each do |column|
191
+ column[row] = MetadataPresenter::Spacer.new
192
+ end
140
193
  end
141
194
  end
142
195
 
196
+ def first_pointer(row)
197
+ row_objects = @ordered.map { |column| column[row] }
198
+ row_objects.find_index { |obj| obj.is_a?(MetadataPresenter::Pointer) }
199
+ end
200
+
143
201
  # Find the very last MetadataPresenter::Flow object in every column and
144
202
  # remove any Spacer objects after that.
145
203
  def trim_spacers
146
- @ordered.each_with_index do |column, index|
147
- last_index_of = column.rindex { |item| item.is_a?(MetadataPresenter::Flow) }
148
- @ordered[index] = @ordered[index][0..last_index_of]
204
+ @ordered.each_with_index do |column, column_number|
205
+ last_index_of = column.rindex { |item| !item.is_a?(MetadataPresenter::Spacer) }
206
+ trimmed_column = @ordered[column_number][0..last_index_of]
207
+
208
+ # We do not need any columns that only contain Spacer objects
209
+ @ordered[column_number] = only_spacers?(trimmed_column) ? [] : trimmed_column
149
210
  end
150
211
  end
151
212
 
213
+ def only_spacers?(trimmed_column)
214
+ trimmed_column.all? { |item| item.is_a?(MetadataPresenter::Spacer) }
215
+ end
216
+
152
217
  # Each branch has a certain number of exits that require their own line
153
218
  # and arrow. Insert any spacers into the necessary row in the column after
154
219
  # the one the branch is located in.
@@ -1,4 +1,5 @@
1
1
  {
2
+ "_uuid": "",
2
3
  "_type": "",
3
4
  "next": "",
4
5
  "expressions": []
@@ -27,6 +27,7 @@
27
27
  "default": "0b297048-aa4d-49b6-ac74-18e069118185",
28
28
  "conditionals": [
29
29
  {
30
+ "_uuid": "ecd60ac9-c3ea-47b1-8f79-c4e42df9a9dd",
30
31
  "_type": "if",
31
32
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
32
33
  "expressions": [
@@ -60,6 +61,7 @@
60
61
  "default": "05c3306c-0a39-42d2-9e0f-93fd49248f4e",
61
62
  "conditionals": [
62
63
  {
64
+ "_uuid": "51b4eda2-a08d-4ab3-a8cb-565091f39424",
63
65
  "_type": "if",
64
66
  "next": "d4342dfd-0d09-4a91-a0ea-d7fd67e706cc",
65
67
  "expressions": [
@@ -72,6 +74,7 @@
72
74
  ]
73
75
  },
74
76
  {
77
+ "_uuid": "0a799cea-f5a4-4b89-9ffe-78515b5cb1d7",
75
78
  "_type": "if",
76
79
  "next": "91e9f7c6-2f75-4b7d-9eb5-0cf352f7be66",
77
80
  "expressions": [
@@ -111,6 +114,7 @@
111
114
  "default": "ef2cafe3-37e2-4533-9b0c-09a970cd38d4",
112
115
  "conditionals": [
113
116
  {
117
+ "_uuid": "0d3410db-1d05-4a32-bafb-65b52408b89b",
114
118
  "_type": "if",
115
119
  "next": "8002df6e-29ab-4cdf-b520-1d7bb931a28f",
116
120
  "expressions": [
@@ -144,6 +148,7 @@
144
148
  "default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
145
149
  "conditionals": [
146
150
  {
151
+ "_uuid": "88b97d53-1da7-4464-a0a5-633a9ffd3d3d",
147
152
  "_type": "if",
148
153
  "next": "b5efc09c-ece7-45ae-b0b3-8a7905e25040",
149
154
  "expressions": [
@@ -177,6 +182,7 @@
177
182
  "default": "dc7454f9-4186-48d7-b055-684d57bbcdc7",
178
183
  "conditionals": [
179
184
  {
185
+ "_uuid": "8a0c225f-b078-4728-a181-c3bdd343801c",
180
186
  "_type": "if",
181
187
  "next": "bc666714-c0a2-4674-afe5-faff2e20d847",
182
188
  "expressions": [
@@ -189,6 +195,7 @@
189
195
  ]
190
196
  },
191
197
  {
198
+ "_uuid": "7d1b29ac-f310-4246-bab9-957c9b2a20f2",
192
199
  "_type": "if",
193
200
  "next": "e2887f44-5e8d-4dc0-b1de-496ab6039430",
194
201
  "expressions": [
@@ -228,6 +235,7 @@
228
235
  "default": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb",
229
236
  "conditionals": [
230
237
  {
238
+ "_uuid": "15e8076f-75ac-4310-89b3-d2b5962babd4",
231
239
  "_type": "or",
232
240
  "next": "2cc66e51-2c14-4023-86bf-ded49887cdb2",
233
241
  "expressions": [
@@ -246,6 +254,7 @@
246
254
  ]
247
255
  },
248
256
  {
257
+ "_uuid": "0811ac93-a73e-4a2d-a8f1-68cc8a52ca69",
249
258
  "_type": "and",
250
259
  "next": "f6c51f88-7be8-4cb7-bbfc-6c905727a051",
251
260
  "expressions": [
@@ -291,6 +300,7 @@
291
300
  "default": "941137d7-a1da-43fd-994a-98a4f9ea6d46",
292
301
  "conditionals": [
293
302
  {
303
+ "_uuid": "5ce78103-3935-4c57-9278-79bf2b8b93b1",
294
304
  "_type": "and",
295
305
  "next": "56e80942-d0a4-405a-85cd-bd1b100013d6",
296
306
  "expressions": [
@@ -315,6 +325,7 @@
315
325
  ]
316
326
  },
317
327
  {
328
+ "_uuid": "d45c65c7-a9b4-4128-8562-89bd4f0167ec",
318
329
  "_type": "or",
319
330
  "next": "6324cca4-7770-4765-89b9-1cdc41f49c8b",
320
331
  "expressions": [
@@ -21,6 +21,7 @@
21
21
  "default": "f475d6fd-0ea4-45d5-985e-e1a7c7a5b992",
22
22
  "conditionals": [
23
23
  {
24
+ "_uuid": "b753b3f0-188e-4435-a84d-894557ba2007",
24
25
  "_type": "if",
25
26
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
26
27
  "expressions": [
@@ -33,6 +34,7 @@
33
34
  ]
34
35
  },
35
36
  {
37
+ "_uuid": "2622668f-7ad2-4130-9d4f-274ff540b7e8",
36
38
  "_type": "if",
37
39
  "next": "3a584d15-6805-4a21-bc05-b61c3be47857",
38
40
  "expressions": [
@@ -102,6 +104,7 @@
102
104
  "default": "d80a2225-63c3-4944-873f-504b61311a15",
103
105
  "conditionals": [
104
106
  {
107
+ "_uuid": "f51a3793-53dc-4537-b84b-399a59c103f4",
105
108
  "_type": "if",
106
109
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
107
110
  "expressions": [
@@ -21,6 +21,7 @@
21
21
  "default": "be130ac1-f33d-4845-807d-89b23b90d205",
22
22
  "conditionals": [
23
23
  {
24
+ "_uuid": "39bab61b-93d5-486c-8e02-cea0aeb48215",
24
25
  "_type": "if",
25
26
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
26
27
  "expressions": [
@@ -33,6 +34,7 @@
33
34
  ]
34
35
  },
35
36
  {
37
+ "_uuid": "96810acb-b5e6-45c1-bacb-6b7a10c0d3a0",
36
38
  "_type": "if",
37
39
  "next": "3a584d15-6805-4a21-bc05-b61c3be47857",
38
40
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "457ca1ed-b188-4980-bf9b-01f8dde5ffe9",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -21,6 +21,7 @@
21
21
  "default": "f475d6fd-0ea4-45d5-985e-e1a7c7a5b992",
22
22
  "conditionals": [
23
23
  {
24
+ "_uuid": "91965137-99bd-4bcf-b9c3-61afaa7fc5c0",
24
25
  "_type": "if",
25
26
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
26
27
  "expressions": [
@@ -33,6 +34,7 @@
33
34
  ]
34
35
  },
35
36
  {
37
+ "_uuid": "10396fae-c28c-445c-a633-14d6439271a8",
36
38
  "_type": "if",
37
39
  "next": "3a584d15-6805-4a21-bc05-b61c3be47857",
38
40
  "expressions": [
@@ -90,6 +92,7 @@
90
92
  "default": "d80a2225-63c3-4944-873f-504b61311a15",
91
93
  "conditionals": [
92
94
  {
95
+ "_uuid": "a2312258-bcbe-48b0-b30c-37d51caaf756",
93
96
  "_type": "if",
94
97
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
95
98
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "b65ad907-d415-4139-8955-9e9a3d119b50",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "2d87a4bf-d532-48f5-956c-31ba5d046f63",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -96,6 +97,7 @@
96
97
  "default": "3a584d15-6805-4a21-bc05-b61c3be47857",
97
98
  "conditionals": [
98
99
  {
100
+ "_uuid": "daccbe9d-f0dc-41eb-8182-c542bfaa015c",
99
101
  "_type": "if",
100
102
  "next": "13ecf9bd-5064-4cad-baf8-3dfa091928cb",
101
103
  "expressions": [
@@ -108,6 +110,7 @@
108
110
  ]
109
111
  },
110
112
  {
113
+ "_uuid": "b4eaf825-a523-4372-a15b-072b016b0ead",
111
114
  "_type": "if",
112
115
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
113
116
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "830295ec-8758-4128-a8ae-c90d2fb3b840",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -84,6 +85,7 @@
84
85
  "default": "3a584d15-6805-4a21-bc05-b61c3be47857",
85
86
  "conditionals": [
86
87
  {
88
+ "_uuid": "957e523e-663f-4cc9-9e8a-36b15bcbcaec",
87
89
  "_type": "if",
88
90
  "next": "13ecf9bd-5064-4cad-baf8-3dfa091928cb",
89
91
  "expressions": [
@@ -96,6 +98,7 @@
96
98
  ]
97
99
  },
98
100
  {
101
+ "_uuid": "b89817e7-c426-4a9a-8814-6ca2ce56f643",
99
102
  "_type": "if",
100
103
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
101
104
  "expressions": [