OSDN Git Service

t#30237:update story view
authoryasushiito <yas@pen-chan.jp>
Sun, 2 Dec 2012 06:54:47 +0000 (15:54 +0900)
committeryasushiito <yas@pen-chan.jp>
Sun, 2 Dec 2012 06:54:47 +0000 (15:54 +0900)
40 files changed:
app/assets/images/artist.gif [new file with mode: 0644]
app/assets/images/author.gif [new file with mode: 0644]
app/assets/images/comic.gif [new file with mode: 0644]
app/assets/images/panel.gif [new file with mode: 0644]
app/assets/images/story.gif [new file with mode: 0644]
app/controllers/home_controller.rb
app/helpers/application_helper.rb
app/models/story.rb
app/views/comics/_form.html.erb
app/views/comics/_list_item.html.erb
app/views/comics/edit.html.erb
app/views/comics/index.html.erb
app/views/comics/show.html.erb
app/views/home/comic.html.erb
app/views/home/panel.html.erb
app/views/home/step2.html.erb [deleted file]
app/views/home/step3.html.erb [deleted file]
app/views/home/story.html.erb [new file with mode: 0644]
app/views/panels/_footer.html.erb
app/views/panels/_form.html.erb
app/views/panels/edit.html.erb
app/views/panels/index.html.erb
app/views/panels/new.html.erb
app/views/panels/show.html.erb
app/views/stories/_comic_header.html.erb [new file with mode: 0644]
app/views/stories/_editform.html.erb [deleted file]
app/views/stories/_footer.html.erb [new file with mode: 0644]
app/views/stories/_form.html.erb [moved from app/views/stories/_newform.html.erb with 78% similarity]
app/views/stories/_header.html.erb [deleted file]
app/views/stories/_licensed_pictures.html.erb
app/views/stories/_list_item.html.erb [new file with mode: 0644]
app/views/stories/_order.html.erb
app/views/stories/comic.html.erb
app/views/stories/edit.html.erb
app/views/stories/index.html.erb
app/views/stories/new.html.erb
app/views/stories/show.html.erb
config/locales/pettanr.ja.yml
spec/controllers/stories_controller_spec.rb
spec/models/story_spec.rb

diff --git a/app/assets/images/artist.gif b/app/assets/images/artist.gif
new file mode 100644 (file)
index 0000000..ae4fda3
Binary files /dev/null and b/app/assets/images/artist.gif differ
diff --git a/app/assets/images/author.gif b/app/assets/images/author.gif
new file mode 100644 (file)
index 0000000..508adea
Binary files /dev/null and b/app/assets/images/author.gif differ
diff --git a/app/assets/images/comic.gif b/app/assets/images/comic.gif
new file mode 100644 (file)
index 0000000..cff7dfa
Binary files /dev/null and b/app/assets/images/comic.gif differ
diff --git a/app/assets/images/panel.gif b/app/assets/images/panel.gif
new file mode 100644 (file)
index 0000000..84cc1b8
Binary files /dev/null and b/app/assets/images/panel.gif differ
diff --git a/app/assets/images/story.gif b/app/assets/images/story.gif
new file mode 100644 (file)
index 0000000..0707502
Binary files /dev/null and b/app/assets/images/story.gif differ
index 264ebfb..8466eb3 100644 (file)
@@ -1,12 +1,12 @@
 class HomeController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
   before_filter :authenticate_user!, :only => [
-    :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3, 
-    :comic, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
+    :index, :show, :profile, :configure, :create_token, :delete_token, 
+    :comic, :story, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
   ]
   before_filter :authenticate_author, :only => [
-    :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3, 
-    :comic, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
+    :index, :show, :profile, :configure, :create_token, :delete_token, 
+    :comic, :story, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
   ]
   before_filter :authenticate_artist, :only => [:picture]
   
@@ -36,42 +36,6 @@ class HomeController < ApplicationController
     end
   end
   
-  def step2
-  end
-  
-  def save_step2
-    respond_to do |format|
-      if @author.step2(params[:author][:name])
-        a = if params[:step3].to_i == 1
-          :step3
-        else
-          :index
-        end
-        format.html { redirect_to({:action => a}, {:notice => 'your name was successfully updated.'}) }
-      else
-        format.html { render action: "step2" }
-      end
-    end
-  end
-  
-  def step3
-  end
-  
-  def save_step3
-    if @author.artist?
-      redirect_to :action => :index
-    else
-      @artist = Artist.new params[:artist]
-      respond_to do |format|
-        if @artist.save
-          format.html { redirect_to({:action => :index}, {:notice => 'artist was successfully registered.'}) }
-        else
-          format.html { render action: "step3" }
-        end
-      end
-    end
-  end
-  
   def comic
     @page = Author.page params[:page]
     @page_size = Author.comic_page_size params[:page_size]
