From 77d426b5cab2ac4ed2a801b7e807b40d389ef45e Mon Sep 17 00:00:00 2001 From: nomeu Date: Sun, 3 Feb 2013 12:32:50 +0900 Subject: [PATCH] add seigas controller --- app/controllers/seigas_controller.rb | 27 +++++++++++++++++++++++++++ app/controllers/welcome_controller.rb | 3 +++ app/helpers/seigas_helper.rb | 5 +++++ app/models/seiga.rb | 25 +++++++++++++++++++++++++ app/views/layouts/arcs.html.erb | 1 + app/views/seigas/index.html.erb | 28 ++++++++++++++++++++++++++++ app/views/seigas/show.html.erb | 16 ++++++++++++++++ app/views/welcome/index.html.erb | 28 ++++++++++++++++++++++++++++ config/locales/translation_ja.yml | 6 ++++++ config/routes.rb | 1 + 10 files changed, 140 insertions(+) create mode 100644 app/controllers/seigas_controller.rb create mode 100644 app/helpers/seigas_helper.rb create mode 100644 app/views/seigas/index.html.erb create mode 100644 app/views/seigas/show.html.erb diff --git a/app/controllers/seigas_controller.rb b/app/controllers/seigas_controller.rb new file mode 100644 index 0000000..4cb5888 --- /dev/null +++ b/app/controllers/seigas_controller.rb @@ -0,0 +1,27 @@ +class SeigasController < ApplicationController + layout 'arcs' + before_filter :login_required, :only => [ :new, :edit, :create, :update, :destroy ] + + # GET /seigas + # GET /seigas.xml + def index + @search = Seiga::Search.new(params[:search]) + @seigas = Seiga.search(@search).paginate([ '_id' ], :size => 30, :page => params[:page]) + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @seigas } + end + end + + # GET /seigas/1 + # GET /seigas/1.xml + def show + @seiga = Seiga.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @seiga } + end + end +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 4369683..8997a40 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -10,6 +10,7 @@ class WelcomeController < ApplicationController @vmds = Vmd.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15) @xes = X.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15) @thumbs = Thumb.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15) + @seigas = Seiga.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15) else @arc_search = Arc::Search.new(params[:search]) @arcs = Arc.search(@arc_search).paginate([ 'site', '_key' ], :size => 15, :page => params[:page]) @@ -21,6 +22,8 @@ class WelcomeController < ApplicationController @xes = X.search(@x_search).paginate([ '_id' ], :size => 15, :page => params[:page]) @thumb_search = Thumb::Search.new(params[:search]) @thumbs = Thumb.search(@thumb_search).paginate([ '_id' ], :size => 15, :page => params[:page]) + @seiga_search = Seiga::Search.new(params[:search]) + @seigas = Seiga.search(@seiga_search).paginate([ '_id' ], :size => 15, :page => params[:page]) end end diff --git a/app/helpers/seigas_helper.rb b/app/helpers/seigas_helper.rb new file mode 100644 index 0000000..1029d0b --- /dev/null +++ b/app/helpers/seigas_helper.rb @@ -0,0 +1,5 @@ +module SeigasHelper + def nico_seiga(image_id) + content_tag 'iframe', '', :src => "http://ext.seiga.nicovideo.jp/thumb/" + u(image_id), :width => 312, :height => 176, :scrolling => "no", :frameborder => 0 + end +end diff --git a/app/models/seiga.rb b/app/models/seiga.rb index e099399..5812c70 100644 --- a/app/models/seiga.rb +++ b/app/models/seiga.rb @@ -1,2 +1,27 @@ class Seiga < ActiveGroonga::Base + def self.search(search) + if search.text.blank? + all + else + select { |rec| + rec.match(search.text) { |mat| + (mat.title * 1) | (mat.description * 1) + } + } + end + end + + def image_id + key + end + + class Search + attr_accessor :text + + def initialize(attributes) + attributes.each do |name, value| + send("#{name}=", value) + end if attributes + end + end end diff --git a/app/views/layouts/arcs.html.erb b/app/views/layouts/arcs.html.erb index 6644fb1..2f2f59f 100644 --- a/app/views/layouts/arcs.html.erb +++ b/app/views/layouts/arcs.html.erb @@ -22,6 +22,7 @@
  • <%= link_menu_to _("x"), xes_path %>
  • <%= link_menu_to _("site"), sites_path %>
  • <%= link_menu_to _("thumb"), thumbs_path %>
  • +
  • <%= link_menu_to _("seiga"), seigas_path %>
  • <%= link_menu_to _("about"), welcome_about_path %>
  • diff --git a/app/views/seigas/index.html.erb b/app/views/seigas/index.html.erb new file mode 100644 index 0000000..538d707 --- /dev/null +++ b/app/views/seigas/index.html.erb @@ -0,0 +1,28 @@ +<%=form_for(@search, :as => :search, :url => seigas_path, :html => { :method => :get }) do |f| %> +

    + <%= _'Seiga|Title' %> or <%= _'Seiga|Description' %>
    + <%= f.text_field :text %> + <%= f.submit t("search") %> +

    +<% end %> + + + + + + + + + + +<% @seigas.each do |seiga| %> + + + + + +<% end %> + +
    <%= _'Seiga|Image' %><%= _'Seiga|Title' %><%= _'Seiga|Description' %>
    <%=link_to seiga.image_id, seiga_path(seiga) %><%= seiga.title %><%= truncate(seiga.description) %>
    + +<%= paginate(@seigas) %> diff --git a/app/views/seigas/show.html.erb b/app/views/seigas/show.html.erb new file mode 100644 index 0000000..6955401 --- /dev/null +++ b/app/views/seigas/show.html.erb @@ -0,0 +1,16 @@ +

    + <%= _'Seiga|Image' %>: + <%= @seiga.image_id %> +

    + +

    + <%= _'Seiga|Title' %>: + <%= @seiga.title %> +

    + +

    + <%= _'Seiga|Description' %>: + <%= @seiga.description %> +

    + +<%= nico_seiga(@seiga.image_id) %> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 57878fc..05a3911 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -164,3 +164,31 @@ <%= link_to t('and_more'), thumbs_path(:search => params[:search]) %> <%-end-%> + +<%-if @seigas.count != 0-%> +

    + <%= _'seiga' %>: +

    + + + + + + + + + + +<% for seiga in @seigas %> + + + + + +<% end %> + +
    <%= _'Seiga|Image' %><%= _'Seiga|Title' %><%= _'Seiga|Description' %>
    <%=link_to seiga.image_id, seiga_path(seiga) %><%= seiga.title %><%= truncate(seiga.description) %>
    + +<%-end-%> diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index b0f5f3f..f79f6f7 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -7,6 +7,7 @@ ja: site: "ロダ" pmd: "モデル" thumb: "動画" + seiga: "静画" user: "User" vmd: "モーション" x: "アクセサリ" @@ -52,6 +53,11 @@ ja: arcs: Arcs arc_thumbs: "書庫動画関連" + seiga: + image: "No." + title: "タイトル" + description: "説明文" + user: login: "ログイン" password: "パスワード" diff --git a/config/routes.rb b/config/routes.rb index 83bf6a9..6aa5572 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ Nimono::Application.routes.draw do resources :vmds, :only => :index resources :xes, :only => :index resources :thumbs, :only => [ :index, :show ] + resources :seigas, :only => [ :index, :show ] resource :session root :to => 'welcome#index' get 'welcome/about' -- 2.11.0