OSDN Git Service

t#31485:editate ground_colors
authoryasushiito <yas@pen-chan.jp>
Mon, 3 Jun 2013 04:31:04 +0000 (13:31 +0900)
committeryasushiito <yas@pen-chan.jp>
Mon, 3 Jun 2013 04:31:04 +0000 (13:31 +0900)
24 files changed:
app/controllers/ground_colors_controller.rb
app/models/ground_color.rb
app/models/panel_picture.rb
app/views/authors/ground_colors.html.erb
app/views/authors/panel_pictures.html.erb
app/views/ground_colors/_body.html.erb [new file with mode: 0644]
app/views/ground_colors/_form.html.erb [new file with mode: 0644]
app/views/ground_colors/_list_item.html.erb
app/views/ground_colors/_standard.html.erb [new file with mode: 0644]
app/views/ground_colors/edit.html.erb [new file with mode: 0644]
app/views/ground_colors/index.html.erb
app/views/ground_colors/new.html.erb [new file with mode: 0644]
app/views/ground_colors/show.html.erb
app/views/home/ground_colors.html.erb
app/views/home/panel_pictures.html.erb
app/views/panel_pictures/_body.html.erb
app/views/panel_pictures/_list_item.html.erb
app/views/panel_pictures/index.html.erb
app/views/panel_pictures/show.html.erb
app/views/panels/_body.html.erb
config/locales/pettanr.ja.yml
config/routes.rb
db/migrate/20130602100811_add_caption_and_t_on_ground_colors.rb [new file with mode: 0644]
db/migrate/20130602100940_add_caption_and_t_on_ground_pictures.rb [new file with mode: 0644]

index da5244f..710a43d 100644 (file)
@@ -1,16 +1,14 @@
 class GroundColorsController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
   if MagicNumber['run_mode'] == 0
-    before_filter :authenticate_user, :only => []
-    before_filter :authenticate_author, :only => []
+    before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
   else
     before_filter :authenticate_reader, :only => [:index, :show]
-    before_filter :authenticate_user, :only => []
-    before_filter :authenticate_author, :only => []
+    before_filter :authenticate_user, :only => [:new, :edit, :create, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :edit, :create, :update, :destroy]
   end
 
-  # GET /ground_colors
-  # GET /ground_colors.json
   def index
     @page = GroundColor.page params[:page]
     @page_size = GroundColor.page_size params[:page_size]
@@ -29,4 +27,83 @@ class GroundColorsController < ApplicationController
       format.json { render json: @ground_color.to_json(GroundColor.show_json_opt) }
     end
   end
