OSDN Git Service

t#30144:hide old edition pictures on pp, gp
authoryasushiito <yas@pen-chan.jp>
Wed, 19 Dec 2012 09:10:45 +0000 (18:10 +0900)
committeryasushiito <yas@pen-chan.jp>
Wed, 19 Dec 2012 09:10:45 +0000 (18:10 +0900)
app/models/picture.rb
app/views/artists/list.html.erb
app/views/ground_pictures/_list_item.html.erb
app/views/panel_pictures/_list_item.html.erb
app/views/panel_pictures/show.html.erb
app/views/pictures/_tail.html.erb
app/views/pictures/show.html.erb
spec/models/picture_spec.rb

index 4e5472d..dfaf583 100644 (file)
@@ -43,9 +43,8 @@ class Picture < ActiveRecord::Base
     return true
   end
   
-  def showable? ar
-    return false unless ar.is_a?(Artist)
-    return true if self.own?(ar)
+  def showable? au = nil
+    return true if self.own?(au)
     self.enable? and self.head?
   end
   
@@ -74,6 +73,15 @@ class Picture < ActiveRecord::Base
     {:src => self.url, :width => tw, :height => th}
   end
   
+  def tail_opt_img_tag img
+    {:src => img, :width => self.width, :height => self.height}
+  end
+  
+  def tail_tmb_opt_img_tag img
+    tw, th = PettanImager.thumbnail_size(self.width, self.height)
+    {:src => img, :width => tw, :height => th}
+  end
+  
   def new_revision
     Picture.maximum(:revision, :conditions => ['original_picture_id = ?', self.original_picture_id]).to_i + 1
   end
index abca085..5fe1d68 100644 (file)
@@ -3,6 +3,7 @@
 <table>
   <tr>
     <th><%= t_m 'Artist.id' -%></th>
+    <th><%= t_m 'Artist.author_id' -%></th>
     <th><%= t_m 'Artist.name' -%></th>
     <th><%= t_m 'Artist.created_at' -%></th>
     <th><%= t_m 'Artist.updated_at' -%></th>
@@ -11,6 +12,7 @@
   <% @artists.each do |artist| %>
     <tr>
       <td><%= link_to artist.id, browse_artist_path(artist) %></td>
+      <td><%= link_to artist.author_id, browse_author_path(artist.author) %></td>
       <td><%= h(truncate(artist.name, :length => 12)) %></td>
       <td><%= l artist.created_at %></td>
       <td><%= l artist.updated_at %></td>
index e2bd16b..88a71eb 100644 (file)
@@ -1,7 +1,14 @@
 <tr>
   <td><%= link_to ground_picture.panel_id, panel_path(ground_picture.panel_id) %></td>
-  <td><%= tag :img, ground_picture.picture.tmb_opt_img_tag -%></td>
-  <td><%= render ground_picture.picture.credit_template, :picture => ground_picture.picture %></td>
+  <% if ground_picture.picture.showable? @author %>
+    <td><%= link_to(tag(:img, ground_picture.picture.tmb_opt_img_tag), ground_picture) -%></td>
+    <td><%= render ground_picture.picture.credit_template, :picture => ground_picture.picture %></td>
+  <% else %>
+    <td>
+      <%= link_to(tag(:img, ground_picture.picture.tail_tmb_opt_img_tag(asset_path('error.png'))), ground_picture) -%>
+    </td>
+    <td></td>
+  <% end %>
   <td><%= ground_picture.z %></td>
   <td><%= ground_picture.repeat %><%= MagicNumber['ground_picture_repeat_items'][ground_picture.repeat] %></td>
   <td><%= ground_picture.x %></td>
index e7c1ff9..6c59f5b 100644 (file)
@@ -1,6 +1,15 @@
 <tr>
-  <td><%= link_to(tag(:img, panel_picture.tmb_opt_img_tag), panel_picture.picture) %></td>
-  <td><%= render panel_picture.picture.credit_template, :picture => panel_picture.picture %></td>
+  <% if panel_picture.picture.showable? @author %>
+    <td>
+      <%= link_to(tag(:img, panel_picture.tmb_opt_img_tag), panel_picture) %>
+    </td>
+    <td><%= render panel_picture.picture.credit_template, :picture => panel_picture.picture %></td>
+  <% else %>
+    <td>
+      <%= link_to(tag(:img, panel_picture.picture.tail_tmb_opt_img_tag(asset_path('error.png'))), panel_picture) -%>
+    </td>
+    <td></td>
+  <% end %>
   <td><%= link_to panel_picture.panel.id, panel_path(panel_picture.panel) %></td>
   <td><%= link_to h(truncate(panel_picture.link, :length => 12)), panel_picture.link %></td>
   <td><%= h(truncate(panel_picture.caption, :length => 12)) %></td>
index c0b19b7..f0b4fab 100644 (file)
@@ -6,10 +6,17 @@
   <%= link_to @panel_picture.panel_id, panel_path(@panel_picture.panel) %>
 </p>
 
-<p>
-  <b><%= t_m 'PanelPicture.picture_id' -%>:</b>
-  <%= link_to tag(:img, @panel_picture.opt_img_tag), picture_path(@panel_picture.picture) %>
-</p>
+<% if @panel_picture.picture.showable? @author %>
+  <p>
+    <b><%= t_m 'PanelPicture.picture_id' -%>:</b>
+    <%= link_to tag(:img, @panel_picture.opt_img_tag), picture_path(@panel_picture.picture) %>
+  </p>
+  <%= render @panel_picture.picture.credit_template, :picture => @panel_picture.picture %>
+<% else %>
+  <p>
+    <%= tag(:img, @panel_picture.picture.tail_opt_img_tag(asset_path('error.png'))) -%>
+  </p>
+<% end %>
 
 <p>
   <b><%= t_m 'PanelPicture.link' -%>:</b>
index bcf0044..c12759a 100644 (file)
@@ -1,7 +1,7 @@
 <table>
   <tr>
     <td>
-      <%= tag :img, :src => asset_path('error.png'), :width => picture.width, :height => picture.height -%>
+      <%= tag(:img, picture.tail_opt_img_tag(asset_path('error.png'))) -%>
     </td>
     <td>
       <h2>
index 8d40ab6..5a11460 100644 (file)
@@ -25,7 +25,7 @@
   <% end %>
 </div>
 
-<% if @picture.showable? @artist %>
+<% if @picture.showable? @author %>
   <%= render 'head', :picture => @picture %>
 <% else %>
   <%= render 'tail', :picture => @picture %>
index a4e372e..8166400 100644 (file)
@@ -297,19 +297,19 @@ describe Picture do
       it '自身にhead判定と有効性判定を問い合わせ、両者がTrueならTrueを返す。' do
         Picture.any_instance.stub(:head?).with(any_args).and_return(true)
         Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
-        r = @p.showable?(@artist)
+        r = @p.showable?(@author)
         r.should be_true
       end
       it 'head判定がFalseならFalseを返す。' do
         Picture.any_instance.stub(:head?).with(any_args).and_return(false)
         Picture.any_instance.stub(:enable?).with(any_args).and_return(true)
-        r = @p.showable?(@artist)
+        r = @p.showable?(@author)
         r.should be_false
       end
       it '有効性判定がFalseならFalseを返す。' do
         Picture.any_instance.stub(:enable?).with(any_args).and_return(false)
         Picture.any_instance.stub(:head?).with(any_args).and_return(true)
-        r = @p.showable?(@artist)
+        r = @p.showable?(@author)
         r.should be_false
       end
     end