OSDN Git Service

add: license publisher
[pettanr/pettanr.git] / app / models / folder.rb
index c3c8673..e004a57 100644 (file)
-class Folder < Peta::Item
+class Folder < Peta::SystemResource
   acts_as_nested_set
   
+  validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 200}
   validates :controller_name, :length => {:maximum => 200}
   validates :action_name, :length => {:maximum => 200}
   validates :category_id, :presence => true, :numericality => true
   validates :t, :presence => true, :numericality => true
   
+  #remove last dir name
+  def dir
+    r = name.split('/')
+    r.pop
+    r.join '/'
+  end
+  
+  def caption
+    name.gsub(/\/$/, '').split('/').last
+  end
+  
+  def filer_caption
+    self.caption
+  end
+  
+  def remote_name
+    '/' + self.controller_name.to_s + '/' + self.action_name.to_s
+  end
+  
+  def self.add_local parent, name
+    key = parent.name + name + '/'
+    attr = {
+      :name => key, :category_id => 0, :t => 0
+    }
+    if i = self.find_by_name(key)
+      i.attributes = attr
+      i.save
+    else
+      i = self.create attr
+    end
+    i.move_to_child_of parent
+    i
+  end
+  
+  def self.add_remote parent, name, controller_name = nil, action_name = nil
+    key = parent.name + name + '/'
+    attr = {
+      :name => key, :category_id => 10, :t => 0, 
+      :controller_name => (controller_name || name), 
+      :action_name => action_name
+    }
+    if i = self.find_by_name(key)
+      i.attributes = attr
+      i.save
+    else
+      i = self.create attr
+    end
+    i.move_to_child_of parent
+    i
+  end
+  
   def self.generate
-    if self.root
+    if r = self.find_by_name('/')
     else
-      self.create :category_id => 0
+      r = self.create :name => '/', :category_id => 0, :t => 0
     end