+  
+  def new
+    @ground_color = GroundColor.new params[:ground_color]
+    @ground_color.supply_default
+    @panel = @author.working_panel
+
+    respond_to do |format|
+      format.html
+      format.json { render :json => @ground_color.to_json(GroundColor.show_json_opt) }
+    end
+  end
+
+  def edit
+    @ground_color = GroundColor.show(params[:id], @author)
+    @panel = Panel.edit(@ground_color.panel.id, @author)
+    
+    respond_to do |format|
+      format.html
+    end
+  end
+
+  def create
+    @ground_color = GroundColor.new params[:ground_color]
+    @ground_color.supply_default
+    @panel = Panel.edit(@author.working_panel, @author)
+    @ground_color.overwrite @panel.id
+    
+    respond_to do |format|
+      if @ground_color.valid?
+        if @ground_color.store @author
+          flash[:notice] = I18n.t('flash.notice.created', :model => Panel.model_name.human)
+          format.html { redirect_to @panel }
+          format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel }
+        else
+          format.html { render action: "panels/new" }
+          format.json { render json: @panel.errors, status: :unprocessable_entity }
+        end
+      else
+        format.html { render action: "new" }
+        format.json { render json: @ground_color.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  def update
+    @ground_color = GroundColor.show(params[:id], @author)
+    @ground_color.attributes = params[:ground_color]
+    @panel = Panel.edit(@ground_color.panel.id, @author)
+    @ground_color.overwrite @panel.id
+    
+    respond_to do |format|
+      if @ground_color.store @author
+        flash[:notice] = I18n.t('flash.notice.updated', :model => GroundColor.model_name.human)
+        format.html { redirect_to @ground_color }
+        format.json { head :ok }
+      else
+        format.html { render action: "edit" }
+        format.json { render json: @ground_color.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  def destroy
+    @ground_color = GroundColor.show(params[:id], @author)
+    @panel = Panel.edit(@ground_color.panel.id, @author)
+    
+    respond_to do |format|
+      if @ground_color.remove @author
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => GroundColor.model_name.human)
+        format.html { redirect_to @panel }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => GroundColor.model_name.human)
+        format.html { redirect_to @ground_color }
+        format.json { render json: @ground_color.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+  
 end
index 98de711..af73c92 100644 (file)
@@ -9,7 +9,8 @@ class GroundColor < ActiveRecord::Base
   def supply_default
   end
   
-  def overwrite
+  def overwrite pid
+    self.panel_id = pid
   end
   
   def visible? roles
@@ -91,6 +92,43 @@ class GroundColor < ActiveRecord::Base
     {:include => {:panel => {:include => {:author => {}}} }}
   end
   
+  def store au
+    if self.new_record?
+      self.panel.ground_colors.build(self.attributes)
+    else
+      self.panel.ground_colors.each do |ground_color|
+        next unless ground_color == self
+        attr = self.attributes
+        attr.delete 'id'
+        ground_color.attributes = attr
+        break
+      end
+    end
+    self.panel.store({}, au)
+  end
+  
+  def remove au
+    PanelPicture.transaction do
+      d = false
+      panel_pictures_attributes = {}
+      
+      self.panel.panel_pictures.each do |panel_picture|
+        attr = panel_picture.attributes
+        if panel_picture == self
+          attr['_destroy'] = true
+          d = true
+        else
+          if d
+            attr['t']  -= 1 
+          end
+        end
+        panel_pictures_attributes[panel_picture.id] = attr
+      end
+      self.panel.attributes = {:panel_pictures_attributes => panel_pictures_attributes}
+      self.panel.store({}, au)
+    end
+  end
+  
   def scenario
     ''
   end
index 59f50f9..3334405 100644 (file)
@@ -176,10 +176,8 @@ class PanelPicture < ActiveRecord::Base
         end
         panel_pictures_attributes[panel_picture.id] = attr
       end
-p panel_pictures_attributes
       self.panel.attributes = {:panel_pictures_attributes => panel_pictures_attributes}
       self.panel.store({}, au)
-p self.panel.errors
     end
   end
   
index 4395ceb..57cba2d 100644 (file)
@@ -2,8 +2,10 @@
 
 <table>
   <tr>
-    <th><%= t_m 'GroundColor.panel_id' -%></th>
+    <th><%= t_m 'GroundColor.id' -%></th>
+    <th><%= t_m 'GroundColor.caption' -%></th>
     <th><%= t_m 'GroundColor.code' -%></th>
+    <th><%= t_m 'GroundColor.panel_id' -%></th>
     <th><%= t_m 'GroundColor.z' -%></th>
     <th><%= t_m 'GroundColor.updated_at' -%></th>
   </tr>
index b6a7e77..07f0900 100644 (file)
@@ -9,6 +9,7 @@
     <th><%=  -%></th>
     <th><%= t_m 'PanelPicture.panel_id' -%></th>
     <th><%= t_m 'PanelPicture.link' -%></th>
+    <th><%= t_m 'PanelPicture.z' -%></th>
     <th><%= t_m 'PanelPicture.updated_at' -%></th>
   </tr>
 
diff --git a/app/views/ground_colors/_body.html.erb b/app/views/ground_colors/_body.html.erb
new file mode 100644 (file)
index 0000000..3316aa8
--- /dev/null
@@ -0,0 +1,26 @@
+<div 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;">
+  <% panel.panel_elements.each do |elm| %>
+    <% case elm.class.to_s %>
+    <% when 'PanelPicture' %>
+      <%= link_to_unless(elm.link.blank?, tag(:img, elm.opt_img_tag(elm == spot ? nil : 33)), elm.link) %>
+    <% when 'SpeechBalloon' %>
+      <% balloon = elm.balloons.first %>
+      <div id="vballoon<%= elm.id -%>" class="pettanr-comic-balloon" style="width:<%= balloon.width -%>px; height:<%= balloon.height -%>px; top:<%= balloon.y -%>px; left:<%= balloon.x -%>px; z-index:<%= elm.z -%>; ">
+        <img src="<%= balloon.system_picture.url -%>" alt="<%= balloon.caption -%>">
+        <% elm.speeches.each do |speech| %>
+          <p style="top:<%= speech.y -%>px; left:<%= speech.x -%>px;width:<%= speech.width -%>px; height:<%= speech.height -%>px;">
+            <span><%= h speech.content -%></span>
+          </p>
+        <% end %>
+      </div>
+    <% when 'GroundColor' %>
+      <div id="ground-color<%= elm.id -%>" class="pettanr-comic-ground-color" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-color:#<%= format("%06x", elm.code) -%>;">
+      
+      </div>
+    <% when 'GroundPicture' %>
+      <div id="ground-picture<%= elm.id -%>" class="pettanr-comic-ground-picture" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-image: url(<%= full_url elm.picture.url -%>); background-repeat: <%= MagicNumber['ground_picture_repeat_items'][elm.repeat] -%>; background-position: <%= elm.x -%>px, <%= elm.y -%>px;">
+        
+      </div>
+    <% end %>
+  <% end %>
+</div>
diff --git a/app/views/ground_colors/_form.html.erb b/app/views/ground_colors/_form.html.erb
new file mode 100644 (file)
index 0000000..8a1d82b
--- /dev/null
@@ -0,0 +1,17 @@
+<%= form_for(@ground_color) do |f| %>
+  <%= render 'system/error_explanation', :obj => @ground_color %>
+
+  <div class="field">
+    <%= f.label :code %><br />
+    <%= f.text_field :code %>
+  </div>
+  <div class="field">
+    <%= f.label :z %><br />
+    <%= f.number_field :z %>
+  </div>
+  <%= f.hidden_field :panel_id %>
+
+  <div class="actions">
+    <%= f.submit %>
+  </div>
+<% end %>
index 101c4c9..b1d1b71 100644 (file)
@@ -1,8 +1,18 @@
 <tr>
   <td>
-    <%= link_to ground_color.panel_id, panel_path(ground_color.panel) %>
+    <%= link_to ground_color.id, ground_color_path(ground_color) %>
+  </td>
+  <td>
+    <%= link_to(h(truncate(ground_color.caption, :length => 12)), ground_color_path(ground_color)) %>
+  </td>
+  <td style="color: #<%= format("%06x", ground_color.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", ground_color.code) -%>;">
+    <%= format("%06x", ground_color.code ^ 0xffffff) %>
+  </td>
+  </td>
+  <td>
+    <%= link_to panel_icon(:object => ground_color.panel, :size => 25), panel_path(ground_color.panel) %>
+    <%= link_to h(truncate((ground_color.panel.caption), :length => 12)), panel_path(ground_color.panel) %>
   </td>
