From fd5eb13471c55b0a27e751c3b28f402d23e5b436 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Mon, 9 Dec 2013 14:07:42 +0900 Subject: [PATCH] temp --- app/controllers/authors_controller.rb | 28 ++++++++++++++-------------- app/models/artist.rb | 2 +- app/models/scroll_panel.rb | 4 ++++ app/views/artists/_form.html.erb | 4 ++-- app/views/artists/edit.html.erb | 2 +- app/views/artists/new.html.erb | 2 +- app/views/authors/_form.html.erb | 4 ++-- app/views/authors/edit.html.erb | 2 +- app/views/authors/new.html.erb | 2 +- app/views/home/configure.html.erb | 24 ++++++++++++------------ app/views/layouts/test.prof.erb | 10 +++++----- app/views/system/prof.prof.erb | 2 +- lib/manifest/list.rb | 18 ++++++++++++++---- lib/manifest/profiler.rb | 6 +++--- lib/operator.rb | 14 ++++++++++++++ 15 files changed, 76 insertions(+), 48 deletions(-) diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index 6c87f0fd..0de98646 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -284,8 +284,8 @@ class AuthorsController < ApplicationController end def new - @au = Author.new - @au.supply_default + @author = Author.new + @author.supply_default respond_to do |format| format.html # new.html.erb @@ -295,19 +295,19 @@ class AuthorsController < ApplicationController end def edit - @au = Author.edit(params[:id], @author) + @author = Author.edit(params[:id], @operators) end def create - @au = Author.new() - @au.supply_default - @au.attributes = params[:author] - @au.overwrite @user.id + @author = Author.new() + @author.supply_default + @author.attributes = params[:author] + @author.overwrite @operators respond_to do |format| - if @au.save + if @author.save flash[:notice] = I18n.t('flash.notice.created', :model => Author.model_name.human) format.html { redirect_to root_path } - format.json { render json: @au.to_json(Author.show_json_opt), status: :created, location: @artist } + format.json { render json: @author.to_json(Author.show_json_opt), status: :created } else flash[:notice] = I18n.t('flash.notice.not_created', :model => Author.model_name.human) format.html { render action: "new" } @@ -317,19 +317,19 @@ class AuthorsController < ApplicationController end def update - @au = Author.edit(params[:id], @author) - @au.attributes = params[:author] - @au.overwrite @user.id + @author = Author.edit(params[:id], @operators) + @author.attributes = params[:author] + @author.overwrite @operators respond_to do |format| - if @au.save + if @author.save flash[:notice] = I18n.t('flash.notice.updated', :model => Author.model_name.human) format.html { redirect_to '/home/configure' } format.json { head :ok } else flash[:notice] = I18n.t('flash.notice.not_updated', :model => Author.model_name.human) format.html { render action: "edit" } - format.json { render json: @au.errors, status: :unprocessable_entity } + format.json { render json: @author.errors, status: :unprocessable_entity } end end end diff --git a/app/models/artist.rb b/app/models/artist.rb index 955c8ffb..e1ef12d4 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -6,7 +6,7 @@ class Artist < Pettanr::Owner validates :name, :presence => true, :length => {:maximum => 30} validates :user_id, :numericality => true, :existence => {:both => false} - validates :provider, :numericality => true + validates :provider_id, :numericality => {:allow_nil => true} @@valid_encode_columns += ['name'] @@visible_count_options = {:conditions => ['artists.author_id is not null']} diff --git a/app/models/scroll_panel.rb b/app/models/scroll_panel.rb index f1314b42..520aacc0 100644 --- a/app/models/scroll_panel.rb +++ b/app/models/scroll_panel.rb @@ -84,6 +84,10 @@ class ScrollPanel < ActiveRecord::Base ['scroll_panels.scroll_id = ?', cid] end + def self.list_order + 'scroll_panels.updated_at desc' + end + def self.list_where 'scrolls.visible > 0' end diff --git a/app/views/artists/_form.html.erb b/app/views/artists/_form.html.erb index 310be37a..d71f45dd 100644 --- a/app/views/artists/_form.html.erb +++ b/app/views/artists/_form.html.erb @@ -1,5 +1,5 @@ -<%= form_for(ar) do |f| %> - <%= render 'system/error_explanation', :obj => ar %> +<%= form_for(artist) do |f| %> + <%= render 'system/error_explanation', :obj => artist %>
<%= f.label :name %>
diff --git a/app/views/artists/edit.html.erb b/app/views/artists/edit.html.erb index 78e99436..1f7a8f3f 100644 --- a/app/views/artists/edit.html.erb +++ b/app/views/artists/edit.html.erb @@ -1,4 +1,4 @@

