From: yasushiito Date: Sun, 15 Jan 2012 05:42:01 +0000 (+0900) Subject: iroiro X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=3bb159eda799aa3c5f19edb73ca9e44fbb6988db iroiro --- diff --git a/app/assets/javascripts/author_registrations.js.coffee b/app/assets/javascripts/author_registrations.js.coffee new file mode 100644 index 00000000..76156794 --- /dev/null +++ b/app/assets/javascripts/author_registrations.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/author_registrations.css.scss b/app/assets/stylesheets/author_registrations.css.scss new file mode 100644 index 00000000..a97efb96 --- /dev/null +++ b/app/assets/stylesheets/author_registrations.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the author_registrations controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/author_registrations_controller.rb b/app/controllers/author_registrations_controller.rb new file mode 100644 index 00000000..9744070f --- /dev/null +++ b/app/controllers/author_registrations_controller.rb @@ -0,0 +1,7 @@ +class AuthorRegistrationsController < Devise::RegistrationsController + protected + + def after_sign_up_path_for(resource) + '/home/step2' + end +end diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index c960bc56..a69fffad 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -33,5 +33,5 @@ class AuthorsController < ApplicationController format.html { render layout: 'system' } end end - + end diff --git a/app/controllers/comics_controller.rb b/app/controllers/comics_controller.rb index 8a5169c5..3513be4c 100644 --- a/app/controllers/comics_controller.rb +++ b/app/controllers/comics_controller.rb @@ -11,7 +11,12 @@ class ComicsController < ApplicationController public def top - @comics = Comic.all + @new_comics = Comic.find(:all, + :include => :author, :conditions => ['visible = 1'], :order => 'updated_at desc', :limit => 5 + ) + @new_pictures = OriginalPicture.find(:all, + :include => [:artist, :lisence, :resource_picture], :order => 'updated_at', :limit => 5 + ) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index cc3895ad..fea06eda 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,8 +1,8 @@ class HomeController < ApplicationController - - def start - - end + before_filter :authenticate_author!, :only => [ + :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3, + :comic, :picture + ] def index end @@ -10,4 +10,93 @@ class HomeController < ApplicationController def profile end + def configure + end + + def create_token + @author = current_author + respond_to do |format| + if @author.create_token + format.html { redirect_to({:action => :configure}, {:notice => 'author token was successfully created.'}) } + else + format.html { render action: "auth_token" } + end + end + end + + def delete_token + current_author.delete_token + respond_to do |format| + format.html { redirect_to :action => :configure} + end + end + + def step2 + @author = current_author + end + + def save_step2 + @author = current_author + 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 + @artist = Artist.new :author_id => current_author.id, :name => current_author.name, :default_lisence_id => 1 + end + + def save_step3 + if current_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 + @comics = Comic.find(:all, + :include => :author, :conditions => ['author_id = ?', current_author.id], + :order => 'updated_at desc', :limit => 20 + ) + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @comics } + end + end + + def picture + if current_author.artist? + @original_pictures = OriginalPicture.find(:all, + :include => [:artist, :lisence, :resource_picture], :conditions => ['artist_id = ?', current_author.artist.id], + :order => 'updated_at', :limit => 20 + ) + + respond_to do |format| + format.html # index.html.erb + format.json { render :json => @original_pictures.to_json( + :include => [:resource_picture, :artist, :lisence] + ) } + end + else + end + end + end diff --git a/app/controllers/system_controller.rb b/app/controllers/system_controller.rb index 69c0a934..a466600e 100644 --- a/app/controllers/system_controller.rb +++ b/app/controllers/system_controller.rb @@ -4,7 +4,19 @@ class SystemController < ApplicationController #layout :system def start - + OriginalPicture.all.each do |a| + a.lisence_id = 1 if a.lisence_id.blank? + a.save + end + ResourcePicture.all.each do |a| + a.lisence_id = 1 if a.lisence_id.blank? + a.artist_id = 1 if a.artist_id.blank? + a.save + end + Artist.all.each do |a| + a.default_lisence_id = 1 if a.default_lisence_id.blank? + a.save + end end def index diff --git a/app/helpers/author_registrations_helper.rb b/app/helpers/author_registrations_helper.rb new file mode 100644 index 00000000..4614791b --- /dev/null +++ b/app/helpers/author_registrations_helper.rb @@ -0,0 +1,2 @@ +module AuthorRegistrationsHelper +end diff --git a/app/models/author.rb b/app/models/author.rb index cc154ca1..2341a9f3 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -7,15 +7,29 @@ class Author < ActiveRecord::Base :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable # Setup accessible (or protected) attributes for your model - attr_accessible :email, :password, :password_confirmation, :remember_me + attr_accessible :id, :name, :password, :password_confirmation, :remember_me #, :email - before_save :ensure_authentication_token before_save do |r| r.name = 'no name' if r.name.blank? end - def artist? - Artist.find_by_author(self) != nil - end - + def artist? + Artist.find_by_author(self) != nil + end + + def create_token + self.ensure_authentication_token + self.save + end + + def delete_token + self.authentication_token = nil + self.save + end + + def step2 n + self.name = n + self.save + end + end diff --git a/app/models/comic.rb b/app/models/comic.rb index ab882cf0..24113183 100644 --- a/app/models/comic.rb +++ b/app/models/comic.rb @@ -11,4 +11,8 @@ class Comic < ActiveRecord::Base editable == 1 ? 'O' : 'X' end + def disp_visible + visible == 1 ? 'O' : 'X' + end + end diff --git a/app/views/artists/list.html.erb b/app/views/artists/list.html.erb index cf81c732..1ffd5d30 100644 --- a/app/views/artists/list.html.erb +++ b/app/views/artists/list.html.erb @@ -20,9 +20,9 @@ <%= h artist.email %> <%= h artist.name %> <%= h artist.homepage_url %> + <%= h artist.api_url %> <%= link_to artist.default_lisence_id, :controller => 'lisences', :action => :browse, :id => artist.default_lisence_id %> <%= artist.crowled_at %> - <%= h artist.api_url %> <%= link_to artist.author_id, :controller => 'authors', :action => :browse, :id => artist.author_id %> <%= artist.created_at %> <%= artist.updated_at %> diff --git a/app/views/author_registrations/new.html.erb b/app/views/author_registrations/new.html.erb new file mode 100644 index 00000000..d15e275a --- /dev/null +++ b/app/views/author_registrations/new.html.erb @@ -0,0 +1,18 @@ +

