Commit 9e6d7e74f4c2e584c1210635c0e53f55782e6b86
1 parent
16987144
Exists in
master
and in
47 other branches
Fix software box organize task
Showing
1 changed file
with
19 additions
and
16 deletions
Show diff stats
src/noosfero-spb/spb_migrations/lib/tasks/box_organizer.rake
... | ... | @@ -6,10 +6,14 @@ namespace :software do |
6 | 6 | software_template = Community["software"] |
7 | 7 | next unless software_template.is_template? |
8 | 8 | |
9 | + existing_blocks = Block.count | |
10 | + | |
11 | + puts "Last block id: #{Block.last.id}" | |
12 | + puts "Create template boxes:" | |
13 | + | |
9 | 14 | software_area_four = software_template.boxes.find_by_position 4 |
10 | 15 | four = false |
11 | 16 | |
12 | - puts "Area Four Blocks" | |
13 | 17 | if software_area_four.blocks.first.class != BreadcrumbsPlugin::ContentBreadcrumbsBlock |
14 | 18 | template_breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" |
15 | 19 | template_breadcrumbs_block.settings[:fixed] = true |
... | ... | @@ -19,7 +23,6 @@ namespace :software do |
19 | 23 | software_area_four.blocks << template_breadcrumbs_block |
20 | 24 | software_area_four.save! |
21 | 25 | |
22 | - # Puts the breadcrumbs as the first one on area four | |
23 | 26 | pos = software_area_four.blocks.order(:position).first.position |
24 | 27 | change_block_pos(software_area_four, template_breadcrumbs_block, pos) |
25 | 28 | print "." |
... | ... | @@ -31,7 +34,6 @@ namespace :software do |
31 | 34 | software_area_two = software_template.boxes.find_by_position 2 |
32 | 35 | two = false |
33 | 36 | |
34 | - puts "Area Two Blocks" | |
35 | 37 | if software_area_two.blocks.last.class != SoftwareEventsBlock |
36 | 38 | template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" |
37 | 39 | template_software_events.title = "Outros Eventos" |
... | ... | @@ -41,7 +43,6 @@ namespace :software do |
41 | 43 | software_area_two.blocks << template_software_events |
42 | 44 | software_area_two.save! |
43 | 45 | |
44 | - # Puts the breadcrumbs as the first one on area four | |
45 | 46 | pos = software_area_two.blocks.order(:position).last.position |
46 | 47 | change_block_pos(software_area_four, template_software_events, pos+1) |
47 | 48 | print "." |
... | ... | @@ -53,7 +54,6 @@ namespace :software do |
53 | 54 | software_area_one = software_template.boxes.find_by_position 1 |
54 | 55 | one = false |
55 | 56 | |
56 | - puts "Area One Blocks" | |
57 | 57 | if software_area_one.blocks[-2].class != SoftwareEventsBlock |
58 | 58 | second_template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" |
59 | 59 | second_template_software_events.display = "except_home_page" |
... | ... | @@ -62,7 +62,6 @@ namespace :software do |
62 | 62 | software_area_one.blocks << second_template_software_events |
63 | 63 | software_area_one.save! |
64 | 64 | |
65 | - # Puts the breadcrumbs as the first one on area four | |
66 | 65 | pos = software_area_one.blocks.order(:position).last.position |
67 | 66 | change_block_pos(software_area_one, second_template_software_events, pos) |
68 | 67 | print "." |
... | ... | @@ -70,10 +69,11 @@ namespace :software do |
70 | 69 | end |
71 | 70 | |
72 | 71 | |
72 | + puts "\nCreate software community boxes:" | |
73 | 73 | Community.joins(:software_info).each do |software_community| |
74 | 74 | software_area_four = software_community.boxes.find_by_position 4 |
75 | 75 | |
76 | - if four | |
76 | + if four && software_area_four.blocks.first.class != BreadcrumbsPlugin::ContentBreadcrumbsBlock | |
77 | 77 | breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" |
78 | 78 | breadcrumbs_block.settings[:fixed] = true |
79 | 79 | breadcrumbs_block.display = "always" |
... | ... | @@ -129,17 +129,20 @@ namespace :software do |
129 | 129 | end |
130 | 130 | |
131 | 131 | print "\n" |
132 | + | |
133 | + puts "Created blocks: #{Block.count - existing_blocks}" | |
132 | 134 | end |
133 | -def change_block_pos(box, block, pos) | |
134 | - box.blocks.each do |b| | |
135 | - if b.position >= pos | |
136 | - b.position += 1 | |
137 | - b.save | |
135 | + | |
136 | + def change_block_pos(box, block, pos) | |
137 | + box.blocks.each do |b| | |
138 | + if b.position >= pos | |
139 | + b.position += 1 | |
140 | + b.save | |
141 | + end | |
138 | 142 | end |
139 | - end | |
140 | 143 | |
141 | - block.position = pos | |
142 | - block.save | |
143 | -end | |
144 | + block.position = pos | |
145 | + block.save | |
146 | + end | |
144 | 147 | end |
145 | 148 | ... | ... |