@@ -83,6 +47,17 @@ class HomeController < ApplicationController
     end
   end
   
+  def story
+    @page = Author.page params[:page]
+    @page_size = Author.story_page_size params[:page_size]
+    @stories = Story.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render text: Story.list_as_json_text(@stories) }
+    end
+  end
+  
   def panel
     @page = Author.page params[:page]
     @page_size = Author.panel_page_size params[:page_size]
index 9b27e32..190debd 100644 (file)
@@ -24,4 +24,30 @@ module ApplicationHelper
     t(MagicNumber[name][index][0])
   end
   
+  def icon_tag name, opt = {}
+    title = opt[:object] ? (name.to_s + ' ID:' + opt[:object].id.to_s) : name
+    size = opt[:size] ? opt[:size].to_i : 35
+    tag :img, :src => asset_path(name.to_s.downcase + '.gif'), :width => size, :height => size, :alt => name.to_s + ' Icon', :title => title
+  end
+  
+  def author_icon opt = {}
+    icon_tag :Author, opt
+  end
+  
+  def artist_icon opt = {}
+    icon_tag :Artist, opt
+  end
+  
+  def comic_icon opt = {}
+    icon_tag :Comic, opt
+  end
+  
+  def story_icon opt = {}
+    icon_tag :Story, opt
+  end
+  
+  def panel_icon opt = {}
+    icon_tag :Panel, opt
+  end
+  
 end
index 6549cfa..3a6cbe0 100644 (file)
@@ -10,6 +10,8 @@ class Story < ActiveRecord::Base
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   
   def supply_default
+    self.comic_id = nil
+    self.panel_id = nil
     self.t = nil
   end
   
@@ -118,7 +120,7 @@ class Story < ActiveRecord::Base
     opt = {}
     opt.merge!(self.list_opt)
     opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
-    opt.merge!({:order => 'updated_at desc'})
+    opt.merge!({:conditions => ['comics.visible > 0'], :order => 'stories.updated_at desc'})
     Story.find(:all, opt)
   end
   
index 8f4ca29..6bb664e 100644 (file)
@@ -2,10 +2,6 @@
   <%= render 'system/error_explanation', :obj => @comic %>
 
   <div class="field">
-    <%= f.label :author_id %><br />
-    <%= h @author.name %>
-  </div>
-  <div class="field">
     <%= f.label :title %><br />
     <%= f.text_field :title %>
   </div>
@@ -13,7 +9,10 @@
     <%= f.label :visible %><br />
     <%= f.collection_select :visible, t_select_items(MagicNumber['comic_visible_items']), :last, :first, :html => {:selected => @comic.visible} %>
   </div>
-
+  <div class="field">
+    <%= f.label :author_id %><br />
+    <%= h @author.name %>
+  </div>
   <div class="actions">
     <%= f.submit %>
   </div>
index 49ad58a..1bf947a 100644 (file)
@@ -1,18 +1,20 @@
 <tr>
   <td>
-    <%= link_to t('link.marker'), comic_path(comic) %>
+    <%= link_to comic_icon(:object => comic, :size => 25), comic_path(comic) %>
     <%= link_to h(truncate(comic.title, :length => 40)), :controller => 'stories', :action => :comic, :id => comic.id %>
+    (<%= comic.stories.size -%>)
   </td>
   <td>
-    <%= link_to h(truncate(comic.author.name, :length => 12)), author_path(comic.author) %>
+    <%= distance_of_time_in_words_to_now comic.updated_at %>
   </td>
   <td>
-    <%= distance_of_time_in_words_to_now comic.updated_at %>
+    <%= link_to author_icon(:object => comic.author, :size => 25), comic_path(comic.author) %>
+    <%= link_to h(truncate(comic.author.name, :length => 12)), author_path(comic.author) %>
   </td>
   <td>
     <% if comic.own? author %>
       <%= link_to t('link.edit'), edit_comic_path(comic) %>
-      <%= link_to t('link.destroy'), comic_path(comic), :method => :dellete %>
+      <%= link_to t('link.destroy'), comic_path(comic), :method => :delete %>
     <% end %>
   </td>
 </tr>
