X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fground_color.rb;h=a4c9a66bd183e1b309abac63cea35002d849ca06;hb=0ead3a286b925e86845cf8211982a7985e522813;hp=cb16e67f5c00bff17563e1823f47771ccdcd19b9;hpb=31124ac1df4b11438308bb83525753b3e40e355a;p=pettanr%2Fpettanr.git diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index cb16e67f..a4c9a66b 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -11,30 +11,31 @@ class GroundColor < Peta::Element 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 @@ -105,49 +106,14 @@ class GroundColor < Peta::Element 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? ''