| Class | Portal |
| In: |
app/models/portal.rb
|
| Parent: | ActiveRecord::Base |
ポータルのモデル。
| LABEL_PATTERN | = | [ [s_("Portal|One Pane"), "AAA"], [s_("Portal|Two Panes 1"), "ABB"], [s_("Portal|Two Panes 2"), "AAB"], [s_("Portal|Three Panes"), "ABC"], ] |
| POSITION | = | {:A => 1, :B => 2, :C => 3} |
| ALL_POSITIONS | = | { :AAA => [1], :ABB => [1, 2], :AAB => [1, 2], :ABC => [1, 2, 3], } |
| SIZE | = | { :AAA => { :A => "L", }, :ABB => { :A => "S", :B => "L", }, :AAB => { :A => "L", :B => "S", }, :ABC => { :A => "S", :B => "L", :C => "S", }, } |
| WIDTH | = | { :AAA => { :A => "900px", }, :ABB => { :A => "200px", :B => "700px", }, :AAB => { :A => "700px", :B => "200px", }, :ABC => { :A => "200px", :B => "500px", :C => "200px", }, } |
縦枠 abc に含まれるポートレットの個数を返す。
# File app/models/portal.rb, line 96
96: def count(abc)
97: abc = abc.to_s.upcase.to_sym
98: pane(abc).portlets.size
99: end
縦枠 abc の横サイズ(3段階)を返す。
# File app/models/portal.rb, line 84
84: def size(abc)
85: abc = abc.to_s.upcase.to_sym
86: SIZE[pattern.to_sym][abc]
87: end
パターンを next_pattern に変更する。
# File app/models/portal.rb, line 102
102: def update_pattern(next_pattern)
103: prev_pattern = pattern.to_sym
104: next_pattern = next_pattern.to_s.upcase.to_sym
105: return if prev_pattern == next_pattern
106: Portal.transaction do
107: pane_a = pane(:A)
108: count_a = count(:A)
109: case prev_pattern
110: when :ABC
111: pane_b = pane(:B)
112: count_b = count(:B)
113: pane_c = pane(:C)
114: case next_pattern
115: when :ABB
116: pane_b.width = WIDTH[:ABB][:B]
117: pane_b.save
118: # portlets.each do |portlet|
119: # if portlet.pane_id == pane_c.id
120: # portlet.pane_id = pane_a.id
121: # portlet.position += count_a
122: # portlet.save
123: # end
124: # end
125: when :AAB
126: pane_b.width = WIDTH[:AAB][:A]
127: pane_b.save
128: pane_b.move_to_top
129: # portlets.each do |portlet|
130: # if portlet.pane_id == pane_c.id
131: # portlet.pane_id = pane_a.id
132: # portlet.position += count_a
133: # portlet.save
134: # end
135: # end
136: when :AAA
137: pane_b.width = WIDTH[:AAA][:A]
138: pane_b.save
139: # portlets.each do |portlet|
140: # if portlet.pane_id == pane_a.id
141: # portlet.pane_id = pane_b.id
142: # portlet.position += count_b
143: # portlet.save
144: # elsif portlet.pane_id == pane_c.id
145: # portlet.pane_id = pane_b.id
146: # portlet.position += count_a + count_b
147: # portlet.save
148: # end
149: # end
150: pane_a.destroy
151: else
152: raise ArgumentError, "invild pattern: #{next_pattern}"
153: end
154: pane_c.destroy
155: when :ABB
156: pane_b = pane(:B)
157: count_b = count(:B)
158: case next_pattern
159: when :ABC
160: pane_b.width = WIDTH[:ABC][:B]
161: pane_b.save
162: pane_n = Pane.create :screen_id => screen.id, :width => WIDTH[:ABC][:C]
163: when :AAB
164: pane_a.move_to_bottom
165: when :AAA
166: pane_b.width = WIDTH[:AAA][:A]
167: pane_b.save
168: # portlets.each do |portlet|
169: # if portlet.pane_id == pane_a.id
170: # portlet.pane_id = pane_b.id
171: # portlet.position += count_b
172: # portlet.save
173: # end
174: # end
175: pane_a.destroy
176: else
177: raise ArgumentError, "invild pattern: #{next_pattern}"
178: end
179: when :AAB
180: pane_b = pane(:B)
181: case next_pattern
182: when :ABC
183: pane_a.width = WIDTH[:ABC][:B]
184: pane_a.save
185: pane_n = Pane.create :screen_id => screen.id, :width => WIDTH[:ABC][:A]
186: pane_n.move_to_top
187: when :ABB
188: pane_a.move_to_bottom
189: when :AAA
190: pane_a.width = WIDTH[:AAA][:A]
191: pane_a.save
192: # portlets.each do |portlet|
193: # if portlet.pane_id == pane_b.id
194: # portlet.pane_id = pane_a.id
195: # portlet.position += count_a
196: # portlet.save
197: # end
198: # end
199: pane_b.destroy
200: else
201: raise ArgumentError, "invild pattern: #{next_pattern}"
202: end
203: when :AAA
204: case next_pattern
205: when :ABC
206: pane_a.width = WIDTH[:ABC][:B]
207: pane_a.save
208: pane_n = Pane.create :screen_id => screen.id, :width => WIDTH[:ABC][:A]
209: pane_n.move_to_top
210: pane_c = Pane.create :screen_id => screen.id, :width => WIDTH[:ABC][:C]
211: when :ABB
212: pane_a.width = WIDTH[:ABB][:B]
213: pane_a.save
214: pane_n = Pane.create :screen_id => screen.id, :width => WIDTH[:ABB][:A]
215: pane_n.move_to_top
216: when :AAB
217: pane_a.width = WIDTH[:AAB][:A]
218: pane_a.save
219: pane_n = Pane.create :screen_id => screen.id, :width => WIDTH[:AAB][:B]
220: else
221: raise ArgumentError, "invild pattern: #{next_pattern}"
222: end
223: end
224: self.pattern = next_pattern.to_s
225: self.save
226: end
227: end