index 53e040e..f33a2f8 100644 (file)
@@ -1,4 +1,3 @@
 <h1><%= t('.title') %></h1>
 
 <%= render 'form' %>
-<%= link_to t('link.back'), comics_path %>
index 57bc9ca..ef4ca5c 100644 (file)
@@ -1,14 +1,8 @@
 <h1><%= t '.title' -%></h1>
 
 <table>
-  <tr>
-    <th><%= t_m 'Comic.title' -%></th>
-    <th><%= t_m 'Comic.author_id' -%></th>
-    <th><%= t_m 'Comic.updated_at' -%></th>
-    <th> </th>
-  </tr>
   <% @comics.each do |comic| %>
     <%= render 'list_item', :comic => comic, :author => @author %>
   <% end %>
 </table>
-<%= link_to t('.new'), new_comic_path %>
+<%= link_to t('comics.new.title'), new_comic_path %>
index 9e8ed5f..aa712a3 100644 (file)
@@ -27,5 +27,3 @@
 </p>
 
 <%= link_to t('link.edit'), edit_comic_path(@comic) %>
-
-<%= link_to t('link.back'), comics_path %>
index b26ab70..3f90c92 100644 (file)
@@ -1,14 +1,8 @@
 <h1><%= t '.title' -%></h1>
 
 <table>
-  <tr>
-    <th><%= t_m 'Comic.title' -%></th>
-    <th><%= t_m 'Comic.author_id' -%></th>
-    <th><%= t_m 'Comic.updated_at' -%></th>
-    <th>edit</th>
-  </tr>
   <% @comics.each do |comic| %>
     <%= render 'comics/list_item', :comic => comic, :author => @author %>
   <% end %>
 </table>
-<%= link_to t('.new'), new_comic_path %>
+<%= link_to t('comics.new.title'), new_comic_path %>
index d0aa666..fb572ad 100644 (file)
@@ -1,7 +1,8 @@
-<h1>Listing My panels</h1>
+<h1><%= t '.title' -%></h1>
 
 <% @panels.each do |panel| %>
   <div>
     <%= render 'panels/standard', :panel => panel, :author => @author %>
   </div>
 <% end %>
+<%= link_to t('panels.new.title'), new_panel_path %>
diff --git a/app/views/home/step2.html.erb b/app/views/home/step2.html.erb
deleted file mode 100644 (file)
index 0b69bf4..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<h1>ようこそ、ぺったんRへ</h1>
-<div>
-<%= h(@user.email) -%>さんはぺったんRで作家としてデビューしました。
-今すぐにでも作品を作れますが、より良い活動をするために作家名を登録してください。
-</div>
-<%= form_for(:author, :url => {:controller => '/home', :action => :save_step2}) do |f| %>
-  <% if @author.errors.any? %>
-    <div id="error_explanation">
-      <h2><%= pluralize(@author.errors.count, "error") %> prohibited this original_license from being saved:</h2>
-
-      <ul>
-      <% @author.errors.full_messages.each do |msg| %>
-        <li><%= msg %></li>
-      <% end %>
-      </ul>
-    </div>
-  <% end %>
-
-  <div class="field">
-    <%= f.label :name %><br />
-    <%= f.text_field :name %>
-  </div>
-  <p>あなたの素材を投稿してみませんか?</p>
-  絵師としての情報を登録すれば、あなたのキャラクターを漫画に登場させるなど、幅広い創作活動ができます。
-  <div class="field">
-    <%= check_box_tag 'step3', 1, false %> 引き続き、絵師登録を行う
-  </div>
-
-  <div class="actions">
-    <%= f.submit '次のステップへ' %>
-  </div>
-<% end %>
diff --git a/app/views/home/step3.html.erb b/app/views/home/step3.html.erb
deleted file mode 100644 (file)
index bc604f0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<h1>ようこそ、ぺったんRへ</h1>
-<%= h(@author.name) -%>さん
-<div>
-  <%= form_for(:artist, :url => {:controller => '/home', :action => :save_step3}) do |f| %>
-    <% if @artist.errors.any? %>
-      <div id="error_explanation">
-        <h2><%= pluralize(@artist.errors.count, "error") %> prohibited this artist from being saved:</h2>
-
-        <ul>
-        <% @artist.errors.full_messages.each do |msg| %>
-          <li><%= msg %></li>
-        <% end %>
-        </ul>
-      </div>
-    <% end %>
-
-    <div class="field">
-      <p>作家名とは別に絵師としてのペンネームを設定できます。</p>
-      <%= f.label :name %><br />
-      <%= f.text_field :name %><br />
-
-      <%= f.hidden_field :author_id, :value => @artist.author_id %>
-    </div>
-    <div class="actions">
-      <%= f.submit '完了' %>
-    </div>
-  <% end %>
-</div>
diff --git a/app/views/home/story.html.erb b/app/views/home/story.html.erb
new file mode 100644 (file)
index 0000000..47e0cac
--- /dev/null
@@ -0,0 +1,8 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @stories.each do |story| %>
+    <%= render 'stories/list_item', :story => story, :author => @author %>
+  <% end %>
+</table>
+<%= link_to t('stories.new.title'), new_story_path %>
index d293a17..6990d3b 100644 (file)
@@ -1,21 +1,13 @@
 <table class="no-border">
   <tr>
     <td>