<%= t '.title' -%>

<%= notice %>

-<%= render 'form', :ar => @ar %> +<%= render 'form', :artist => @artist %> diff --git a/app/views/artists/new.html.erb b/app/views/artists/new.html.erb index f6db1ed3..4abac294 100644 --- a/app/views/artists/new.html.erb +++ b/app/views/artists/new.html.erb @@ -2,6 +2,6 @@

素材の投稿には絵師登録が必要です。

下記フォームで登録してください。

-<%= render 'form', :ar => @ar %> +<%= render 'form', :artist => @artist %> <%= link_to t('link.back'), artists_path %> diff --git a/app/views/authors/_form.html.erb b/app/views/authors/_form.html.erb index 46296965..3cb583a9 100644 --- a/app/views/authors/_form.html.erb +++ b/app/views/authors/_form.html.erb @@ -1,5 +1,5 @@ -<%= form_for(au) do |f| %> - <%= render 'system/error_explanation', :obj => au %> +<%= form_for(author) do |f| %> + <%= render 'system/error_explanation', :obj => author %>
<%= f.label :name %>
diff --git a/app/views/authors/edit.html.erb b/app/views/authors/edit.html.erb index ea180933..c714a958 100644 --- a/app/views/authors/edit.html.erb +++ b/app/views/authors/edit.html.erb @@ -1,5 +1,5 @@

<%= t '.title' -%>

<%= notice %>

-<%= render 'form', :au => @au %> +<%= render 'form', :author => @author %> diff --git a/app/views/authors/new.html.erb b/app/views/authors/new.html.erb index 149cd95c..6fc715a0 100644 --- a/app/views/authors/new.html.erb +++ b/app/views/authors/new.html.erb @@ -1,5 +1,5 @@

<%= t '.title' -%>

<%= t '.announce' -%>

-<%= render 'form', :au => @au %> +<%= render 'form', :author => @author %> diff --git a/app/views/home/configure.html.erb b/app/views/home/configure.html.erb index 70dea5c1..96371d88 100644 --- a/app/views/home/configure.html.erb +++ b/app/views/home/configure.html.erb @@ -1,15 +1,15 @@

<%= t '.title' -%>

<%= notice %>

-<%= t('home.configure.caption', :email => @user.email) %> +<%= t('home.configure.caption', :email => @operators.user.email) %> diff --git a/app/views/layouts/test.prof.erb b/app/views/layouts/test.prof.erb index e819a265..18351311 100644 --- a/app/views/layouts/test.prof.erb +++ b/app/views/layouts/test.prof.erb @@ -20,7 +20,7 @@

<%= t 'home.configure.password_caption' -%>

- <%= render '/users/registrations/form', :resource => @user %> + <%= render '/users/registrations/form', :resource => @operators.user %>

<%= t 'home.configure.token_caption' -%>

- <% if @user.authentication_token %> -
<%= t 'home.configure.your_token', :token => @user.authentication_token -%>
+ <% if @operators.user.authentication_token %> +
<%= t 'home.configure.your_token', :token => @operators.user.authentication_token -%>
<%= link_to t('home.configure.delete_token'), :action => :delete_token %> <% else %>
<%= t 'home.configure.about_token' -%>
@@ -20,22 +20,22 @@

<%= t_m 'Author' -%>

- <% if @author %> - <%= render '/authors/form', :au => @author %> + <% if @operators.author %> + <%= render '/authors/form', :author => @operators.author %> <% else %>
<%= t 'home.configure.no_author' -%>
<%= t 'home.configure.about_author' -%>
- <% @au = Author.new ; @au.supply_default %> - <%= render '/authors/form', :au => @au %> + <% @author = Author.new ; @author.supply_default %> + <%= render '/authors/form', :author => @author %> <% end %>

<%= t_m 'Artist' -%>

