From c3657f326edd98cafdb015ec62eef32851e1d129 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Mon, 3 Jun 2013 13:31:04 +0900 Subject: [PATCH] t#31485:editate ground_colors --- app/controllers/ground_colors_controller.rb | 89 ++++++++++++++++++++-- app/models/ground_color.rb | 40 +++++++++- app/models/panel_picture.rb | 2 - app/views/authors/ground_colors.html.erb | 4 +- app/views/authors/panel_pictures.html.erb | 1 + app/views/ground_colors/_body.html.erb | 26 +++++++ app/views/ground_colors/_form.html.erb | 17 +++++ app/views/ground_colors/_list_item.html.erb | 14 +++- app/views/ground_colors/_standard.html.erb | 6 ++ app/views/ground_colors/edit.html.erb | 6 ++ app/views/ground_colors/index.html.erb | 6 +- app/views/ground_colors/new.html.erb | 6 ++ app/views/ground_colors/show.html.erb | 34 +++++++++ app/views/home/ground_colors.html.erb | 5 +- app/views/home/panel_pictures.html.erb | 1 + app/views/panel_pictures/_body.html.erb | 6 +- app/views/panel_pictures/_list_item.html.erb | 13 +++- app/views/panel_pictures/index.html.erb | 1 + app/views/panel_pictures/show.html.erb | 4 - app/views/panels/_body.html.erb | 6 +- config/locales/pettanr.ja.yml | 17 +++++ config/routes.rb | 8 +- ...602100811_add_caption_and_t_on_ground_colors.rb | 11 +++ ...2100940_add_caption_and_t_on_ground_pictures.rb | 11 +++ 24 files changed, 301 insertions(+), 33 deletions(-) create mode 100644 app/views/ground_colors/_body.html.erb create mode 100644 app/views/ground_colors/_form.html.erb create mode 100644 app/views/ground_colors/_standard.html.erb create mode 100644 app/views/ground_colors/edit.html.erb create mode 100644 app/views/ground_colors/new.html.erb create mode 100644 db/migrate/20130602100811_add_caption_and_t_on_ground_colors.rb create mode 100644 db/migrate/20130602100940_add_caption_and_t_on_ground_pictures.rb diff --git a/app/controllers/ground_colors_controller.rb b/app/controllers/ground_colors_controller.rb index da5244f2..710a43de 100644 --- a/app/controllers/ground_colors_controller.rb +++ b/app/controllers/ground_colors_controller.rb @@ -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 diff --git a/app/models/ground_color.rb b/app/models/ground_color.rb index 98de711c..af73c92d 100644 --- a/app/models/ground_color.rb +++ b/app/models/ground_color.rb @@ -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 diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index 59f50f98..3334405f 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -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 diff --git a/app/views/authors/ground_colors.html.erb b/app/views/authors/ground_colors.html.erb index 4395cebf..57cba2de 100644 --- a/app/views/authors/ground_colors.html.erb +++ b/app/views/authors/ground_colors.html.erb @@ -2,8 +2,10 @@ - + + + diff --git a/app/views/authors/panel_pictures.html.erb b/app/views/authors/panel_pictures.html.erb index b6a7e77a..07f09006 100644 --- a/app/views/authors/panel_pictures.html.erb +++ b/app/views/authors/panel_pictures.html.erb @@ -9,6 +9,7 @@ + diff --git a/app/views/ground_colors/_body.html.erb b/app/views/ground_colors/_body.html.erb new file mode 100644 index 00000000..3316aa86 --- /dev/null +++ b/app/views/ground_colors/_body.html.erb @@ -0,0 +1,26 @@ +
+ <% 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 %> +
+ <%= balloon.caption -%> + <% elm.speeches.each do |speech| %> +

+ <%= h speech.content -%> +

+ <% end %> +
+ <% when 'GroundColor' %> +
;"> + +
+ <% when 'GroundPicture' %> +
+ +
+ <% end %> + <% end %> +
diff --git a/app/views/ground_colors/_form.html.erb b/app/views/ground_colors/_form.html.erb new file mode 100644 index 00000000..8a1d82b1 --- /dev/null +++ b/app/views/ground_colors/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@ground_color) do |f| %> + <%= render 'system/error_explanation', :obj => @ground_color %> + +
+ <%= f.label :code %>
+ <%= f.text_field :code %> +
+
+ <%= f.label :z %>
+ <%= f.number_field :z %> +
+ <%= f.hidden_field :panel_id %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/ground_colors/_list_item.html.erb b/app/views/ground_colors/_list_item.html.erb index 101c4c90..b1d1b714 100644 --- a/app/views/ground_colors/_list_item.html.erb +++ b/app/views/ground_colors/_list_item.html.erb @@ -1,8 +1,18 @@ + + + + - diff --git a/app/views/ground_colors/_standard.html.erb b/app/views/ground_colors/_standard.html.erb new file mode 100644 index 00000000..47dee5de --- /dev/null +++ b/app/views/ground_colors/_standard.html.erb @@ -0,0 +1,6 @@ +<%= t_m 'Panel.caption' -%>: +<%= 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 index 00000000..7fb5b02a --- /dev/null +++ b/app/views/ground_colors/edit.html.erb @@ -0,0 +1,6 @@ +

