From: yasushiito Date: Wed, 12 Jun 2013 10:44:02 +0000 (+0900) Subject: #31540:try sort X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=bf89ae0a5c0f77ce2e9782b28023ff8ac521c501;hp=53eae67e5bdc9d50e748b3381bdbd536ef20f9c7 #31540:try sort --- diff --git a/app/models/panel.rb b/app/models/panel.rb index 2167d937..6aaf3c56 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -179,6 +179,14 @@ class Panel < ActiveRecord::Base res end + def zorderd_elements + res = [] + self.parts_element.each do |e| + res[e.z-1] = e + end + res + end + def panel_elements parts end diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index ba599206..59f04a92 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -63,7 +63,7 @@ class PanelPicture < ActiveRecord::Base def opt_img_tag spot = nil, opacity = 20 o = (spot and spot != self) ? "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});" : '' - {:src => self.url, :vPicture => self.id, :width => self.width.abs, :height => self.height.abs, :alt => self.caption, :style => "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; #{o}"} + {:src => self.url, :id => "panel-picture#{self.id}", :vPicture => self.id, :width => self.width.abs, :height => self.height.abs, :alt => self.caption, :style => "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; #{o}"} end def tmb_opt_img_tag diff --git a/app/views/panels/_body.html.erb b/app/views/panels/_body.html.erb index 3e813b51..3a024aa0 100644 --- a/app/views/panels/_body.html.erb +++ b/app/views/panels/_body.html.erb @@ -1,12 +1,14 @@ -
+
<% panel.panel_elements.each do |elm| %> <% case elm.class.to_s %> <% when 'PanelPicture' %> - <%= link_to_unless(elm.link.blank?, tag(:img, elm.opt_img_tag(spot)), elm.link) %> +
+ <%= link_to_unless(elm.link.blank?, tag(:img, elm.opt_img_tag(spot)), elm.link) %> +
<% when 'SpeechBalloon' %>
- <%= elm.caption -%> -

+ <%= elm.caption -%> +

<%= h elm.speech.content -%>

diff --git a/app/views/panels/_form.html.erb b/app/views/panels/_form.html.erb index 90170af6..fb8ce514 100644 --- a/app/views/panels/_form.html.erb +++ b/app/views/panels/_form.html.erb @@ -1,88 +1,183 @@ -<%= form_for(@panel) do |f| %> - <%= render 'system/error_explanation', :obj => @panel %> +
+ +
+ <%= form_for(@panel) do |f| %> + <%= render 'system/error_explanation', :obj => @panel %> -
- <%= f.label :caption %>
- <%= f.text_field :caption %> -
-
- <%= f.label :width %>
- <%= f.number_field :width %> -
-
- <%= f.label :height %>
- <%= f.number_field :height %> -
-
- <%= f.label :border %>
- <%= f.number_field :border %> -
-
- <%= f.label :publish %>
- <%= f.collection_select :publish, t_select_items(MagicNumber['panel_visible_items']), :last, :first, :html => {:selected => @panel.publish} %> -
-
- <%= f.submit %> -
-<% end %> +
+ <%= f.label :caption %>
+ <%= f.text_field :caption %> +
+
+ <%= f.label :width %>
+ <%= f.number_field :width, :id => 'panel-width' %> +
+
+ <%= f.label :height %>
+ <%= f.number_field :height, :id => 'panel-height' %> +
+
+ <%= f.label :border %>
+ <%= f.number_field :border %> +
+
+ <%= f.label :publish %>
+ <%= f.collection_select :publish, t_select_items(MagicNumber['panel_visible_items']), :last, :first, :html => {:selected => @panel.publish} %> +
+
+ <%= f.submit %> +
+ <% end %> +

<%= t 'panels.create_from_json' -%>

+ <%= form_for(@panel) do |f| %> + <%= render 'system/error_explanation', :obj => @panel %> -

<%= t 'panels.create_from_json' -%>

-<%= form_for(@panel) do |f| %> - <%= render 'system/error_explanation', :obj => @panel %> - -
- +
+ +
+ <%= text_field_tag "json" %> +
+ <%= submit_tag t('panels.create_from_json') -%> +
+ <% end %> +
+
+

<%= 't reorder' -%>

