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
- {
- :ground_colors => {
- }
- }
+ scope :find_index, -> do
+ with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
end
- def self.show_opt_for_panel
- {
- :ground_colors => {
- }
- }
+ 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.json_opt_for_panel
+ def self.by_author_list_includes
{
+ :panel => {
+ :author => {}
+ }
}
end
r
end
- def self.public_list_where
+ def self.public_list_where list
'panels.publish > 0'
end
- def self.list_order
- 'ground_colors.updated_at desc'
- end
-
- def self.list_opt
- {:panel => {:author => {}} }
- end
-
- def self.list_json_opt
- {:include => {:panel => {:include => {:author => {}}} }}
- end
-
def self.show_opt
{:include => {:panel => {:author => {}} }}
end
- def self.show_json_opt
- {:include => {:panel => {:include => {:author => {}}} }}
- end
-
- def store operators
- if self.new_record?
- self.panel.ground_colors.build(self.attributes)
- else
- self.panel.ground_colors.each do |ground_color|
- next unless ground_color == self
- attr = self.attributes
- attr.delete 'id'
- ground_color.attributes = attr
- break
- end
- end
- self.panel.store({}, operators)
- end
-
- def remove operators
- self.panel.remove_element(self, operators)
- end
-
def scenario
if caption.blank?
''