OSDN Git Service

t#31702:add icon
authoryasushiito <yas@pen-chan.jp>
Thu, 11 Jul 2013 10:27:27 +0000 (19:27 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 11 Jul 2013 10:27:27 +0000 (19:27 +0900)
app/models/speech_balloon_template.rb
app/views/panels/_form.html.erb
app/views/speech_balloon_templates/browse.html.erb
app/views/speech_balloon_templates/index.html.erb
app/views/speech_balloon_templates/list.html.erb
app/views/speech_balloon_templates/show.html.erb
config/locales/pettanr.ja.yml
db/migrate/20130710235123_add_system_picture_id_on_speech_balloon_templates.rb [new file with mode: 0644]
spec/factories.rb
spec/models/speech_balloon_template_spec.rb

index 7fcae92..4aa68e5 100644 (file)
@@ -1,11 +1,13 @@
 #フキダシテンプレート
 class SpeechBalloonTemplate < ActiveRecord::Base
   has_many :speech_balloons
+  belongs_to :system_picture
   
   validates :name, :presence => true, :uniqueness => true, :length => {:maximum => 50}
   validates :classname, :presence => true, :length => {:maximum => 50}
   validates :caption, :presence => true, :length => {:maximum => 30}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
+  validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :settings, :presence => true
   
   before_validation :valid_encode
@@ -61,8 +63,8 @@ class SpeechBalloonTemplate < ActiveRecord::Base
   
   def self.store name, attr
     #settingsにはHashデータが丸っと文字列化されて入る
-    r = SpeechBalloonTemplate.replace_system_picture(attr["settings"] || {})
-    attr["settings"] = r ? r.to_json : nil
+    r = SpeechBalloonTemplate.replace_system_picture(attr || {})
+    attr["settings"] = r["settings"] ? r["settings"].to_json : nil
     r = SpeechBalloonTemplate.modify_object name, attr
     r.overwrite
     r.save
index f99dd66..a642258 100644 (file)
       <ul>
         <% @panel.panel_elements.each do |elm| %>
           <li><a href="#elements-tabs-<%= elm.t -%>">
-            <% case elm.class.to_s %>
-            <% when 'PanelPicture' %>
-              <%= tag(:img, elm.tmb_opt_img_tag) %>
-            <% when 'SpeechBalloon' %>
-              <%= h(truncate(elm.speech.content, :length => 6)) %>
-            <% when 'GroundPicture' %>
-              <%= tag(:img, elm.tmb_opt_img_tag) -%>
-            <% when 'GroundColor' %>
-              <div style="color: #<%= format("%06x", elm.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", elm.code) -%>;">
-                <%= format("%06x", elm.code) %>
-              </div>
-            <% end %>
+            <div>
+              <% case elm.class.to_s %>
+              <% when 'PanelPicture' %>
+                <%= tag(:img, elm.tmb_opt_img_tag) %>
+                <div>
+                  <%= h(truncate(elm.caption, :length => 6)) %>
+                </div>
+              <% when 'SpeechBalloon' %>
+                <%= tag(:img, elm.speech_balloon_template.system_picture.tmb_opt_img_tag) %>
+                <div>
+                  <%= h(truncate(elm.speech.content, :length => 6)) %>
+                </div>
+              <% when 'GroundPicture' %>
+                <%= tag(:img, elm.tmb_opt_img_tag) -%>
+                <div>
+                  <%= h(truncate(elm.caption, :length => 6)) %>
+                </div>
+              <% when 'GroundColor' %>
+                <div style="color: #<%= format("%06x", elm.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", elm.code) -%>;">
+                  <%= format("%06x", elm.code) %>
+                </div>
+                <div>
+                  <%= h(truncate(elm.caption, :length => 6)) %>
+                </div>
+              <% end %>
+            </div>
           </a></li>
         <% end %>
       </ul>
index 8fb2bf1..ebc97da 100644 (file)
 </p>
 
 <p>
+  <b><%= t_m 'SpeechBalloonTemplate.system_picture_id' -%>:</b>
+  <%= @speech_balloon_template.system_picture_id %>
+</p>
+
+<p>
   <b><%= t_m 'SpeechBalloonTemplate.settings' -%>:</b>
   <%= h @speech_balloon_template.settings %>
 </p>
index 70af039..f1a9ebd 100644 (file)
@@ -1,13 +1,14 @@
 <h1><%= t '.title' -%></h1>
 
-<table>
-  <tr>
-    <th><%= t_m 'SpeechBalloonTemplate.caption' -%></th>
-  </tr>
-
+<ul>
   <% @speech_balloon_templates.each do |st| %>
-    <tr>
-      <td><%= link_to h(st.caption), speech_balloon_template_path(st) %></td>
-    </tr>
+    <li>
+      <div>
+        <%= link_to tag(:img, st.system_picture.tmb_opt_img_tag), speech_balloon_template_path(st) %>
+        <div>
+          <%= link_to h(st.caption), speech_balloon_template_path(st) %>
+        </div>
+      </div>
+    </li>
   <% end %>