+ + + <% @panel.panel_elements.each do |elm| %> + + <% case elm.class.to_s %> + <% when 'PanelPicture' %> + + <% when 'SpeechBalloon' %> + + <% when 'GroundPicture' %> + + <% when 'GroundColor' %> + + <% end %> + + + <% end %> + +
+ <%= tag(:img, elm.tmb_opt_img_tag) %> + + <%= elm.id -%> + <%= elm.caption -%> + + <%= tag(:img, elm.tmb_opt_img_tag) -%> + ; background-color: #<%= format("%06x", elm.code) -%>;"> + <%= format("%06x", elm.code ^ 0xffffff) %> + + <%= h(truncate(elm.caption, :length => 12)) %> +
+ <%= form_for(@panel) do |f| %> + <%= hidden_field_tag "json", nil, :id => 't-reorder' %> + <% unless @panel.new_record? -%> + <%= content_tag :div, '', :id => "panel-id-elm", :oid => @panel.id -%> + <% end %> +
+ <%= submit_tag t('panels.create.title') -%> +
+ <% end %>
- <%= text_field_tag "json" %> -
- <%= submit_tag t('panels.create_from_json') -%> +
+

<%= 'z reorder' -%>

+ + + <% @panel.zorderd_elements.each do |elm| %> + + <% case elm.class.to_s %> + <% when 'PanelPicture' %> + + <% when 'SpeechBalloon' %> + + <% when 'GroundPicture' %> + + <% when 'GroundColor' %> + + <% end %> + + + <% end %> + +
+ <%= tag(:img, elm.tmb_opt_img_tag) %> + + <%= elm.id -%> + <%= elm.caption -%> + + <%= tag(:img, elm.tmb_opt_img_tag) -%> + ; background-color: #<%= format("%06x", elm.code) -%>;"> + <%= format("%06x", elm.code ^ 0xffffff) %> + + <%= h(truncate(elm.caption, :length => 12)) %> +
+ <%= form_for(@panel) do |f| %> + <%= hidden_field_tag "json", nil, :id => 'z-reorder' %> + <% unless @panel.new_record? -%> + <%= content_tag :div, '', :id => "panel-id-zorderd", :oid => @panel.id -%> + <% end %> +
+ <%= submit_tag t('panels.create.title') -%> +
+ <% end %>
-<% end %> +
-

<%= 't reorder' -%>

- - - <% @panel.panel_elements.each do |elm| %> - + diff --git a/app/views/panels/edit.html.erb b/app/views/panels/edit.html.erb index bc01cd6e..f5979824 100644 --- a/app/views/panels/edit.html.erb +++ b/app/views/panels/edit.html.erb @@ -1,6 +1,7 @@

<%= t '.title' -%>

<%= notice %>

-<%= render 'standard', :panel => @panel, :author => @author %> +<%= render 'panels/body', :panel => @panel, :author => @author, :spot => nil %> <%= render 'form' %> <%= link_to t('link.destroy'), panel_path(@panel), :method => :delete %> +<%= render 'panels/licensed_pictures', :licensed_pictures => @panel.licensed_pictures %> diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 17714c36..7542b207 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -836,6 +836,59 @@ describe Panel do end end end + + describe 'z順コマ部品に於いて' do + before do + #コマを作成しておく。 + @panel = FactoryGirl.create :panel, :author_id => @author.id + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :width => @p.width, :height => @p.height + @sb = @panel.speech_balloons.create( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1) + ) + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4) + ) + @panel.reload + end + context 'つつがなく終わるとき' do + it 'コマ部品集合を利用している' do + Panel.any_instance.stub(:parts_element).with(any_args).and_return([]) + Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1) + r = @panel.zorderd_elements + end + end + it 'リストを返している' do + r = @panel.zorderd_elements + r.is_a?(Array).should be_true + r.size.should eq 4 + end + it 'zでオフセットを0でソートしている' do + r = @panel.zorderd_elements + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @gc + r[3].should eq @gp + end + context 'さらに末尾にフキダシを追加したとき' do + before do + @sb2 = @panel.speech_balloons.create( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5) + ) + @panel.reload + end + it 'zでソートしている' do + r = @panel.zorderd_elements + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @gc + r[3].should eq @gp + r[4].should eq @sb2 + end + end + end describe 'コマ要素に於いて' do before do #コマを作成しておく。