OSDN Git Service

fix root json
authoryasushiito <yas@pen-chan.jp>
Mon, 9 Jun 2014 02:54:49 +0000 (11:54 +0900)
committeryasushiito <yas@pen-chan.jp>
Mon, 9 Jun 2014 02:54:49 +0000 (11:54 +0900)
13 files changed:
app/assets/javascripts/manifest/work/models.js.coffee.erb
app/controllers/application_controller.rb
app/controllers/panels_controller.rb
app/controllers/sheets_controller.rb
app/models/balloon.rb
app/models/ground_color.rb
app/models/ground_picture.rb
app/models/panel_picture.rb
app/models/speech.rb
app/models/speech_balloon.rb
lib/peta/element_part.rb [deleted file]
lib/peta/root.rb
public/manifest.json

index af1ff24..b78faa7 100644 (file)
       belongs_to: {\r
         panel: {\r
         }, \r
+        speech_balloon_template: {\r
+        }, \r
       },\r
       has_many: {\r
       },\r
index beb0c2b..00f2d46 100644 (file)
@@ -178,6 +178,10 @@ class ApplicationController < ActionController::Base
     format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
   end
   
+  def show_json_format_for_root format
+    format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
+  end
+  
   def set_new
     set_model
     @item = @my_model_class.new
index 16ab110..3b49da4 100644 (file)
@@ -67,7 +67,7 @@ class PanelsController < ApplicationController
     respond_to do |format|
       show_html_format format
       show_prof_format format
-      show_json_format format
+      show_json_format_for_root format
     end
   end
 
index f65a4bf..ec3dfc9 100644 (file)
@@ -46,7 +46,7 @@ class SheetsController < ApplicationController
     respond_to do |format|
       show_html_format format
       show_prof_format format
-      show_json_format format
+      show_json_format_for_root format
     end
   end
   
index c79616d..71d97e7 100644 (file)
@@ -37,10 +37,6 @@ self.system_picture_id = 1
     'panels.publish > 0'
   end
   
-  def self.list_order
-    'balloons.updated_at desc'
-  end
-  
   def self.by_author_list_includes
     {
       :speech_balloon => {
@@ -51,22 +47,10 @@ self.system_picture_id = 1
     }
   end
   
-  def self.list_opt
-    {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}
-  end
-  
-  def self.list_json_opt
-    {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
-  end
-  
   def self.show_opt
     {:include => {:speech_balloon => {:panel => {:author => {}}, :speech => {}, :speech_balloon_template => {} }}}
   end
   
-  def self.show_json_opt
-    {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :speech => {}, :speech_balloon_template => {} }}}}
-  end
-  
   def style
     {
       'width' => self.width.to_s + 'px','height' => self.height.to_s + 'px',
index 16db781..27e1281 100644 (file)
@@ -19,25 +19,6 @@ class GroundColor < Peta::Element
     }
   end
   
-  def self.list_opt_for_panel
-    {
-      :ground_colors => {
-      }
-    }
-  end
-  
-  def self.show_opt_for_panel
-    {
-      :ground_colors => {
-      }
-    }
-  end
-  
-  def self.json_opt_for_panel
-    {
-    }
-  end
-  
   def self.has_picture?
     false
   end
@@ -113,10 +94,6 @@ class GroundColor < Peta::Element
     {:include => {:panel => {:author => {}} }}
   end
   
-  def self.show_json_opt
-    {:include => {:panel => {:include => {:author => {}}} }}
-  end
-  
   def scenario
     if caption.blank?
       ''
index af2940f..36461d3 100644 (file)
@@ -21,28 +21,6 @@ class GroundPicture < Peta::Element
     }
   end
   
-  def self.list_opt_for_panel
-    {
-      :ground_pictures => {
-        :picture => {:artist => {}, :license => {}}
-      }
-    }
-  end
-  
-  def self.show_opt_for_panel
-    {
-      :ground_pictures => {
-        :picture => {:artist => {}, :license => {}}
-      }
-    }
-  end
-  
-  def self.json_opt_for_panel
-    {
-      :picture => {:artist => {}, :license => {}}
-    }
-  end
-  
   def self.has_picture?
     true
   end
@@ -93,10 +71,6 @@ class GroundPicture < Peta::Element
     {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
   end
   
-  def self.show_json_opt
-    {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
-  end
-  
   def scenario
     if caption.blank?
       ''
index 21b3c24..df7df24 100644 (file)
@@ -21,28 +21,6 @@ class PanelPicture < Peta::Element
     }
   end
   
-  def self.list_opt_for_panel
-    {
-      :panel_pictures => {
-        :picture => {:artist => {}, :license => {}}
-      }
-    }
-  end
-  
-  def self.show_opt_for_panel
-    {
-      :panel_pictures => {
-        :picture => {:artist => {}, :license => {}}
-      }
-    }
-  end
-  
-  def self.json_opt_for_panel
-    {
-      :picture => {:artist => {}, :license => {}}
-    }
-  end
-  
   def self.has_picture?
     true
   end
@@ -109,10 +87,6 @@ class PanelPicture < Peta::Element
     {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
   end
   
-  def self.show_json_opt
-    {:include => {:panel => {:include => {:author => {}}}, :picture => {:include => {:artist => {}, :license => {}}} }}
-  end
-  
   def scenario
     if caption.blank?
       ''
index 1f0a5a5..efe2ab7 100644 (file)
@@ -66,22 +66,10 @@ class Speech < Peta::Element
     }
   end
   
-  def self.list_opt
-    {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {}} }
-  end
-  
-  def self.list_json_opt
-    {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech_balloon_template => {} }}}}
-  end
-  
   def self.show_opt
     {:include => {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {} }}}
   end
   
