list_name: 'by_panel',\r
},\r
},\r
+ play: {\r
+ type: 'list',\r
+ list: {\r
+ list_name: 'play',\r
+ },\r
+ },\r
show: {\r
type: 'show',\r
name: 'show',\r
list_name: 'by_author',\r
},\r
},\r
+ play: {\r
+ type: 'list',\r
+ list: {\r
+ list_name: 'play',\r
+ },\r
+ },\r
},\r
},\r
story_sheet: {\r
list_name: 'by_author',\r
},\r
},\r
+ play: {\r
+ type: 'list',\r
+ list: {\r
+ list_name: 'play',\r
+ },\r
+ },\r
},\r
},\r
sheet_panel: {\r
through: 'scroll_panels',\r
filter_key: 'panel_id',\r
},\r
+ play: {\r
+ type: 'play',\r
+ model: 'scroll_panel',\r
+ filter_key: 'scroll_id',\r
+ },\r
},\r
},\r
scroll_panel: {\r
from: 'author',\r
filter_key: 'author_id',\r
},\r
+ play: {\r
+ type: 'play',\r
+ model: 'story_sheet',\r
+ filter_key: 'story_id',\r
+ },\r
},\r
},\r
story_sheet: {\r
from: 'author',\r
filter_key: 'author_id',\r
},\r
+ play: {\r
+ type: 'play',\r
+ model: 'sheet_panel',\r
+ filter_key: 'sheet_id',\r
+ },\r
},\r
},\r
sheet_panel: {\r
:filer => @filer
}
}
- format.json { render json: @items.to_json(Scroll.list_json_opt) }
+ format.json { render json: @items.to_json(self.class.model.list_json_opt) }
end
end
end
def play
- @scroll = Scroll.show(params[:id], @operators)
- cnt = ScrollPanel.count(:conditions => ['scroll_id = ?', @scroll.id]).to_i
- @offset = ScrollPanel.offset cnt, params[:offset]
- @panel_count = ScrollPanel.panel_count cnt, params[:count]
- @scroll_panels = ScrollPanel.play_list(@scroll, @author, @offset, @panel_count)
+ @item = self.class.model.show(params[:id], @operators)
+ action_name = params[:action]
+ @action = self.class.controller.open(action_name, params, @operators)
+ @items = @action.list.items @item
respond_to do |format|
format.html {
- @prev_offset = if @offset > 0
- if @offset - @panel_count < 0
- 0
- else
- @offset - @panel_count
- end
- else
- nil
- end
- @next_offset = if @offset + @panel_count > cnt
- nil
- else
- @offset + @panel_count
- end
- if @author
- @new_panels = Panel.mylist(@author, 1, 5)
+ @count = @action.list.count @item
+ @prev_offset = @action.list.prev_offset @item
+ @next_offset = @action.list.next_offset @item
+ if @operators.author
+ @new_panel_items = assist_items('panel', 'private_list')
+ @new_panel_filer = assist_filer 'panel', @new_panel_items
end
}
- format.json {render text: ScrollPanel.list_as_json_text(@scroll_panels, @operators)}
- format.jsonp {
- render :json => "callback(" + @scroll_panels.to_json_list + ");"
- }
+ format.json { render json: @items.to_json(self.class.model.list_json_opt) }
end
end
end
def play
- @sheet = Sheet.show(params[:id], @operators)
+ @item = self.class.model.show(params[:id], @operators)
+ action_name = params[:action]
+ @action = self.class.controller.open(action_name, params, @operators)
+ @items = @action.list.items @item
respond_to do |format|
format.html {
- if @author
- @new_panels = Panel.mylist(@author, 1, 5)
+ @count = @action.list.count @item
+ @prev_offset = @action.list.prev_offset @item
+ @next_offset = @action.list.next_offset @item
+ if @operators.author
+ @new_panel_items = assist_items('panel', 'private_list')
+ @new_panel_filer = assist_filer 'panel', @new_panel_items
end
}
- format.json {render json: @sheet.to_json(Sheet.show_json_opt)}
- format.jsonp {
- render :json => "callback(" + @sheet_panels.to_json_list + ");"
- }
+ format.json { render json: @items.to_json(self.class.model.list_json_opt) }
end
end
end
def play
- @story = Story.show(params[:id], @operators)
+ @item = Story.show(params[:id], @operators)
@page = StorySheet.page params[:page]
- @sheet = StorySheet.play_sheet(@story, @author, @page)
+ @sheet = StorySheet.play_sheet(@item, @operators, @page)
respond_to do |format|
format.html {
- @paginate = StorySheet.play_paginate(@story, @page)
- if @author
- @new_sheets = Sheet.mylist(@author, 1, 5)
+ @paginate = StorySheet.play_paginate(@item, @page)
+ if @operators.author
+ @new_sheet_items = assist_items('sheet', 'private_list')
+ @new_sheet_filer = assist_filer 'sheet', @new_sheet_items
end
}
format.json {
['story_sheets.story_id = ?', sid]
end
- def self.play_sheet story, au, page = 1
+ def self.page prm = nil
+ page = prm.to_i
+ page = 1 if page < 1
+ page
+ end
+ def self.play_sheet story, operators, page = 1
ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
if ss
if ss.sheet
- Sheet.show(ss.sheet.id, au)
+ Sheet.show(ss.sheet.id, operators)
else
nil
end
<h2><%= t('home.index.catch') -%></h2>
<%= render 'panels/standard', :panel => @panel, :operators => @operators %>
-<h2><%= t('ground_colors.update_color') -%></h2>
<%= render @ground_picture.form_template, :elm => @ground_picture, :no_attr => 0 %>
<h2><%= t('home.index.catch') -%></h2>
<%= render 'panels/standard', :panel => @panel, :operators => @operators %>
-<h2><%= t('ground_pictures.create_ground_picture') -%></h2>
-<% if @ground_picture.picture and @ground_picture.picture.resource_picture %>
- <table>
- <tr>
- <th></th>
- <th></th>
- <th><%= t_m 'ResourcePicture.artist_id' -%></th>
- <th><%= t_m 'ResourcePicture.ext' -%></th>
- <th><%= t_m 'ResourcePicture.width' -%></th>
- <th><%= t_m 'ResourcePicture.height' -%></th>
- <th><%= t_m 'ResourcePicture.filesize' -%></th>
- </tr>
-
- <%= render 'resource_pictures/list_item', :resource_picture => @ground_picture.picture.resource_picture %>
- </table>
-<% end %>
<%= render @ground_picture.form_template, :elm => @ground_picture, :no_attr => 0 %>
<div class="field">
<%= f.label :width %>
<%= f.number_field :width, elm.field_tag_attributes(:width, no_attr, :size => 5) %>
- <% if elm.has_helper?(:width) %>
- <%= render elm.form_helper_template(:width), :elm => elm, :no_attr => no_attr, :opt => {:class => "panel_picture_width_tool"} %>
- <% end %>
</div>
<div class="row_break">
</div>
<div class="field">
<%= f.label :height %>
<%= f.number_field :height, elm.field_tag_attributes(:height, no_attr, :size => 5) %>
- <% if elm.has_helper?(:height) %>
- <%= render elm.form_helper_template(:height), :elm => elm, :no_attr => no_attr, :opt => {:class => "panel_picture_height_tool"} %>
- <% end %>
</div>
<div class="row_break">
</div>
<h2><%= t('home.index.catch') -%></h2>
<%= render 'panels/standard', :panel => @panel, :operators => @operators %>
-<h2><%= t('panel_pictures.resource_picture') -%></h2>
-<% if @panel_picture.picture and @panel_picture.picture.resource_picture %>
- <table>
- <tr>
- <th></th>
- <th></th>
- <th><%= t_m 'ResourcePicture.artist_id' -%></th>
- <th><%= t_m 'ResourcePicture.ext' -%></th>
- <th><%= t_m 'ResourcePicture.width' -%></th>
- <th><%= t_m 'ResourcePicture.height' -%></th>
- <th><%= t_m 'ResourcePicture.filesize' -%></th>
- </tr>
-
- <%= render 'resource_pictures/list_item', :resource_picture => @panel_picture.picture.resource_picture %>
- </table>
-<% end %>
-<%= render 'panels/element_form', :form => @form %>
+<%= render @item.form_template, :elm => @item, :no_attr => 0 %>
+<%# render 'panels/element_form', :form => @form %>
-<%= content_tag :span, '', helper.field.element.tag_attributes('', :class => helper.options[:class]) %>
+<%= content_tag :span, '', helper.field.element.tag_attributes('', :class => helper.options[:class] || helper.options['class']) %>
<%= l scroll_panel.updated_at %>
</td>
<td>
- <% if scroll_panel.own? author %>
+ <% if scroll_panel.own? operators %>
<%= render 'scroll_panels/order', :scroll_panel => scroll_panel %>
<% else %>
No.<%= scroll_panel.t %>
<%= link_to scroll_icon, scroll_path(scroll) %>
<%= link_to h(scroll.title), play_scroll_path(scroll) %>
</h1>
-<% if scroll.own? author -%>
+<% if scroll.own? operators -%>
<%= form_for(scroll) do |f| %>
<div class="field">
<%= f.label :title %><br />
-<% @page_title = @scroll.title %>
+<% @page_title = @item.title %>
<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
-<%= render 'scroll_panels/scroll_header', :scroll => @scroll, :author => @author %>
-<% if @scroll_panels.empty? -%>
+<% if @items.empty? -%>
<h2><%= t('scrolls.play.empty') %></h2>
<% else %>
- <% @scroll_panels.each do |scroll_panel| %>
+ <% @items.each do |scroll_panel| %>
<% if scroll_panel.panel -%>
- <%= render 'panels/body', :panel => scroll_panel.panel, :author => @author, :spot => nil %>
+ <%= render 'panels/body', :panel => scroll_panel.panel, :operators => @operators, :spot => nil %>
<% end %>
- <%= render 'scroll_panels/footer', :scroll_panel => scroll_panel, :author => @author %>
+ <%= render 'scroll_panels/footer', :scroll_panel => scroll_panel, :operators => @operators %>
<% end %>
- <%= render 'scroll_panels/licensed_pictures', :licensed_pictures => ScrollPanel.licensed_pictures(@scroll_panels) %>
+ <%= render 'scroll_panels/licensed_pictures', :licensed_pictures => ScrollPanel.licensed_pictures(@items) %>
<% if @prev_offset -%>
- <%= link_to h('<<prev'), play_scroll_path(@scroll, {:offset => @prev_offset, :count => @panel_count}) %>
+ <%= link_to h('<<prev'), play_scroll_path(@scroll, {:offset => @prev_offset, :count => @count}) %>
<% end %>
<% if @next_offset -%>
- <%= link_to h('next>>'), play_scroll_path(@scroll, {:offset => @next_offset, :count => @panel_count}) %>
+ <%= link_to h('next>>'), play_scroll_path(@scroll, {:offset => @next_offset, :count => @count}) %>
<% end %>
<% end %>
-<% if @scroll.own? @author -%>
+<% if @item.own? @operators -%>
<h3><%= t('scroll_panels.append.new_panels') -%></h3>
<table>
- <% @new_panels.each do |panel| %>
- <%= render 'scroll_panels/append_panel', :scroll => @scroll, :panel => panel, :author => @author %>
+ <% @new_panel_items.each do |panel| %>
+ <%= render 'scroll_panels/append_panel', :panel => panel, :scroll => @item, :operators => @operators %>
<% end %>
</table>
<% end %>
-<% @page_caption = @sheet.caption %>
+<% @page_caption = @item.caption %>
<p id="notice"><%= notice %></p>
-<%= render 'sheet_panels/play_header', :sheet => @sheet, :author => @author %>
-<% if @sheet.sheet_elements.empty? -%>
+<% if @item.sheet_elements.empty? -%>
<h2><%= t('sheet_panels.sheet.empty') %></h2>
<% else %>
- <div id="<%= @sheet.tag_id -%>wrapper" sheet_id="<%= @sheet.tag_sheet_id -%>" class="pettanr-sheet-wrapper" editable="true">
- <%= render 'sheets/standard', :sheet => @sheet, :author => @author %>
+ <div id="<%= @item.tag_id -%>wrapper" sheet_id="<%= @item.tag_sheet_id -%>" class="pettanr-sheet-wrapper" editable="true">
+ <%= render 'sheets/standard', :sheet => @item, :operators => @operators %>
</div>
<% end %>
-<% if @sheet.own? @author -%>
+<% if @item.own? @operators -%>
<h3><%= t('sheet_panels.append.new_panels') -%></h3>
<table>
- <% @new_panels.each do |panel| %>
- <%= render 'sheet_panels/append_panel', :sheet => @sheet, :panel => panel, :author => @author %>
+ <% @new_panel_items.each do |panel| %>
+ <%= render 'sheet_panels/append_panel', :sheet => @item, :panel => panel, :operators => @operators %>
<% end %>
</table>
<% end %>
<%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
<%= link_to h(truncate(story.title, :length => 12)), play_story_path(story) %>
</td>
- <% if story.own? @author -%>
+ <% if story.own? operators -%>
<td>
<%= form_for(story) do |f| %>
No.
-<% @page_caption = @story.title %>
+<% @page_caption = @item.title %>
<p id="notice"><%= notice %></p>
-<%= render 'story_sheets/play_header', :story => @story, :author => @author %>
<% if @sheet -%>
<%= paginate(@paginate) %>
- <% @sheet_panels = SheetPanel.play_list(@sheet, @author) -%>
- <%= render 'sheets/standard', :sheet_panels => @sheet_panels, :sheet => @sheet, :author => @author %>
+ <% @sheet_panels = SheetPanel.play_list(@sheet, @operators) -%>
+ <%= render 'sheets/standard', :sheet_panels => @sheet_panels, :sheet => @sheet, :operators => @operators %>
<%= paginate(@paginate) %>
- <%= render 'story_sheets/play_footer', :story => @story, :sheet => @sheet, :author => @author %>
+ <%= render 'story_sheets/play_footer', :story => @item, :sheet => @sheet, :operators => @operators %>
<% else %>
<h2><%= t('stories.play.empty') %></h2>
<% end %>
-<%= render 'stories/play_footer', :story => @story, :author => @author %>
+<%= render 'stories/play_footer', :story => @item, :operators => @operators %>
-<% if @story.own? @author -%>
+<% if @item.own? @operators -%>
<h3><%= t('story_sheets.append.new_sheets') -%></h3>
<table>
- <% @new_sheets.each do |sheet| %>
- <%= render 'story_sheets/append_sheet', :story => @story, :sheet => sheet, :author => @author %>
+ <% @new_sheet_items.each do |sheet| %>
+ <%= render 'story_sheets/append_sheet', :story => @item, :sheet => sheet, :operators => @operators %>
<% end %>
</table>
<% end %>
module Pettanr
class ControllerManager
class ActionList
+ attr :list
def initialize action_name, item_name, operators, list, conf, manifest
@action_name = action_name
@item_name = item_name
@model = @item_name.classify.constantize
@offset = (@page -1) * @page_size
@table_name = @model.table_name
- if @model.content?
+ if @model.content?
@owner_model = @model.owner_model
@owner_table_name = @owner_model.table_name if @owner_model
end
end
+ class PlayList
+ attr :params_offset, :params_count, :offset, :count, :limit
+ def initialize params_offset, params_count, operators, item_name, list_name, conf, manifest
+ @operators = operators
+ @item_name = item_name
+ @list_name = list_name
+ @conf = conf
+ @manifest = manifest
+
+ @default_page_size = @conf['default_page_size'] || 25
+ @max_page_size = @conf['max_page_size'] || 100
+ @params_offset = params_offset
+ @params_count = params_count
+ @list_list_conf = @manifest.list(@item_name).lists[list_name] || {}
+ @model_name = @list_list_conf['model']
+ @filter_key = @list_list_conf['filter_key']
+ @model = @model_name.classify.constantize
+ @table_name = @model.table_name
+ if @model.content?
+ @owner_model = @model.owner_model
+ @owner_table_name = @owner_model.table_name if @owner_model
+ end
+ end
+
+ def offset cnt, prm = nil
+ offset = prm.to_i
+ offset = cnt - 1 if offset >= cnt
+ offset = cnt - offset.abs if offset < 0
+ offset = 0 if offset < 0
+ offset
+ end
+
+ def limit prm
+ prm ||= @default_page_size
+ count = prm.to_i
+ count = @max_page_size if count > @max_page_size
+ count = @default_page_size if count < 1
+ count
+ end
+
+ def count filter_item
+ @count ||= @model.count(:conditions => self.where(filter_item), :include => self.includes).to_i
+ end
+
+ def where filter_item
+ w = @model.list_where
+ w += ' and ' unless w.blank?
+ [w + @table_name + '.' + @filter_key + ' = ?', filter_item.id]
+ end
+
+ def includes
+ {@owner_model.item_name => {}}
+ end
+
+ def order
+ @table_name + '.t'
+ end
+
+ def items filter_item
+ c = @count || self.count(filter_item)
+ o = self.offset c, @offset
+ l = self.limit @count
+ @model.where(self.where(filter_item)).includes(self.includes).order(self.order).offset(o).limit(l)
+ end
+
+ def prev_offset filter_item
+ c = @count || self.count(filter_item)
+ o = self.offset c, @offset
+ l = self.limit @count
+ if o > 0
+ if o - l < 0
+ 0
+ else
+ o - l
+ end
+ else
+ nil
+ end
+ end
+
+ def next_offset filter_item
+ c = @count || self.count(filter_item)
+ o = self.offset c, @offset
+ l = self.limit @count
+ if o + l > c
+ nil
+ else
+ o + l
+ end
+ end
+ end
+
@@types = {
'public' => PublicList, 'private' => PrivateList, 'system_resource' => SystemResourceList,
'has_many' => HasManyList, 'filter' => FilterList,
- 'through_filter' => ThroughFilterList, 'element_filter' => ElementFilterList
+ 'through_filter' => ThroughFilterList, 'element_filter' => ElementFilterList,
+ 'play' => PlayList
}
def initialize list_manifest
@list_manifest = list_manifest
"list_name": "by_panel"\r
}\r
},\r
+ "play": {\r
+ "type": "list",\r
+ "list": {\r
+ "list_name": "play"\r
+ }\r
+ },\r
"show": {\r
"type": "show",\r
"name": "show"\r
"list": {\r
"list_name": "by_author"\r
}\r
+ },\r
+ "play": {\r
+ "type": "list",\r
+ "list": {\r
+ "list_name": "play"\r
+ }\r
}\r
}\r
},\r
"list": {\r
"list_name": "by_author"\r
}\r
+ },\r
+ "play": {\r
+ "type": "list",\r
+ "list": {\r
+ "list_name": "play"\r
+ }\r
}\r
}\r
},\r
"from": "panel",\r
"through": "scroll_panels",\r
"filter_key": "panel_id"\r
+ },\r
+ "play": {\r
+ "type": "play",\r
+ "model": "scroll_panel",\r
+ "filter_key": "scroll_id"\r
}\r
}\r
},\r
"type": "element_filter",\r
"from": "author",\r
"filter_key": "author_id"\r
+ },\r
+ "play": {\r
+ "type": "play",\r
+ "model": "story_sheet",\r
+ "filter_key": "story_id"\r
}\r
}\r
},\r
"type": "filter",\r
"from": "author",\r
"filter_key": "author_id"\r
+ },\r
+ "play": {\r
+ "type": "play",\r
+ "model": "sheet_panel",\r
+ "filter_key": "sheet_id"\r
}\r
}\r
},\r