-  <td style="color: #<%= format("%06x", ground_color.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", ground_color.code) -%>;"><%= format("%06x", ground_color.code ^ 0xffffff) %></td>
   <td>
     <%= ground_color.z %>
   </td>
diff --git a/app/views/ground_colors/_standard.html.erb b/app/views/ground_colors/_standard.html.erb
new file mode 100644 (file)
index 0000000..47dee5d
--- /dev/null
@@ -0,0 +1,6 @@
+<b><%= t_m 'Panel.caption' -%>:</b>
+<%= h(panel.caption) %>
+<%= render 'panel_pictures/body', :panel => panel, :author => author, :spot => spot %>
+<%= render 'panels/footer', :panel => panel, :author => author %>
+<%= render 'panels/licensed_pictures', :licensed_pictures => panel.licensed_pictures %>
+
diff --git a/app/views/ground_colors/edit.html.erb b/app/views/ground_colors/edit.html.erb
new file mode 100644 (file)
index 0000000..7fb5b02
--- /dev/null
@@ -0,0 +1,6 @@
+<h1><%= t('.title') %></h1>
+
+<h2><%= t('home.index.catch') -%></h2>
+<%= render 'panels/standard', :panel => @panel, :author => @author %>
+<h2><%= t('ground_colors.update_color') -%></h2>
+<%= render 'form' %>
index 29c99e5..f0ddff4 100644 (file)
@@ -2,10 +2,11 @@
 
 <table>
   <tr>
-    <th><%= t_m 'GroundColor.panel_id' -%></th>
+    <th><%= t_m 'GroundColor.id' -%></th>
+    <th><%= t_m 'GroundColor.caption' -%></th>
     <th><%= t_m 'GroundColor.code' -%></th>
+    <th><%= t_m 'GroundColor.panel_id' -%></th>
     <th><%= t_m 'GroundColor.z' -%></th>
-    <th><%= t_m 'GroundColor.created_at' -%></th>
     <th><%= t_m 'GroundColor.updated_at' -%></th>
   </tr>
 
@@ -13,3 +14,4 @@
     <%= render 'list_item', :ground_color => gc %>
   <% end -%>
 </table>