- <% if @artist %> - <%= render '/artists/form', :ar => @artist %> + <% if @operators.artist %> + <%= render '/artists/form', :artist => @operators.artist %> <% else %>
<%= t 'home.configure.no_artist' -%>
<%= t 'home.configure.about_artist' -%>
- <% @ar = Artist.new ; @ar.supply_default %> - <%= render '/artists/form', :ar => @ar %> + <% @artist = Artist.new ; @artist.supply_default %> + <%= render '/artists/form', :artist => @artist %> <% end %>
diff --git a/app/views/system/prof.prof.erb b/app/views/system/prof.prof.erb index 1ddb2ccb..6faf50e8 100644 --- a/app/views/system/prof.prof.erb +++ b/app/views/system/prof.prof.erb @@ -18,7 +18,7 @@
<%= 'has_many' %>
-<% profiler.each_belongs_to do |has_many_filer| %> +<% profiler.each_has_many do |has_many_filer| %> <%= render 'system/filer.html', :filer => has_many_filer %> <% end %>
diff --git a/lib/manifest/list.rb b/lib/manifest/list.rb index 3ac07653..4882d2eb 100644 --- a/lib/manifest/list.rb +++ b/lib/manifest/list.rb @@ -70,7 +70,7 @@ module Pettanr end def paginate - @model.list_paginate(@page, @page_size) + Kaminari.paginate_array(Array.new(@model.where(self.where()).includes(@model.list_opt).count, nil)).page(page).per(page_size) end end @@ -104,7 +104,7 @@ module Pettanr end def paginate - @model.list_paginate(@page, @page_size) + Kaminari.paginate_array(Array.new(@model.where(self.where(parent_item)).includes(@model.list_opt).count, nil)).page(page).per(page_size) end end @@ -122,12 +122,22 @@ module Pettanr @filter_key = @conf['filter_key'] end + def where filter_item + w = @model.list_where + w += ' and ' unless w.blank? + p w + p @model.table_name + p @filter_key + p filter_item + [w + @model.table_name + '.' + @filter_key + ' = ?', filter_item.id] + end + def items filter_item - @model.filtered_list filter_item, @filter_key, @operators, @page, @page_size + @model.where(self.where(filter_item)).includes(@model.list_opt).order(@model.list_order).offset(@offset).limit(@page_size) end def paginate filter_item - @model.list_paginate(filter_item, @filter_key, @operators, @page, @page_size) + Kaminari.paginate_array(Array.new(@model.where(self.where(filter_item)).includes(@model.list_opt).count, nil)).page(page).per(page_size) end end diff --git a/lib/manifest/profiler.rb b/lib/manifest/profiler.rb index 1512dbb9..30df16aa 100644 --- a/lib/manifest/profiler.rb +++ b/lib/manifest/profiler.rb @@ -120,10 +120,10 @@ module Pettanr def each_has_many @has_many_conf.each do |profiler_list_name| - model_name = @lists['model_name'] - list_name = @lists['list_name'] + model_name = @lists[profiler_list_name]['model_name'] + list_name = @lists[profiler_list_name]['list_name'] list = @manifest.list_managers[model_name].open(list_name, 1, 3, @operators) - items = list.items + items = list.items @item has_many_filer = @manifest.filer_managers[model_name].open model_name, items, @operators, nil yield has_many_filer end diff --git a/lib/operator.rb b/lib/operator.rb index 316bcbb6..a0104fb4 100644 --- a/lib/operator.rb +++ b/lib/operator.rb @@ -7,6 +7,15 @@ class Operator end #InstanceMethods + def find_user + @operators.each do |operator| + return operator if operator.is_a?(User) + return operator.user if operator.is_a?(Author) + return operator.user if operator.is_a?(Artist) + end + nil + end + def find_author @operators.each do |operator| return operator if operator.is_a?(Author) @@ -32,6 +41,11 @@ class Operator nil end + def user + return @user if @user + @user = find_user + end + def author return @author if @author @author = find_author -- 2.11.0
-

<%= link_to MagicNumber['profile']['users']['caption'], main_app.root_path %>

+

<%= link_to manifest.magic_numbers['profile']['users']['caption'], main_app.root_path %>

<% if user_signed_in? %> @@ -29,13 +29,13 @@
- <% if @author %> - <%= link_to h(truncate(@author.name, :length => 12)), main_app.author_path(@author) %> + <% if @operators.author %> + <%= link_to h(truncate(@operators.author.name, :length => 12)), main_app.author_path(@operators.author) %> <% end %>
- <% if @artist %> - <%= link_to h(truncate(@artist.name, :length => 12)), main_app.artist_path(@artist) %> + <% if @operators.artist %> + <%= link_to h(truncate(@operators.artist.name, :length => 12)), main_app.artist_path(@operators.artist) %> <% end %>