box_organizer.rake
5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#encoding: utf-8
namespace :software do
desc "Create missing blocks in software and templates"
task :box_organize => :environment do
software_template = Community["software"]
next unless software_template.is_template?
software_area_four = software_template.boxes.find_by_position 4
four = false
puts "Area Four Blocks"
if software_area_four.blocks.first.class != BreadcrumbsPlugin::ContentBreadcrumbsBlock
template_breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none"
template_breadcrumbs_block.settings[:fixed] = true
template_breadcrumbs_block.display = "always"
template_breadcrumbs_block.save!
software_area_four.blocks << template_breadcrumbs_block
software_area_four.save!
# Puts the breadcrumbs as the first one on area four
pos = software_area_four.blocks.order(:position).first.position
change_block_pos(software_area_four, template_breadcrumbs_block, pos)
print "."
four = true
end
############################################################################
software_area_two = software_template.boxes.find_by_position 2
two = false
puts "Area Two Blocks"
if software_area_two.blocks.last.class != SoftwareEventsBlock
template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all"
template_software_events.title = "Outros Eventos"
template_software_events.display = "except_home_page"
template_software_events.save!
software_area_two.blocks << template_software_events
software_area_two.save!
# Puts the breadcrumbs as the first one on area four
pos = software_area_two.blocks.order(:position).last.position
change_block_pos(software_area_four, template_software_events, pos+1)
print "."
two = true
end
############################################################################
software_area_one = software_template.boxes.find_by_position 1
one = false
puts "Area One Blocks"
if software_area_one.blocks[-2].class != SoftwareEventsBlock
second_template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all"
second_template_software_events.display = "except_home_page"
second_template_software_events.save!
software_area_one.blocks << second_template_software_events
software_area_one.save!
# Puts the breadcrumbs as the first one on area four
pos = software_area_one.blocks.order(:position).last.position
change_block_pos(software_area_one, second_template_software_events, pos)
print "."
one = true
end
Community.joins(:software_info).each do |software_community|
software_area_four = software_community.boxes.find_by_position 4
if four
breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none"
breadcrumbs_block.settings[:fixed] = true
breadcrumbs_block.display = "always"
breadcrumbs_block.mirror_block_id = template_breadcrumbs_block.id
breadcrumbs_block.save!
software_area_four.blocks << breadcrumbs_block
software_area_four.save!
# Puts the breadcrumbs as the first one on area four
pos = software_area_four.blocks.order(:position).first.position
change_block_pos(software_area_four, breadcrumbs_block, pos)
print "."
end
############################################################################
software_area_two = software_community.boxes.find_by_position 2
if two
software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all"
software_events.title = "Outros Eventos"
software_events.display = "except_home_page"
software_events.mirror_block_id = template_software_events.id
software_events.save!
software_area_two.blocks << software_events
software_area_two.save!
# Puts the breadcrumbs as the first one on area four
pos = software_area_two.blocks.order(:position).last.position
change_block_pos(software_area_four, software_events, pos+1)
print "."
end
############################################################################
software_area_one = software_community.boxes.find_by_position 1
if one
software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all"
software_events.display = "except_home_page"
software_events.mirror_block_id = second_template_software_events.id
software_events.save!
software_area_one.blocks << software_events
software_area_one.save!
# Puts the breadcrumbs as the first one on area four
pos = software_area_one.blocks.order(:position).last.position
change_block_pos(software_area_one, software_events, pos)
print "."
end
end
print "\n"
end
def change_block_pos(box, block, pos)
box.blocks.each do |b|
if b.position >= pos
b.position += 1
b.save
end
end
block.position = pos
block.save
end
end