validates :panel_id, :numericality => {:allow_blank => true}
validates :picture_id, :numericality => true, :existence => {:both => false}
- validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
+ validates :link, :length => {:maximum => 200}, :allow_blank => true
+ #validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
validates :x, :presence => true, :numericality => true
validates :y, :presence => true, :numericality => true
- validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => true, :sync_vh => true
- validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :resize => true, :sync_vh => true
+ validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true
+ validates :height, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true
validates :z, :presence => true, :numericality => {:greater_than => 0}
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
- def self.by_author_list_includes
- {
- :panel => {
- :author => {}
- }
- }
+ scope :with_panel, -> do
+ includes(:panel)
end
- def self.list_opt_for_panel
- {
- :panel_pictures => {
- :picture => {:artist => {}, :license => {}}
- }
- }
+ scope :find_index, -> do
+ with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
end
- def self.show_opt_for_panel
- {
- :panel_pictures => {
- :picture => {:artist => {}, :license => {}}
- }
- }
+ 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
- def self.json_opt_for_panel
+ def self.by_author_list_includes
{
- :picture => {:artist => {}, :license => {}}
+ :panel => {
+ :author => {}
+ }
}
end
def flip
res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h')
- res += '/' unless res.empty?
+ res = res # format of /1.png?subdir=v
+ # res += '/' unless res.empty? # format of /v/1.png
res
end
def filename
- self.flip + self.picture.filename
+ q = self.flip.empty? ? '' : '?subdir=' + self.flip
+ self.picture.filename + q
end
def url
self.picture.symbol_option
end
- def self.list_where
+ def self.public_list_where list
'panels.publish > 0'
end
- def self.list_order
- 'panel_pictures.updated_at desc'
- end
-
- def self.list_opt
- {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}} }
- end
-
- def self.list_json_opt
- {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
- end
-
def self.show_opt
{:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
end
- def self.show_json_opt
- {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
- end
-
- def store operators
- if self.new_record?
- self.panel.panel_pictures.build(self.attributes)
+ def disp_link
+ if self.link =~ /\:\/\//
+ self.link
else
- self.panel.panel_pictures.each do |panel_picture|
- next unless panel_picture == self
- attr = self.attributes
- attr.delete 'id'
- panel_picture.attributes = attr
- break
- end
+ '/' + self.link.to_s
end
- self.panel.store({}, operators)
- end
-
- def remove operators
- self.panel.remove_element(self, operators)
end
def scenario