-      <%= link_to '■', panel_path(panel) %>
-    </td>
-    <td>
-      <%= link_to h(panel.author.name), author_path(panel.author) %>
-    </td>
-    <td>
-      <%= panel.width %>x<%= panel.height %>
-    </td>
-    <td>
+      <%= link_to panel_icon(:object => panel, :size => 25), panel_path(panel) %>
+      <%= link_to author_icon(:object => panel.author, :size => 17), author_path(panel.author) %>
       <%= l panel.updated_at %>
     </td>
     <td>
       <% if panel.own? author %>
-        <%= link_to 'edit', edit_panel_path(panel) %>
-        <%= link_to 'destroy', panel_path(panel), :method => :delete %>
+        <%= link_to t('link.edit'), edit_panel_path(panel) %>
       <% end %>
     </td>
   </tr>
index 81965fd..08f1296 100644 (file)
@@ -1,5 +1,10 @@
 <%= form_tag( {:controller => 'panels',:action => "create"}) do %>
   <%= render 'system/error_explanation', :obj => @panel %>
-  <label for="json">json data</label> <%= text_field_tag "json" %>
-  <%= submit_tag 'upload' -%>
+  <div>
+    <label for="json">json data</label>
+  </div>
+  <%= text_field_tag "json" %>
+  <div>
+    <%= submit_tag t('panels.create_from_json') -%>
+  </div>
 <% end -%>
index 208c00d..dd4f037 100644 (file)
@@ -1,3 +1,4 @@
-<h1>コマの編集</h1>
+<h1><%= t '.title' -%></h1>
 <%= render 'standard', :panel => @panel, :author => @author %>
 <%= render 'form' %>
+<%= link_to t('link.destroy'), panel_path(@panel), :method => :delete %>
index cac4b55..0f61452 100644 (file)
@@ -2,7 +2,4 @@
 <% @panels.each do |panel| %>
   <%= render 'standard', :panel => panel, :author => @author %>
 <% end %>
-<%= link_to 'open form', new_panel_path, :remote => true %>
-  <div id="newpanel">
-    ...
-  </div>
+<%= link_to t('panels.new.title'), new_panel_path %>
index 2e796ef..fc4811c 100644 (file)
@@ -1,2 +1,2 @@
-<h1>コマの新規作成</h1>
+<h1><%= t '.title' -%></h1>
 <%= render 'form' %>
index 90a1de8..d8bfa24 100644 (file)
@@ -1,5 +1,6 @@
-<h1>コマの表示</h1>
+<h1><%= t '.title' -%></h1>
 <p id="notice"><%= notice %></p>
 <%= render 'standard', :panel => @panel, :author => @author %>
 