+<%= link_to t('ground_colors.new.title'), new_ground_color_path %>
diff --git a/app/views/ground_colors/new.html.erb b/app/views/ground_colors/new.html.erb
new file mode 100644 (file)
index 0000000..da2a5cb
--- /dev/null
@@ -0,0 +1,6 @@
+<h1><%= t('.title') %></h1>
+
+<h2><%= t('home.index.catch') -%></h2>
+<%= render 'panels/standard', :panel => @panel, :author => @author %>
+<h2><%= t('ground_colors.create_color') -%></h2>
+<%= render 'form' %>
index 51e0115..782cf41 100644 (file)
@@ -1,3 +1,37 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
+<%= render 'panel_pictures/standard', :panel => @ground_color.panel, :author => @author, :spot => @ground_color %>
+
+<p>
+  <b><%= t_m 'GroundColor.caption' -%>:</b>
+  <%= h @ground_color.caption %>
+</p>
+
+<p>
+  <b><%= t_m 'GroundColor.z' -%>:</b>
+  <%= @ground_color.z %>
+</p>
+
+<p>
+  <b><%= t_m 'GroundColor.t' -%>:</b>
+  <%= @ground_color.t %>
+</p>
+
+<p>
+  <b><%= t_m 'GroundColor.code' -%>:</b>
+  <%= @ground_color.code %>
+</p>
+
+<p>
+  <b><%= t_m 'GroundColor.created_at' -%>:</b>
+  <%= l @ground_color.created_at %>
+</p>
+
+<p>
+  <b><%= t_m 'GroundColor.updated_at' -%>:</b>
+  <%= l @ground_color.updated_at %>
+</p>
+
+<%= link_to t('link.edit'), edit_ground_color_path(@ground_color) %>
+<%= link_to t('link.destroy'), ground_color_path(@ground_color), :method => :delete %>
index bc07f67..25c0232 100644 (file)
@@ -2,8 +2,10 @@
 
 <table>
   <tr>
-    <th><%= t_m 'GroundColor.color_id' -%></th>
+    <th><%= t_m 'GroundColor.id' -%></th>
+    <th><%= t_m 'GroundColor.caption' -%></th>
     <th><%= t_m 'GroundColor.code' -%></th>
+    <th><%= t_m 'GroundColor.panel_id' -%></th>
     <th><%= t_m 'GroundColor.z' -%></th>
     <th><%= t_m 'GroundColor.updated_at' -%></th>
   </tr>
@@ -12,3 +14,4 @@
     <%= render 'ground_colors/list_item', :ground_color => gc, :author => @author %>
   <% end -%>
 </table>
+<%= link_to t('ground_colors.new.title'), new_ground_color_path %>
index 219ef08..ccf3ec0 100644 (file)
@@ -8,6 +8,7 @@
     <th><%=  -%></th>
     <th><%= t_m 'PanelPicture.panel_id' -%></th>
     <th><%= t_m 'PanelPicture.link' -%></th>
+    <th><%= t_m 'PanelPicture.z' -%></th>
     <th><%= t_m 'PanelPicture.updated_at' -%></th>
   </tr>
 
index ad7cc2d..3316aa8 100644 (file)
         <% end %>
       </div>
     <% when 'GroundColor' %>
-      <div id="ground-color<%= elm.id -%>" class="pettanr-comic-ground-color" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-color:<%= elm.color.name -%>;">
-      
-      </div>
-    <% when 'PanelColor' %>
-      <div id="panel-color<%= elm.id -%>" class="pettanr-comic-panel-color" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-color:#<%= format("%06x", elm.code) -%>;">
+      <div id="ground-color<%= elm.id -%>" class="pettanr-comic-ground-color" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-color:#<%= format("%06x", elm.code) -%>;">
       
       </div>
     <% when 'GroundPicture' %>
index 63afb00..7201de2 100644 (file)
   <% end %>
   <td>
     <%= link_to panel_icon(:object => panel_picture.panel, :size => 25), panel_path(panel_picture.panel) %>
-    <%= h(truncate((panel_picture.panel.caption), :length => 12)) %></td>
+    <%= link_to h(truncate((panel_picture.panel.caption), :length => 12)), panel_path(panel_picture.panel) %>
+  </td>
+  <td>
+    <%= link_to h(truncate(panel_picture.link, :length => 12)), panel_picture.link %>
+  </td>
   <td>
-    <%= link_to h(truncate(panel_picture.link, :length => 12)), panel_picture.link %></td>
-  <td><%= distance_of_time_in_words_to_now panel_picture.updated_at %></td>
+    <%= panel_picture.z %>
+  </td>
+  <td>
+    <%= distance_of_time_in_words_to_now panel_picture.updated_at %>
+  </td>
 </tr>
index 70f01ee..bf79478 100644 (file)
@@ -8,6 +8,7 @@
     <th><%=  -%></th>
     <th><%= t_m 'PanelPicture.panel_id' -%></th>
     <th><%= t_m 'PanelPicture.link' -%></th>
