OSDN Git Service

fix leaf sort
[pettanr/pettanr.git] / app / models / scroll_panel.rb
index 3b8b76c..e70bc5d 100644 (file)
@@ -20,12 +20,7 @@ class ScrollPanel < Peta::Leaf
     self.author_id = operators.author.id
   end
   
-  def visible? operators
-    return false unless super
-    self.owner_model.visible? operators
-  end
-  
-  def self.list_order
+  def self.public_list_order
     'scroll_panels.updated_at desc'
   end
   
@@ -116,76 +111,6 @@ class ScrollPanel < Peta::Leaf
     r
   end
   
-  def self.new_t scroll_id
-    r = ScrollPanel.max_t(scroll_id)
-    r.blank? ? 0 : r.to_i + 1
-  end
-  
-  def self.max_t scroll_id
-    ScrollPanel.maximum(:t, :conditions => ['scroll_id = ?', scroll_id])
-  end
-  
-  def self.find_t scroll_id, t
-    ScrollPanel.find(:first, :conditions => ['scroll_id = ? and t = ?', scroll_id, t])
-  end
-  
-  def self.collect_t scroll_panel
-    r = ScrollPanel.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't')
-    r.map {|sp| sp.t}
-  end
-  
-  def self.serial? ary
-    i = 0
-    ary.compact.sort.each do |t|
-      break false unless t == i
-      i += 1
-    end
-    ary.compact.size == i
-  end
-  
-  def self.validate_t scroll_panel
-    ScrollPanel.serial?(ScrollPanel.collect_t(scroll_panel))
-  end
-  
-  def insert_shift
-    ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and t >= ?', self.scroll_id, self.t])
-  end
-  
-  def lesser_shift old_t
-    self.t = 0 if self.t < 0
-    ScrollPanel.update_all('t = t + 1', ['scroll_id = ? and (t >= ? and t < ?)', self.scroll_id, self.t, old_t])
-  end
-  
-  def higher_shift old_t
-    nf = ScrollPanel.find_t(self.scroll_id, self.t)
-    max_t = ScrollPanel.max_t(self.scroll_id).to_i
-    self.t = max_t if self.t > max_t
-    ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ? and t <= ?)', self.scroll_id, old_t, self.t])
-  end
-  
-  def update_shift old_t
-    if self.t > old_t
-      higher_shift old_t
-    else
-      lesser_shift old_t
-    end
-  end
-  
-  def rotate old_t = nil
-    if self.new_record?
-      if self.t.blank?
-        self.t = ScrollPanel.new_t self.scroll_id
-      else
-        self.insert_shift
-      end
-    else
-      if self.t.blank?
-      else
-        self.update_shift old_t
-      end
-    end
-  end
-  
   def allow? operators
     return nil if self.scroll_id == nil or self.panel_id == nil
     self.scroll.own?(operators) and self.panel.usable?(operators)
@@ -203,7 +128,7 @@ class ScrollPanel < Peta::Leaf
       end
       res = self.save
       raise ActiveRecord::Rollback unless res
-      res = ScrollPanel.validate_t(self) 
+      res = ScrollPanel.validate_t(self.scroll_id
       unless res
         self.errors.add :t, 'unserialized'
         raise ActiveRecord::Rollback 
@@ -212,14 +137,4 @@ class ScrollPanel < Peta::Leaf
     res
   end
   
-  def destroy_and_shorten
-    res = false
-    ScrollPanel.transaction do
-      ScrollPanel.update_all('t = t - 1', ['scroll_id = ? and (t > ?)', self.scroll_id, self.t])
-      raise ActiveRecord::Rollback unless self.destroy
-      res = true
-    end
-    res
-  end
-  
 end