Sign up

+ +<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> + <%= devise_error_messages! %> + +
<%= f.label :email %>
+ <%= f.email_field :email %>
+ +
<%= f.label :password %>
+ <%= f.password_field :password %>
+ +
<%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation %>
+ +
<%= f.submit "Sign up" %>
+<% end %> + +<%= render :partial => "devise/shared/links" %> diff --git a/app/views/authors/registrations/new.html.erb b/app/views/authors/registrations/new.html.erb index 3ae6813a..d15e275a 100644 --- a/app/views/authors/registrations/new.html.erb +++ b/app/views/authors/registrations/new.html.erb @@ -3,9 +3,6 @@ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> -
<%= f.label :name %>
- <%= f.text_field :name %>
-
<%= f.label :email %>
<%= f.email_field :email %>
diff --git a/app/views/comics/top.html.erb b/app/views/comics/top.html.erb index 696809ee..df6393a2 100644 --- a/app/views/comics/top.html.erb +++ b/app/views/comics/top.html.erb @@ -1,5 +1,6 @@ -

<%= link_to '新着', comics_path %>

- +<%= link_to "comics", comics_path %> +

コミック

+<%= link_to '新着', comics_path %> @@ -9,7 +10,7 @@ -<% @comics.each do |comic| %> +<% @new_comics.each do |comic| %> @@ -25,5 +26,17 @@ <% end %>
Title
<%= link_to h(comic.title), :action => :play, :id => comic.id %> <%= comic.editable %>
-

