@@ -7,15 +7,13 @@ module BetterTogether
77 class NavigationBuilder < Builder # rubocop:todo Metrics/ClassLength
88 class << self
99 def seed_data
10- ::BetterTogether ::NavigationArea . transaction do
11- I18n . with_locale ( :en ) do
12- build_header
13- build_host
14- build_better_together
15- build_footer
10+ I18n . with_locale ( :en ) do
11+ build_header
12+ build_host
13+ build_better_together
14+ build_footer
1615
17- create_unassociated_pages
18- end
16+ create_unassociated_pages
1917 end
2018 end
2119
@@ -45,26 +43,28 @@ def build_better_together # rubocop:todo Metrics/MethodLength
4543 ]
4644 )
4745
48- ::BetterTogether ::NavigationArea . create! do |area |
46+ area = ::BetterTogether ::NavigationArea . create! do |area |
4947 area . name = 'Better Together'
5048 area . slug = 'better-together'
5149 area . visible = true
5250 area . protected = true
51+ end
5352
54- # Create Host Navigation Item
55- better_together_nav_item = area . navigation_items . build (
56- title : 'Powered with <3 by Better Together' ,
57- slug : 'better-together-nav' ,
58- position : 0 ,
59- visible : true ,
60- protected : true ,
61- item_type : 'dropdown' ,
62- url : '#'
63- )
53+ # Create Host Navigation Item
54+ better_together_nav_item = area . navigation_items . create! (
55+ title : 'Powered with <3 by Better Together' ,
56+ slug : 'better-together-nav' ,
57+ position : 0 ,
58+ visible : true ,
59+ protected : true ,
60+ item_type : 'dropdown' ,
61+ url : '#'
62+ )
6463
65- # Add children to Better Together Navigation Item
66- better_together_nav_item . build_children ( better_together_pages , area )
67- end
64+ # Add children to Better Together Navigation Item
65+ better_together_nav_item . build_children ( better_together_pages , area . reload )
66+
67+ area . save!
6868 end
6969 end
7070
@@ -133,14 +133,16 @@ def build_footer # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
133133 )
134134
135135 # Create Platform Footer Navigation Area and its Navigation Items
136- ::BetterTogether ::NavigationArea . create! do |area |
136+ area = ::BetterTogether ::NavigationArea . create! do |area |
137137 area . name = 'Platform Footer'
138138 area . slug = 'platform-footer'
139139 area . visible = true
140140 area . protected = true
141-
142- area . build_page_navigation_items ( footer_pages )
143141 end
142+
143+ area . reload . build_page_navigation_items ( footer_pages )
144+
145+ area . save!
144146 end
145147 end
146148
@@ -164,103 +166,107 @@ def build_header # rubocop:todo Metrics/MethodLength
164166 )
165167
166168 # Create Platform Header Navigation Area
167- ::BetterTogether ::NavigationArea . create! do |area |
169+ area = ::BetterTogether ::NavigationArea . create! do |area |
168170 area . name = 'Platform Header'
169171 area . slug = 'platform-header'
170172 area . visible = true
171173 area . protected = true
172-
173- area . build_page_navigation_items ( header_pages )
174174 end
175+
176+ area . build_page_navigation_items ( header_pages )
177+
178+ area . save!
175179 end
176180 end
177181
178182 # rubocop:todo Metrics/MethodLength
179183 def build_host # rubocop:todo Metrics/MethodLength
180184 I18n . with_locale ( :en ) do # rubocop:todo Metrics/BlockLength
181185 # Create Platform Header Host Navigation Area and its Navigation Items
182- ::BetterTogether ::NavigationArea . create! do |area | # rubocop:todo Metrics/BlockLength
186+ area = ::BetterTogether ::NavigationArea . create! do |area | # rubocop:todo Metrics/BlockLength
183187 area . name = 'Platform Host'
184188 area . slug = 'platform-host'
185189 area . visible = true
186190 area . protected = true
191+ end
187192
188- # byebug
189- # Create Host Navigation Item
190- host_nav = area . navigation_items . build (
191- title : 'Host' ,
192- slug : 'host-nav' ,
193- position : 0 ,
194- visible : true ,
195- protected : true ,
196- item_type : 'dropdown' ,
197- url : '#'
198- )
193+ # byebug
194+ # Create Host Navigation Item
195+ host_nav = area . navigation_items . create! (
196+ title : 'Host' ,
197+ slug : 'host-nav' ,
198+ position : 0 ,
199+ visible : true ,
200+ protected : true ,
201+ item_type : 'dropdown' ,
202+ url : '#'
203+ )
199204
200- # Add children to Host Navigation Item
201- host_nav_children = [
202- {
203- title : 'Dashboard' ,
204- slug : 'host-dashboard' ,
205- position : 0 ,
206- item_type : 'link' ,
207- route_name : 'host_dashboard_path'
208- } ,
209- {
210- title : 'Communities' ,
211- slug : 'communities' ,
212- position : 1 ,
213- item_type : 'link' ,
214- route_name : 'communities_path'
215- } ,
216- {
217- title : 'Navigation Areas' ,
218- slug : 'navigation-areas' ,
219- position : 2 ,
220- item_type : 'link' ,
221- route_name : 'navigation_areas_path'
222- } ,
223- {
224- title : 'Pages' ,
225- slug : 'pages' ,
226- position : 3 ,
227- item_type : 'link' ,
228- route_name : 'pages_path'
229- } ,
230- {
231- title : 'People' ,
232- slug : 'people' ,
233- position : 4 ,
234- item_type : 'link' ,
235- route_name : 'people_path'
236- } ,
237- {
238- title : 'Platforms' ,
239- slug : 'platforms' ,
240- position : 5 ,
241- item_type : 'link' ,
242- route_name : 'platforms_path'
243- } ,
244- {
245- title : 'Roles' ,
246- slug : 'roles' ,
247- position : 6 ,
248- item_type : 'link' ,
249- route_name : 'roles_path'
250- } ,
251- {
252- title : 'Resource Permissions' ,
253- slug : 'resource_permissions' ,
254- position : 7 ,
255- item_type : 'link' ,
256- route_name : 'resource_permissions_path'
257- }
258- ]
205+ # Add children to Host Navigation Item
206+ host_nav_children = [
207+ {
208+ title : 'Dashboard' ,
209+ slug : 'host-dashboard' ,
210+ position : 0 ,
211+ item_type : 'link' ,
212+ route_name : 'host_dashboard_path'
213+ } ,
214+ {
215+ title : 'Communities' ,
216+ slug : 'communities' ,
217+ position : 1 ,
218+ item_type : 'link' ,
219+ route_name : 'communities_path'
220+ } ,
221+ {
222+ title : 'Navigation Areas' ,
223+ slug : 'navigation-areas' ,
224+ position : 2 ,
225+ item_type : 'link' ,
226+ route_name : 'navigation_areas_path'
227+ } ,
228+ {
229+ title : 'Pages' ,
230+ slug : 'pages' ,
231+ position : 3 ,
232+ item_type : 'link' ,
233+ route_name : 'pages_path'
234+ } ,
235+ {
236+ title : 'People' ,
237+ slug : 'people' ,
238+ position : 4 ,
239+ item_type : 'link' ,
240+ route_name : 'people_path'
241+ } ,
242+ {
243+ title : 'Platforms' ,
244+ slug : 'platforms' ,
245+ position : 5 ,
246+ item_type : 'link' ,
247+ route_name : 'platforms_path'
248+ } ,
249+ {
250+ title : 'Roles' ,
251+ slug : 'roles' ,
252+ position : 6 ,
253+ item_type : 'link' ,
254+ route_name : 'roles_path'
255+ } ,
256+ {
257+ title : 'Resource Permissions' ,
258+ slug : 'resource_permissions' ,
259+ position : 7 ,
260+ item_type : 'link' ,
261+ route_name : 'resource_permissions_path'
262+ }
263+ ]
259264
260- host_nav_children . each do |child_attrs |
261- host_nav . children . build ( child_attrs . merge ( visible : true , protected : true , navigation_area : area ) )
262- end
265+ host_nav_children . each do |child_attrs |
266+ host_nav . children . create! ( child_attrs . merge ( visible : true , protected : true , navigation_area : area ) )
263267 end
268+
269+ area . reload . save!
264270 end
265271 end
266272 # rubocop:enable Metrics/MethodLength
0 commit comments