-<%= link_to 'Back', panels_path %>
+<%= link_to t('link.edit'), edit_panel_path(@panel) %>
+<%= link_to t('link.destroy'), panel_path(@panel), :method => :delete %>
diff --git a/app/views/stories/_comic_header.html.erb b/app/views/stories/_comic_header.html.erb
new file mode 100644 (file)
index 0000000..d1eb9e7
--- /dev/null
@@ -0,0 +1,40 @@
+<h1>
+  <%= link_to comic_icon, comic_path(comic) %>
+  <%= link_to h(comic.title), :controller => 'stories', :action => :comic, :id => comic.id %>
+</h1>
+<% if comic.own? author -%>
+  <%= form_for(comic) do |f| %>
+    <div class="field">
+      <%= f.label :title %><br />
+      <%= f.text_field :title %>
+    </div>
+    <div class="field">
+      <%= f.label :visible %><br />
+      <%= f.collection_select :visible, t_select_items(MagicNumber['comic_visible_items']), :last, :first, :html => {:selected => @comic.visible} %>
+    </div>
+    <div class="actions">
+      <%= f.submit %>
+    </div>
+  <% end %>
+<% else %>
+  <p>
+    <b><%= t_m 'Comic.visible' -%>:</b>
+    <%= t_selected_item('comic_visible_items', @comic.visible) %>
+  </p>
+<% end %>
+
+<p>
+  <b><%= t_m 'Comic.author_id' -%>:</b>
+  <%= link_to h(@comic.author.name), author_path(@comic.author) %>
+</p>
+
+<p>
+  <b><%= t_m 'Comic.created_at' -%>:</b>
+  <%= l @comic.created_at %>
+</p>
+
+<p>
+  <b><%= t_m 'Comic.updated_at' -%>:</b>
+  <%= l @comic.updated_at %>
+</p>
+
diff --git a/app/views/stories/_editform.html.erb b/app/views/stories/_editform.html.erb
deleted file mode 100644 (file)
index 73f55bf..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<%= form_for(@story) do |f| %>
-  <%= render 'system/error_explanation', :obj => @story %>
-
-  <div class="field">
-    <%= f.hidden_field :comic_id %>
-  </div>
-  <div class="field">
-    <%= f.number_field :t %>
-  </div>
-  <div class="field">
-    <%= f.hidden_field :panel_id %>
-  </div>
-
-  <div class="actions">
-    <%= f.submit %>
-  </div>
-<% end %>
-<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %>
diff --git a/app/views/stories/_footer.html.erb b/app/views/stories/_footer.html.erb
new file mode 100644 (file)
index 0000000..d2dcb6f
--- /dev/null
@@ -0,0 +1,21 @@
+<table class="no-border" style="margin: 0px; padding: 0px; width=100%">
+  <tr>
+    <td>
+      <%= link_to panel_icon(:object => story.panel, :size => 25), panel_path(story.panel) %>
+      <%= link_to author_icon(:object => story.panel.author, :size => 17), author_path(story.panel.author) %>
+      <%= distance_of_time_in_words_to_now story.panel.updated_at %>
+    </td>
+    <td>
+      <%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
+      <%= link_to author_icon(:object => story.author, :size => 17), author_path(story.author) %>
+      <%= l story.updated_at %>
+    </td>
+    <td>
+      <% if story.own? author %>
+        <%= render 'order', :story => story %>
+      <% else %>
+        No.<%= story.t %>
+      <% end %>
+    </td>
+  </tr>
+</table>
similarity index 78%
rename from app/views/stories/_newform.html.erb
rename to app/views/stories/_form.html.erb
index 7ec5e4a..8d705f5 100644 (file)
@@ -2,12 +2,15 @@
   <%= render 'system/error_explanation', :obj => @story %>
 
   <div class="field">
+    <%= f.label :comic_id %><br />
     <%= f.number_field :comic_id %>
   </div>
   <div class="field">
+    <%= f.label :t %><br />
     <%= f.number_field :t %>
   </div>
   <div class="field">
+    <%= f.label :panel_id %><br />
     <%= f.number_field :panel_id %>
   </div>
 
diff --git a/app/views/stories/_header.html.erb b/app/views/stories/_header.html.erb
deleted file mode 100644 (file)
index 50b563b..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<table class="no-border">
-  <tr>
-    <td>
-      No.<%= link_to story.t, story_path(story) %>:
-    </td>
-    <td>
-      <%= link_to h(story.panel.author.name), author_path(story.panel.author) %>
-    </td>
-    <td>
-      <%= story.updated_at %>
-    </td>
-    <td>
-      <% if story.own? @author -%>
-        <%= link_to 'edit', edit_story_path(story), :remote => true %>
-          <span id="story-update-<%= @story.id -%>">
-            ...
-          </span>
-      <% end -%>
-    </td>
-  </tr>
-</table>
index b00d63b..1c10cc7 100644 (file)
@@ -3,7 +3,7 @@
     <table class="no-border">
       <tr>
         <td>
-          <%= link_to(tag(:img, picture.opt_img_tag), picture_path(picture.id)) -%>
+          <%= link_to(tag(:img, picture.tmb_opt_img_tag), picture_path(picture.id)) -%>
         </td>
         <td>
           <%= render picture.credit_template, :picture => picture %>