+    <th><%= t_m 'PanelPicture.z' -%></th>
     <th><%= t_m 'PanelPicture.updated_at' -%></th>
   </tr>
 
index eb83223..f558950 100644 (file)
@@ -2,10 +2,6 @@
 <p id="notice"><%= notice %></p>
 
 <%= render 'panel_pictures/standard', :panel => @panel_picture.panel, :author => @author, :spot => @panel_picture %>
-<p>
-  <b><%= t_m 'PanelPicture.panel_id' -%>:</b>
-  <%= link_to @panel_picture.panel_id, panel_path(@panel_picture.panel) %>
-</p>
 
 <p>
   <b><%= t_m 'PanelPicture.caption' -%>:</b>
index bc598d6..09fd3b8 100644 (file)
         <% end %>
       </div>
     <% when 'GroundColor' %>
-      <div id="ground-color<%= elm.id -%>" class="pettanr-comic-ground-color" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-color:<%= elm.color.name -%>;">
-      
-      </div>
-    <% when 'PanelColor' %>
-      <div id="panel-color<%= elm.id -%>" class="pettanr-comic-panel-color" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-color:#<%= format("%06x", elm.code) -%>;">
+      <div id="ground-color<%= elm.id -%>" class="pettanr-comic-ground-color" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-color:#<%= format("%06x", elm.code) -%>;">
       
       </div>
     <% when 'GroundPicture' %>
index b347027..e765971 100644 (file)
@@ -141,12 +141,16 @@ ja:
         x: X
         y: Y
         z: 重なり
+        t: 話順
+        caption: 様子
         created_at: 作成
         updated_at: 更新
       ground_color:
         panel_id: コマ
         code: カラーコード
         z: 重なり
+        t: 話順
+        caption: 様子
         created_at: 作成
         updated_at: 更新
       original_picture:
@@ -225,6 +229,7 @@ ja:
       author:
         name: ペンネーム
         user_id: ユーザ
+        working_panel_id: つかんでいるコマ
         created_at: 作成
         updated_at: 更新
       artist:
@@ -549,10 +554,22 @@ ja:
       title: 色地一覧
     show:
       title: 色地詳細
+    new:
+      title: 色地作成
+    edit:
+      title: 色地編集
+    create:
+      title: 色地作成
+    update:
+      title: 色地編集
+    destroy:
+      title: 色地削除
     list:
       title: 色地 生一覧
     browse:
       title: 色地 生単票
+    create_color: 追加する色地
+    update_color: 変更する色地
   original_pictures:
     index:
       title: 原画一覧
index 632f6ad..38fe01c 100644 (file)
@@ -155,11 +155,17 @@ Pettanr::Application.routes.draw do
     end
   end
   resources :ground_colors do
+    new do
+      get :new
+    end
     collection do
       get :index
       get :show
     end
     member do
+      get :edit
+      put :update
+      delete :destroy
       get :browse
     end
   end
@@ -405,5 +411,5 @@ Pettanr::Application.routes.draw do
 
   # This is a legacy wild controller route that's not recommended for RESTful applications.
   # Note: This route will make all actions in every controller accessible via GET requests.
-  #match ':controller(/:action(/:id(.:format)))'
+  match ':controller(/:action(/:id(.:format)))'
 end
diff --git a/db/migrate/20130602100811_add_caption_and_t_on_ground_colors.rb b/db/migrate/20130602100811_add_caption_and_t_on_ground_colors.rb
new file mode 100644 (file)
index 0000000..14f3598
--- /dev/null
@@ -0,0 +1,11 @@
+class AddCaptionAndTOnGroundColors < ActiveRecord::Migration
+  def up
+    add_column :ground_colors, :t, :integer, :null => false, :default => 0
+    add_column :ground_colors, :caption, :string
+  end
+
+  def down
+    remove_column :ground_colors, :t
+    remove_column :ground_colors, :caption
+  end
+end
diff --git a/db/migrate/20130602100940_add_caption_and_t_on_ground_pictures.rb b/db/migrate/20130602100940_add_caption_and_t_on_ground_pictures.rb
new file mode 100644 (file)
index 0000000..1f4665e
--- /dev/null
@@ -0,0 +1,11 @@
+class AddCaptionAndTOnGroundPictures < ActiveRecord::Migration
+  def up
+    add_column :ground_pictures, :t, :integer, :null => false, :default => 0
+    add_column :ground_pictures, :caption, :string
+  end
+
+  def down
+    remove_column :ground_pictures, :t
+    remove_column :ground_pictures, :caption
+  end
+end