<%= t('.title') %>

+ +

<%= t('home.index.catch') -%>

+<%= render 'panels/standard', :panel => @panel, :author => @author %> +

<%= t('ground_colors.update_color') -%>

+<%= render 'form' %> diff --git a/app/views/ground_colors/index.html.erb b/app/views/ground_colors/index.html.erb index 29c99e5a..f0ddff44 100644 --- a/app/views/ground_colors/index.html.erb +++ b/app/views/ground_colors/index.html.erb @@ -2,10 +2,11 @@
<%= t_m 'GroundColor.panel_id' -%><%= t_m 'GroundColor.id' -%><%= t_m 'GroundColor.caption' -%> <%= t_m 'GroundColor.code' -%><%= t_m 'GroundColor.panel_id' -%> <%= t_m 'GroundColor.z' -%> <%= t_m 'GroundColor.updated_at' -%>
<%= -%> <%= t_m 'PanelPicture.panel_id' -%> <%= t_m 'PanelPicture.link' -%><%= t_m 'PanelPicture.z' -%> <%= t_m 'PanelPicture.updated_at' -%>
- <%= link_to ground_color.panel_id, panel_path(ground_color.panel) %> + <%= link_to ground_color.id, ground_color_path(ground_color) %> + + <%= link_to(h(truncate(ground_color.caption, :length => 12)), ground_color_path(ground_color)) %> + ; background-color: #<%= format("%06x", ground_color.code) -%>;"> + <%= format("%06x", ground_color.code ^ 0xffffff) %> + + <%= 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) %> ; background-color: #<%= format("%06x", ground_color.code) -%>;"><%= format("%06x", ground_color.code ^ 0xffffff) %> <%= ground_color.z %>
- + + + - @@ -13,3 +14,4 @@ <%= render 'list_item', :ground_color => gc %> <% end -%>
<%= t_m 'GroundColor.panel_id' -%><%= t_m 'GroundColor.id' -%><%= t_m 'GroundColor.caption' -%> <%= t_m 'GroundColor.code' -%><%= t_m 'GroundColor.panel_id' -%> <%= t_m 'GroundColor.z' -%><%= t_m 'GroundColor.created_at' -%> <%= t_m 'GroundColor.updated_at' -%>
+<%= 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 index 00000000..da2a5cbf --- /dev/null +++ b/app/views/ground_colors/new.html.erb @@ -0,0 +1,6 @@ +

<%= t('.title') %>

+ +

<%= t('home.index.catch') -%>

+<%= render 'panels/standard', :panel => @panel, :author => @author %> +

<%= t('ground_colors.create_color') -%>

+<%= render 'form' %> diff --git a/app/views/ground_colors/show.html.erb b/app/views/ground_colors/show.html.erb index 51e01157..782cf415 100644 --- a/app/views/ground_colors/show.html.erb +++ b/app/views/ground_colors/show.html.erb @@ -1,3 +1,37 @@

<%= t('.title') %>

<%= notice %>

+<%= render 'panel_pictures/standard', :panel => @ground_color.panel, :author => @author, :spot => @ground_color %> + +

+ <%= t_m 'GroundColor.caption' -%>: + <%= h @ground_color.caption %> +

+ +

+ <%= t_m 'GroundColor.z' -%>: + <%= @ground_color.z %> +

+ +

+ <%= t_m 'GroundColor.t' -%>: + <%= @ground_color.t %> +

+ +

+ <%= t_m 'GroundColor.code' -%>: + <%= @ground_color.code %> +

+ +

+ <%= t_m 'GroundColor.created_at' -%>: + <%= l @ground_color.created_at %> +

+ +

+ <%= t_m 'GroundColor.updated_at' -%>: + <%= l @ground_color.updated_at %> +