人気

- +<%= link_to '人気', comics_path %> +

コマ

+<%= link_to '新着', panels_path %> +<%= link_to '人気', panels_path %> +

素材

+<% @new_pictures.each do |picture| %> +
+ + 画:<%= h picture.artist.name %> +
+<% end %> +<%= link_to "もっと見る", original_pictures_path %> +

ライセンス

+<%= link_to "lisences", lisences_path %> diff --git a/app/views/home/comic.html.erb b/app/views/home/comic.html.erb new file mode 100644 index 00000000..6c9b62da --- /dev/null +++ b/app/views/home/comic.html.erb @@ -0,0 +1,14 @@ +

Listing comics

+ +<% @comics.each do |comic| %> +
+
+ <%= link_to h(comic.title), :action => :play, :id => comic.id %> + 一般投稿:<%= comic.disp_editable %> + 公開:<%= comic.disp_visible %> +
+
+ 更新:<%= comic.updated_at %> +
+
+<% end %> diff --git a/app/views/home/configure.html.erb b/app/views/home/configure.html.erb new file mode 100644 index 00000000..38b80aff --- /dev/null +++ b/app/views/home/configure.html.erb @@ -0,0 +1,15 @@ +

認証トークン

+
+あなたの認証トークンは<%= current_author.authentication_token %>です +
+
+ <% if current_author.authentication_token %> + <%= link_to 'delete token', :action => :delete_token %> + <% else %> + <%= link_to 'generate token', :action => :create_token %> + <% end %> +
+

退会

+
+ <%= link_to('退会する', {:controller => 'author_registrations', :action => :destroy, :id => current_author.id}, {:method => :delete}) %> +
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index e45cd11b..ea26dcb7 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,7 +1,4 @@

<%= h(current_author.name) -%>(<%= h(current_author.email) -%>)

-
-あなたの認証トークンは<%= current_author.authentication_token %>です -

絵師活動

diff --git a/app/views/home/picture.html.erb b/app/views/home/picture.html.erb new file mode 100644 index 00000000..e948534f --- /dev/null +++ b/app/views/home/picture.html.erb @@ -0,0 +1,10 @@ +

Listing my pictures

+ +<% @original_pictures.each do |original_picture| %> +
+ <%= original_picture.filename %> + + <%= original_picture.width %>x<%= original_picture.height %> + <%= original_picture.filesize %>bytes +
+<% end %> diff --git a/app/views/home/step2.html.erb b/app/views/home/step2.html.erb new file mode 100644 index 00000000..70281cbc --- /dev/null +++ b/app/views/home/step2.html.erb @@ -0,0 +1,32 @@ +

ようこそ、ぺったんRへ

+
+<%= h(current_author.email) -%>さんはぺったんRで作家としてデビューしました。 +今すぐにでも作品を作れますが、より良い活動をするために作家名を登録してください。 +
+<%= form_for(:author, :url => {:controller => '/home', :action => :save_step2}) do |f| %> + <% if @author.errors.any? %> +
+

<%= pluralize(@author.errors.count, "error") %> prohibited this original_lisence from being saved:

+ +
    + <% @author.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+

あなたの素材を投稿してみませんか?

+ 絵師としての情報を登録すれば、あなたのキャラクターを漫画に登場させるなど、幅広い創作活動ができます。 +
+ <%= check_box_tag 'step3', 1, false %> 引き続き、絵師登録を行う +
+ +
+ <%= f.submit '次のステップへ' %> +
+<% end %> diff --git a/app/views/home/step3.html.erb b/app/views/home/step3.html.erb new file mode 100644 index 00000000..13a37a1c --- /dev/null +++ b/app/views/home/step3.html.erb @@ -0,0 +1,31 @@ +

ようこそ、ぺったんRへ

+<%= h(current_author.name) -%>さん +
+ <%= form_for(:artist, :url => {:controller => '/home', :action => :save_step3}) do |f| %> + <% if @artist.errors.any? %> +
+