diff --git a/app/views/stories/_list_item.html.erb b/app/views/stories/_list_item.html.erb
new file mode 100644 (file)
index 0000000..0d3eacf
--- /dev/null
@@ -0,0 +1,26 @@
+<table class="no-border" style="margin: 0px; padding: 0px; width=100%">
+  <tr>
+    <td>
+      <div>
+        <%= link_to comic_icon(:object => story.comic, :size => 25), comic_path(story.comic) %>
+        <%= link_to h(story.comic.title), :controller => 'stories', :action => :comic, :id => story.comic.id %>
+      </div>
+      <%= link_to author_icon(:object => story.comic.author, :size => 17), author_path(story.comic.author) %>
+    </td>
+    <td>
+      <div>
+        <%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
+        <%= link_to author_icon(:object => story.author, :size => 17), author_path(story.author) %>
+      </div>
+      <div>
+        No.<%= story.t %>
+        <%= l story.updated_at %>
+      </div>
+    </td>
+    <td>
+      <% if story.panel %>
+        <%= render 'panels/standard', :panel => story.panel, :author => @author %>
+      <% end %>
+    </td>
+  </tr>
+</table>
index 9cc6dd4..e0ceadf 100644 (file)
@@ -1,28 +1,15 @@
-<%= form_for(@story) do |f| %>
-  <% if @story.errors.any? %>
-    <div id="error_explanation">
-      <h2><%= pluralize(@story.errors.count, "error") %> prohibited this comic from being saved:</h2>
-
-      <ul>
-      <% @story.errors.full_messages.each do |msg| %>
-        <li><%= msg %></li>
-      <% end %>
-      </ul>
-    </div>
-  <% end %>
-
-  <div class="field">
-    <%= f.hidden_field :comic_id %>
-  </div>
-  <div class="field">
-    <%= f.number_field :t %>
-  </div>
-  <div class="field">
-    <%= f.hidden_field :panel_id %>
-  </div>
-
-  <div class="actions">
-    <%= f.submit %>
-  </div>
+<%= form_for(story) do |f| %>
+  <table class="no-border">
+    <tr>
+      <td>
+        No.
+        <%= f.number_field :t, :size => 3 %>
+        <%= f.hidden_field :panel_id %>
+        <%= f.hidden_field :comic_id %>
+      </td>
+      <td>
+        <%= f.submit t 'stories.move' %>
+      </td>
+    </tr>
+  </table>
 <% end %>
-<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %>
index 305621d..63c22b5 100644 (file)
@@ -1,16 +1,34 @@
-<h1><%= h @comic.title %> <%= link_to 'p', comic_path(@comic) %> <%= link_to 'edit', edit_comic_path(@comic) %></h1>
+<h1><%= t '.title' -%></h1>
+<%= render 'comic_header', :comic => @comic, :author => @author %>
 
-<% @stories.each do |story| %>
-  <% @story = story %>
-  <%= render 'header', :story => story, :author => @author %>
-  <%= render 'panels/body', :panel => story.panel, :author => @author %>
-  <%= render 'panels/footer', :panel => story.panel, :author => @author %>
+<% if @stories.empty? -%>
+  <h2><%= t('stories.comic.empty') %></h2>
+<% else %>
+  <% @stories.each do |story| %>
+    <%= render 'panels/body', :panel => story.panel, :author => @author %>
+    <%= render 'footer', :story => story, :author => @author %>
+  <% end %>
+  <%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %>
 <% end %>
-<%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %>
 <% if @comic.own? @author -%>
-  <%= link_to 'add panel', new_story_path, :remote => true %>
-    <div id="story-create">
-      t
+  <h3><%= t('stories.new.title') %></h3>
+  <% @story = Story.new ; @story.comic_id = @comic.id ; @story.t = Story.new_t @comic.id -%>
+  <%= form_for(@story) do |f| %>
+
+    <div class="field">
+      <%= f.hidden_field :comic_id %>
+    </div>
+    <div class="field">
+      <%= f.label :t %><br />
+      <%= f.number_field :t %>
+    </div>
+    <div class="field">
+      <%= f.label :panel_id %><br />
+      <%= f.number_field :panel_id %>
+    </div>
+
+    <div class="actions">
+      <%= f.submit %>
     </div>
+  <% end %>
 <% end %>
