From: yasushiito Date: Wed, 19 Mar 2014 23:13:04 +0000 (+0900) Subject: add binder X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=a4c744c11df4f274b702045ccaa7a0c7c4629716;ds=sidebyside add binder --- diff --git a/app/assets/javascripts/manifest/work/models.js.coffee.erb b/app/assets/javascripts/manifest/work/models.js.coffee.erb index d62deb56..8437e64c 100644 --- a/app/assets/javascripts/manifest/work/models.js.coffee.erb +++ b/app/assets/javascripts/manifest/work/models.js.coffee.erb @@ -1,6 +1,12 @@ #マニフェスト @models = { scroll: { + peta: { + type: 'binder', + args: { + leaf_tree_name: 'owner', + }, + }, associations: { belongs_to: { author: { @@ -52,6 +58,9 @@ }, }, scroll_panel: { + peta: { + type: 'leaf', + }, associations: { belongs_to: { panel: { @@ -99,6 +108,12 @@ }, }, comic: { + peta: { + type: 'binder', + args: { + leaf_tree_name: 'owner', + }, + }, associations: { belongs_to: { author: { @@ -147,6 +162,12 @@ }, }, story: { + peta: { + type: 'binder', + args: { + leaf_tree_name: 'owner', + }, + }, associations: { belongs_to: { comic: { @@ -205,6 +226,9 @@ }, }, story_sheet: { + peta: { + type: 'leaf', + }, associations: { belongs_to: { story: { @@ -250,6 +274,12 @@ }, }, sheet: { + peta: { + type: 'root', + args: { + element_tree_name: 'owner', + }, + }, associations: { belongs_to: { author: { @@ -314,6 +344,12 @@ }, }, sheet_panel: { + peta: { + type: 'element', + args: { + element_tree_name: 'owner', + }, + }, associations: { belongs_to: { sheet: { @@ -468,6 +504,12 @@ }, }, panel_picture: { + peta: { + type: 'element', + args: { + element_tree_name: 'panel', + }, + }, associations: { belongs_to: { panel: { @@ -553,6 +595,12 @@ }, }, speech_balloon: { + peta: { + type: 'element', + args: { + element_tree_name: 'panel', + }, + }, extend_column_name: 'classname', associations: { belongs_to: { @@ -622,6 +670,12 @@ }, }, balloon: { + peta: { + type: 'element', + args: { + element_tree_name: 'panel', + }, + }, associations: { belongs_to: { speech_balloon: { @@ -696,6 +750,12 @@ }, }, speech: { + peta: { + type: 'element', + args: { + element_tree_name: 'panel', + }, + }, associations: { belongs_to: { speech_balloon: { @@ -812,6 +872,12 @@ }, }, ground_picture: { + peta: { + type: 'element', + args: { + element_tree_name: 'panel', + }, + }, associations: { belongs_to: { panel: { @@ -891,6 +957,12 @@ }, }, ground_color: { + peta: { + type: 'element', + args: { + element_tree_name: 'panel', + }, + }, associations: { belongs_to: { panel: { diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2d4d0d90..620649cf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -217,13 +217,12 @@ class ApplicationController < ActionController::Base end def assist_items item_name, list_name - list = Manifest.manifest.list_groups[item_name].lists[list_name] + list = Manifest::View::ListGroup.list item_name, list_name list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5}) list_result.items end def assist_filer item_name, items - @filer = Manifest::View::Filer.new @list.item_name, list_result.items, list_result.paginate, @operators filer_manager = Pettanr::Application::manifest.filer_managers[item_name] filer_manager.open(item_name, items, @operators, nil) end diff --git a/app/models/balloon.rb b/app/models/balloon.rb index b6a4bbb0..a4c04cb2 100644 --- a/app/models/balloon.rb +++ b/app/models/balloon.rb @@ -1,4 +1,4 @@ -class Balloon < Peta::Content +class Balloon < Peta::Element load_manifest belongs_to :speech_balloon belongs_to :system_picture diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index f8036bdc..581cfa92 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -1,6 +1,5 @@ class GroundColor < Peta::Element load_manifest - include ElementInspire belongs_to :panel belongs_to :color diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index fe67caa6..eb9f38d0 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -1,6 +1,5 @@ class GroundPicture < Peta::Element load_manifest - include ElementInspire belongs_to :panel belongs_to :picture diff --git a/app/models/license_group.rb b/app/models/license_group.rb index 638cb366..b8f0ea20 100644 --- a/app/models/license_group.rb +++ b/app/models/license_group.rb @@ -1,5 +1,5 @@ #ライセンスグループ -class LicenseGroup < Peta::Item +class LicenseGroup < Peta::SystemResource load_manifest has_many :licenses @@ -22,12 +22,6 @@ class LicenseGroup < Peta::Item 'license_groups.name asc' end - def self.enable_list - LicenseGroup.find(:all).delete_if {|lg| - lg.enable? == false - } - end - def self.list_opt {:include => {:licenses => {}}} end diff --git a/app/models/panel.rb b/app/models/panel.rb index 4deb49f2..606b7623 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -206,7 +206,6 @@ class Panel < Peta::Root res = false Panel.transaction do self.panel_elements.each do |elm| - elm.new_panel = self elm.boost end #self.publish = nil @@ -253,23 +252,6 @@ class Panel < Peta::Root res end - def copy - attr = self.copy_attributes - self.class.child_models('panel') do |child_model| - attr.merge! child_model.panelize(self.element_items(child_model).map {|elm| elm.copy_attributes}) - end - attr - end - - def copy_attributes - r = self.attributes - r.delete 'id' - r.delete 'author_id' - r.delete 'created_at' - r.delete 'updated_at' - r - end - def self.panelize panel attr = panel.attributes attr.delete 'id' diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index e79836a6..2943844a 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -1,6 +1,5 @@ class PanelPicture < Peta::Element load_manifest - include ElementInspire belongs_to :panel belongs_to :picture diff --git a/app/models/scroll.rb b/app/models/scroll.rb index 4c1d21a8..10baaefc 100644 --- a/app/models/scroll.rb +++ b/app/models/scroll.rb @@ -1,4 +1,4 @@ -class Scroll < Peta::Content +class Scroll < Peta::Binder load_manifest has_many :scroll_panels belongs_to :author diff --git a/app/models/scroll_panel.rb b/app/models/scroll_panel.rb index ea41ed21..8d9f4223 100644 --- a/app/models/scroll_panel.rb +++ b/app/models/scroll_panel.rb @@ -1,4 +1,4 @@ -class ScrollPanel < Peta::Element +class ScrollPanel < Peta::Leaf load_manifest belongs_to :author belongs_to :panel diff --git a/app/models/sheet.rb b/app/models/sheet.rb index b36a3b11..ffcb3dde 100644 --- a/app/models/sheet.rb +++ b/app/models/sheet.rb @@ -1,4 +1,4 @@ -class Sheet < Peta::Content +class Sheet < Peta::Root load_manifest has_many :sheet_panels has_many :story_sheets diff --git a/app/models/speech.rb b/app/models/speech.rb index fd0dd993..36cae49b 100644 --- a/app/models/speech.rb +++ b/app/models/speech.rb @@ -1,4 +1,4 @@ -class Speech < Peta::Content +class Speech < Peta::Element load_manifest belongs_to :speech_balloon belongs_to :writing_format diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb index 4a2ab3ce..098e0d06 100644 --- a/app/models/speech_balloon.rb +++ b/app/models/speech_balloon.rb @@ -1,6 +1,5 @@ class SpeechBalloon < Peta::Element load_manifest - include ElementInspire has_one :balloon, :dependent => :destroy has_one :speech, :dependent => :destroy belongs_to :speech_balloon_template diff --git a/app/models/speech_balloon_template.rb b/app/models/speech_balloon_template.rb index a4ad04ad..9351b3ae 100644 --- a/app/models/speech_balloon_template.rb +++ b/app/models/speech_balloon_template.rb @@ -1,5 +1,5 @@ #フキダシテンプレート -class SpeechBalloonTemplate < Peta::Item +class SpeechBalloonTemplate < Peta::SystemResource load_manifest has_many :speech_balloons belongs_to :system_picture @@ -22,12 +22,6 @@ class SpeechBalloonTemplate < Peta::Item self.system_picture.tmb_opt_img_tag end - def self.enable_list - SpeechBalloonTemplate.find(:all).delete_if {|sbt| - sbt.enable? == false - } - end - def self.list_opt {} end diff --git a/app/models/story.rb b/app/models/story.rb index 2cb5ab4f..6d2aaf9e 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -1,5 +1,5 @@ #ストーリー -class Story < Peta::Content +class Story < Peta::Binder load_manifest has_many :story_sheets belongs_to :comic diff --git a/app/models/story_sheet.rb b/app/models/story_sheet.rb index 140fa752..d1a3961a 100644 --- a/app/models/story_sheet.rb +++ b/app/models/story_sheet.rb @@ -1,4 +1,4 @@ -class StorySheet < Peta::Element +class StorySheet < Peta::Leaf load_manifest belongs_to :author belongs_to :story diff --git a/app/models/writing_format.rb b/app/models/writing_format.rb index 44fe9f0d..f55aa7d6 100644 --- a/app/models/writing_format.rb +++ b/app/models/writing_format.rb @@ -1,4 +1,4 @@ -class WritingFormat < Peta::Item +class WritingFormat < Peta::SystemResource load_manifest has_many :speeches belongs_to :system_picture @@ -29,12 +29,6 @@ class WritingFormat < Peta::Item def self.list self.enable_list end - def self.enable_list - WritingFormat.find(:all).delete_if {|wf| - wf.enable? == false - } - end - def self.list_opt {} end diff --git a/app/views/panels/show.html.erb b/app/views/panels/show.html.erb index ee95f4e5..f6222f01 100644 --- a/app/views/panels/show.html.erb +++ b/app/views/panels/show.html.erb @@ -13,7 +13,7 @@