-</table>
+</ul>
index 07c9800..94c6cdf 100644 (file)
@@ -7,6 +7,7 @@
     <th><%= t_m 'SpeechBalloonTemplate.classname' -%></th>
     <th><%= t_m 'SpeechBalloonTemplate.caption' -%></th>
     <th><%= t_m 'SpeechBalloonTemplate.t' -%></th>
+    <th><%= t_m 'SpeechBalloonTemplate.system_picture_id' -%></th>
     <th><%= t_m 'SpeechBalloonTemplate.settings' -%></th>
     <th><%= t_m 'SpeechBalloonTemplate.created_at' -%></th>
     <th><%= t_m 'SpeechBalloonTemplate.updated_at' -%></th>
@@ -27,6 +28,9 @@
         <%= speech_balloon_template.t %>
       </td>
       <td>
+        <%= link_to tag(:img, speech_balloon_template.system_picture.tmb_opt_img_tag), speech_balloon_template_path(speech_balloon_template.system_picture) %>
+      </td>
+      <td>
         <%= h(truncate(speech_balloon_template.settings, :length => 10)) %>
       </td>
       <td>
index 6bae80c..74f810e 100644 (file)
@@ -1,10 +1,12 @@
 <h1><%= t '.title' -%></h1>
 <p id="notice"><%= notice %></p>
 
-<p>
-  <b>caption:</b>
-  <%= h @speech_balloon_template.caption %>
-</p>
+<div>
+  <%= link_to tag(:img, @speech_balloon_template.system_picture.tmb_opt_img_tag), speech_balloon_template_path(@speech_balloon_template) %>
+  <div>
+    <%= link_to h(@speech_balloon_template.caption), speech_balloon_template_path(@speech_balloon_template) %>
+  </div>
+</div>
 
 <% if @author and @author.working? -%>
   <h3><%= t('home.index.catch') -%></h3>
index cba7825..319bfc3 100644 (file)
@@ -206,6 +206,7 @@ ja:
         classname: クラス名
         caption: 名前
         t: 並び順
+        system_picture_id: アイコン
         settings: 拡張データ
         created_at: 作成
         updated_at: 更新
diff --git a/db/migrate/20130710235123_add_system_picture_id_on_speech_balloon_templates.rb b/db/migrate/20130710235123_add_system_picture_id_on_speech_balloon_templates.rb
new file mode 100644 (file)
index 0000000..f18a069
--- /dev/null
@@ -0,0 +1,9 @@
+class AddSystemPictureIdOnSpeechBalloonTemplates < ActiveRecord::Migration
+  def up
+    add_column :speech_balloon_templates, :system_picture_id, :integer, :null => false, :default => 1
+  end
+
+  def down
+    remove_column :speech_balloon_templates, :system_picture_id
+  end
+end
index 92838a2..8500814 100644 (file)
@@ -124,6 +124,7 @@ FactoryGirl.define do
     sbt.classname 'Plain'
     sbt.caption 'normal fuki'
     sbt.t 0
+    sbt.system_picture_id 1 
     sbt.settings '{}'
   end
 
index 7e09239..544879a 100644 (file)
@@ -21,6 +21,7 @@ describe SpeechBalloonTemplate do
     @other_user = FactoryGirl.create( :user_yas)
     @other_author = FactoryGirl.create :author, :user_id => @other_user.id
     @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+    @sp = FactoryGirl.create :system_picture
   end
   
   describe '検証に於いて' do
@@ -92,6 +93,20 @@ describe SpeechBalloonTemplate do
         @st.should_not be_valid
       end
     end
+    context 'system_picture_idを検証するとき' do
+      it 'nullなら失敗する' do
+        @st.system_picture_id = nil
+        @st.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @st.system_picture_id = 'a'
+        @st.should_not be_valid
+      end
+      it '存在するシステム画像でなければ失敗する' do
+        @st.system_picture_id = 0
+        @st.should_not be_valid
+      end
+    end
     context 'settingsを検証するとき' do
       it 'nullなら失敗する' do
         @st.settings = nil
@@ -280,19 +295,19 @@ describe SpeechBalloonTemplate do
         "speech_balloon" => {"default" => 1}, 
         "one" => {"balloon" => {"system_picture_id" => @sp.id}}
       }
-      @attr = {"classname" => 'store', "caption" => 'store test',
+      @attr = {"classname" => 'store', "caption" => 'store test', "system_picture_id" => @sp.id, 
         "settings" => @settings
       }
     end
     context '事前チェック' do
       before do
-        SpeechBalloonTemplate.stub(:replace_system_picture).with(@settings).and_return(@settings)
+        SpeechBalloonTemplate.stub(:replace_system_picture).with(@attr).and_return(@attr)
         SpeechBalloonTemplate.stub(:modify_object).with(any_args).and_return(@st)
         SpeechBalloonTemplate.any_instance.stub(:overwrite).with(any_args).and_return(true)
         SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(true)
       end
       it 'システム画像置換に依頼している' do
-        SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@settings).exactly(1)
+        SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@attr).exactly(1)
         r = SpeechBalloonTemplate.store 'circle_v01', @attr
       end
       it 'インポート処理のデータ更新準備に依頼している' do