+    #
+    # child of root
+    #
+    manga = self.add_local r, 'manga'
+    o = self.add_local r, 'people'
+    doc = self.add_local r, 'documents'
+    mydoc = self.add_local r, 'my documents'
+    sr = self.add_local r, 'system_resource'
+    
+    # child of /manga
+    manga_scroll = self.add_remote manga, 'scrolls'
+    manga_panel = self.add_remote manga, 'panels'
+    
+    # child of /people  (owner)
+    au = self.add_remote o, 'authors'
+    ar = self.add_remote o, 'artists'
+    
+    # child of /documents
+    docman = self.add_local doc, 'manga'
+    docpic = self.add_local doc, 'pictures'
+    docparts = self.add_local doc, 'parts'
+    docidx = self.add_local doc, 'index'
+    # child of /documents/manga
+    docman_scroll = self.add_remote docman, 'scrolls'
+    docman_panel = self.add_remote docman, 'panels'
+    # child of /documents/pictures
+    docpic_resource_picture = self.add_remote docpic, 'resource_pictures'
+    # child of /documents/parts
+    docparts_panel_picture = self.add_remote docparts, 'panel_pictures'
+    docparts_speech_balloon = self.add_remote docparts, 'speech_balloons'
+    docparts_balloon = self.add_remote docparts, 'balloons'
+    docparts_speech = self.add_remote docparts, 'speeches'
+    docparts_ground_picture = self.add_remote docparts, 'ground_pictures'
+    docparts_ground_color = self.add_remote docparts, 'ground_colors'
+    # child of /documents/index  (all public contents)
+    docidx_scroll = self.add_remote docidx, 'scrolls'
+    docidx_scroll_panel = self.add_remote docidx, 'scroll_panels'
+    docidx_comic = self.add_remote docidx, 'comics'
+    docidx_comic_story = self.add_remote docidx, 'comic_stories'
+    docidx_story = self.add_remote docidx, 'stories'
+    docidx_story_sheet = self.add_remote docidx, 'story_sheets'
+    docidx_sheet = self.add_remote docidx, 'sheets'
+    docidx_sheet_panel = self.add_remote docidx, 'sheet_panels'
+    docidx_panel = self.add_remote docidx, 'panels'
+    docidx_panel_picture = self.add_remote docidx, 'panel_pictures'
+    docidx_speech_balloon = self.add_remote docidx, 'speech_balloons'
+    docidx_balloon = self.add_remote docidx, 'balloons'
+    docidx_speech = self.add_remote docidx, 'speeches'
+    docidx_ground_picture = self.add_remote docidx, 'ground_pictures'
+    docidx_ground_color = self.add_remote docidx, 'ground_colors'
+    docidx_resource_picture = self.add_remote docidx, 'resource_pictures'
+    
+    # child of /my documents
+    mydocman = self.add_local mydoc, 'manga'
+    mydocpic = self.add_local mydoc, 'pictures'
+    mydocparts = self.add_local mydoc, 'parts'
+    mydocidx = self.add_local mydoc, 'index'
+    mydocedt = self.add_local mydoc, 'create'
+    # child of /my documents/manga
+    mydocman_scroll = self.add_remote mydocman, 'scrolls', 'home', 'scrolls'
+    mydocman_panel = self.add_remote mydocman, 'panels', 'home', 'panels'
+    # child of /my documents/pictures
+    mydocpic_original_picture = self.add_remote mydocpic, 'original_pictures'
+    mydocpic_resource_picture = self.add_remote mydocpic, 'resource_pictures', 'home', 'resource_pictures'
+    # child of /my documents/parts
+    mydocparts_panel_picture = self.add_remote mydocparts, 'panel_pictures'
+    mydocparts_speech_balloon = self.add_remote mydocparts, 'speech_balloons'
+    mydocparts_balloon = self.add_remote mydocparts, 'balloons'
+    mydocparts_speech = self.add_remote mydocparts, 'speeches'
+    mydocparts_ground_picture = self.add_remote mydocparts, 'ground_pictures'
+    mydocparts_ground_color = self.add_remote mydocparts, 'ground_colors'
+    # child of /my documents/index
+    mydocidx_scroll = self.add_remote mydocidx, 'scrolls', 'home', 'scrolls'
+    mydocidx_scroll_panel = self.add_remote mydocidx, 'scroll_panels', 'home', 'scroll_panels'
+    mydocidx_comic = self.add_remote mydocidx, 'comics', 'home', 'comics'
+    mydocidx_comic_story = self.add_remote mydocidx, 'comic_stories', 'home', 'comic_stories'
+    mydocidx_story = self.add_remote mydocidx, 'stories', 'home', 'stories'
+    mydocidx_story_sheet = self.add_remote mydocidx, 'story_sheets', 'home', 'story_sheets'
+    mydocidx_sheet = self.add_remote mydocidx, 'sheets', 'home', 'sheets'
+    mydocidx_sheet_panel = self.add_remote mydocidx, 'sheet_panels', 'home', 'sheet_panels'
+    mydocidx_panel = self.add_remote mydocidx, 'panels', 'home', 'panels'
+    mydocidx_panel_picture = self.add_remote mydocidx, 'panel_pictures', 'home', 'panel_pictures'
+    mydocidx_speech_balloon = self.add_remote mydocidx, 'speech_balloons', 'home', 'speech_balloons'
+    mydocidx_balloon = self.add_remote mydocidx, 'balloons', 'home', 'balloons'
+    mydocidx_speech = self.add_remote mydocidx, 'speeches', 'home', 'speeches'
+    mydocidx_ground_picture = self.add_remote mydocidx, 'ground_pictures', 'home', 'ground_pictures'
+    mydocidx_ground_color = self.add_remote mydocidx, 'ground_colors', 'home', 'ground_colors'
+    mydocpic_original_picture = self.add_remote mydocpic, 'original_pictures'
+    mydocidx_resource_picture = self.add_remote mydocidx, 'resource_pictures', 'home', 'resource_pictures'
+    # child of /my documents/create
+    mydocedt_scroll = self.add_remote mydocedt, 'new scroll', 'scrolls', 'new'
+    mydocedt_panel = self.add_remote mydocedt, 'new panel', 'panels', 'new'
+    mydocedt_original_picture = self.add_remote mydocedt, 'upload picture', 'original_pictures', 'new'
+    # child of /my documents/create/index
+    mydocedtidx = self.add_local mydocedt, 'index'
+    mydocedtidx_scroll = self.add_remote mydocedtidx, 'new scroll', 'scrolls', 'new'
+    mydocedtidx_comic = self.add_remote mydocedtidx, 'new comic', 'comics', 'new'
+    mydocedtidx_story = self.add_remote mydocedtidx, 'new story', 'stories', 'new'
+    mydocedtidx_sheet = self.add_remote mydocedtidx, 'new sheet', 'sheets', 'new'
+    mydocedtidx_panel = self.add_remote mydocedtidx, 'new panel', 'panels', 'new'
+    
+    # child of /system_resource
+    sbt = self.add_remote sr, 'speech_balloon_templates'
+    lg = self.add_remote sr, 'license_groups'
+    ls = self.add_remote sr, 'licenses'
+    sp = self.add_remote sr, 'system_pictures'
+    wf = self.add_remote sr, 'writing_formats'
     
   end