OSDN Git Service

temp
authoryasushiito <yas@pen-chan.jp>
Wed, 11 Dec 2013 01:25:05 +0000 (10:25 +0900)
committeryasushiito <yas@pen-chan.jp>
Wed, 11 Dec 2013 01:25:05 +0000 (10:25 +0900)
app/models/author.rb
app/models/scroll.rb
lib/item.rb
lib/manifest/filer.rb
lib/manifest/list.rb

index 1c88fba..d095613 100644 (file)
@@ -10,25 +10,8 @@ class Author < Pettanr::Owner
   validates :working_panel_id, :numericality => {:allow_nil => true}
   validates :user_id, :numericality => true, :existence => {:both => false}
   
-  cattr_reader :singular, :plural
   @@singular = 'Author'
   @@plural = 'Authors'
-  def self.item_name
-    self.singular.underscore
-  end
-  
-  def item_name
-    self.class.item_name
-  end
-  
-  def self.path_name with_engine = false
-    self.plural.underscore
-  end
-  
-  def path_name 
-    self.class.path_name
-  end
-  
   @@valid_encode_columns += ['name']
   # @@visible_count_options = {}
   
index 4fe7a52..73eed47 100644 (file)
@@ -1,4 +1,4 @@
-class Scroll < ActiveRecord::Base
+class Scroll < Pettanr::Item
   has_many :scroll_panels
   belongs_to :author
   
@@ -6,38 +6,18 @@ class Scroll < ActiveRecord::Base
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
 
-  before_validation :valid_encode
-  
-  cattr_reader :singular, :plural
-  @@singular = 'Scroll'
-  @@plural = 'Scrolls'
-  def self.item_name
-    self.singular.underscore
-  end
-  
-  def item_name
-    self.class.item_name
+  def self.singular
+    'Scroll'
   end
   
-  def self.path_name with_engine = false
-    self.plural.underscore
-  end
-  
-  def path_name 
-    self.class.path_name
+  def self.plural
+    'Scrolls'
   end
   
   def self.owner_type
     :author
   end
   
-  def valid_encode
-    ['title', 'description'].each do |a|
-      next if attributes[a] == nil
-      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
-    end
-  end
-  
   def supply_default
     self.visible = 0 if self.visible.blank?
   end
@@ -55,11 +35,7 @@ class Scroll < ActiveRecord::Base
   end
   
   def visible? operators
-    if MagicNumber['run_mode'] == 0
-      return false unless operators.guest?
-    else
-      return false unless operators.resource_reader?
-    end
+    return false unless super
     self.visible > 0
   end
   
@@ -67,35 +43,6 @@ class Scroll < ActiveRecord::Base
     ScrollPanel.where(['scroll_panels.scroll_id = ?', self.id]).count
   end
   
-  def self.default_page_size
-    25
-  end
-  
-  def self.max_page_size
-    100
-  end
-  
-  def self.default_panel_size
-    30
-  end
-  
-  def self.max_panel_size
-    200
-  end
-  
-  def self.page prm = nil
-    page = prm.to_i
-    page = 1 if page < 1
-    page
-  end
-  
-  def self.page_size prm = self.default_page_size
-    page_size = prm.to_i
-    page_size = self.max_page_size if page_size > self.max_page_size
-    page_size = self.default_page_size if page_size < 1
-    page_size
-  end
-  
   def self.list_order
     'scrolls.updated_at desc'
   end
@@ -104,52 +51,6 @@ class Scroll < ActiveRecord::Base
     'scrolls.visible > 0'
   end
   
