From a139b5ea7fe0f0cefa75e4fc64d8aa33029dedc4 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Sat, 8 Mar 2014 12:28:10 +0900 Subject: [PATCH] fix model --- app/models/balloon.rb | 17 ------ app/models/ground_color.rb | 15 ----- app/models/ground_picture.rb | 7 --- app/models/panel.rb | 69 +++------------------- app/models/panel_picture.rb | 18 ------ app/models/scroll.rb | 1 + app/models/scroll_panel.rb | 5 -- app/models/sheet.rb | 22 ------- app/models/sheet_panel.rb | 126 ---------------------------------------- app/models/speech.rb | 17 ------ app/models/speech_balloon.rb | 28 --------- app/models/story.rb | 5 -- app/models/story_sheet.rb | 5 -- app/views/panels/_body.html.erb | 3 +- lib/peta/element.rb | 2 +- lib/peta/item.rb | 1 + public/manifest.json | 31 +++++----- 17 files changed, 29 insertions(+), 343 deletions(-) diff --git a/app/models/balloon.rb b/app/models/balloon.rb index b36a825c..8f08c83c 100644 --- a/app/models/balloon.rb +++ b/app/models/balloon.rb @@ -1,6 +1,5 @@ class Balloon < Peta::Content load_manifest - include Peta::ElementPart belongs_to :speech_balloon belongs_to :system_picture @@ -14,14 +13,6 @@ class Balloon < Peta::Content # validates :caption, :presence => true validates :settings, :extend_balloon => true - def self.colum_structures - @@colum_structures ||= { - :r => { - :helper => 'panels/tail_angle_helper' - } - } - end - def url '/system_pictures/' + self.system_picture.filename end @@ -44,14 +35,6 @@ self.system_picture_id = 1 self.get_parent.speech_balloon_template.symbol_option end - def get_parent - self.speech_balloon || @new_parent - end - - def tag_element_part_type - 'balloon' - end - def self.list_where 'panels.publish > 0' end diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index cf78ded4..f8036bdc 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -12,14 +12,6 @@ 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.colum_structures - @@colum_structures ||= { - :code => { - :helper => 'panels/color_helper' - } - } - end - def self.list_opt_for_panel { :ground_colors => { @@ -111,13 +103,6 @@ class GroundColor < Peta::Element r end - def boost - end - - def tag_element_type - 'ground_color' - end - def self.list_where 'panels.publish > 0' end diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index 779848dc..fe67caa6 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -79,13 +79,6 @@ class GroundPicture < Peta::Element self.tmb_opt_img_tag end - def boost - end - - def tag_element_type - 'ground_picture' - end - def repeat_text @@repeat_texts[self.repeat] end diff --git a/app/models/panel.rb b/app/models/panel.rb index 1c81e698..c2e0b607 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -19,10 +19,6 @@ class Panel < Peta::Content validates :author_id, :presence => true, :numericality => true, :existence => {:both => false} validates :publish, :presence => true, :numericality => true - def self.valid_encode_columns - super + ['caption'] - end - def self.each_element_class_names Manifest.manifest.system_resources.elements.each do |k, n| yield k @@ -68,60 +64,21 @@ class Panel < Peta::Content self.publish > 0 end - # ground_picture element template - def style_wh + def style { - 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px' + 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px', + 'border-style' => 'solid', 'border-width' => self.border.to_s + 'px', + 'border-color' => 'black', 'background-color' => 'white' } end - def tag_id c = nil - 'panel' + self.tag_panel_id + c.to_s - end - - def tag_panel_id - self.new_record? ? '0' : self.id.to_s - end - - def field_tag_id f - self.tag_id + f.to_s - end - - def tag_attributes column = nil, opt = {} + # ground_picture element template + def style_wh { - :id => self.field_tag_id(column), :panel_id => self.tag_panel_id - }.merge(opt) - end - - def select_tag_attributes(selected, column, opt = {}) - [ - {:html => {:selected => selected}}, - self.field_tag_attributes(column, opt) - ] - end - - def field_tag_attributes column, no_attr, opt = {} - self.tag_attributes(column).merge( - {:column => column} - ).merge(opt) - end - - def tag_attr column = nil, opt = {} - self.tag_attributes(column, opt).to_attr - end - - def field_tag_attr column, no_attr, opt = {} - self.field_tag_attributes(column, no_attr, opt).to_attr + 'width' => self.width.to_s + 'px', 'height' => self.height.to_s + 'px' + } end - def render_count - @render_count ||= 1 - end - - def rendered - @render_count = render_count + 1 - end - def self.list_where 'panels.publish > 0' end @@ -268,16 +225,6 @@ class Panel < Peta::Content Panel.validate_elements_serial validate_serial_list end - def boost - @new_element_index = 0 - self.panel_elements.each do |elm| - if elm.new_record? - elm.new_index = @new_element_index - @new_element_index += 1 - end - end - end - def store attr, operators if attr == false self.errors.add :base, I18n.t('errors.invalid_json') diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index 4c463d9a..e79836a6 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -14,17 +14,6 @@ class PanelPicture < Peta::Element validates :z, :presence => true, :numericality => {:greater_than => 0} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - def self.colum_structures - @@colum_structures ||= { - :width => { - :helper => 'panels/size_helper' - }, - :height => { - :helper => 'panels/size_helper' - } - } - end - def self.list_opt_for_panel { :panel_pictures => { @@ -109,13 +98,6 @@ class PanelPicture < Peta::Element self.picture.symbol_option end - def boost - end - - def tag_element_type - 'panel_picture' - end - def self.list_where 'panels.publish > 0' end diff --git a/app/models/scroll.rb b/app/models/scroll.rb index a5690134..4c1d21a8 100644 --- a/app/models/scroll.rb +++ b/app/models/scroll.rb @@ -6,6 +6,7 @@ class Scroll < Peta::Content validates :title, :presence => true, :length => {:maximum => 100} validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1} validates :author_id, :presence => true, :numericality => true, :existence => {:both => false} + def supply_default self.visible = 0 if self.visible.blank? end diff --git a/app/models/scroll_panel.rb b/app/models/scroll_panel.rb index 356efd0e..ea41ed21 100644 --- a/app/models/scroll_panel.rb +++ b/app/models/scroll_panel.rb @@ -9,11 +9,6 @@ class ScrollPanel < Peta::Element validates :author_id, :presence => true, :numericality => true, :existence => {:both => false} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - def tag_attributes column = nil, opt = {} - { - } - end - def supply_default self.scroll_id = nil self.panel_id = nil diff --git a/app/models/sheet.rb b/app/models/sheet.rb index ee85e6f0..b36a3b11 100644 --- a/app/models/sheet.rb +++ b/app/models/sheet.rb @@ -53,18 +53,6 @@ class Sheet < Peta::Content def symbol_filename end - def tag_id - 'sheet' + self.tag_sheet_id - end - - def tag_sheet_id - self.new_record? ? '0' : self.id.to_s - end - - def field_tag_id f - self.tag_id + f.to_s - end - def self.list_where 'sheets.visible > 0' end @@ -173,16 +161,6 @@ class Sheet < Peta::Content Sheet.validate_elements_serial validate_serial_list end - def boost - @new_element_index = 0 - self.panel_elements.each do |elm| - if elm.new_record? - elm.new_index = @new_element_index - @new_element_index += 1 - end - end - end - def store attr, operators if attr == false self.errors.add :base, I18n.t('errors.invalid_json') diff --git a/app/models/sheet_panel.rb b/app/models/sheet_panel.rb index 300980c2..28944840 100644 --- a/app/models/sheet_panel.rb +++ b/app/models/sheet_panel.rb @@ -155,16 +155,6 @@ class SheetPanel < Peta::Element end end - def boost operators - if self.panel - self.panel.author_id = operators.author.id - self.panel.panel_elements.each do |elm| - elm.new_panel = self - elm.boost - end - end - end - def panel_attributes if self.panel {'panel_attributes' => self.panel.copy} @@ -279,120 +269,4 @@ class SheetPanel < Peta::Element res end - # element.rb - def self.colum_structures - @@colum_structures ||= { - } - end - - def self.path_name with_engine = false - self.to_s.tableize - end - - def new_index - @new_index - end - - def new_index= v - @new_index = v - end - - def new_sheet - @new_sheet - end - - def new_sheet= v - @new_sheet = v - end - - def get_sheet - self.sheet || @new_sheet - end - - def tag_id c = nil - 'sheet' + self.tag_sheet_id + self.tag_element_type + self.tag_element_id + c.to_s - end - - def field_tag_id f - self.tag_id + f.to_s - end - - def tag_sheet_id - (self.get_sheet == nil or self.get_sheet.new_record?) ? '0' : self.get_sheet.id.to_s - end - - def tag_element_id - self.new_record? ? '0' : self.id.to_s - end - - def tag_element_type - 'sheet_panel' - end - - def tag_new_index - self.new_index.to_s - end - - def path_name with_engine = false - self.class.path_name(with_engine) - end - - def form_template with_engine = false - self.path_name(with_engine) + '/form' - end - - def scenario_template with_engine = false - self.path_name(with_engine) + '/scenario' - end - - def element_face_template with_engine = false - self.path_name(with_engine) + '/element_face' - end - - def form_helper_template(colum_name) - self.class.colum_structures[colum_name][:helper] - end - - def tag_attributes column = nil, opt = {} - { - :id => self.field_tag_id(column), :sheet_id => self.tag_sheet_id, - :element_id => self.tag_element_id, :element_type => self.tag_element_type - }.merge(opt) - end - - def field_tag_attributes column, no_attr, opt = {} - self.tag_attributes(column).merge( - {:column => column, :new_index => self.tag_new_index, :no_attr => no_attr} - ).merge(opt) - end - - #render element by body - def any_tag_attributes name = nil, opt = {} - r = self.tag_attributes(name) - r.merge!( - {:new_index => self.tag_new_index} - ) if self.new_index - r.merge(opt) - end - - def select_tag_attributes(selected, column, no_attr) - [ - :last, :first, - {:html => {:selected => selected}}, - self.field_tag_attributes(column, no_attr) - ] - end - - def tag_attr column = nil, opt = {} - self.tag_attributes(column, opt).to_attr - end - - def field_tag_attr column, no_attr, opt = {} - self.field_tag_attributes(column, no_attr, opt).to_attr - end - - def any_tag_attr name = nil, opt = {} - self.any_tag_attributes(name, opt).to_attr - end - end diff --git a/app/models/speech.rb b/app/models/speech.rb index 506671c6..f42b2a7b 100644 --- a/app/models/speech.rb +++ b/app/models/speech.rb @@ -1,6 +1,5 @@ class Speech < Peta::Content load_manifest - include Peta::ElementPart belongs_to :speech_balloon belongs_to :writing_format @@ -18,14 +17,6 @@ class Speech < Peta::Content @@text_align_texts = ['left', 'left', 'right', 'center'] - def self.colum_structures - @@colum_structures ||= { - :fore_color => { - :helper => 'panels/color_helper' - } - } - end - def supply_default self.x = 0 self.y = 0 @@ -42,14 +33,6 @@ class Speech < Peta::Content self.get_parent.speech_balloon_template.symbol_option end - def get_parent - self.speech_balloon || @new_parent - end - - def tag_element_part_type - 'speech' - end - def outer_style { 'top' => self.y, 'left' => self.x, diff --git a/app/models/speech_balloon.rb b/app/models/speech_balloon.rb index 50775504..f9d9ceca 100644 --- a/app/models/speech_balloon.rb +++ b/app/models/speech_balloon.rb @@ -58,30 +58,6 @@ class SpeechBalloon < Peta::Element self.speech_balloon_template.symbol_option end - def new_balloon - @new_balloon - end - - def new_balloon= v - @new_balloon = v - end - - def get_balloon - self.balloon || @new_balloon - end - - def new_speech - @new_speech - end - - def new_speech= v - @new_speech = v - end - - def get_speech - self.speech || @new_speech - end - def boost self.extend self.speech_balloon_template.engine_extend_module if self.balloon @@ -137,10 +113,6 @@ class SpeechBalloon < Peta::Element 'speech_balloons.updated_at desc' end - def self.list_opt - {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} } - end - def self.list_json_opt {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }} end diff --git a/app/models/story.rb b/app/models/story.rb index 91532304..2cb5ab4f 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -9,11 +9,6 @@ class Story < Peta::Content validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - def tag_attributes column = nil, opt = {} - { - } - end - def supply_default self.comic_id = nil self.visible = 0 if self.visible.blank? diff --git a/app/models/story_sheet.rb b/app/models/story_sheet.rb index 3650fe5f..140fa752 100644 --- a/app/models/story_sheet.rb +++ b/app/models/story_sheet.rb @@ -9,11 +9,6 @@ class StorySheet < Peta::Element validates :author_id, :presence => true, :numericality => true, :existence => {:both => false} validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} - def tag_attributes column = nil, opt = {} - { - } - end - def supply_default self.story_id = nil self.sheet_id = nil diff --git a/app/views/panels/_body.html.erb b/app/views/panels/_body.html.erb index bdfa554a..f7bc7374 100644 --- a/app/views/panels/_body.html.erb +++ b/app/views/panels/_body.html.erb @@ -1,4 +1,4 @@ -<%= content_tag :div, :id => panel.tag_id, :panel_id => panel.tag_panel_id, :class => "pettanr-comic-panel", :style => "width: #{panel.width}px; height: #{panel.height}px; border-style: solid; border-width: #{panel.border}px; border-color: black; background-color: white;" do %> +<%= content_tag :div, panel.tag_attributes(nil, {:panel_id => panel.id, :class => "pettanr-comic-panel", :style => raw(panel.style.to_style)}) do %> <% if panel.visible? operators -%> <% panel.panel_elements.each do |element| %> <%= render element.path_name + '/element', :element => element, :root => panel, :spot => spot %> @@ -7,4 +7,3 @@