+ +<%= link_to t('link.edit'), edit_ground_color_path(@ground_color) %> +<%= link_to t('link.destroy'), ground_color_path(@ground_color), :method => :delete %> diff --git a/app/views/home/ground_colors.html.erb b/app/views/home/ground_colors.html.erb index bc07f67d..25c02325 100644 --- a/app/views/home/ground_colors.html.erb +++ b/app/views/home/ground_colors.html.erb @@ -2,8 +2,10 @@ - + + + @@ -12,3 +14,4 @@ <%= render 'ground_colors/list_item', :ground_color => gc, :author => @author %> <% end -%>
<%= t_m 'GroundColor.color_id' -%><%= t_m 'GroundColor.id' -%><%= t_m 'GroundColor.caption' -%> <%= t_m 'GroundColor.code' -%><%= t_m 'GroundColor.panel_id' -%> <%= t_m 'GroundColor.z' -%> <%= t_m 'GroundColor.updated_at' -%>
+<%= link_to t('ground_colors.new.title'), new_ground_color_path %> diff --git a/app/views/home/panel_pictures.html.erb b/app/views/home/panel_pictures.html.erb index 219ef085..ccf3ec0e 100644 --- a/app/views/home/panel_pictures.html.erb +++ b/app/views/home/panel_pictures.html.erb @@ -8,6 +8,7 @@ <%= -%> <%= t_m 'PanelPicture.panel_id' -%> <%= t_m 'PanelPicture.link' -%> + <%= t_m 'PanelPicture.z' -%> <%= t_m 'PanelPicture.updated_at' -%> diff --git a/app/views/panel_pictures/_body.html.erb b/app/views/panel_pictures/_body.html.erb index ad7cc2de..3316aa86 100644 --- a/app/views/panel_pictures/_body.html.erb +++ b/app/views/panel_pictures/_body.html.erb @@ -14,11 +14,7 @@ <% end %> <% when 'GroundColor' %> -
- -
- <% when 'PanelColor' %> -
;"> +
;">
<% when 'GroundPicture' %> diff --git a/app/views/panel_pictures/_list_item.html.erb b/app/views/panel_pictures/_list_item.html.erb index 63afb00e..7201de22 100644 --- a/app/views/panel_pictures/_list_item.html.erb +++ b/app/views/panel_pictures/_list_item.html.erb @@ -18,8 +18,15 @@ <% end %> <%= link_to panel_icon(:object => panel_picture.panel, :size => 25), panel_path(panel_picture.panel) %> - <%= h(truncate((panel_picture.panel.caption), :length => 12)) %> + <%= link_to h(truncate((panel_picture.panel.caption), :length => 12)), panel_path(panel_picture.panel) %> + + + <%= link_to h(truncate(panel_picture.link, :length => 12)), panel_picture.link %> + - <%= link_to h(truncate(panel_picture.link, :length => 12)), panel_picture.link %> - <%= distance_of_time_in_words_to_now panel_picture.updated_at %> + <%= panel_picture.z %> + + + <%= distance_of_time_in_words_to_now panel_picture.updated_at %> + diff --git a/app/views/panel_pictures/index.html.erb b/app/views/panel_pictures/index.html.erb index 70f01eeb..bf794786 100644 --- a/app/views/panel_pictures/index.html.erb +++ b/app/views/panel_pictures/index.html.erb @@ -8,6 +8,7 @@ <%= -%> <%= t_m 'PanelPicture.panel_id' -%> <%= t_m 'PanelPicture.link' -%> + <%= t_m 'PanelPicture.z' -%> <%= t_m 'PanelPicture.updated_at' -%> diff --git a/app/views/panel_pictures/show.html.erb b/app/views/panel_pictures/show.html.erb index eb832236..f558950c 100644 --- a/app/views/panel_pictures/show.html.erb +++ b/app/views/panel_pictures/show.html.erb @@ -2,10 +2,6 @@

<%= notice %>

<%= render 'panel_pictures/standard', :panel => @panel_picture.panel, :author => @author, :spot => @panel_picture %> -

- <%= t_m 'PanelPicture.panel_id' -%>: - <%= link_to @panel_picture.panel_id, panel_path(@panel_picture.panel) %> -

<%= t_m 'PanelPicture.caption' -%>: diff --git a/app/views/panels/_body.html.erb b/app/views/panels/_body.html.erb index bc598d65..09fd3b86 100644 --- a/app/views/panels/_body.html.erb +++ b/app/views/panels/_body.html.erb @@ -14,11 +14,7 @@ <% end %>

<% when 'GroundColor' %> -
- -
- <% when 'PanelColor' %> -
;"> +
;">
<% when 'GroundPicture' %> diff --git a/config/locales/pettanr.ja.yml b/config/locales/pettanr.ja.yml index b3470274..e765971c 100644 --- a/config/locales/pettanr.ja.yml +++ b/config/locales/pettanr.ja.yml @@ -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: 原画一覧 diff --git a/config/routes.rb b/config/routes.rb index 632f6ade..38fe01c6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 index 00000000..14f35988 --- /dev/null +++ b/db/migrate/20130602100811_add_caption_and_t_on_ground_colors.rb @@ -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 index 00000000..1f4665ed --- /dev/null +++ b/db/migrate/20130602100940_add_caption_and_t_on_ground_pictures.rb @@ -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 -- 2.11.0