<%= t('panels.show.copy') -%>

<%= form_for(Panel.new, :html => {:jqform => 'pettanr-panel-form'}) do |f| %> - <%= hidden_field_tag "json", @panel.copy().to_json %> + <%= hidden_field_tag "json", @panel.post_attributes(:all).to_json %>
<%= submit_tag t('panels.show.inspire') -%>
diff --git a/config/environment.rb b/config/environment.rb index 2da6f447..81c96d01 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -2,7 +2,6 @@ require File.expand_path('../application', __FILE__) require 'RMagick' require 'rest_client' -require 'inspire' require 'picture_io' require 'pettan_imager' diff --git a/config/environments/development.rb b/config/environments/development.rb index 4b6668dd..650c671f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -2,8 +2,8 @@ Pettanr::Application.configure do ActiveSupport::Dependencies.autoload_paths << File::join( Rails.root, 'lib') ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Editor' - ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Manifest' ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Peta' + ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Manifest' # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on diff --git a/lib/inspire.rb b/lib/inspire.rb deleted file mode 100644 index ca844eda..00000000 --- a/lib/inspire.rb +++ /dev/null @@ -1,69 +0,0 @@ -module ElementInspire - def self.included(base) - base.extend(ClassMethods) - base.__send__ :include, InstanceMethods - end - - module ClassMethods - def panelize elements_attributes - elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array) - hash = {} - index = 0 - elements_attributes.each do |element_attributes| - hash[self.to_s.tableize + '_attributes'] ||= {} - n = if element_attributes['id'] - element_attributes['id'].to_s - else - index += 1 - 'new' + index.to_s - end - hash[self.to_s.tableize + '_attributes'][n] = element_attributes - end - hash - end - end - - module InstanceMethods - private - - public - - def parts - @parts ||= [] - end - - def copy_attributes - r = self.attributes - r.delete 'id' - r.delete 'panel_id' - r.delete 'created_at' - r.delete 'updated_at' - self.parts.each do |part| - new_part_attr = part ? part.class.panelize(part.copy_attributes) : {} - r.merge! new_part_attr - end - r - end - - def copy to_panel - new_element = self.class.new self.copy_attributes - new_element.t = to_panel.new_t - new_element.z = to_panel.new_z - new_attr = new_element.class.panelize new_element.copy_attributes - r = {} #Panel.panelize to_panel - r.merge! new_attr - r - end - - def copy_all index - new_element = self.class.new self.copy_attributes - new_attr = new_element.class.panelize(new_element.copy_attributes, index) - r = {} #Panel.panelize to_panel - r.merge! new_attr - r - end - - end - -end - diff --git a/lib/manifest/local/view/list_group/list/system_resource.rb b/lib/manifest/local/view/list_group/list/system_resource.rb index a614e28a..321746ef 100644 --- a/lib/manifest/local/view/list_group/list/system_resource.rb +++ b/lib/manifest/local/view/list_group/list/system_resource.rb @@ -8,7 +8,10 @@ module Manifest end def items operators, options, offset, page_size - @model.enable_list + # enable_list does not work when configured auto load in development.rb + # auto loader undefing MODEL at reload manifest file + # @model.enable_list + super end end diff --git a/lib/manifest/manifest.rb b/lib/manifest/manifest.rb index 12f5c89f..866ed0da 100644 --- a/lib/manifest/manifest.rb +++ b/lib/manifest/manifest.rb @@ -33,20 +33,6 @@ module Manifest end end - def add_action - return - @controllers.each do |controller_name, controller| - model_name = controller.model_name - next if model_name.blank? - controller.actions.each do |action_name, conf| - next unless conf['type'] == 'list' - list_name = conf['list']['list_name'] - list = Pettanr::Application::manifest.list_managers[model_name] - list.add_action action_name, list_name - end - end - end - end module ModuleMethods diff --git a/lib/manifest/model/peta.rb b/lib/manifest/model/peta.rb index 32b30d04..ec46382e 100644 --- a/lib/manifest/model/peta.rb +++ b/lib/manifest/model/peta.rb @@ -4,13 +4,16 @@ require_dependency "manifest/model/peta/owner" require_dependency "manifest/model/peta/content" require_dependency "manifest/model/peta/root" require_dependency "manifest/model/peta/element" +require_dependency "manifest/model/peta/binder" +require_dependency "manifest/model/peta/leaf" module Manifest module ModelModule class PetaFactory include PetaModule @@types = { 'item' => ItemPeta, 'owner' => OwnerPeta, 'content' => ContentPeta, - 'root' => RootPeta, 'element' => ElementPeta + 'root' => RootPeta, 'element' => ElementPeta, + 'binder' => BinderPeta, 'leaf' => LeafPeta } def self.factory model, my_manifest my_manifest['type'] ||= 'item' diff --git a/lib/manifest/model/peta/binder.rb b/lib/manifest/model/peta/binder.rb new file mode 100644 index 00000000..1f85e940 --- /dev/null +++ b/lib/manifest/model/peta/binder.rb @@ -0,0 +1,21 @@ +module Manifest + module ModelModule + module PetaModule + class BinderPeta < BasePeta + attr :leaf_tree_name + + def set_default + super + raise "undefined leaf_tree_name for models> #{@model.model_name} > peta \n" unless @peta_manifest['args']['leaf_tree_name'] + end + + def init + super + @leaf_tree_name = @args['leaf_tree_name'] + end + + end + + end + end +end diff --git a/lib/manifest/model/peta/element.rb b/lib/manifest/model/peta/element.rb index cf7c5419..434094bc 100644 --- a/lib/manifest/model/peta/element.rb +++ b/lib/manifest/model/peta/element.rb @@ -2,13 +2,16 @@ module Manifest module ModelModule module PetaModule class ElementPeta < BasePeta + attr :element_tree_name def set_default super + raise "undefined element_tree_name for models> #{@model.model_name} > peta \n" unless @peta_manifest['args']['element_tree_name'] end def init super + @element_tree_name = @args['element_tree_name'] end end diff --git a/lib/manifest/model/peta/leaf.rb b/lib/manifest/model/peta/leaf.rb new file mode 100644 index 00000000..ad672f33 --- /dev/null +++ b/lib/manifest/model/peta/leaf.rb @@ -0,0 +1,18 @@ +module Manifest + module ModelModule + module PetaModule + class LeafPeta < BasePeta + + def set_default + super + end + + def init + super + end + + end + + end + end +end diff --git a/lib/peta.rb b/lib/peta.rb index bb701f47..7e50b1de 100644 --- a/lib/peta.rb +++ b/lib/peta.rb @@ -2,8 +2,11 @@ module Peta end require_dependency 'peta/item' require_dependency 'peta/owner' +require_dependency 'peta/system_resource' require_dependency 'peta/content' -require_dependency 'peta/element' -require_dependency 'peta/element_part' +require_dependency 'peta/element_nestable_content' require_dependency 'peta/root' +require_dependency 'peta/element' +require_dependency 'peta/binder' +require_dependency 'peta/leaf' require_dependency 'peta/editize' diff --git a/lib/peta/binder.rb b/lib/peta/binder.rb new file mode 100644 index 00000000..9d0aa6c1 --- /dev/null +++ b/lib/peta/binder.rb @@ -0,0 +1,33 @@ +module Peta + class Binder < Content + self.abstract_class = true + + # Dynamic Methods + + def self._leaf_tree_name + self.my_manifest.peta.leaf_tree_name + end + + def self.load_manifest + super + # Class Methods + n = self._leaf_tree_name + define_singleton_method("leaf_tree_name") do + n + end + # Instance Methods + define_method("leaf_items") do |leaf_model| + self.__send__ self.class.my_manifest.associations.child_element_name(leaf_model) + end + define_method("leafs_items") do + self.class.child_models(self.class.leaf_tree_name).map {|child_model| + self.leaf_items child_model + }.flatten + end + end + + # Class Methods + + end +end + diff --git a/lib/peta/editize.rb b/lib/peta/editize.rb index ce2be2fa..ff8550b5 100644 --- a/lib/peta/editize.rb +++ b/lib/peta/editize.rb @@ -46,6 +46,14 @@ module Peta super.merge!({'id' => self.dom_item_id(name)}) end + def post_attribute_key + if self.new_record? + self.dom_pool_type + else + super + end + end + end end diff --git a/lib/peta/element.rb b/lib/peta/element.rb index 3ce72c25..ccdbbf86 100644 --- a/lib/peta/element.rb +++ b/lib/peta/element.rb @@ -1,5 +1,5 @@ module Peta - class Element < Content + class Element < ElementNestableContent self.abstract_class = true # Dynamic ClassMethods @@ -17,6 +17,23 @@ module Peta {} end + def self.panelize elements_attributes + elements_attributes = [elements_attributes] unless elements_attributes.is_a?(Array) + hash = {} + index = 0 + elements_attributes.each do |element_attributes| + hash[self.to_s.tableize + '_attributes'] ||= {} + n = if element_attributes['id'] + element_attributes['id'].to_s + else + index += 1 + 'new' + index.to_s + end + hash[self.to_s.tableize + '_attributes'][n] = element_attributes + end + hash + end + def has_picture? false end @@ -58,6 +75,17 @@ module Peta }) end + def copy_attributes opt = {} + r = self.attributes + r.delete 'id' + r.delete 'panel_id' + r.delete 't' unless opt[:all] + r.delete 'z' unless opt[:all] + r.delete 'created_at' + r.delete 'updated_at' + r + end + end end diff --git a/lib/peta/element_nestable_content.rb b/lib/peta/element_nestable_content.rb new file mode 100644 index 00000000..eed0fa19 --- /dev/null +++ b/lib/peta/element_nestable_content.rb @@ -0,0 +1,51 @@ +module Peta + class ElementNestableContent < Content + self.abstract_class = true + + # Dynamic Methods + + def self._element_tree_name + self.my_manifest.peta.element_tree_name + end + + def self.load_manifest + super + # Class Methods + n = self._element_tree_name + define_singleton_method("element_tree_name") do + n + end + c = self.child_models(self.element_tree_name) + define_singleton_method("element_models") do + c + end + # Instance Methods + define_method("element_items") do |element_model| + self.__send__ self.class.my_manifest.associations.child_element_name(element_model) + end + define_method("elements_items") do + self.class.element_models.map {|element_model| + self.element_items element_model + }.flatten + end + end + + # Class Methods + + # Instance Methods + def post_attributes opt = {} + attr = self.copy_attributes + hash = {} + self.class.element_models.each do |element_model| + name = self.class.my_manifest.associations.child_element_name(element_model) + '_attributes' + hash[name] ||= {} + self.element_items(element_model).each do |element| + hash[name][element.post_attribute_key] = element.post_attributes opt + end + end + attr.merge hash + end + + end +end + diff --git a/lib/peta/item.rb b/lib/peta/item.rb index 83466156..b6ac63da 100644 --- a/lib/peta/item.rb +++ b/lib/peta/item.rb @@ -226,5 +226,9 @@ module Peta ) end + def post_attribute_key + self.dom_id + end + end end diff --git a/lib/peta/leaf.rb b/lib/peta/leaf.rb new file mode 100644 index 00000000..8dedbd6d --- /dev/null +++ b/lib/peta/leaf.rb @@ -0,0 +1,132 @@ +module Peta + class Leaf < Content + self.abstract_class = true + + # Dynamic ClassMethods + + def self.play_list_where cid + ['scroll_panels.scroll_id = ?', cid] + end + + def self.play_list scroll, author, offset = 0, limit = ScrollPanel.default_panel_size + ScrollPanel.where(self.play_list_where(scroll.id)).includes(ScrollPanel.list_opt).order('scroll_panels.t').offset(offset).limit(limit) + end + + def self.play_sheet_where sid + ['story_sheets.story_id = ?', sid] + end + + def self.play_sheet story, operators, page = 1 + ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first + if ss + if ss.sheet + Sheet.show(ss.sheet.id, operators) + else + nil + end + else + nil + end + end + + def self.play_paginate story, page + Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1) + end + + def self.new_t binder_id + r = ScrollPanel.max_t(binder_id) + r.blank? ? 0 : r.to_i + 1 + end + + def self.max_t binder_id + self.class..maximum(:t, :conditions => ['scroll_id = ?', binder_id]) + end + + def self.find_t binder_id, t + self.class.find(:first, :conditions => ['scroll_id = ? and t = ?', binder_id, t]) + end + + def self.collect_t scroll_panel + r = self.class.find(:all, :conditions => ['scroll_id = ?', scroll_panel.scroll_id], :order => 't') + r.map {|sp| sp.t} + end + + def self.top_sheet story, author + StorySheet.play_list(story, author).first + end + + def self.collect_t story_sheet + r = StorySheet.find(:all, :conditions => ['story_id = ?', story_sheet.story_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) + 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 +end + diff --git a/lib/peta/root.rb b/lib/peta/root.rb index 0bcfb35c..5646504d 100644 --- a/lib/peta/root.rb +++ b/lib/peta/root.rb @@ -1,33 +1,27 @@ module Peta - class Root < Content + class Root < ElementNestableContent self.abstract_class = true # Dynamic Methods - def self._element_tree_name - self.my_manifest.peta.element_tree_name - end - def self.load_manifest super # Class Methods - n = self._element_tree_name - define_singleton_method("element_tree_name") do - n - end # Instance Methods - define_method("element_items") do |element_model| - self.__send__ self.class.my_manifest.associations.child_element_name(element_model) - end - define_method("elements_items") do - self.class.child_models(self.class.element_tree_name).map {|child_model| - self.element_items child_model - }.flatten - end end # Class Methods + # Instance Methods + def copy_attributes opt = {} + r = self.attributes + r.delete 'id' + r.delete 'author_id' + r.delete 'created_at' + r.delete 'updated_at' + r + end + end end diff --git a/lib/peta/system_resource.rb b/lib/peta/system_resource.rb new file mode 100644 index 00000000..324e6329 --- /dev/null +++ b/lib/peta/system_resource.rb @@ -0,0 +1,16 @@ +module Peta + class SystemResource < Item + self.abstract_class = true + + # Dynamic ClassMethods + + # ClassMethods + + def self.enable_list + self.find(:all).delete_if {|sbt| + sbt.enable? == false + } + end + + end +end diff --git a/public/manifest.json b/public/manifest.json index 5bce8b69..370e21c3 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -896,6 +896,12 @@ }, "models": { "scroll": { + "peta": { + "type": "binder", + "args": { + "leaf_tree_name": "owner" + } + }, "associations": { "belongs_to": { "author": {} @@ -944,6 +950,9 @@ } }, "scroll_panel": { + "peta": { + "type": "leaf" + }, "associations": { "belongs_to": { "panel": {}, @@ -988,6 +997,12 @@ } }, "comic": { + "peta": { + "type": "binder", + "args": { + "leaf_tree_name": "owner" + } + }, "associations": { "belongs_to": { "author": {} @@ -1033,6 +1048,12 @@ } }, "story": { + "peta": { + "type": "binder", + "args": { + "leaf_tree_name": "owner" + } + }, "associations": { "belongs_to": { "comic": {} @@ -1087,6 +1108,9 @@ } }, "story_sheet": { + "peta": { + "type": "leaf" + }, "associations": { "belongs_to": { "story": {}, @@ -1129,6 +1153,12 @@ } }, "sheet": { + "peta": { + "type": "root", + "args": { + "element_tree_name": "owner" + } + }, "associations": { "belongs_to": { "author": {} @@ -1189,6 +1219,12 @@ } }, "sheet_panel": { + "peta": { + "type": "element", + "args": { + "element_tree_name": "owner" + } + }, "associations": { "belongs_to": { "sheet": {}, @@ -1332,6 +1368,12 @@ } }, "panel_picture": { + "peta": { + "type": "element", + "args": { + "element_tree_name": "panel" + } + }, "associations": { "belongs_to": { "panel": {} @@ -1414,6 +1456,12 @@ } }, "speech_balloon": { + "peta": { + "type": "element", + "args": { + "element_tree_name": "panel" + } + }, "extend_column_name": "classname", "associations": { "belongs_to": { @@ -1477,6 +1525,12 @@ } }, "balloon": { + "peta": { + "type": "element", + "args": { + "element_tree_name": "panel" + } + }, "associations": { "belongs_to": { "speech_balloon": {}, @@ -1547,6 +1601,12 @@ } }, "speech": { + "peta": { + "type": "element", + "args": { + "element_tree_name": "panel" + } + }, "associations": { "belongs_to": { "speech_balloon": {}, @@ -1663,6 +1723,12 @@ } }, "ground_picture": { + "peta": { + "type": "element", + "args": { + "element_tree_name": "panel" + } + }, "associations": { "belongs_to": { "panel": {} @@ -1742,6 +1808,12 @@ } }, "ground_color": { + "peta": { + "type": "element", + "args": { + "element_tree_name": "panel" + } + }, "associations": { "belongs_to": { "panel": {} @@ -2950,8 +3022,7 @@ "belongs_to": [ "system_picture" ], - "has_many": [ - ] + "has_many": [] } }, "license_group": {