OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / models / panel_picture.rb
index 38995ab..3713764 100644 (file)
@@ -13,7 +13,40 @@ class PanelPicture < Peta::Element
   validates :z, :presence => true, :numericality => {:greater_than => 0}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
-  def _y
+  scope :with_panel, -> do
+    includes(:panel)
+  end
+  
+  scope :find_index, -> do
+    with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
+  end
+  
+  scope :find_private, -> (operators) do 
+    with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
+  end
+  
+  scope :find_by_panel, -> (panel_id) do 
+    find_index.where(panel_id: panel_id).references(:panel)
+  end
+  
+  scope :find_by_author, -> (author_id) do 
+    find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
+  end
+  
+  def self.pickup_item_name
+    Picture.item_name
+  end
+  
+  def self.pickup_column_name
+    self.pickup_item_name + '_id'
+  end
+  
+  def pickup_id
+    # get :picture_id if head revision
+    self.attributes[self.pickup_column_name]
+  end
+  
+  def y
     self.attributes['y']
   end
   
@@ -54,7 +87,8 @@ class PanelPicture < Peta::Element
   end
   
   def filename
-    self.picture.filename + '?subdir=' + self.flip
+    q = self.flip.empty? ? '' : '?subdir=' + self.flip
+    self.picture.filename + q
   end
   
   def url
@@ -62,7 +96,7 @@ class PanelPicture < Peta::Element
   end
   
   def opt_div_style
-    "top:#{self._y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
+    "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; position: absolute;"
   end
   
   def opt_img_tag spot = nil, opacity = 20
@@ -83,7 +117,7 @@ class PanelPicture < Peta::Element
     self.picture.symbol_option
   end
   
-  def self.public_list_where
+  def self.public_list_where list
     'panels.publish > 0'
   end