<%= pluralize(@artist.errors.count, "error") %> prohibited this artist from being saved:

+ +
    + <% @artist.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+

作家名とは別に絵師としてのペンネームを設定できます。

+ <%= f.label :name %>
+ <%= f.text_field :name %>
+ +

素材をアップロードするときのデフォルトライセンスを選択します。

+ <%= f.label :default_lisence_id %>
+ <%= f.select :default_lisence_id, Lisence.all.map {|l| [l.name, l.id] }, :html => {:selected => @artist.default_lisence_id} %> + <%= f.hidden_field :author_id, :value => @artist.author_id %> +
+
+ <%= f.submit '完了' %> +
+ <% end %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 22a644ca..be0c608b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -12,12 +12,21 @@
<% if author_signed_in? %> <%= link_to "my home", :controller => '/home' %> + <%= link_to "my comics", :controller => '/home', :action => :comic %> + <%= link_to "my pictures", :controller => '/home', :action => :picture %> + <%= link_to "config", :controller => '/home', :action => :configure %> <%= link_to "ログアウト", destroy_author_session_path, :method => :delete %> <% else %> <%= link_to "ログイン", new_author_session_path %> <% end %>
+

<%= notice %>

+

<%= alert %>

+
+<%= yield %> + +
<% if admin_signed_in? %> <%= link_to "system", :controller => '/system' %> <%= link_to "ログアウト", destroy_admin_session_path, :method => :delete %> @@ -25,15 +34,5 @@ <%= link_to "管理者", new_admin_session_path %> <% end %>
-
-

<%= notice %>

-

<%= alert %>

-
-<%= link_to "comics", comics_path %> -<%= link_to "panels", panels_path %> -<%= link_to "pictures", original_pictures_path %> -<%= link_to "lisences", lisences_path %> -<%= yield %> - diff --git a/app/views/original_pictures/_uploader.html.erb b/app/views/original_pictures/_uploader.html.erb index 21555b37..8514d843 100644 --- a/app/views/original_pictures/_uploader.html.erb +++ b/app/views/original_pictures/_uploader.html.erb @@ -2,6 +2,8 @@ <% if current_author.artist? -%> <%= form_tag( {:action => "create"} , { :multipart => true }) do %> <%= file_field_tag "original_picture[file]" %> + lisence + <%= collection_select :original_picture, :lisence_id, Lisence.all.map {|l| [l.name, l.id] }, :last, :first, :html => {:selected => current_author.artist.default_lisence_id} %> <%= submit_tag 'upload' -%> <% end -%> <% else -%> diff --git a/app/views/original_pictures/index.html.erb b/app/views/original_pictures/index.html.erb index 43c5fb27..096b4b36 100644 --- a/app/views/original_pictures/index.html.erb +++ b/app/views/original_pictures/index.html.erb @@ -8,5 +8,6 @@ <%= original_picture.width %>x<%= original_picture.height %> <%= original_picture.filesize %>bytes 画:<%= h original_picture.artist.name %> + lisence:<%= h Lisence.find(original_picture.lisence_id || 1).name %>
<% end %> diff --git a/config/routes.rb b/config/routes.rb index 2032dec1..2a20daaf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Pettanr::Application.routes.draw do devise_for :admins - devise_for :authors + devise_for :authors, :controllers => { :registrations => "author_registrations" } match 'original_pictures/:id(.:format)/refresh' => 'original_pictures#refresh' diff --git a/spec/controllers/author_registrations_controller_spec.rb b/spec/controllers/author_registrations_controller_spec.rb new file mode 100644 index 00000000..99509203 --- /dev/null +++ b/spec/controllers/author_registrations_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe AuthorRegistrationsController do + +end diff --git a/spec/helpers/author_registrations_helper_spec.rb b/spec/helpers/author_registrations_helper_spec.rb new file mode 100644 index 00000000..ceaabcbb --- /dev/null +++ b/spec/helpers/author_registrations_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the AuthorRegistrationsHelper. For example: +# +# describe AuthorRegistrationsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe AuthorRegistrationsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end