From: yasushiito Date: Sun, 16 Nov 2014 07:37:27 +0000 (+0900) Subject: fix alias action X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=3abebc1507b6c53bd4505eed11b5f83b8efb7001 fix alias action --- diff --git a/app/assets/javascripts/work/controllers.js.coffee.erb b/app/assets/javascripts/work/controllers.js.coffee.erb index d23b2cea..8f03709a 100644 --- a/app/assets/javascripts/work/controllers.js.coffee.erb +++ b/app/assets/javascripts/work/controllers.js.coffee.erb @@ -778,6 +778,8 @@ args: { param_id: 'none', max_page_size: -1, + order: 't', + direction: 1 }, }, by_panel: { @@ -819,6 +821,8 @@ args: { param_id: 'none', max_page_size: -1, + order: 't', + direction: 1 }, }, by_system_picture: { @@ -854,6 +858,8 @@ args: { param_id: 'none', max_page_size: -1, + order: 't', + direction: 1 }, }, by_resource_picture: { @@ -889,12 +895,16 @@ args: { param_id: 'none', max_page_size: -1, + order: 'name', + direction: 1 }, }, by_license_group: { type: 'list', args: { param_id: 'suffix', + order: 'name', + direction: 1 }, }, by_system_picture: { @@ -997,120 +1007,103 @@ scrolls: { type: 'list', args: { - item_name: 'scroll', - param_id: 'none', + alias: 'scrolls.index', }, }, scroll_panels: { type: 'list', args: { - item_name: 'scroll_panel', - param_id: 'none', + alias: 'scroll_panels.index', }, }, comics: { type: 'list', args: { - item_name: 'comic', - param_id: 'none', + alias: 'comics.index', }, }, comic_stories: { type: 'list', args: { - item_name: 'comic_story', - param_id: 'none', + alias: 'comic_stories.index', }, }, stories: { type: 'list', args: { - item_name: 'story', - param_id: 'none', + alias: 'stories.index', }, }, story_sheets: { type: 'list', args: { - item_name: 'story_sheet', - param_id: 'none', + alias: 'story_sheets.index', }, }, sheets: { type: 'list', args: { - item_name: 'sheet', - param_id: 'none', + alias: 'sheets.index', }, }, sheet_panels: { type: 'list', args: { - item_name: 'sheet_panel', - param_id: 'none', + alias: 'sheet_panels.index', }, }, panels: { type: 'list', args: { - item_name: 'panel', - param_id: 'none', + alias: 'panels.index', }, }, panel_pictures: { type: 'list', args: { - item_name: 'panel_picture', - param_id: 'none', + alias: 'panel_pictures.index', }, }, speech_balloons: { type: 'list', args: { - item_name: 'speech_balloon', - param_id: 'none', + alias: 'speech_balloons.index', }, }, speeches: { type: 'list', args: { - item_name: 'speech', - param_id: 'none', + alias: 'speeches.index', }, }, balloons: { type: 'list', args: { - item_name: 'balloon', - param_id: 'none', + alias: 'balloons.index', }, }, ground_pictures: { type: 'list', args: { - item_name: 'ground_picture', - param_id: 'none', + alias: 'ground_pictures.index', }, }, ground_colors: { type: 'list', args: { - item_name: 'ground_color', - param_id: 'none', + alias: 'ground_colors.index', }, }, original_pictures: { type: 'list', args: { - item_name: 'original_picture', - param_id: 'none', + alias: 'original_pictures.index', }, }, resource_pictures: { type: 'list', args: { - item_name: 'resource_picture', - param_id: 'none', + alias: 'resource_pictures.index', }, }, }, diff --git a/app/assets/javascripts/work/list_groups.js.coffee.erb b/app/assets/javascripts/work/list_groups.js.coffee.erb index 1712ae6f..97b3a4b5 100644 --- a/app/assets/javascripts/work/list_groups.js.coffee.erb +++ b/app/assets/javascripts/work/list_groups.js.coffee.erb @@ -22,7 +22,12 @@ }, }, play: { - type: 'play', + type: 'filter', + args: { + filter_item_name: 'scroll', + item_wheres: ['index'], + list_wheres: ['play'], + }, }, }, }, @@ -62,7 +67,7 @@ }, }, play: { - type: 'play', + type: 'public', }, }, }, @@ -108,7 +113,7 @@ type: 'filter', }, play: { - type: 'play', + type: 'public', }, }, }, @@ -154,7 +159,7 @@ type: 'filter', }, play: { - type: 'play', + type: 'public', }, }, }, @@ -333,7 +338,11 @@ original_pictures: { lists: { index: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, }, }, @@ -386,6 +395,9 @@ lists: { index: { type: 'public', + args: { + after_method_name: 'enable', + }, }, by_system_picture: { type: 'filter', @@ -439,55 +451,123 @@ home: { lists: { scrolls: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, scroll_panels: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, comics: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, comic_stories: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, stories: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, story_sheets: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, sheets: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, sheet_panels: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, panels: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, panel_pictures: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, speech_balloons: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, speeches: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, balloons: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, ground_pictures: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, ground_colors: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, original_pictures: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, resource_pictures: { - type: 'private', + type: 'public', + args: { + item_wheres: ['index'], + list_wheres: ['private'], + }, }, }, }, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dd356509..8a751a7a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -114,7 +114,7 @@ class ApplicationController < ActionController::Base set_model @my_list_model = Manifest.manifest.models[@my_action.item_name] @my_list_model_class = @my_list_model.classify - @list = Locmare::ListGroup.list @my_controller.name, @my_action.action_name, @operators, params + @list = Locmare::ListGroup.list @my_action.controller.name, @my_action.action_name, @operators, params end def filer_list @@ -146,8 +146,8 @@ class ApplicationController < ActionController::Base def set_play set_list - @binder_controller = Manifest.manifest.controllers[params[:controller].to_s] - @binder_action = @my_controller.actions[params[:action].to_s] + @binder_action = @my_action.original + @binder_controller = @binder_action.controller @binder_model = Manifest.manifest.models[@binder_action.item_name] @binder_model_class = @binder_model.classify @item = @binder_model_class.show(params[:id], @operators) @@ -155,11 +155,13 @@ class ApplicationController < ActionController::Base def play_list @options = params - @options[:my_play] = @item.own?(@operators) - list_result = @list.open(@operators) - @items = list_result.items - @count = list_result.count - @pager = list_result.paginate + if @item.own?(@operators) + @list.item_wheres = [] + @list.list_wheres = ['private', 'play'] + end + @items = @list.items #.map {|sp| sp.root } + @count = @list.total + @pager = @list.page_status.pager end def set_show @@ -415,10 +417,9 @@ class ApplicationController < ActionController::Base } end - def assist_items controller_name, list_name - list = Locmare::ListGroup.list controller_name, list_name, @operators, {:id => @item.id, :page => 1, :page_size => 5} - list_result = list.open(@operators) - list_result.items + def assist_items controller_name, action_name + list = Locmare::ListGroup.list controller_name, action_name, @operators, {:id => @item.id, :page => 1, :page_size => 5} + list.items end def set_image(file) diff --git a/app/controllers/panels_controller.rb b/app/controllers/panels_controller.rb index 8d5d44b3..f97960c2 100644 --- a/app/controllers/panels_controller.rb +++ b/app/controllers/panels_controller.rb @@ -13,9 +13,8 @@ class PanelsController < ApplicationController private def panel_list set_list - list_result = @list.open(@operators) - @items = list_result.items - @pager = list_result.paginate + @items = @list.items + @pager = @list.page_status.pager respond_to do |format| format.html format.json { render json: @items.map{|i| i.attributes}.to_json } @@ -136,11 +135,11 @@ class PanelsController < ApplicationController jsn = JSON.parse(params[:json]) end @prm = params[:panel] || jsn - self.model.fold_extend_settings @prm + @item.class.fold_extend_settings @prm @item.attributes = @prm - @item.refresh + # @item.refresh respond_to do |format| - if @item.store @item.packed_attributes, @operators + if @item.store @prm, @operators updated_html_format format updated_json_format format else diff --git a/app/controllers/scroll_panels_controller.rb b/app/controllers/scroll_panels_controller.rb index e0fbda4e..2f8b930d 100644 --- a/app/controllers/scroll_panels_controller.rb +++ b/app/controllers/scroll_panels_controller.rb @@ -4,7 +4,7 @@ class ScrollPanelsController < ApplicationController before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] else before_filter :authenticate_reader, :only => [ - :index, :show, :by_panel, :by_scroll, :by_author, :play :play + :index, :show, :by_panel, :by_scroll, :by_author ] before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy] before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy] @@ -26,10 +26,6 @@ class ScrollPanelsController < ApplicationController filer_list end - def play - filer_list - end - def show set_show respond_to do |format| diff --git a/app/models/artist.rb b/app/models/artist.rb index 83ecf69e..e37ceb8d 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -18,7 +18,7 @@ class Artist < Peta::Owner Artist.find( :first, :conditions => ['author_id = ?', author.id]) end - def self.list_where + def self.index_list_where 'artists.provider_id is null' end diff --git a/app/models/license.rb b/app/models/license.rb index 53e6344e..ea2a716a 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -21,14 +21,10 @@ class License < Peta::SystemResource self.license_group.caption + '/' + self.caption end - def self.list_where + def self.index_list_where '' end - def self.list_order - 'licenses.name' - end - def self.show_opt {:include => {:license_group => {}}} end diff --git a/app/models/resource_picture.rb b/app/models/resource_picture.rb index 57c2a8e2..b74b1154 100644 --- a/app/models/resource_picture.rb +++ b/app/models/resource_picture.rb @@ -95,14 +95,6 @@ class ResourcePicture < Peta::Content self.tmb_opt_img_tag end - def self.list_order - 'resource_pictures.updated_at desc' - end - - def self.list_where - '' - end - def self.list_opt {:license => {}, :artist => {}, :picture => {} } end diff --git a/app/views/panels/index.html.erb b/app/views/panels/index.html.erb index 8cd2db66..4c3e69cb 100644 --- a/app/views/panels/index.html.erb +++ b/app/views/panels/index.html.erb @@ -2,11 +2,11 @@

<%= t('panels.empty') %>

<% else %>

<%= link_to t('panels.filer'), main_app.panels_path(:mode => 'filer', :page => params[:page], :page_size => params[:page_size]) %>

- <%= paginate(@pager) %> + <%= render @pager.template_name, :pager => @pager %> <% @items.each do |panel| %> <%= render 'body', :panel => panel, :operators => @operators, :spot => nil %> <%= render 'panels/footer', :panel => panel, :operators => @operators %> <% end %> + <%= render @pager.template_name, :pager => @pager %> <%= render 'panels/licensed_pictures', :licensed_pictures => Panel.licensed_pictures(@items) %> - <%= paginate(@pager) %> <% end %> diff --git a/app/views/scrolls/play.html.erb b/app/views/scrolls/play.html.erb index 90c22fba..9b3163a6 100644 --- a/app/views/scrolls/play.html.erb +++ b/app/views/scrolls/play.html.erb @@ -9,7 +9,7 @@ <% if @items.empty? -%>

<%= t('scrolls.play.empty') %>

<% else %> - <%= paginate(@pager) %> + <%# paginate(@pager) %> <% @items.each do |scroll_panel| %> <% if scroll_panel.panel -%> <%= render 'panels/body', :panel => scroll_panel.panel, :operators => @operators, :spot => nil %> @@ -17,7 +17,7 @@ <%= render 'scroll_panels/footer', :scroll_panel => scroll_panel, :operators => @operators %> <% end %> <%= render 'panels/licensed_pictures', :licensed_pictures => ScrollPanel.licensed_pictures(@items) %> - <%= paginate(@pager) %> + <%# paginate(@pager) %> <% end %> <% if @item.own? @operators -%>

<%= t('editor') -%>

diff --git a/lib/local_manifest/list_group/list.rb b/lib/local_manifest/list_group/list.rb index 1309e082..3ea261e2 100644 --- a/lib/local_manifest/list_group/list.rb +++ b/lib/local_manifest/list_group/list.rb @@ -1,5 +1,5 @@ ManifestBase.require_modules "local_manifest/list_group/list/", - %w|base public private system_resource filter through_filter foreign_filter play| + %w|base public system_resource filter through_filter foreign_filter| module LocalManifest module ListGroupModule @@ -8,9 +8,8 @@ module LocalManifest def self.types { - 'public' => PublicList, 'private' => PrivateList, 'system_resource' => SystemResourceList, - 'filter' => FilterList, 'through_filter' => ThroughFilterList, 'foreign_filter' => ForeignFilterList, - 'play' => PlayList + 'public' => PublicList, 'system_resource' => SystemResourceList, + 'filter' => FilterList, 'through_filter' => ThroughFilterList, 'foreign_filter' => ForeignFilterList } end diff --git a/lib/local_manifest/list_group/list/base.rb b/lib/local_manifest/list_group/list/base.rb index d0a0c41d..91f75113 100644 --- a/lib/local_manifest/list_group/list/base.rb +++ b/lib/local_manifest/list_group/list/base.rb @@ -1,24 +1,30 @@ ManifestBase.require_modules "local_manifest/list_group/list/", - %w|where includes| + %w|includes| module LocalManifest module ListGroupModule module ListModule class Base < ManifestBase::TypeNameArgs - attr :where, :includes + attr :list_wheres, :includes def set_default super - @args['where'] ||= {} + @args['list_wheres'] ||= [] @args['includes'] ||= {} end def init super - @where = ManifestBase.load_type_args self, @args, 'where', WhereFactory + @item_wheres = @args['item_wheres'] + @list_wheres = @args['list_wheres'] @includes = ManifestBase.load_type_args self, @args, 'includes', IncludeFactory end + def item_wheres + return @item_wheres if @item_wheres + @item_wheres = @args['item_wheres'] || (self.model.content? ? ['index', 'public'] : ['index']) + end + def model_manifest ::Manifest.manifest.models[self.item_name] end diff --git a/lib/local_manifest/list_group/list/play.rb b/lib/local_manifest/list_group/list/play.rb deleted file mode 100644 index bdc688bc..00000000 --- a/lib/local_manifest/list_group/list/play.rb +++ /dev/null @@ -1,22 +0,0 @@ -module LocalManifest - module ListGroupModule - module ListModule - class PlayList < Base - attr :filter_item_name, :filter_key - - def set_default - super - @args['filter_item_name'] ||= @name.gsub(/^by_/, '') - @args['filter_key'] ||= @args['filter_item_name'] + '_id' - end - - def init - super - @filter_item_name = @args['filter_item_name'] - @filter_key = @args['filter_key'] - end - - end - end - end -end diff --git a/lib/local_manifest/list_group/list/private.rb b/lib/local_manifest/list_group/list/private.rb deleted file mode 100644 index 580ceeea..00000000 --- a/lib/local_manifest/list_group/list/private.rb +++ /dev/null @@ -1,9 +0,0 @@ -module LocalManifest - module ListGroupModule - module ListModule - class PrivateList < Base - end - - end - end -end diff --git a/lib/local_manifest/list_group/list/where.rb b/lib/local_manifest/list_group/list/where.rb deleted file mode 100644 index f27c8aee..00000000 --- a/lib/local_manifest/list_group/list/where.rb +++ /dev/null @@ -1,23 +0,0 @@ -ManifestBase.require_modules "local_manifest/list_group/list/where/", - %w|base method auto| - -module LocalManifest - module ListGroupModule - module ListModule - class WhereFactory < ManifestBase::Factory - include WhereModule - - def self.types - { - 'method' => WhereMethod, 'auto' => WhereAuto - } - end - - def self.default_type - 'auto' - end - - end - end - end -end diff --git a/lib/local_manifest/list_group/list/where/auto.rb b/lib/local_manifest/list_group/list/where/auto.rb deleted file mode 100644 index ae975582..00000000 --- a/lib/local_manifest/list_group/list/where/auto.rb +++ /dev/null @@ -1,31 +0,0 @@ -module LocalManifest - module ListGroupModule - module ListModule - module WhereModule - class WhereAuto < Base - def set_default - super - end - - def init - super - end - - def method_name - if self.model.content? - 'public_list_where' - else - 'list_where' - end - end - - def conditions - yield self.method_name - end - - end - - end - end - end -end diff --git a/lib/local_manifest/list_group/list/where/base.rb b/lib/local_manifest/list_group/list/where/base.rb deleted file mode 100644 index b84cae24..00000000 --- a/lib/local_manifest/list_group/list/where/base.rb +++ /dev/null @@ -1,32 +0,0 @@ -module LocalManifest - module ListGroupModule - module ListModule - module WhereModule - class Base < ManifestBase::TypeArgs - - def set_default - super - end - - def init - super - end - - def item_name - @parent.item_name - end - - def list_name - @parent.name - end - - def model - @parent.model - end - - end - - end - end - end -end diff --git a/lib/local_manifest/list_group/list/where/method.rb b/lib/local_manifest/list_group/list/where/method.rb deleted file mode 100644 index 72e79de7..00000000 --- a/lib/local_manifest/list_group/list/where/method.rb +++ /dev/null @@ -1,27 +0,0 @@ -module LocalManifest - module ListGroupModule - module ListModule - module WhereModule - class WhereMethod < Base - attr :method_name - - def set_default - super - @args['method_name'] ||= @parent.name + '_list_where' - end - - def init - super - @method_name = @args['method_name'] - end - - def conditions - yield @method_name - end - - end - - end - end - end -end diff --git a/lib/locmare/filer/body/file_body/file_item/caption/default/link/link.rb b/lib/locmare/filer/body/file_body/file_item/caption/default/link/link.rb index 0e75bb1f..b1ab8941 100644 --- a/lib/locmare/filer/body/file_body/file_item/caption/default/link/link.rb +++ b/lib/locmare/filer/body/file_body/file_item/caption/default/link/link.rb @@ -25,7 +25,8 @@ module Locmare def url controller_manifest = @item.class.my_controller action_manifest = controller_manifest.actions[@link_manifest.action_name] - action_manifest.url({'id' => @item.id.to_s}) + mani = action_manifest.original || action_manifest + mani.url({'id' => @item.id.to_s}) end end diff --git a/lib/locmare/list_group.rb b/lib/locmare/list_group.rb index dabc160e..7db471ad 100644 --- a/lib/locmare/list_group.rb +++ b/lib/locmare/list_group.rb @@ -1,6 +1,5 @@ require_dependency "locmare/list_group/list/base" require_dependency "locmare/list_group/list/public" -require_dependency "locmare/list_group/list/private" require_dependency "locmare/list_group/list/system_resource" require_dependency "locmare/list_group/list/filter" require_dependency "locmare/list_group/list/through_filter" @@ -14,7 +13,7 @@ module Locmare def self.types { - 'public' => PublicList, 'private' => PrivateList, 'system_resource' => SystemResourceList, + 'public' => PublicList, 'system_resource' => SystemResourceList, 'filter' => FilterList, 'through_filter' => ThroughFilterList, 'foreign_filter' => ForeignFilterList, 'play' => PlayList } diff --git a/lib/locmare/list_group/lib/page_status.rb b/lib/locmare/list_group/lib/page_status.rb index 0c58d0a9..06e53955 100644 --- a/lib/locmare/list_group/lib/page_status.rb +++ b/lib/locmare/list_group/lib/page_status.rb @@ -56,8 +56,16 @@ module Locmare @list.max_page_size end + def mod + @total % self.limit + end + + def adjust + self.mod == 0 ? 0 : 1 + end + def total_page - (@total / self.limit) + 1 + (@total / self.limit) + self.adjust end def pageable? diff --git a/lib/locmare/list_group/lib/pager.rb b/lib/locmare/list_group/lib/pager.rb index cf5d4d08..7b5897aa 100644 --- a/lib/locmare/list_group/lib/pager.rb +++ b/lib/locmare/list_group/lib/pager.rb @@ -18,6 +18,7 @@ module Locmare @template_name = @template_dir + 'default' @controller = Manifest.manifest.controllers[@options['controller'].to_s] @action = @controller.actions[@options['action'].to_s] + @action = @action.original if @action.original @current_page = @page_status.page @per_page = @page_status.limit diff --git a/lib/locmare/list_group/list/base.rb b/lib/locmare/list_group/list/base.rb index e9fbbc93..ab10b2f1 100644 --- a/lib/locmare/list_group/list/base.rb +++ b/lib/locmare/list_group/list/base.rb @@ -1,9 +1,9 @@ module Locmare module ListGroupModule class Base - attr :list_group_name, :list_name, :options, :item_name, - :controller_manifest, :action_manifest, :list_manifest, :model, - :page_status + attr_accessor :list_group_name, :list_name, :operators, :options, :item_name, + :controller_manifest, :action_manifest, :list_manifest, :model, :table_name, + :page_status, :item_wheres, :list_wheres def initialize list_group_name, list_name, operators, options = {} @list_group_name = list_group_name @@ -13,7 +13,8 @@ module Locmare @list_group_manifest = LocalManifest.manifest.list_groups[@list_group_name] @list_manifest = @list_group_manifest.lists[@list_name] - @where = @list_manifest.where + @item_wheres = @list_manifest.item_wheres + @list_wheres = @list_manifest.list_wheres @includes = @list_manifest.includes @controller_name = @list_group_name @@ -28,7 +29,6 @@ module Locmare def init @page_status = LibModule::PageStatus.load self, self.total, @options - self.boost items end def model_name @@ -76,38 +76,35 @@ module Locmare self.order + ' ' + self.direction end - def base_where_condition - method_name = @where.conditions do |name| - name - end - @model.__send__ method_name - end - def where_condition - base_where_condition + @item_wheres.map {|key| @model.__send__(key + '_list_where')}.compact.join(' and ') end def include_hash @includes.includes end + def arel + r = @model.where(self.where_condition) + @list_wheres.each do |key| + r = r.where(@model.__send__(key + '_list_where', self)) + end + r.includes( + self.include_hash + ) + end + def items return [] unless @page_status - @items ||= @model.where( - self.where_condition - ).includes( - self.include_hash - ).order( + @items ||= self.arel.order( self.order_by ).offset(@page_status.offset).limit(@page_status.limit) + self.boost + @items end def total - @model.where( - self.where_condition - ).includes( - self.include_hash - ).count + self.arel.count # return string : =>"25" end @@ -117,9 +114,9 @@ module Locmare end end - def boost items + def boost manifests = self.boost_manifests - items.each do |item| + @items.each do |item| manifests.each do |boost_manifest| item.boost_manifest # ? end diff --git a/lib/locmare/list_group/list/filter.rb b/lib/locmare/list_group/list/filter.rb index 97200dd8..66084d38 100644 --- a/lib/locmare/list_group/list/filter.rb +++ b/lib/locmare/list_group/list/filter.rb @@ -12,7 +12,7 @@ module Locmare end def where_condition - w = self.base_where_condition + w = super w += ' and ' unless w.blank? [w + @table_name + '.' + @filter_key + ' = ?', self.filter_id] end diff --git a/lib/locmare/list_group/list/foreign_filter.rb b/lib/locmare/list_group/list/foreign_filter.rb index c86a453c..7eee78c3 100644 --- a/lib/locmare/list_group/list/foreign_filter.rb +++ b/lib/locmare/list_group/list/foreign_filter.rb @@ -8,7 +8,7 @@ module Locmare end def where_condition - w = self.base_where_condition + w = super w += ' and ' unless w.blank? [w + @filter_table_name + '.id' + ' = ?', self.filter_id] end diff --git a/lib/locmare/list_group/list/private.rb b/lib/locmare/list_group/list/private.rb deleted file mode 100644 index 3b05203b..00000000 --- a/lib/locmare/list_group/list/private.rb +++ /dev/null @@ -1,45 +0,0 @@ -module Locmare - module ListGroupModule - class PrivateList < Base - - def init - super - end - - def where_condition - owner_model = if @model.element? - @model.root_model - else - @model - end - case owner_model.owner_type - when :author - operator = @operators.author - when :artist - operator = @operators.artist - end - [owner_model.table_name + '.' + owner_model.owner_type.to_s + '_id = ?', operator.id] - end - - def items - @model.where( - self.where_condition - ).includes( - self.include_hash - ).order( - self.order_by - ).offset(@offset).limit(@limit) - end - - def count - @model.where( - self.where_condition - ).includes( - self.include_hash - ).count - end - - end - - end -end diff --git a/lib/locmare/list_group/list/through_filter.rb b/lib/locmare/list_group/list/through_filter.rb index 16d0fc2f..930c236b 100644 --- a/lib/locmare/list_group/list/through_filter.rb +++ b/lib/locmare/list_group/list/through_filter.rb @@ -13,7 +13,7 @@ module Locmare end def where_condition - w = self.base_where_condition + w = super w += ' and ' unless w.blank? [w + @filter_table_name + '.id' + ' = ?', self.filter_id] end diff --git a/lib/manifest/controller/action/base.rb b/lib/manifest/controller/action/base.rb index ebed55a5..2dc905b0 100644 --- a/lib/manifest/controller/action/base.rb +++ b/lib/manifest/controller/action/base.rb @@ -2,7 +2,7 @@ module Manifest module ControllerModule module ActionModule class Base < ManifestBase::TypeNameArgs - attr :param_id, :item_name, :action_name + attr :alias, :param_id, :item_name, :action_name, :original def set_default super @@ -13,8 +13,29 @@ module Manifest def init super @action_name = @name + @alias = @args['alias'] @item_name = @args['item_name'] @param_id = @args['param_id'] + # source manifest of alias manifest + @original = @args['original'] + end + + def a_arg_names + [] + end + + def b_arg_names + ['item_name', 'param_id'] + end + + def controller + @parent + end + + def alias_action + s = @alias.split('.') + c = ::Manifest.manifest.controllers[s[0]] + c.actions[s[1]] end def path_name diff --git a/lib/manifest/controller/action/list.rb b/lib/manifest/controller/action/list.rb index 3a544837..c6779b6c 100644 --- a/lib/manifest/controller/action/list.rb +++ b/lib/manifest/controller/action/list.rb @@ -2,7 +2,7 @@ module Manifest module ControllerModule module ActionModule class ActionList < Base - attr :alias, :order, :direction, :default_page_size, :max_page_size + attr :order, :direction, :default_page_size, :max_page_size def set_default super @@ -13,17 +13,14 @@ module Manifest def init super - @alias = @args['alias'] @order = @args['order'] || 'updated_at' @direction = @args['direction'].to_i @default_page_size = @args['default_page_size'] @max_page_size = @args['max_page_size'] end - def alias_action - s = @alias.split('.') - c = ::Manifest.manifest.controllers[s[0]] - c.actions[s[1]] + def a_arg_names + super + ['order', 'direction', 'default_page_size', 'max_page_size'] end end diff --git a/lib/manifest/manifest.rb b/lib/manifest/manifest.rb index 1fc9df72..bc561163 100644 --- a/lib/manifest/manifest.rb +++ b/lib/manifest/manifest.rb @@ -26,6 +26,7 @@ module Manifest end @items = ManifestBase.load_type_name_args(self, @global_json, 'items', ItemFactory) @controllers = Controller.load(self, @global_json, 'controllers') + self.replace_action_alias @models = Model.load(self, @global_json, 'models') end @@ -33,6 +34,36 @@ module Manifest @system_resources.init end + def replace_action_alias + replaces = {} + @controllers.each do |controller_name, controller_manifest| + controller_manifest.actions.each do |action_name, action_manifest| + next unless action_manifest.alias + alias_action = action_manifest.alias_action + next unless alias_action.type == action_manifest.type + args = {} + action_manifest.a_arg_names.each do |name| + args[name] = action_manifest.__send__(name) || alias_action.__send__(name) + end + action_manifest.b_arg_names.each do |name| + args[name] = alias_action.__send__(name) || action_manifest.__send__(name) + end + args['original'] = action_manifest + json = {'type' => alias_action.type, 'args' => args} + new_action_manifest = ControllerModule::ActionFactory.factory( + controller_manifest, action_manifest.name, json, action_manifest.module_name + ) + replaces[controller_name] ||= {} + replaces[controller_name][action_name] = new_action_manifest + end + end + replaces.each do |controller_name, controller| + controller.each do |action_name, action_manifest| + ::Manifest.manifest.controllers[controller_name].actions[action_name] = action_manifest + end + end + end + def load_models_manifest @models.each do |model_name, model| # skip extend model. diff --git a/lib/manifest_base/type_name_args.rb b/lib/manifest_base/type_name_args.rb index 688bbe65..3eb0394c 100644 --- a/lib/manifest_base/type_name_args.rb +++ b/lib/manifest_base/type_name_args.rb @@ -1,6 +1,6 @@ module ManifestBase class TypeNameArgs - attr :parent, :name, :json, :type, :module_name + attr :parent, :name, :json, :type, :args, :module_name def initialize parent, name, json, module_name @parent = parent diff --git a/lib/peta/content.rb b/lib/peta/content.rb index 5ff3f9b0..083ac392 100644 --- a/lib/peta/content.rb +++ b/lib/peta/content.rb @@ -35,7 +35,22 @@ module Peta end def self.public_list_where - '' + nil + end + + def self.private_list_where list + owner_model = if self.element? + self.root_model + else + self + end + case owner_model.owner_type + when :author + operator = list.operators.author + when :artist + operator = list.operators.artist + end + [owner_model.table_name + '.' + owner_model.owner_type.to_s + '_id = ?', operator.id] end def self.edit content_id, operators diff --git a/lib/peta/item.rb b/lib/peta/item.rb index 0dadd32c..7bb9cb69 100644 --- a/lib/peta/item.rb +++ b/lib/peta/item.rb @@ -114,8 +114,8 @@ module Peta self.my_peta.extend_column? column_name end - def self.list_where - '' + def self.index_list_where + nil end def self.list_opt diff --git a/lib/peta/leaf.rb b/lib/peta/leaf.rb index 6d987c6e..d6e86b87 100644 --- a/lib/peta/leaf.rb +++ b/lib/peta/leaf.rb @@ -65,6 +65,10 @@ module Peta self.table_name + '.t' end + def self.play_list_where list + [list.table_name + '.' + list.filter_key + ' = ?', list.filter_id] + end + def self.new_t binder_id r = self.max_t(binder_id) r.blank? ? 0 : r.to_i + 1 diff --git a/public/local_manifest.json b/public/local_manifest.json index e8da658f..cd2c50dd 100644 --- a/public/local_manifest.json +++ b/public/local_manifest.json @@ -22,7 +22,16 @@ } }, "play": { - "type": "play" + "type": "filter", + "args": { + "filter_item_name": "scroll", + "item_wheres": [ + "index" + ], + "list_wheres": [ + "play" + ] + } } } }, @@ -62,7 +71,7 @@ } }, "play": { - "type": "play" + "type": "public" } } }, @@ -108,7 +117,7 @@ "type": "filter" }, "play": { - "type": "play" + "type": "public" } } }, @@ -154,7 +163,7 @@ "type": "filter" }, "play": { - "type": "play" + "type": "public" } } }, @@ -333,7 +342,15 @@ "original_pictures": { "lists": { "index": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } } } }, @@ -385,7 +402,10 @@ "writing_formats": { "lists": { "index": { - "type": "public" + "type": "public", + "args": { + "after_method_name": "enable" + } }, "by_system_picture": { "type": "filter" @@ -439,55 +459,191 @@ "home": { "lists": { "scrolls": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "scroll_panels": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "comics": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "comic_stories": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "stories": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "story_sheets": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "sheets": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "sheet_panels": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "panels": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "panel_pictures": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "speech_balloons": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "speeches": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "balloons": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "ground_pictures": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "ground_colors": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "original_pictures": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } }, "resource_pictures": { - "type": "private" + "type": "public", + "args": { + "item_wheres": [ + "index" + ], + "list_wheres": [ + "private" + ] + } } } } diff --git a/public/manifest.json b/public/manifest.json index da1b7f76..85f150a0 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1014,7 +1014,9 @@ "type": "list", "args": { "param_id": "none", - "max_page_size": -1 + "max_page_size": -1, + "order": "t", + "direction": 1 } }, "by_panel": { @@ -1055,7 +1057,9 @@ "type": "list", "args": { "param_id": "none", - "max_page_size": -1 + "max_page_size": -1, + "order": "t", + "direction": 1 } }, "by_system_picture": { @@ -1090,7 +1094,9 @@ "type": "list", "args": { "param_id": "none", - "max_page_size": -1 + "max_page_size": -1, + "order": "t", + "direction": 1 } }, "by_resource_picture": { @@ -1125,13 +1131,17 @@ "type": "list", "args": { "param_id": "none", - "max_page_size": -1 + "max_page_size": -1, + "order": "name", + "direction": 1 } }, "by_license_group": { "type": "list", "args": { - "param_id": "suffix" + "param_id": "suffix", + "order": "name", + "direction": 1 } }, "by_system_picture": { @@ -1234,120 +1244,103 @@ "scrolls": { "type": "list", "args": { - "item_name": "scroll", - "param_id": "none" + "alias": "scrolls.index" } }, "scroll_panels": { "type": "list", "args": { - "item_name": "scroll_panel", - "param_id": "none" + "alias": "scroll_panels.index" } }, "comics": { "type": "list", "args": { - "item_name": "comic", - "param_id": "none" + "alias": "comics.index" } }, "comic_stories": { "type": "list", "args": { - "item_name": "comic_story", - "param_id": "none" + "alias": "comic_stories.index" } }, "stories": { "type": "list", "args": { - "item_name": "story", - "param_id": "none" + "alias": "stories.index" } }, "story_sheets": { "type": "list", "args": { - "item_name": "story_sheet", - "param_id": "none" + "alias": "story_sheets.index" } }, "sheets": { "type": "list", "args": { - "item_name": "sheet", - "param_id": "none" + "alias": "sheets.index" } }, "sheet_panels": { "type": "list", "args": { - "item_name": "sheet_panel", - "param_id": "none" + "alias": "sheet_panels.index" } }, "panels": { "type": "list", "args": { - "item_name": "panel", - "param_id": "none" + "alias": "panels.index" } }, "panel_pictures": { "type": "list", "args": { - "item_name": "panel_picture", - "param_id": "none" + "alias": "panel_pictures.index" } }, "speech_balloons": { "type": "list", "args": { - "item_name": "speech_balloon", - "param_id": "none" + "alias": "speech_balloons.index" } }, "speeches": { "type": "list", "args": { - "item_name": "speech", - "param_id": "none" + "alias": "speeches.index" } }, "balloons": { "type": "list", "args": { - "item_name": "balloon", - "param_id": "none" + "alias": "balloons.index" } }, "ground_pictures": { "type": "list", "args": { - "item_name": "ground_picture", - "param_id": "none" + "alias": "ground_pictures.index" } }, "ground_colors": { "type": "list", "args": { - "item_name": "ground_color", - "param_id": "none" + "alias": "ground_colors.index" } }, "original_pictures": { "type": "list", "args": { - "item_name": "original_picture", - "param_id": "none" + "alias": "original_pictures.index" } }, "resource_pictures": { "type": "list", "args": { - "item_name": "resource_picture", - "param_id": "none" + "alias": "resource_pictures.index" } } }