-<%= link_to 'Back', comics_path %>
index 9f2b842..1390df9 100644 (file)
@@ -1 +1,4 @@
-<%= render 'editform' %>
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
+<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %>
index da8cdb8..1ab65ec 100644 (file)
@@ -1,4 +1,5 @@
 <h1><%= t '.title' -%></h1>
 <% @stories.each do |story| %>
-  <%= render 'panels/standard', :panel => story.panel, :author => @author %>
+  <%= render 'list_item', :story => story, :author => @author %>
 <% end %>
+<%= link_to t('stories.new.title'), new_story_path %>
index 47cd6d9..f33a2f8 100644 (file)
@@ -1 +1,3 @@
-<%= render 'newform' %>
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
index 16cc6dd..871fd95 100644 (file)
@@ -1,18 +1,40 @@
-  <%= render 'panels/standard', :panel => @story.panel, :author => @author %>
-  <% if @story.author.id == @author.id -%>
-    <span>
-    t:<%= @story.t %>
-    </span>
-<%= button_to 'Destroy', @story, confirm: 'Are you sure?', method: :delete %>
-    <%= render 'editform' %>
-    <%= link_to 'open js', edit_story_path(@story), :remote => true %>
-      <div id="story-update-<%= @story.id -%>">
-        t
-      </div>
-  <% end -%>
-<% if @story.comic.own? @author -%>
-  <%= link_to 'add panel', new_story_path, :remote => true %>
-    <div id="story-create">
-      t
-    </div>
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<p>
+  <b><%= t_m 'Story.comic_id' -%>:</b>
+  <%= link_to comic_icon(:object => @story.comic), comic_path(@story.comic) %>
+  <%= link_to h(@story.comic.title), :controller => 'stories', :action => :comic, :id => @story.comic.id %>
+</p>
+
+<p>
+  <b><%= t_m 'Story.panel_id' -%>:</b>
+  <%= link_to panel_icon(:object => @story.panel), panel_path(@story.panel) %>
+</p>
+
+<p>
+  <b><%= t_m 'Story.t' -%>:</b>
+  <%= @story.t %>
+</p>
+
+<p>
+  <b><%= t_m 'Story.author_id' -%>:</b>
+  <%= link_to author_icon(:object => @story.author), author_path(@story.author) %>
+  <%= link_to h(@story.author.name), author_path(@story.author) %>
+</p>
+
+<p>
+  <b><%= t_m 'Story.created_at' -%>:</b>
+  <%= l @story.created_at %>
+</p>
+
+<p>
+  <b><%= t_m 'Story.updated_at' -%>:</b>
+  <%= l @story.updated_at %>
+</p>
+<% if @story.own? @author -%>
+  <%= link_to t('link.edit'), edit_story_path(@story) %>
 <% end %>
+
+<hr>
+<%= render 'panels/standard', :panel => @story.panel, :author => @author %>
index 37dd2ec..f61cb78 100644 (file)
@@ -245,6 +245,8 @@ ja:
       updated_picture: 最近更新した画像
     comic:
       title: 最近更新したコミック
+    story:
+      title: 最近更新したストーリー
     panel:
       title: 最近更新したコマ
     picture:
@@ -305,10 +307,14 @@ ja:
       title: ストーリー追加
     edit:
       title: 並び替え
+    comic:
+      title: コミックを読む
+      empty: ストーリーはありません
     list:
       title: ストーリー 生一覧
     browse:
       title: ストーリー 生単票
+    move: 移動
   panels:
     index:
       title: コマ一覧
@@ -316,10 +322,13 @@ ja:
       title: コマ詳細
     new:
       title: コマ作成
+    edit:
+      title: コマ編集
     list:
       title: コマ 生一覧
     browse:
       title: コマ 生単票
+    create_from_json: jsonデータからコマ作成する
   panel_pictures:
     index:
       title: コマ絵一覧
index 095b54e..2b325ed 100644 (file)
@@ -14,6 +14,104 @@ describe StoriesController do
   end
   
   describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      Story.stub(:list).and_return([@story, @story, @story])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :index, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :index
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :index, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :index
+        assigns(:page_size).should eq Story.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 1500
+        assigns(:page_size).should eq Story.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 0
+        assigns(:page_size).should eq Story.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      it 'ストーリーモデルに一覧を問い合わせている' do
+        Story.should_receive(:list).exactly(1)
+        get :index
+      end
+      it '@storiesにリストを取得している' do
+        get :index
+        assigns(:stories).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
+          Story.should_receive(:list_json_opt).exactly(1)
+          get :index, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("comic_id").should be_true
+          json.first.has_key?("t").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
   end
   
   describe '単体表示に於いて' do