-  def self.mylist_where au
-    ['scrolls.author_id = ?', au.id]
-  end
-  
-  def self.himlist_where au
-    ['scrolls.author_id = ? and scrolls.visible > 0', au.id]
-  end
-  
-  def self.list page = 1, page_size = self.default_page_size
-    Scroll.where(self.list_where()).includes(Scroll.list_opt).order('scrolls.updated_at desc').offset((page -1) * page_size).limit(page_size)
-  end
-  
-  def self.mylist au, page = 1, page_size = Author.default_scroll_page_size
-    Scroll.where(self.mylist_where(au)).includes(Scroll.list_opt).order('scrolls.updated_at desc').offset((page -1) * page_size).limit(page_size)
-  end
-  
-  def self.himlist au, page = 1, page_size = Author.default_scroll_page_size
-    Scroll.where(self.himlist_where(au)).includes(Scroll.list_opt).order('scrolls.updated_at desc').offset((page -1) * page_size).limit(page_size)
-  end
-  
-  def self.list_paginate page = 1, page_size = self.default_page_size
-    Kaminari.paginate_array(Array.new(Scroll.where(self.list_where()).count, nil)).page(page).per(page_size)
-  end
-  
-  def self.mylist_paginate au, page = 1, page_size = Author.default_scroll_page_size
-    Kaminari.paginate_array(Array.new(Scroll.where(self.mylist_where(au)).count, nil)).page(page).per(page_size)
-  end
-  
-  def self.himlist_paginate au, page = 1, page_size = Author.default_scroll_page_size
-    Kaminari.paginate_array(Array.new(Scroll.where(self.himlist_where(au)).count, nil)).page(page).per(page_size)
-  end
-  
-  def self.list_by_panel panel_id, roles, page = 1, page_size = self.default_page_size
-    self.where(ScrollPanel.list_by_panel_where(panel_id)).includes(
-      {:scroll_panels => {}}
-    ).order('scroll_panels.updated_at desc').offset((page -1) * page_size).limit(page_size)
-  end
-  
-  def self.list_by_author_where author_id
-    ['scrolls.author_id = ?', author_id]
-  end
-  
-  def self.list_by_author author_id, roles, page = 1, page_size = self.default_page_size
-    self.where(self.list_by_author_where(author_id)).includes(self.list_opt).order('scrolls.updated_at desc').offset((page -1) * page_size).limit(page_size)
-  end
-  
   def self.list_opt
     {:scroll_panels => {:panel => {}}, :author => {} }
   end
index 765480d..173850c 100644 (file)
@@ -6,14 +6,16 @@ class Pettanr::Item < ActiveRecord::Base
   
   before_validation :valid_encode
   
-  cattr_accessor :valid_encode_columns, :default_page_size, :max_page_size, :visible_count_options
+  cattr_accessor :valid_encode_columns, :visible_count_options
   @@valid_encode_columns = []
-  @@default_page_size = 25
-  @@max_page_size = 100
   @@visible_count_options = {}
-  cattr_reader :singular, :plural
-  @@singular = 'Item'
-  @@plural = 'Items'
+  def self.singular
+    'Item'
+  end
+  
+  def self.plural
+    'Items'
+  end
   
   def self.item_name
     self.singular.underscore
@@ -23,21 +25,6 @@ class Pettanr::Item < ActiveRecord::Base
     self.plural.underscore
   end
   
-  def public_list
-  end
-  
-  def private_list operators
-  end
-  
-  def has_many_list foreign_key, item, operators
-  end
-  
-  def has_many_through_list foreign_key, item, operators
-  end
-  
-  def filtered_list filter_key, item, operators
-  end
-  
   def self.list_where
     ''
   end
@@ -46,16 +33,6 @@ class Pettanr::Item < ActiveRecord::Base
     ''
   end
   
-  def self.list page = 1, page_size = self.default_page_size
-    self.where(self.list_where()).includes(self.list_opt).order(self.list_order).offset((page -1) * page_size).limit(page_size)
-  end
-  
-  def self.list_paginate page = 1, page_size = self.default_page_size
-    Kaminari.paginate_array(
-      Array.new(self.where(self.list_where()).includes(self.list_opt).count, nil)
-    ).page(page).per(page_size)
-  end
-  
   def self.list_opt
     {}
   end
index 177ef20..03eea9f 100644 (file)
@@ -278,7 +278,7 @@ module Pettanr
       
       def type_account view, item, operators
         if item.own? operators
-          view.link_to tag(:img, :src => view.asset_path('edit.png'), :width => 32, :height => 32), 
+          view.link_to view.tag(:img, :src => view.asset_path('edit.png'), :width => 32, :height => 32), 
             '/home/configure'
         end
       end
index a1e4c6d..ec08314 100644 (file)
@@ -39,7 +39,7 @@ module Pettanr
       end
       
       def paginate
-        @model.list_paginate(@page, @page_size)
+        Kaminari.paginate_array(Array.new(@model.where(self.where()).includes(@model.list_opt).count, nil)).page(@offset).per(@page_size)
       end
       
     end