OSDN Git Service

replace codes
authoryasushiito <yas@pen-chan.jp>
Thu, 5 Jan 2012 22:28:57 +0000 (07:28 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 5 Jan 2012 22:28:57 +0000 (07:28 +0900)
24 files changed:
app/controllers/comics_controller.rb
app/controllers/panels_controller.rb
app/models/admin.rb
app/models/common_lisence.rb
app/models/original_lisence.rb
app/models/panel.rb
app/models/speach_balloon.rb
app/views/comics/index.html.erb
app/views/comics/show.html.erb
app/views/common_lisences/_form.html.erb
app/views/common_lisences/index.html.erb
app/views/common_lisences/show.html.erb
app/views/lisences/index.html.erb
app/views/original_lisences/_form.html.erb
app/views/original_lisences/show.html.erb
app/views/panel_pictures/index.html.erb
app/views/panels/_standard.html.erb
app/views/panels/index.html.erb
app/views/speach_balloons/index.html.erb
app/views/speach_balloons/show.html.erb
db/migrate/20111206092734_devise_create_admins.rb
db/migrate/20111206113803_create_panel_pictures.rb
db/schema.rb
db/seeds.rb

index 2d3664a..7200ab0 100644 (file)
@@ -35,7 +35,7 @@ class ComicsController < ApplicationController
   end
 
   def play
-    @comic = Comic.find(params[:id], include: {:panels => [:panel_pictures => :resource_picture, :balloons => :speaches]}, order: 'panels.seqno')
+    @comic = Comic.find(params[:id], include: {:panels => [:panel_pictures => :resource_picture, :balloons => :speaches]}, order: 'panels.t')
 
     respond_to do |format|
       format.html # index.html.erb
index d35751c..c67cc58 100644 (file)
@@ -86,8 +86,8 @@ class PanelsController < ApplicationController
     if @panel.own? current_author
       respond_to do |format|
         Panel.transaction do
-          if params[:panel][:seqno] and params[:panel][:seqno].to_i != @panel.seqno
-            @panel.move_to params[:panel][:seqno].to_i
+          if params[:panel][:t] and params[:panel][:t].to_i != @panel.t
+            @panel.move_to params[:panel][:t].to_i
           end
           if @panel.update_attributes(params[:panel])
             format.html { redirect_to @panel, notice: 'Panel was successfully updated.' }
@@ -124,10 +124,10 @@ class PanelsController < ApplicationController
   
   def move
     @panel = Panel.find(params[:id])
-    @new_seq = params[:panel][:seqno].to_i
+    @new_seq = params[:panel][:t].to_i
     respond_to do |format|
       Panel.transaction do
-        if @panel.move_to(@new_seq)
+        if @panel.move_to(@new_t)
           format.html { redirect_to @panel, notice: 'Panel was successfully moved.' }
           format.json { head :ok }
         else
index cc28a10..b4a6f9c 100644 (file)
@@ -1,16 +1,21 @@
 class Admin < ActiveRecord::Base
   # Include default devise modules. Others available are:
-  # , :encryptable, :lockable, :timeoutable and :omniauthable
+  # , :encryptable, :lockable, :timeoutable and :omniauthable, :confirmable
   devise :database_authenticatable, :registerable,
-         :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :confirmable
+         :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
 
   # Setup accessible (or protected) attributes for your model
   attr_accessible :email, :password, :password_confirmation, :remember_me
   before_save :ensure_authentication_token\r
   
+  def active_for_authentication?\r
+    super && (self.approve == 1)\r
+  end
+
   def self.start(email, passwd)
     a = Admin.create! :email => email, :password => passwd, :password_confirmation => passwd
-    a.confirm!
+    a.approve = 1
+    a.save!
   end
   
 end
index ea1fb4b..8a94de9 100644 (file)
@@ -4,7 +4,7 @@ class CommonLisence < ActiveRecord::Base
   def save_save
     lisence = Lisence.new( {
       :name => self.name, :url => self.url, :cc_by => self.cc_by, :cc_sa => self.cc_sa, :cc_nd => self.cc_nd, :cc_nc => self.cc_nc, 
-      :no_resize => self.no_resize, :no_flip => self.no_flip, :keep_aspect_ratio => self.keep_aspect_ratio
+      :no_resize => self.no_resize, :no_flip => self.no_flip, :no_convert => self.no_convert, :keep_aspect_ratio => self.keep_aspect_ratio
     })
     self.lisence_id = 0
     res = self.save
index ae1eb92..75f2f0e 100644 (file)
@@ -5,7 +5,7 @@ class OriginalLisence < ActiveRecord::Base
   def save_save
     lisence = Lisence.new( {
       :name => self.name, :url => self.url, :cc_by => self.cc_by, :cc_sa => self.cc_sa, :cc_nd => self.cc_nd, :cc_nc => self.cc_nc, 
-      :no_resize => self.no_resize, :no_flip => self.no_flip, :keep_aspect_ratio => self.keep_aspect_ratio
+      :no_resize => self.no_resize, :no_flip => self.no_flip, :no_convert => self.no_convert, :keep_aspect_ratio => self.keep_aspect_ratio
     })
     return false unless lisence.save
     self.lisence_id = lisence.id
index efc3a4d..f60b801 100644 (file)
@@ -5,44 +5,44 @@ class Panel < ActiveRecord::Base
   accepts_nested_attributes_for :panel_pictures, :allow_destroy => true
   accepts_nested_attributes_for :balloons, :allow_destroy => true
 
-  def self.max_seq comic_id
-    Panel.maximum(:seqno, :conditions => ['comic_id = ?', comic_id]).to_i
+  def self.max_t comic_id
+    Panel.maximum(:t, :conditions => ['comic_id = ?', comic_id]).to_i
   end
   
-  def self.find_seq comic_id, seqno
-    Panel.find(:first, :conditions => ['comic_id = ? and seqno = ?', comic_id, seqno])
+  def self.find_t comic_id, t
+    Panel.find(:first, :conditions => ['comic_id = ? and t = ?', comic_id, t])
   end
 
   #更新する時にPanelIDをチェックしとかないと勝手に所属先を変えられるゾ!?
 
   def vdt_save
     f = nil
-    max_seq = Panel.max_seq self.comic_id
-    f = Panel.find_seq(self.comic_id, self.seqno) if self.seqno
+    max_t = Panel.max_t self.comic_id
+    f = Panel.find_t(self.comic_id, self.t) if self.t
     if f
-      Panel.update_all('seqno = seqno + 1', ['comic_id = ? and seqno >= ?', self.comic_id, self.seqno])
+      Panel.update_all('t = t + 1', ['comic_id = ? and t >= ?', self.comic_id, self.t])
     else
-      self.seqno = max_seq + 1
+      self.t = max_t + 1
     end
     self.save
   end
   
-  def move_to new_seq
-    return true if self.seqno == new_seq
-    if self.seqno > new_seq
-      Panel.update_all('seqno = seqno + 1', ['comic_id = ? and (seqno >= ? and seqno < ?)', self.comic_id, new_seq, self.seqno])
+  def move_to new_t
+    return true if self.t == new_t
+    if self.t > new_t
+      Panel.update_all('t = t + 1', ['comic_id = ? and (t >= ? and t < ?)', self.comic_id, new_t, self.t])
     else
-      nf = Panel.find_seq(self.comic_id, new_seq)
-      max_seq = Panel.max_seq self.comic_id
-      new_seq = max_seq if new_seq > max_seq
-      Panel.update_all('seqno = seqno - 1', ['comic_id = ? and (seqno > ? and seqno <= ?)', self.comic_id, self.seqno, new_seq])
+      nf = Panel.find_t(self.comic_id, new_t)
+      max_t = Panel.max_t self.comic_id
+      new_t = max_t if new_t > max_t
+      Panel.update_all('t = t - 1', ['comic_id = ? and (t > ? and t <= ?)', self.comic_id, self.t, new_t])
     end
-    self.seqno = new_seq
+    self.t = new_t
     self.save
   end
   
   def destroy_and_shorten
-    Panel.update_all('seqno = seqno - 1', ['comic_id = ? and (seqno > ?)', self.comic_id, self.seqno])
+    Panel.update_all('t = t - 1', ['comic_id = ? and (t > ?)', self.comic_id, self.t])
     self.destroy
   end
   
index 3264e4c..5858562 100644 (file)
@@ -1,4 +1,10 @@
 class SpeachBalloon < ActiveRecord::Base
   has_many :balloon_templates, :dependent => :destroy
   accepts_nested_attributes_for :balloon_templates
+  before_create :supply_t
+  
+  def supply_t
+    self.t = SpeachBalloon.maximum(:t).to_i + 1
+  end
+  
 end
index 508620e..21909c0 100644 (file)
@@ -4,10 +4,12 @@
   <tr>
     <th>id</th>
     <th>Title</th>
-    <th>Default width</th>
-    <th>Default height</th>
+    <th>width</th>
+    <th>height</th>
     <th>author_id</th>
     <th>updated_at</th>
+    <th>visible</th>
+    <th>editable</th>
     <th></th>
     <th></th>
     <th></th>
@@ -19,6 +21,8 @@
     <td><%= h comic.title %></td>
     <td><%= comic.width %></td>
     <td><%= comic.height %></td>
+    <td><%= comic.visible %></td>
+    <td><%= comic.editable %></td>
     <td><%= comic.author_id%></td>
     <td><%= comic.updated_at %></td>
     <td><%= link_to 'Show', comic %></td>
index 624205c..e238a2f 100644 (file)
@@ -6,13 +6,23 @@
 </p>
 
 <p>
-  <b>Default width:</b>
+  <b>width:</b>
   <%= @comic.width %>
 </p>
 
 <p>
-  <b>Default height:</b>
+  <b>height:</b>
   <%= @comic.height %>
 </p>
 
+<p>
+  <b>visible:</b>
+  <%= @comic.visible %>
+</p>
+
+<p>
+  <b>editable:</b>
+  <%= @comic.editable %>
+</p>
+
 <%= link_to 'Back', comics_path %>
index cb73f6a..01c77e3 100644 (file)
     <%= f.check_box :no_flip %>
   </div>
   <div class="field">
+    <%= f.label :no_convert %><br />
+    <%= f.check_box :no_convert %>
+  </div>
+  <div class="field">
     <%= f.label :keep_aspect_ratio %><br />
     <%= f.check_box :keep_aspect_ratio %>
   </div>
index 4639c68..3170468 100644 (file)
@@ -10,6 +10,7 @@
     <th>cc_nc</th>
     <th>no_resize</th>
     <th>no_flip</th>
+    <th>no_convert</th>
     <th>keep_aspect_ratio</th>
     <th></th>
     <th></th>
 
 <% @common_lisences.each do |common_lisence| %>
   <tr>
-    <td><%= h @common_lisence.name %></td>
-    <td><%= h @common_lisence.url %></td>
-    <td><%= @common_lisence.cc_by %></td>
-    <td><%= @common_lisence.cc_sa %></td>
-    <td><%= @common_lisence.cc_nd %></td>
-    <td><%= @common_lisence.cc_nc %></td>
-    <td><%= @common_lisence.no_resize %></td>
-    <td><%= @common_lisence.no_flip %></td>
-    <td><%= @common_lisence.keep_aspect_ratio %></td>
+    <td><%= h common_lisence.name %></td>
+    <td><%= h common_lisence.url %></td>
+    <td><%= common_lisence.cc_by %></td>
+    <td><%= common_lisence.cc_sa %></td>
+    <td><%= common_lisence.cc_nd %></td>
+    <td><%= common_lisence.cc_nc %></td>
+    <td><%= common_lisence.no_resize %></td>
+    <td><%= common_lisence.no_flip %></td>
+    <td><%= common_lisence.no_convert %></td>
+    <td><%= common_lisence.keep_aspect_ratio %></td>
     <td><%= link_to 'Show', common_lisence %></td>
     <td><%= link_to 'Edit', edit_common_lisence_path(common_lisence) %></td>
     <td><%= link_to 'Destroy', common_lisence, confirm: 'Are you sure?', method: :delete %></td>
index d313be6..c1f9623 100644 (file)
 </p>
 
 <p>
+  <b>no_convert:</b>
+  <%= @common_lisence.no_convert %>
+</p>
+
+<p>
   <b>keep_aspect_ratio:</b>
   <%= @common_lisence.keep_aspect_ratio %>
 </p>
index 56111b4..5936046 100644 (file)
@@ -10,6 +10,7 @@
     <th>cc_nc</th>
     <th>no_resize</th>
     <th>no_flip</th>
+    <th>no_convert</th>
     <th>keep_aspect_ratio</th>
     <th></th>
   </tr>
@@ -24,6 +25,7 @@
     <td><%= lisence.cc_nc %></td>
     <td><%= lisence.no_resize %></td>
     <td><%= lisence.no_flip %></td>
+    <td><%= lisence.no_convert %></td>
     <td><%= lisence.keep_aspect_ratio %></td>
     <td>
       <% if lisence.common_lisence -%>
index 9e9aaf4..efe93bb 100644 (file)
     <%= f.check_box :no_flip %>
   </div>
   <div class="field">
+    <%= f.label :no_convert %><br />
+    <%= f.check_box :no_convert %>
+  </div>
+  <div class="field">
     <%= f.label :keep_aspect_ratio %><br />
     <%= f.check_box :keep_aspect_ratio %>
   </div>
index 49ef7ce..b0e3fe4 100644 (file)
 </p>
 
 <p>
+  <b>no_convert:</b>
+  <%= @original_lisence.no_convert %>
+</p>
+
+<p>
   <b>keep_aspect_ratio:</b>
   <%= @original_lisence.keep_aspect_ratio %>
 </p>
index c1c9378..5a54844 100644 (file)
@@ -5,11 +5,13 @@
     <th>id</th>
     <th>panel</th>
     <th>resource_picture</th>
+    <th>url</th>
     <th>Width</th>
     <th>Height</th>
-    <th>Top offset</th>
-    <th>Left offset</th>
+    <th>x</th>
+    <th>y</th>
     <th>z</th>
+    <th>t</th>
     <th>flip</th>
     <th>updated_at</th>
   </tr>
     <td><%= panel_picture.id %></td>
     <td><%= panel_picture.panel_id %></td>
     <td><%= panel_picture.resource_picture_id %></td>
-    <td><%= panel_picture.width %></td>
-    <td><%= panel_picture.height %></td>
-    <td><%= panel_picture.y %></td>
+    <td><%= h panel_picture.url %></td>
     <td><%= panel_picture.x %></td>
+    <td><%= panel_picture.y %></td>
     <td><%= panel_picture.z %></td>
+    <td><%= panel_picture.t %></td>
+    <td><%= panel_picture.width %></td>
+    <td><%= panel_picture.height %></td>
     <td><%= panel_picture.flip %></td>
     <td><%= panel_picture.updated_at %></td>
   </tr>
index 11e32b7..0cf3c24 100644 (file)
@@ -1,5 +1,5 @@
 <span>
-Seqno:<%= @panel.seqno %>
+t:<%= @panel.t %>
 </span>
 <div class="panel" style="width:<%= @panel.width %>px;height:<%= @panel.height %>px;overflow:hidden; border:solid black <%= @panel.border %>px; background:white;">
   <% @panel.panel_pictures.each do |panel_picture| %>
@@ -32,7 +32,7 @@ Height:<%= @panel.height %>
 </span>
 <%= form_for(@panel) do |f| %>
     <%= f.submit 'move to' %>
-     <%= f.number_field :seqno %>
+     <%= f.number_field :t %>
 <% end %>
 <%= button_to 'Destroy', @panel, confirm: 'Are you sure?', method: :delete %>
 
index d0d77e4..0910ddb 100644 (file)
@@ -8,7 +8,10 @@
     <th>Width</th>
     <th>Height</th>
     <th>Border</th>
-    <th>Seqno</th>
+    <th>x</th>
+    <th>y</th>
+    <th>z</th>
+    <th>t</th>
     <th>author_id</th>
     <th>updated_at</th>
     <th></th>
     <td><%= panel.width %></td>
     <td><%= panel.height %></td>
     <td><%= panel.border %></td>
-    <td><%= panel.seqno %></td>
+    <td><%= panel.x %></td>
+    <td><%= panel.y %></td>
+    <td><%= panel.z %></td>
+    <td><%= panel.t %></td>
     <td><%= panel.author_id %></td>
     <td><%= panel.updated_at %></td>
     <td><%= link_to 'Show', panel %></td>
index 371a262..09ba60b 100644 (file)
@@ -4,6 +4,7 @@
     <th>Name</th>
     <th>Tail limit</th>
     <th>size limit</th>
+    <th>t</th>
     <th></th>
     <th></th>
   </tr>
@@ -13,6 +14,7 @@
     <td><%= h speach_balloon.name %></td>
     <td><%= speach_balloon.tail_count %></td>
     <td><%= speach_balloon.size_count %></td>
+    <td><%= speach_balloon.t %></td>
     <td><%= link_to 'show', speach_balloon %></td>
     <td>
       <% if admin_signed_in? -%>
index 9f93eef..d59af76 100644 (file)
   <b>size limit:</b>
   <%= @speach_balloon.size_count %>
 </p>
+
+<p>
+  <b>t:</b>
+  <%= @speach_balloon.t %>
+</p>
 <% @speach_balloon.balloon_templates.each do |balloon_template| -%>\r
   <div>\r
     <p>\r
index 2f3571b..03fb591 100644 (file)
@@ -10,6 +10,7 @@ class DeviseCreateAdmins < ActiveRecord::Migration
       t.confirmable
       # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
       t.token_authenticatable
+      t.integer :approve, :null => false, :default => 0
 
       t.timestamps
     end
index 465bc36..2011abb 100644 (file)
@@ -3,7 +3,7 @@ class CreatePanelPictures < ActiveRecord::Migration
     create_table :panel_pictures do |t|
       t.integer :panel_id, :null => false
       t.integer :resource_picture_id, :null => false
-      t.string :url, :limit => 200
+      t.string :link, :limit => 200
       t.integer :x, :null => false
       t.integer :y, :null => false
       t.integer :z, :null => false
index 818bfaf..270ec85 100644 (file)
@@ -28,6 +28,7 @@ ActiveRecord::Schema.define(:version => 20120102071851) do
     t.datetime "confirmed_at"\r
     t.datetime "confirmation_sent_at"\r
     t.string   "authentication_token"\r
+    t.integer  "approve",                               :default => 0,  :null => false\r
     t.datetime "created_at"\r
     t.datetime "updated_at"\r
   end\r
@@ -188,7 +189,7 @@ ActiveRecord::Schema.define(:version => 20120102071851) do
   create_table "panel_pictures", :force => true do |t|\r
     t.integer  "panel_id",                                          :null => false\r
     t.integer  "resource_picture_id",                               :null => false\r
-    t.string   "url",                 :limit => 200\r
+    t.string   "link",                :limit => 200\r
     t.integer  "x",                                                 :null => false\r
     t.integer  "y",                                                 :null => false\r
     t.integer  "z",                                                 :null => false\r
index f86207c..6db2992 100644 (file)
@@ -7,29 +7,29 @@
 #   Mayor.new(name: 'Emanuel', city: cities.first)
 cl = CommonLisence.new name: 'Public Domain', 
   url: 'http://ja.wikipedia.org/wiki/%E3%83%91%E3%83%96%E3%83%AA%E3%83%83%E3%82%AF%E3%83%89%E3%83%A1%E3%82%A4%E3%83%B3', 
-  cc_by: 0, cc_sa: 0, cc_nd: 0, cc_nc: 0, no_resize: 0, no_flip: 0, keep_aspect_ratio: 0
+  cc_by: 0, cc_sa: 0, cc_nd: 0, cc_nc: 0, no_resize: 0, no_flip: 0, no_convert: 0, keep_aspect_ratio: 0
 cl = CommonLisence.new name: 'Creative Commons 3.0(by)', 
   url: 'http://creativecommons.org/licenses/by/3.0/legalcode', 
-  cc_by: 1, cc_sa: 0, cc_nd: 0, cc_nc: 0, no_resize: 0, no_flip: 0, keep_aspect_ratio: 0
+  cc_by: 1, cc_sa: 0, cc_nd: 0, cc_nc: 0, no_resize: 0, no_flip: 0, no_convert: 0, keep_aspect_ratio: 0
 cl.save_save
 cl = CommonLisence.new name: 'Creative Commons 3.0(by_sa)', 
   url: 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', 
-  cc_by: 1, cc_sa: 1, cc_nd: 0, cc_nc: 0, no_resize: 0, no_flip: 0, keep_aspect_ratio: 0
+  cc_by: 1, cc_sa: 1, cc_nd: 0, cc_nc: 0, no_resize: 0, no_flip: 0, no_convert: 0, keep_aspect_ratio: 0
 cl.save_save
 cl = CommonLisence.new name: 'Creative Commons 3.0(by_nd)', 
   url: 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', 
-  cc_by: 1, cc_sa: 0, cc_nd: 1, cc_nc: 0, no_resize: 0, no_flip: 0, keep_aspect_ratio: 0
+  cc_by: 1, cc_sa: 0, cc_nd: 1, cc_nc: 0, no_resize: 0, no_flip: 0, no_convert: 0, keep_aspect_ratio: 0
 cl.save_save
 cl = CommonLisence.new name: 'Creative Commons 3.0(by_nc)', 
   url: 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', 
-  cc_by: 1, cc_sa: 0, cc_nd: 0, cc_nc: 1, no_resize: 0, no_flip: 0, keep_aspect_ratio: 0
+  cc_by: 1, cc_sa: 0, cc_nd: 0, cc_nc: 1, no_resize: 0, no_flip: 0, no_convert: 0, keep_aspect_ratio: 0
 cl.save_save
 cl = CommonLisence.new name: 'Creative Commons 3.0(by_nc_sa)', 
   url: 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', 
-  cc_by: 1, cc_sa: 1, cc_nd: 0, cc_nc: 1, no_resize: 0, no_flip: 0, keep_aspect_ratio: 0
+  cc_by: 1, cc_sa: 1, cc_nd: 0, cc_nc: 1, no_resize: 0, no_flip: 0, no_convert: 0, keep_aspect_ratio: 0
 cl.save_save
 cl = CommonLisence.new name: 'Creative Commons 3.0(by_nc_nd)', 
   url: 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', 
-  cc_by: 1, cc_sa: 0, cc_nd: 1, cc_nc: 1, no_resize: 0, no_flip: 0, keep_aspect_ratio: 0
+  cc_by: 1, cc_sa: 0, cc_nd: 1, cc_nc: 1, no_resize: 0, no_flip: 0, no_convert: 0, keep_aspect_ratio: 0
 cl.save_save