<%= t('panels.hidden') %>

<% end %> <% end %> -<% panel.rendered %> diff --git a/lib/peta/element.rb b/lib/peta/element.rb index 3587186c..3ce72c25 100644 --- a/lib/peta/element.rb +++ b/lib/peta/element.rb @@ -47,7 +47,7 @@ module Peta def tag_attributes column = nil, opt = {} r = super - r.merge({'data-parent_dom_id' => self.parent.dom_item_id}) if self.editor + r.merge({'data-parent_dom_id' => self.parent.dom_item_id}) if self.editize? r end diff --git a/lib/peta/item.rb b/lib/peta/item.rb index 2d9604ba..9f84df3a 100644 --- a/lib/peta/item.rb +++ b/lib/peta/item.rb @@ -165,6 +165,7 @@ module Peta end def engine? + return false unless self.my_engine_resource self.my_engine_resource.resource_items.include? self.attributes[self.extend_column_name] end diff --git a/public/manifest.json b/public/manifest.json index 2fe139d1..742b311e 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1565,7 +1565,7 @@ } }, "speech_balloon": { - "extend": "classname", + "extend_column_name": "classname", "associations": { "belongs_to": { "panel": {} @@ -2322,6 +2322,7 @@ } }, "speech_balloon_template": { + "extend_column_name": "classname", "associations": { "belongs_to": { "system_picture": {} @@ -2388,6 +2389,7 @@ } }, "writing_format": { + "extend_column_name": "classname", "associations": { "belongs_to": { "system_picture": {} @@ -2443,6 +2445,7 @@ } }, "license_group": { + "extend_column_name": "classname", "associations": { "belongs_to": {}, "has_many": { @@ -2682,6 +2685,13 @@ "SquareSpeechBalloon": "square_speech_balloon" } }, + "speech_balloons": { + "resource_items": { + "CircleSpeechBalloon": "circle_speech_balloon", + "PlainSpeechBalloon": "plain_speech_balloon", + "SquareSpeechBalloon": "square_speech_balloon" + } + }, "writing_formats": { "has_route": 0, "resource_items": { @@ -4695,8 +4705,7 @@ "size": { "type": "size", "args": { - "path": "panels/size_helper", - "class": "panel_picture_width_tool" + "dom_class": "panel_picture_width_tool" } } }, @@ -4719,8 +4728,7 @@ "size": { "type": "size", "args": { - "path": "panels/size_helper", - "class": "panel_picture_height_tool" + "dom_class": "panel_picture_height_tool" } } }, @@ -4768,9 +4776,8 @@ }, "helpers": { "popup": { - "type": "size", + "type": "popup", "args": { - "path": "panels/popup_helper", "source": "pictures" } } @@ -4963,9 +4970,7 @@ "helpers": { "tail_angle": { "type": "size", - "args": { - "path": "panels/tail_angle_helper" - } + "args": {} } }, "row_break": true @@ -5228,9 +5233,8 @@ }, "helpers": { "color": { - "type": "size", + "type": "color", "args": { - "path": "panels/color_helper", "wrapper": "speech-fore_color-wrap" } } @@ -5423,9 +5427,8 @@ }, "helpers": { "color": { - "type": "size", + "type": "color", "args": { - "path": "panels/color_helper", "wrapper": "ground_color-code-wrap" } } -- 2.11.0