index 6c4a84c..9c747d7 100644 (file)
@@ -212,7 +212,7 @@ describe Story do
     end
   end
   
-  describe '一覧取得に於いて' do
+  describe 'プレイリスト取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
       @panel = FactoryGirl.create :panel, :author_id => @author.id
@@ -361,6 +361,94 @@ describe Story do
   describe 'json一覧出力オプションに於いて' do
   end
   
+  describe '一覧取得に於いて' do
+    before do
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+      @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
+      @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+      @hidden_comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
+    end
+    context 'page補正について' do
+      it '文字列から数値に変換される' do
+        Story.page('8').should eq 8
+      end
+      it 'nilの場合は1になる' do
+        Story.page().should eq 1
+      end
+      it '0以下の場合は1になる' do
+        Story.page('0').should eq 1
+      end
+    end
+    context 'page_size補正について' do
+      it '文字列から数値に変換される' do
+        Story.page_size('7').should eq 7
+      end
+      it 'nilの場合はStory.default_page_sizeになる' do
+        Story.page_size().should eq Story.default_page_size
+      end
+      it '0以下の場合はStory.default_page_sizeになる' do
+        Story.page_size('0').should eq Story.default_page_size
+      end
+      it 'Story.max_page_sizeを超えた場合はStory.max_page_sizeになる' do
+        Story.page_size('1000').should eq Story.max_page_size
+      end
+    end
+    it 'リストを返す' do
+      c = Story.list
+      c.should eq [@story]
+    end
+    it '時系列で並んでいる' do
+      #公開コミックのStoryは(他人のStoryであっても)含んでいる
+      v = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 0, :updated_at => Time.now + 100
+      c = Story.list 
+      c.should eq [ v, @story]
+    end
+    it '非公開のストーリーは(自分のストーリーであっても)含まない' do
+      h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hidden_comic.id, :panel_id => @panel.id, :t => 0
+      c = Story.list 
+      c.should eq [ @story]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
+        @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
+        @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
+        @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+      end
+      it '通常は2件を返す' do
+        l = Story.list 1, 2
+        l.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        l = Story.list 1, 2
+        l.should eq [@story5, @story4]
+      end
+      it 'page=2なら中間2件を返す' do
+        l = Story.list 2, 2
+        l.should eq [@story3, @story2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        l = Story.list 3, 2
+        l.should eq [@story]
+      end
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
+        @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
+        @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
+        @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+        Story.stub(:default_page_size).and_return(2)
+      end
+      it '件数0は全件(5件)を返す' do
+        r = Story.list 5, 0
+        r.should have(5).items 
+      end
+    end
+  end
   describe '自分のストーリー一覧取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
@@ -403,34 +491,35 @@ describe Story do
         @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
         @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
         @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+        Story.stub(:default_page_size).and_return(2)
       end
       it '通常は2件を返す' do
-        c = Story.mylist @author, 1, 2
-        c.should have(2).items 
+        l = Story.mylist @author, 1, 2
+        l.should have(2).items 
       end
       it 'page=1なら末尾2件を返す' do
         #時系列で並んでいる
-        c = Story.mylist(@author, 1, 2)
-        c.should eq [@story5, @story4]
+        l = Story.mylist @author, 1, 2
+        l.should eq [@story5, @story4]
       end
       it 'page=2なら中間2件を返す' do
-        c = Story.mylist(@author, 2, 2)
-        c.should eq [@story3, @story2]
+        l = Story.mylist @author, 2, 2
+        l.should eq [@story3, @story2]
       end
       it 'page=3なら先頭1件を返す' do
-        c = Story.mylist(@author, 3, 2)
-        c.should eq [@story]
+        l = Story.mylist @author, 3, 2
+        l.should eq [@story]
       end
     end
-    context 'DBに5件あって1ページの件数を0件に変えたとして' do
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
       before do
         @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
         @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
         @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
         @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
-        Author.stub(:default_story_size).and_return(2)
+        Author.stub(:default_story_page_size).and_return(2)
       end
-      it '通常は全件(5件)を返す' do
+      it '件数0は全件(5件)を返す' do
         r = Story.mylist @author, 5, 0
         r.should have(5).items 
       end