-  def self.show_json_opt
-    {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech_balloon_template => {} }}}}
-  end
-  
   def copy_attributes
     r = self.attributes
     r.delete 'id'
index 87272e6..9b0f612 100644 (file)
@@ -23,24 +23,6 @@ class SpeechBalloon < Peta::Element
     }
   end
   
-  def self.list_opt_for_panel
-    {
-      :speech_balloons => {:balloon => {}, :speech => {}}
-    }
-  end
-  
-  def self.show_opt_for_panel
-    {
-      :speech_balloons => {:balloon => {}, :speech => {}}
-    }
-  end
-  
-  def self.json_opt_for_panel
-    {
-      :balloon => {}, :speech => {}
-    }
-  end
-  
   def self.has_picture?
     false
   end
@@ -60,10 +42,6 @@ class SpeechBalloon < Peta::Element
     self.speech_balloon_template.symbol_option
   end
   
-  def tag_element_type
-    'speech_balloon'
-  end
-  
   def self.public_list_where
     'panels.publish > 0'
   end
@@ -72,35 +50,6 @@ class SpeechBalloon < Peta::Element
     {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
   end
   
-  def self.show_json_opt
-    {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
-  end
-  
-  def parts
-    @parts ||= [self.balloon, self.speech]
-  end
-  
-  def engine_path_name 
-    self.speech_balloon_template.engine_name + '/'
-  end
-  
-  def path_name with_engine = false
-    (with_engine ? self.engine_path_name : '') + 
-      self.class.path_name
-  end
-  
-  def form_template with_engine = false
-    self.path_name(true) + '/form'
-  end
-  
-  def speech_form_template with_engine = false
-    self.engine_path_name + 'speeches/form'
-  end
-  
-  def balloon_form_template with_engine = false
-    self.engine_path_name + 'balloons/form'
-  end
-  
   def scenario_template with_engine = false
     self.path_name(true) + '/scenario'
   end
diff --git a/lib/peta/element_part.rb b/lib/peta/element_part.rb
deleted file mode 100644 (file)
index 26ef2bc..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-module Peta
-  module ElementPart
-    def self.included(base)
-      base.extend(ClassMethods)
-      base.__send__ :include, InstanceMethods
-    end
-    
-    module ClassMethods
-      def colum_structures
-        raise
-      end
-      
-      def list_opt_for_panel
-        {}
-      end
-      
-      def show_opt_for_panel
-        {}
-      end
-      
-      def json_opt_for_panel
-        {}
-      end
-      
-      def path_name with_engine = false
-        self.to_s.tableize
-      end
-      
-    end
-    
-    module InstanceMethods
-      private
-      
-      public
-      
-      def has_picture?
-        false
-      end
-      
-      def has_helper? column_name
-        self.class.colum_structures[column_name] and self.class.colum_structures[column_name][:helper]
-      end
-      
-      def new_parent
-        @new_parent
-      end
-      
-      def new_parent= v
-        @new_parent = v
-      end
-      
-      def get_parent
-        raise
-      end
-      
-      def get_panel_id
-        if self.get_parent == nil or self.get_parent.panel == nil or self.get_parent.panel.new_record?
-          0
-        else
-          self.get_parent.panel.id
-        end
-      end
-      
-      def tag_id c = nil
-        'panel' + self.tag_panel_id + self.tag_element_type + self.tag_element_id + self.tag_element_part_type + self.tag_element_part_id + c.to_s
-      end
-      
-      def field_tag_id f
-        self.tag_id + f.to_s
-      end
-      
-      def tag_panel_id
-        self.get_panel_id.to_s
-      end
-      
-      def tag_element_id
-        r = if self.get_parent == nil or self.get_parent.new_record?
-          0
-        else
-          self.get_parent.id
-        end
-        r.to_s
-      end
-      
-      def tag_element_type
-        self.get_parent.tag_element_type
-      end
-      
-      def tag_element_part_id
-        self.new_record? ? '0' : self.id.to_s
-      end
-      
-      def tag_element_part_type
-        'speech'
-      end
-      
-      def tag_new_index
-        if self.get_parent == nil
-          nil
-        else
-          self.get_parent.tag_new_index
-        end
-      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), :panel_id => self.tag_panel_id, 
-          :element_id => self.tag_element_id, :element_type => self.tag_element_type,
-          :element_part_id => self.tag_element_part_id, :element_part_type => self.tag_element_part_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
-  end
-end
-
index db49986..9ff74f3 100644 (file)
@@ -12,6 +12,24 @@ module Peta
     
     # Class Methods
     
+    def self.show_json_opt_for_root
+      r = (self.build_json_opt(self))
+      r[:include].merge!(:author => {})
+      r
+    end
+      
+    def self.build_json_opt my_model
+      if my_model.child_models.empty?
+        {}
+      else
+        r = {}
+        my_model.child_models.each do |child_model|
+          r[my_model.my_manifest.associations.child_element_name(child_model).to_sym] = self.build_json_opt(child_model)
+        end
+        {:include => r}
+      end
+    end
+    
     # Instance Methods
     def copy_attributes opt = {}
       r = self.attributes
index efcd87f..0e60659 100644 (file)
     "speech_balloon": {\r
       "associations": {\r
         "belongs_to": {\r
-          "panel": {}\r
+          "panel": {},\r
+          "speech_balloon_template": {}\r
         },\r
         "has_many": {},\r
         "has_one": {\r