From a060bd77160f7efcad5d4580e9b476a5b2431c45 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Sun, 16 Feb 2014 11:25:55 +0900 Subject: [PATCH] manifest view profiler --- .../manifest/work/controllers.js.coffee.erb | 72 ++++++++++++- .../javascripts/manifest/work/models.js.coffee.erb | 5 + .../manifest/work/profilers.js.coffee.erb | 12 +-- app/controllers/application_controller.rb | 28 ++++- app/controllers/artists_controller.rb | 17 +-- app/controllers/authors_controller.rb | 17 +-- app/controllers/balloons_controller.rb | 16 +-- app/controllers/comics_controller.rb | 14 ++- app/controllers/ground_colors_controller.rb | 16 +-- app/controllers/ground_pictures_controller.rb | 16 +-- app/controllers/license_groups_controller.rb | 16 +-- app/controllers/licenses_controller.rb | 16 +-- app/controllers/original_pictures_controller.rb | 29 ++--- app/controllers/panel_pictures_controller.rb | 17 +-- app/controllers/panels_controller.rb | 39 +++---- app/controllers/pictures_controller.rb | 17 +-- app/controllers/resource_pictures_controller.rb | 17 +-- app/controllers/scroll_panels_controller.rb | 5 +- app/controllers/scrolls_controller.rb | 26 ++--- app/controllers/sheet_panels_controller.rb | 5 +- app/controllers/sheets_controller.rb | 35 +++--- .../speech_balloon_templates_controller.rb | 19 ++-- app/controllers/speech_balloons_controller.rb | 16 +-- app/controllers/speeches_controller.rb | 16 +-- app/controllers/stories_controller.rb | 23 ++-- app/controllers/story_sheets_controller.rb | 7 +- app/controllers/system_pictures_controller.rb | 17 +-- app/controllers/writing_formats_controller.rb | 17 +-- app/views/system/prof.prof.erb | 33 +----- app/views/templates/r/filer/_filer.html.erb | 5 + app/views/templates/r/filer/filer.html.erb | 6 +- .../templates/r/profiler/_associations.html.erb | 23 ++++ app/views/templates/r/profiler/_column.html.erb | 5 + app/views/templates/r/profiler/_columns.html.erb | 5 + app/views/templates/r/profiler/_header.html.erb | 3 + app/views/templates/r/profiler/_profiler.html.erb | 5 + .../r/profiler/column_note/_default.html.erb | 1 + .../r/profiler/column_note/_none.html.erb | 0 .../r/profiler/column_value/_date.html.erb | 1 + .../r/profiler/column_value/_default.html.erb | 1 + app/views/templates/r/profiler/profiler.html.erb | 1 + lib/manifest/list/base.rb | 11 +- lib/manifest/list/filter.rb | 8 +- lib/manifest/list/private.rb | 5 + lib/manifest/list/through_filter.rb | 11 +- lib/manifest/local/view.rb | 1 + lib/manifest/local/view/profiler.rb | 65 ++++++++++++ lib/manifest/local/view/profiler/association.rb | 70 ++++++++++++ .../local/view/profiler/association/belongs_to.rb | 52 +++++++++ .../local/view/profiler/association/has_many.rb | 35 ++++++ .../local/view/profiler/association/has_one.rb | 64 +++++++++++ lib/manifest/local/view/profiler/column.rb | 118 +++++++++++++++++++++ lib/manifest/local/view/profiler/header.rb | 19 ++++ lib/manifest/local/view/profiler/profiler.rb | 116 -------------------- lib/manifest/manifest.rb | 2 +- lib/manifest/model.rb | 5 +- lib/manifest/model/association.rb | 6 +- lib/manifest/model/association/belongs_to.rb | 4 + lib/manifest/model/association/has_many.rb | 4 + lib/manifest/model/association/has_one.rb | 4 + lib/manifest/model/attribute.rb | 3 +- lib/manifest/model/list/filter.rb | 3 +- lib/manifest/model/list/through_filter.rb | 15 +-- lib/manifest/profiler.rb | 10 +- lib/manifest/profiler/association.rb | 2 +- lib/manifest/profiler/association/belongs_to.rb | 4 + lib/manifest/profiler/association/has_many.rb | 35 +++++- lib/manifest/profiler/association/has_one.rb | 4 + lib/manifest/profiler/list.rb | 6 +- public/manifest.json | 83 +++++++++++++-- 70 files changed, 1001 insertions(+), 403 deletions(-) create mode 100644 app/views/templates/r/filer/_filer.html.erb create mode 100644 app/views/templates/r/profiler/_associations.html.erb create mode 100644 app/views/templates/r/profiler/_column.html.erb create mode 100644 app/views/templates/r/profiler/_columns.html.erb create mode 100644 app/views/templates/r/profiler/_header.html.erb create mode 100644 app/views/templates/r/profiler/_profiler.html.erb create mode 100644 app/views/templates/r/profiler/column_note/_default.html.erb create mode 100644 app/views/templates/r/profiler/column_note/_none.html.erb create mode 100644 app/views/templates/r/profiler/column_value/_date.html.erb create mode 100644 app/views/templates/r/profiler/column_value/_default.html.erb create mode 100644 app/views/templates/r/profiler/profiler.html.erb create mode 100644 lib/manifest/local/view/profiler.rb create mode 100644 lib/manifest/local/view/profiler/association.rb create mode 100644 lib/manifest/local/view/profiler/association/belongs_to.rb create mode 100644 lib/manifest/local/view/profiler/association/has_many.rb create mode 100644 lib/manifest/local/view/profiler/association/has_one.rb create mode 100644 lib/manifest/local/view/profiler/column.rb create mode 100644 lib/manifest/local/view/profiler/header.rb delete mode 100644 lib/manifest/local/view/profiler/profiler.rb diff --git a/app/assets/javascripts/manifest/work/controllers.js.coffee.erb b/app/assets/javascripts/manifest/work/controllers.js.coffee.erb index 3eaf78c2..604e2057 100644 --- a/app/assets/javascripts/manifest/work/controllers.js.coffee.erb +++ b/app/assets/javascripts/manifest/work/controllers.js.coffee.erb @@ -22,7 +22,6 @@ }, show: { type: 'show', - name: 'show', }, count: { type: 'count', @@ -56,6 +55,9 @@ by_scroll: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -82,6 +84,9 @@ by_author: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -117,6 +122,9 @@ list_name: 'play', }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -149,6 +157,9 @@ by_sheet: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -187,6 +198,9 @@ list_name: 'play', }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -219,6 +233,9 @@ by_panel: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -254,6 +271,9 @@ by_speech_balloon_template: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -289,6 +309,9 @@ by_author: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -318,6 +341,9 @@ by_author: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -344,6 +370,9 @@ by_writing_format: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -370,6 +399,9 @@ # list_name: 'by_system_picture', # }, #}, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -393,6 +425,9 @@ by_author: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -422,6 +457,9 @@ by_author: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -445,6 +483,9 @@ }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -454,6 +495,11 @@ }, }, pictures: { + actions: { + show: { + type: 'show', + }, + }, }, resource_pictures: { actions: { @@ -470,6 +516,9 @@ by_artist: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -493,6 +542,9 @@ }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -513,6 +565,9 @@ by_system_picture: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -533,6 +588,9 @@ }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -556,6 +614,9 @@ by_system_picture: { type: 'list', }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -633,6 +694,9 @@ list_name: 'ground_colors', }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -656,6 +720,9 @@ list_name: 'resource_pictures', }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { @@ -673,6 +740,9 @@ }, }, + show: { + type: 'show', + }, count: { type: 'count', args: { diff --git a/app/assets/javascripts/manifest/work/models.js.coffee.erb b/app/assets/javascripts/manifest/work/models.js.coffee.erb index a198d4ff..f8c3a269 100644 --- a/app/assets/javascripts/manifest/work/models.js.coffee.erb +++ b/app/assets/javascripts/manifest/work/models.js.coffee.erb @@ -732,6 +732,11 @@ }, by_scroll: { type: 'through_filter', + args: { + filter_item_name: 'scroll', + through: 'scroll_panels', + filter_key: 'scroll_id', + }, }, by_sheet: { type: 'through_filter', diff --git a/app/assets/javascripts/manifest/work/profilers.js.coffee.erb b/app/assets/javascripts/manifest/work/profilers.js.coffee.erb index e21f097b..0402e94e 100644 --- a/app/assets/javascripts/manifest/work/profilers.js.coffee.erb +++ b/app/assets/javascripts/manifest/work/profilers.js.coffee.erb @@ -11,7 +11,7 @@ list_name: 'by_scroll', }, }, - columns: [ + column_names: [ 'id', 'title', 'description', @@ -715,10 +715,10 @@ # model_name: 'balloon', # list_name: 'by_system_picture', #}, - 'speech_balloon_templates.by_system_picture': { - model_name: 'speech_balloon_template', - list_name: 'by_system_picture', - }, + #'speech_balloon_templates.by_system_picture': { + # model_name: 'speech_balloon_template', + # list_name: 'by_system_picture', + #}, 'licenses.by_system_picture': { model_name: 'license', list_name: 'by_system_picture', @@ -739,7 +739,7 @@ ], has_many: [ #'balloons.by_system_picture', - 'speech_balloon_templates.by_system_picture', + #'speech_balloon_templates.by_system_picture', 'licenses.by_system_picture', ], has_one: [ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fed89b0f..4d8ca5f6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -133,12 +133,31 @@ class ApplicationController < ActionController::Base :filer => @filer } } - format.json { render json: @items.to_json(self.class.model.list_json_opt) } + format.json { render json: @items.to_json(@my_model_class.list_json_opt) } format.atom format.rss end end + def set_show + set_model + @item = @my_model_class.show(params[:id], @operators) + end + + def show_prof_format format + format.prof { + self.formats = [:html] + @profiler = Manifest::View::Profiler.new @my_model.model_name, @item, @operators + render @profiler.template_name, :locals => { + :profiler => @profiler + } + } + end + + def show_json_format format + format.json { render json: @item.to_json(@my_model_class.show_json_opt) } + end + def form_new set_model @item = @my_model_class.new @@ -183,12 +202,13 @@ class ApplicationController < ActionController::Base end def assist_items item_name, list_name - list_manager = Pettanr::Application::manifest.list_managers[item_name] - list = list_manager.open list_name, 1, 5, @operators - list.items + list = Manifest.manifest.lists[item_name][list_name] + list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5}) + list_result.items end def assist_filer item_name, items + @filer = Manifest::View::Filer.new @list.item_name, list_result.items, list_result.paginate, @operators filer_manager = Pettanr::Application::manifest.filer_managers[item_name] filer_manager.open(item_name, items, @operators, nil) end diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index a5fe524d..db1101b6 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -16,15 +16,18 @@ class ArtistsController < ApplicationController filer_list end + def show_html_format format + format.html { + @artist = @item + } + end + def show - @item = Artist.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - @artist = @item - } - format_prof format - format.json { render :json => @item.to_json(Artist.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index dfa8feb3..b9956d6f 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -16,15 +16,18 @@ class AuthorsController < ApplicationController filer_list end + def show_html_format format + format.html { + @author = @item + } + end + def show - @item = Author.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - @author = @item - } - format_prof format - format.json { render :json => @item.to_json(Author.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/balloons_controller.rb b/app/controllers/balloons_controller.rb index e7847386..3237c7a2 100644 --- a/app/controllers/balloons_controller.rb +++ b/app/controllers/balloons_controller.rb @@ -23,14 +23,18 @@ class BalloonsController < ApplicationController filer_list end + def show_html_format format + format.html { + @balloon = @item + } + end + def show - @item = Balloon.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - @balloon = @item - } - format_prof format - format.json { render json: @item.to_json(Balloon.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/comics_controller.rb b/app/controllers/comics_controller.rb index 316f0dd2..ea08d00f 100644 --- a/app/controllers/comics_controller.rb +++ b/app/controllers/comics_controller.rb @@ -20,13 +20,17 @@ class ComicsController < ApplicationController filer_list end + def show_html_format format + format.html { + } + end + def show - @item = Comic.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - } - format_prof format - format.json { render json: @item.to_json(Comic.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format format.atom format.rss end diff --git a/app/controllers/ground_colors_controller.rb b/app/controllers/ground_colors_controller.rb index 8e0a1fad..32e3d644 100644 --- a/app/controllers/ground_colors_controller.rb +++ b/app/controllers/ground_colors_controller.rb @@ -26,14 +26,18 @@ class GroundColorsController < ApplicationController filer_list end + def show_html_format format + format.html { + @ground_color = @item + } + end + def show - @item = GroundColor.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - @ground_color = @item - } - format_prof format - format.json { render json: @item.to_json(GroundColor.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/ground_pictures_controller.rb b/app/controllers/ground_pictures_controller.rb index 515b0c00..a4616e68 100644 --- a/app/controllers/ground_pictures_controller.rb +++ b/app/controllers/ground_pictures_controller.rb @@ -26,14 +26,18 @@ class GroundPicturesController < ApplicationController filer_list end + def show_html_format format + format.html { + @ground_picture = @item + } + end + def show - @item = GroundPicture.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - @ground_picture = @item - } - format_prof format - format.json { render json: @item.to_json(GroundPicture.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/license_groups_controller.rb b/app/controllers/license_groups_controller.rb index 1f0c0f83..5c2aedfd 100644 --- a/app/controllers/license_groups_controller.rb +++ b/app/controllers/license_groups_controller.rb @@ -9,14 +9,18 @@ class LicenseGroupsController < ApplicationController filer_list end + def show_html_format format + format.html { + @license_group = @item + } + end + def show - @item = LicenseGroup.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - @license_group = @item - } - format_prof format - format.json { render json: @item.to_json(LicenseGroup.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/licenses_controller.rb b/app/controllers/licenses_controller.rb index d5376def..40518652 100644 --- a/app/controllers/licenses_controller.rb +++ b/app/controllers/licenses_controller.rb @@ -19,14 +19,18 @@ class LicensesController < ApplicationController filer_list end + def show_html_format format + format.html { + @license = @item + } + end + def show - @item = License.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - @license = @item - } - format_prof format - format.json { render json: @item.to_json(License.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/original_pictures_controller.rb b/app/controllers/original_pictures_controller.rb index 7bf19ccf..0c5801b2 100644 --- a/app/controllers/original_pictures_controller.rb +++ b/app/controllers/original_pictures_controller.rb @@ -12,22 +12,25 @@ class OriginalPicturesController < ApplicationController filer_list end + def show_html_format format + format.html { + @original_picture = @item + #ライセンス付与のために原画ライセンスグループ作成準備 + @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @item.id + render + } + end + def show - @item = OriginalPicture.show(params[:id], @operators) - + set_show respond_to do |format| opt = {:type => @item.mime_type, :disposition=>"inline"} - format.png { send_data(@item.restore, opt ) } - format.gif { send_data(@item.restore, opt ) } - format.jpeg { send_data(@item.restore, opt ) } - format.html { - @original_picture = @item - #ライセンス付与のために原画ライセンスグループ作成準備 - @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @item.id - render - } - format_prof format - format.json { render json: @item.to_json(OriginalPicture.show_json_opt)} + format.png { send_data(@item.restore(params[:subdir]), opt ) } + format.gif { send_data(@item.restore(params[:subdir]), opt ) } + format.jpeg { send_data(@item.restore(params[:subdir]), opt ) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/panel_pictures_controller.rb b/app/controllers/panel_pictures_controller.rb index 180bed52..728215c0 100644 --- a/app/controllers/panel_pictures_controller.rb +++ b/app/controllers/panel_pictures_controller.rb @@ -26,15 +26,18 @@ class PanelPicturesController < ApplicationController filer_list end + def show_html_format format + format.html { + @panel_picture = @item + } + end + def show - @item = PanelPicture.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - @panel_picture = @item - } - format_prof format - format.json { render :json => @item.to_json(PanelPicture.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/panels_controller.rb b/app/controllers/panels_controller.rb index 83853101..7220b2f7 100644 --- a/app/controllers/panels_controller.rb +++ b/app/controllers/panels_controller.rb @@ -30,26 +30,29 @@ class PanelsController < ApplicationController filer_list end + def show_html_format format + format.html { + @panel = @item + if @operators.author + @new_scroll_items = assist_items('scroll', 'private_list') + #@new_scroll_filer = assist_filer 'scroll', @new_scroll_items + @fresh_scroll_items = assist_items('scroll_panel', 'private_list').map {|sp| sp.scroll} + #@fresh_scroll_filer = assist_filer 'scroll', @fresh_scroll_items + + @new_sheet_items = assist_items('sheet', 'private_list') + #@new_sheet_filer = assist_filer 'sheet', @new_sheet_items + @fresh_sheet_items = assist_items('sheet_panel', 'private_list').map {|sp| sp.sheet} + #@fresh_sheet_filer = assist_filer 'sheet', @fresh_sheet_items + end + } + end + def show - @item = Panel.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - @panel = @item - if @operators.author - @new_scroll_items = assist_items('scroll', 'private_list') - @new_scroll_filer = assist_filer 'scroll', @new_scroll_items - @fresh_scroll_items = assist_items('scroll_panel', 'private_list').map {|sp| sp.scroll} - @fresh_scroll_filer = assist_filer 'scroll', @fresh_scroll_items - - @new_sheet_items = assist_items('sheet', 'private_list') - @new_sheet_filer = assist_filer 'sheet', @new_sheet_items - @fresh_sheet_items = assist_items('sheet_panel', 'private_list').map {|sp| sp.sheet} - @fresh_sheet_filer = assist_filer 'sheet', @fresh_sheet_items - end - } - format_prof format - format.json { render json: @item.panel_elements_as_json } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/pictures_controller.rb b/app/controllers/pictures_controller.rb index 81b5ad48..9e1bae8c 100644 --- a/app/controllers/pictures_controller.rb +++ b/app/controllers/pictures_controller.rb @@ -8,19 +8,22 @@ class PicturesController < ApplicationController before_filter :authenticate_author, :only => [] end + def show_html_format format + format.html { + @picture = @item + } + end + def show - @item = Picture.show(params[:id], @operators) - + set_show respond_to do |format| opt = {:type => @item.mime_type, :disposition=>"inline"} format.png { send_data(@item.restore(params[:subdir]), opt ) } format.gif { send_data(@item.restore(params[:subdir]), opt ) } format.jpeg { send_data(@item.restore(params[:subdir]), opt ) } - format.html { - @picture = @item - } - format_prof format - format.json { render :json => @item.to_json} + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/resource_pictures_controller.rb b/app/controllers/resource_pictures_controller.rb index da074af1..5049b5ee 100644 --- a/app/controllers/resource_pictures_controller.rb +++ b/app/controllers/resource_pictures_controller.rb @@ -26,19 +26,22 @@ class ResourcePicturesController < ApplicationController filer_list end + def show_html_format format + format.html { + @resource_picture = @item + } + end + def show - @item = ResourcePicture.show(params[:id], @operators) - + set_show respond_to do |format| opt = {:type => @item.mime_type, :disposition=>"inline"} format.png { send_data(@item.restore(params[:subdir]), opt ) } format.gif { send_data(@item.restore(params[:subdir]), opt ) } format.jpeg { send_data(@item.restore(params[:subdir]), opt ) } - format.html { - @resource_picture = @item - } - format_prof format - format.json { render :json => @item.to_json(ResourcePicture.show_json_opt)} + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/scroll_panels_controller.rb b/app/controllers/scroll_panels_controller.rb index a7852877..27de3f9e 100644 --- a/app/controllers/scroll_panels_controller.rb +++ b/app/controllers/scroll_panels_controller.rb @@ -27,10 +27,9 @@ class ScrollPanelsController < ApplicationController end def show - @item = ScrollPanel.show(params[:id], @operators) - + set_show respond_to do |format| - format_prof format + show_prof_format format format.json { render json: @item.scroll_panel_as_json(@operators.author) } end end diff --git a/app/controllers/scrolls_controller.rb b/app/controllers/scrolls_controller.rb index 33bb1f62..581d8b30 100644 --- a/app/controllers/scrolls_controller.rb +++ b/app/controllers/scrolls_controller.rb @@ -24,20 +24,22 @@ class ScrollsController < ApplicationController filer_list end + def show_html_format format + format.html { + @scroll = @item + if @operators.author + @new_panel_items = assist_items('panel', 'private_list') + #@new_panel_filer = assist_filer 'panel', @new_panel_items + end + } + end + def show - @item = Scroll.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - 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: @item.to_json(Scroll.show_json_opt) } - format_prof format - format.atom - format.rss + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/sheet_panels_controller.rb b/app/controllers/sheet_panels_controller.rb index b3296ee2..5d300d00 100644 --- a/app/controllers/sheet_panels_controller.rb +++ b/app/controllers/sheet_panels_controller.rb @@ -27,10 +27,9 @@ class SheetPanelsController < ApplicationController end def show - @item = SheetPanel.show(params[:id], @operators) - + set_show respond_to do |format| - format_prof format + show_prof_format format format.json { render json: @item.sheet_panel_as_json(@operators.author) } end end diff --git a/app/controllers/sheets_controller.rb b/app/controllers/sheets_controller.rb index 6b621a6c..c241f388 100644 --- a/app/controllers/sheets_controller.rb +++ b/app/controllers/sheets_controller.rb @@ -30,25 +30,26 @@ class SheetsController < ApplicationController filer_list end + def show_html_format format + format.html { + if @operators.author + @new_panel_items = assist_items('panel', 'private_list') + #new_panel_filer = assist_filer 'panel', @new_panel_items + + @new_story_items = assist_items('story', 'private_list') + #new_story_filer = assist_filer 'story', @new_story_items + @fresh_story_items = assist_items('story_sheet', 'private_list').map {|ss| ss.story} + #@fresh_story_filer = assist_filer 'story', @fresh_story_items + end + } + end + def show - @item = Sheet.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - if @operators.author - @new_panel_items = assist_items('panel', 'private_list') - @new_panel_filer = assist_filer 'panel', @new_panel_items - - @new_story_items = assist_items('story', 'private_list') - @new_story_filer = assist_filer 'story', @new_story_items - @fresh_story_items = assist_items('story_sheet', 'private_list').map {|ss| ss.story} - @fresh_story_filer = assist_filer 'story', @fresh_story_items - end - } - format_prof format - format.json { render json: @item.to_json(Sheet.show_json_opt) } - format.atom - format.rss + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/speech_balloon_templates_controller.rb b/app/controllers/speech_balloon_templates_controller.rb index 1e3b1c96..61be8512 100644 --- a/app/controllers/speech_balloon_templates_controller.rb +++ b/app/controllers/speech_balloon_templates_controller.rb @@ -21,17 +21,18 @@ class SpeechBalloonTemplatesController < ApplicationController filer_list end + def show_html_format format + format.html { + @speech_balloon_template = @item + } + end + def show - @item = SpeechBalloonTemplate.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - @speech_balloon_template = @item - } - format_prof format - format.json { - render :json => @item.to_json(SpeechBalloonTemplate.show_json_opt) - } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/speech_balloons_controller.rb b/app/controllers/speech_balloons_controller.rb index 02033091..be0bdf70 100644 --- a/app/controllers/speech_balloons_controller.rb +++ b/app/controllers/speech_balloons_controller.rb @@ -26,14 +26,18 @@ class SpeechBalloonsController < ApplicationController filer_list end + def show_html_format format + format.html { + @speech_balloon = @item + } + end + def show - @item = SpeechBalloon.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - @speech_balloon = @item - } - format_prof format - format.json { render json: @item.to_json(SpeechBalloon.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/speeches_controller.rb b/app/controllers/speeches_controller.rb index 19e3fc05..432c6967 100644 --- a/app/controllers/speeches_controller.rb +++ b/app/controllers/speeches_controller.rb @@ -27,14 +27,18 @@ class SpeechesController < ApplicationController filer_list end + def show_html_format format + format.html { + @speech = @item + } + end + def show - @item = Speech.show(params[:id], @operators) + set_show respond_to do |format| - format.html { - @speech = @item - } - format_prof format - format.json { render json: @item.to_json(Speech.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index e4595287..37bfe314 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -30,18 +30,21 @@ class StoriesController < ApplicationController filer_list end + def show_html_format format + format.html { + if @operators.author + @new_sheet_items = assist_items('sheet', 'private_list') + #@new_sheet_filer = assist_filer 'sheet', @new_sheet_items + end + } + end + def show - @item = Story.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - if @operators.author - @new_sheet_items = assist_items('sheet', 'private_list') - @new_sheet_filer = assist_filer 'sheet', @new_sheet_items - end - } - format_prof format - format.json { render json: @item.to_json(Story.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/story_sheets_controller.rb b/app/controllers/story_sheets_controller.rb index e4edfac8..5d9ee601 100644 --- a/app/controllers/story_sheets_controller.rb +++ b/app/controllers/story_sheets_controller.rb @@ -27,11 +27,10 @@ class StorySheetsController < ApplicationController end def show - @item = StorySheet.show(params[:id], @operators) - + set_show respond_to do |format| - format_prof format - format.json { render json: @item.to_json(StorySheet.show_json_opt) } + show_prof_format format + show_json_format format end end diff --git a/app/controllers/system_pictures_controller.rb b/app/controllers/system_pictures_controller.rb index b151632a..5b9f7e69 100644 --- a/app/controllers/system_pictures_controller.rb +++ b/app/controllers/system_pictures_controller.rb @@ -17,19 +17,22 @@ class SystemPicturesController < ApplicationController filer_list end + def show_html_format format + format.html { + @system_picture = @item + } + end + def show - @item = SystemPicture.show(params[:id], @operators) - + set_show respond_to do |format| opt = {:type => @item.mime_type, :disposition=>"inline"} format.png { send_data(@item.restore, opt ) } format.gif { send_data(@item.restore, opt ) } format.jpeg { send_data(@item.restore, opt ) } - format.html { - @system_picture = @item - } - format_prof format - format.json { render json: @item.to_json(SystemPicture.show_json_opt)} + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/controllers/writing_formats_controller.rb b/app/controllers/writing_formats_controller.rb index ab7f6065..520cf61b 100644 --- a/app/controllers/writing_formats_controller.rb +++ b/app/controllers/writing_formats_controller.rb @@ -15,15 +15,18 @@ class WritingFormatsController < ApplicationController filer_list end + def show_html_format format + format.html { + @writing_format = @item + } + end + def show - @item = WritingFormat.show(params[:id], @operators) - + set_show respond_to do |format| - format.html { - @writing_format = @item - } - format_prof format - format.json { render :json => @item.to_json(WritingFormat.show_json_opt) } + show_html_format format + show_prof_format format + show_json_format format end end diff --git a/app/views/system/prof.prof.erb b/app/views/system/prof.prof.erb index 22895879..6ef43e35 100644 --- a/app/views/system/prof.prof.erb +++ b/app/views/system/prof.prof.erb @@ -1,30 +1,5 @@ -<%= render 'system/filer.html', :filer => profiler.header_filer %> -<% profiler.each_column do |column| %> -
- <%= column.label self %> - <%= column.disp_value self %> - <%= column.note self %> -
-<% end %> -
- <%= 'associations' %> +
+ <%= render profiler.header_template_name, :profiler => profiler %> + <%= render profiler.columns_template_name, :profiler => profiler %> + <%= render profiler.associations_template_name, :profiler => profiler %>
-
- <%= 'belongs_to' %> -
-<% profiler.each_belongs_to do |parent_filer| %> - <%= render 'system/filer.html', :filer => parent_filer %> -<% end %> -
- <%= 'has_many' %> -
-<% profiler.each_has_many do |has_many_filer, more_url| %> - <%= render 'system/filer.html', :filer => has_many_filer %> - <%= link_to h('more'), more_url %> -<% end %> -
- <%= 'has_one' %> -
-<% profiler.each_has_one do |has_one_filer| %> - <%= render 'system/filer.html', :filer => has_one_filer %> -<% end %> diff --git a/app/views/templates/r/filer/_filer.html.erb b/app/views/templates/r/filer/_filer.html.erb new file mode 100644 index 00000000..5ff03c53 --- /dev/null +++ b/app/views/templates/r/filer/_filer.html.erb @@ -0,0 +1,5 @@ +
+ <%= render filer.header.template_name, :header => filer.header %> + <%= render filer.body.template_name, :body => filer.body %> + <%= render filer.footer.template_name, :footer => filer.footer %> +
diff --git a/app/views/templates/r/filer/filer.html.erb b/app/views/templates/r/filer/filer.html.erb index 5ff03c53..a2dc13ad 100644 --- a/app/views/templates/r/filer/filer.html.erb +++ b/app/views/templates/r/filer/filer.html.erb @@ -1,5 +1 @@ -
- <%= render filer.header.template_name, :header => filer.header %> - <%= render filer.body.template_name, :body => filer.body %> - <%= render filer.footer.template_name, :footer => filer.footer %> -
+<%= render filer.template_name, :filer => filer %> diff --git a/app/views/templates/r/profiler/_associations.html.erb b/app/views/templates/r/profiler/_associations.html.erb new file mode 100644 index 00000000..806f054e --- /dev/null +++ b/app/views/templates/r/profiler/_associations.html.erb @@ -0,0 +1,23 @@ +
+
+ <%= 'associations' %> +
+
+ <%= 'belongs_to' %> +
+ <% associations.each_belongs_to_filer do |filer| %> + <%= render filer.template_name, :filer => filer %> + <% end %> +
+ <%= 'has_many' %> +
+ <% associations.each_has_many_filer do |filer| %> + <%= render filer.template_name, :filer => filer %> + <% end %> +
+ <%= 'has_one' %> +
+ <% associations.each_has_one_filer do |filer| %> + <%= render filer.template_name, :filer => filer %> + <% end %> +
diff --git a/app/views/templates/r/profiler/_column.html.erb b/app/views/templates/r/profiler/_column.html.erb new file mode 100644 index 00000000..b1b93c43 --- /dev/null +++ b/app/views/templates/r/profiler/_column.html.erb @@ -0,0 +1,5 @@ +
+ <%= column.label %> + <%= render column.value_template_name, :column => column %> + <%= render column.note_template_name, :column => column %> +
diff --git a/app/views/templates/r/profiler/_columns.html.erb b/app/views/templates/r/profiler/_columns.html.erb new file mode 100644 index 00000000..6df659a9 --- /dev/null +++ b/app/views/templates/r/profiler/_columns.html.erb @@ -0,0 +1,5 @@ +
+ <% profiler.columns.each do |column| %> + <%= render column.template_name, :column => column %> + <% end %> +
diff --git a/app/views/templates/r/profiler/_header.html.erb b/app/views/templates/r/profiler/_header.html.erb new file mode 100644 index 00000000..c4a1fa09 --- /dev/null +++ b/app/views/templates/r/profiler/_header.html.erb @@ -0,0 +1,3 @@ +
+ <%= render header.filer.template_name, :filer => header.filer %> +
diff --git a/app/views/templates/r/profiler/_profiler.html.erb b/app/views/templates/r/profiler/_profiler.html.erb new file mode 100644 index 00000000..131c4865 --- /dev/null +++ b/app/views/templates/r/profiler/_profiler.html.erb @@ -0,0 +1,5 @@ +
+ <%= render profiler.header_template_name, :header => profiler.header %> + <%= render profiler.columns_template_name, :profiler => profiler %> + <%= render profiler.associations_template_name, :associations => profiler.associations %> +
diff --git a/app/views/templates/r/profiler/column_note/_default.html.erb b/app/views/templates/r/profiler/column_note/_default.html.erb new file mode 100644 index 00000000..fbefb96f --- /dev/null +++ b/app/views/templates/r/profiler/column_note/_default.html.erb @@ -0,0 +1 @@ +(<%= t_selected_item(column.select_item_name, column.value) %>) diff --git a/app/views/templates/r/profiler/column_note/_none.html.erb b/app/views/templates/r/profiler/column_note/_none.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/templates/r/profiler/column_value/_date.html.erb b/app/views/templates/r/profiler/column_value/_date.html.erb new file mode 100644 index 00000000..8968a262 --- /dev/null +++ b/app/views/templates/r/profiler/column_value/_date.html.erb @@ -0,0 +1 @@ +<%= l column.value %> diff --git a/app/views/templates/r/profiler/column_value/_default.html.erb b/app/views/templates/r/profiler/column_value/_default.html.erb new file mode 100644 index 00000000..ce22060c --- /dev/null +++ b/app/views/templates/r/profiler/column_value/_default.html.erb @@ -0,0 +1 @@ +<%= column.value %> diff --git a/app/views/templates/r/profiler/profiler.html.erb b/app/views/templates/r/profiler/profiler.html.erb new file mode 100644 index 00000000..4418e652 --- /dev/null +++ b/app/views/templates/r/profiler/profiler.html.erb @@ -0,0 +1 @@ +<%= render profiler.template_name, :profiler => profiler %> diff --git a/lib/manifest/list/base.rb b/lib/manifest/list/base.rb index 58e7a7e8..8516bd77 100644 --- a/lib/manifest/list/base.rb +++ b/lib/manifest/list/base.rb @@ -78,11 +78,11 @@ module Manifest end def count operators, options - @model.where(self.where).includes(self.includes) + @model.where(self.where).includes(self.includes).count end - def paginate items, offset, page_size - c = items ? items.count : 0 + def paginate count, offset, page_size + c = count ? count.to_i : 0 Kaminari.paginate_array(Array.new(c, nil)).page(offset).per(page_size) end @@ -91,8 +91,9 @@ module Manifest page_size = self.page_size options[:page_size] offset = (page -1) * page_size items = self.items operators, options, offset, page_size - paginate = self.paginate items, offset, page_size - ListResult.new items, paginate + count = self.count operators, options + pg = self.paginate count, offset, page_size + ListResult.new items, pg end end diff --git a/lib/manifest/list/filter.rb b/lib/manifest/list/filter.rb index 2a06ffba..440b1faf 100644 --- a/lib/manifest/list/filter.rb +++ b/lib/manifest/list/filter.rb @@ -8,6 +8,7 @@ module Manifest def init super + @filter_item_name = @model_list_manifest.filter_item_name @filter_key = @model_list_manifest.filter_key end @@ -20,12 +21,13 @@ module Manifest def includes return @includes if @includes w = @owner_model ? {@owner_model.item_name => {}} : {} - w.merge({@from => {} }) + w.merge({@filter_item_name => {} }) if @filter_item_name + w end - def items options, offset, page_size + def items operators, options, offset, page_size filter_item_id = options[:id] - @model.where(self.where(filter_item_)).includes(self.includes).order(self.order).offset(offset).limit(page_size) + @model.where(self.where(filter_item_id)).includes(self.includes).order(self.order).offset(offset).limit(page_size) end def count operators, options diff --git a/lib/manifest/list/private.rb b/lib/manifest/list/private.rb index 5014234c..8ba028e0 100644 --- a/lib/manifest/list/private.rb +++ b/lib/manifest/list/private.rb @@ -24,6 +24,11 @@ module Manifest @model.where(self.where(operators)).includes(self.includes).order(self.order).offset(offset).limit(page_size) end + def count operators, options + filter_item_id = options[:id] + @model.where(self.where(operators)).includes(self.includes).count + end + end end diff --git a/lib/manifest/list/through_filter.rb b/lib/manifest/list/through_filter.rb index d8b35dde..b5a0a632 100644 --- a/lib/manifest/list/through_filter.rb +++ b/lib/manifest/list/through_filter.rb @@ -9,18 +9,19 @@ module Manifest def init super - return - @through = @list_list_conf['through'] + @through = @model_list_manifest.through end def includes - {@through => {@from => {}} } + {@through => {@filter_item_name => {}} } end - def where filter_item + def where filter_item_id w = @model.list_where w += ' and ' unless w.blank? - [w + @through + '.' + @filter_key + ' = ?', filter_item.id] + p @through + p @filter_key + [w + @through + '.' + @filter_key + ' = ?', filter_item_id] end end diff --git a/lib/manifest/local/view.rb b/lib/manifest/local/view.rb index fbf11b51..5671b23a 100644 --- a/lib/manifest/local/view.rb +++ b/lib/manifest/local/view.rb @@ -1,5 +1,6 @@ require_dependency "manifest/local/view/filer" require_dependency "manifest/local/view/form" +require_dependency "manifest/local/view/profiler" module Manifest module View end diff --git a/lib/manifest/local/view/profiler.rb b/lib/manifest/local/view/profiler.rb new file mode 100644 index 00000000..ffb9efd8 --- /dev/null +++ b/lib/manifest/local/view/profiler.rb @@ -0,0 +1,65 @@ +require_dependency "manifest/local/view/profiler/header" +require_dependency "manifest/local/view/profiler/column" +require_dependency "manifest/local/view/profiler/association" +module Manifest + module View + class Profiler + include ProfilerModule + attr :profiler_manifest, :item_name, :item, :operators, :template_dir, + :header, :columns, :associations + def initialize item_name, item, operators + @item_name = item_name + @item = item + @operators = operators + @profiler_manifest = Manifest.manifest.profilers[@item_name] + @template_dir = 'templates/r/profiler/' + @header = Header.new self + @columns = @profiler_manifest.column_names.map {|column_name| + Column.new self, column_name + } + @associations = Association.new self, @profiler_manifest.associations + end + + def model + ::Manifest::item_name_to_model @item_name + end + + def template_file_name + "profiler" + end + + def template_name + self.template_dir + self.template_file_name + end + + def header_template_file_name + "header" + end + + def header_template_name + self.template_dir + self.header_template_file_name + end + + def columns_template_file_name + "columns" + end + + def columns_template_name + self.template_dir + self.columns_template_file_name + end + + def associations_template_file_name + "associations" + end + + def associations_template_name + self.template_dir + self.associations_template_file_name + end + + def image_dir + '/images/' + end + + end + end +end diff --git a/lib/manifest/local/view/profiler/association.rb b/lib/manifest/local/view/profiler/association.rb new file mode 100644 index 00000000..35cde9c5 --- /dev/null +++ b/lib/manifest/local/view/profiler/association.rb @@ -0,0 +1,70 @@ +require_dependency "manifest/local/view/profiler/association/belongs_to" +require_dependency "manifest/local/view/profiler/association/has_many" +require_dependency "manifest/local/view/profiler/association/has_one" +module Manifest + module View + module ProfilerModule + class Association + include AssociationModule + attr :profiler, :association_manifest, + :belongs_to, :has_many, :has_one + def initialize profiler, association_manifest + @profiler = profiler + @association_manifest = association_manifest + @belongs_to = @association_manifest.belongs_to.map {|belongs_to_manifest| + BelongsTo.new self, belongs_to_manifest + } + @has_many = @association_manifest.has_many.map {|list_name| + HasMany.new self, list_name + } + @has_one = @association_manifest.has_one.map {|list_name| + HasOne.new self, list_name + } + end + + def item + @profiler.item + end + + def model_manifest + ::Manifest.manifest.models[@profiler.item_name] + end + + def model_attribute_manifest + model_manifest.attributes[@column_name] + end + + def template_dir + @profiler.template_dir + end + + def template_file_name + "associations" + end + + def template_name + self.template_dir + self.template_file_name + end + + def each_belongs_to_filer + @belongs_to.each {|b| + yield b.filer + } + end + + def each_has_many_filer + @has_many.each {|h| + yield h.filer + } + end + + def each_has_one_filer + @has_one.each {|h| + yield h.filer + } + end + + end + end + end +end diff --git a/lib/manifest/local/view/profiler/association/belongs_to.rb b/lib/manifest/local/view/profiler/association/belongs_to.rb new file mode 100644 index 00000000..8955be08 --- /dev/null +++ b/lib/manifest/local/view/profiler/association/belongs_to.rb @@ -0,0 +1,52 @@ +module Manifest + module View + module ProfilerModule + module AssociationModule + class BelongsTo + attr :association, :belongs_to_manifest + def initialize association, belongs_to_manifest + @association = association + @belongs_to_manifest = belongs_to_manifest + end + + def item + self.profiler.item + end + + def parent_model + @belongs_to_manifest.model + end + + def parent_id + self.item.attributes[self.model_belongs_to_manifest.id_column] + end + + def filer + filer = nil + begin + r = self.parent_model.show(self.parent_id, self.profiler.operators) + if r + filer = ::Manifest::View::Filer.new self.parent_model.item_name, [r], nil, self.profiler.operators + end + rescue ActiveRecord::RecordNotFound, ActiveRecord::Forbidden + end + filer + end + + def model_manifest + ::Manifest.manifest.models[self.profiler.item_name] + end + + def model_belongs_to_manifest + self.model_manifest.associations.belongs_to[@belongs_to_manifest.model_name] + end + + def profiler + @association.profiler + end + + end + end + end + end +end diff --git a/lib/manifest/local/view/profiler/association/has_many.rb b/lib/manifest/local/view/profiler/association/has_many.rb new file mode 100644 index 00000000..6a9711a9 --- /dev/null +++ b/lib/manifest/local/view/profiler/association/has_many.rb @@ -0,0 +1,35 @@ +module Manifest + module View + module ProfilerModule + module AssociationModule + class HasMany + attr :association, :has_many_manifest + def initialize association, has_many_manifest + @association = association + @has_many_manifest = has_many_manifest + end + + def item + self.profiler.item + end + + def has_many_model + @has_many_manifest.model + end + + def filer + l = @has_many_manifest.list + list_result = @has_many_manifest.list.open(self.profiler.operators, {:id => self.item.id, :page => 1, :page_size => 3}) + items = list_result.items + ::Manifest::View::Filer.new self.has_many_model.item_name, items, nil, self.profiler.operators + end + + def profiler + @association.profiler + end + + end + end + end + end +end diff --git a/lib/manifest/local/view/profiler/association/has_one.rb b/lib/manifest/local/view/profiler/association/has_one.rb new file mode 100644 index 00000000..6b732cd2 --- /dev/null +++ b/lib/manifest/local/view/profiler/association/has_one.rb @@ -0,0 +1,64 @@ +module Manifest + module View + module ProfilerModule + module AssociationModule + class HasOne + attr :association, :column_name + def initialize association, belongs_to_name + @association = association + @belongs_to_name = belongs_to_name + end + + def profiler + @association.profiler + end + + def item + self.profiler.item + end + + def parent_model + self.model_belongs_to_manifest.model + end + + def parent_id + self.item.attributes[self.model_belongs_to_manifest.id_column] + end + + def filer + filer = nil + begin + r = self.parent_model.show(self.parent_id, self.profiler.operators) + if r + filer = Manifest::View::Filer.new self.item.item_name, [r], nil, self.profiler.operators + end + rescue ActiveRecord::RecordNotFound, ActiveRecord::Forbidden + end + filer + end + + def model_manifest + ::Manifest.manifest.models[@profiler.item_name] + end + + def model_belongs_to_manifest + self.model_manifest.belongs_to[@belongs_to_name] + end + + def template_dir + @profiler.template_dir + end + + def template_file_name + "ssociations" + end + + def template_name + self.template_dir + self.template_file_name + end + + end + end + end + end +end diff --git a/lib/manifest/local/view/profiler/column.rb b/lib/manifest/local/view/profiler/column.rb new file mode 100644 index 00000000..9a7dc0ad --- /dev/null +++ b/lib/manifest/local/view/profiler/column.rb @@ -0,0 +1,118 @@ +module Manifest + module View + module ProfilerModule + class Column + attr :profiler, :column_name + def initialize profiler, column_name + @profiler = profiler + @column_name = column_name + end + + def label + self.item.class.human_attribute_name(@column_name) + end + + def value + self.item.attributes[@column_name] + end + + def note + end + + def date? + case model_attribute_manifest.type + when 'datetime' + if self.value + true + else + false + end + else + false + end + end + + def note? + if self.model_attribute_source_manifest + case self.model_attribute_source_manifest.type + when 'magic_number' + true + when 'model' + false + else + false + end + else + false + end + end + + def select_item_name + self.model_attribute_source_manifest.select_item_name + end + + def item + @profiler.item + end + + def model_manifest + ::Manifest.manifest.models[@profiler.item_name] + end + + def model_attribute_manifest + self.model_manifest.attributes[@column_name] + end + + def model_attribute_source_manifest + self.model_attribute_manifest.source + end + + def template_dir + @profiler.template_dir + end + + def template_file_name + "column" + end + + def template_name + self.template_dir + self.template_file_name + end + + def value_template_dir + @profiler.template_dir + "column_value/" + end + + def value_template_file_name + if self.date? + 'date' + else + 'default' + end + end + + def value_template_name + self.value_template_dir + self.value_template_file_name + end + + def note_template_dir + @profiler.template_dir + "column_note/" + end + + def note_template_file_name + if self.note? + 'default' + else + 'none' + end + end + + def note_template_name + self.note_template_dir + self.note_template_file_name + end + + end + end + end +end + diff --git a/lib/manifest/local/view/profiler/header.rb b/lib/manifest/local/view/profiler/header.rb new file mode 100644 index 00000000..80a1d154 --- /dev/null +++ b/lib/manifest/local/view/profiler/header.rb @@ -0,0 +1,19 @@ +module Manifest + module View + module ProfilerModule + class Header + attr :profiler + def initialize profiler + @profiler = profiler + end + + def filer + ::Manifest::View::Filer.new @profiler.item_name, [@profiler.item], nil, @profiler.operators + end + + end + + end + end +end + diff --git a/lib/manifest/local/view/profiler/profiler.rb b/lib/manifest/local/view/profiler/profiler.rb deleted file mode 100644 index 1caab9fe..00000000 --- a/lib/manifest/local/view/profiler/profiler.rb +++ /dev/null @@ -1,116 +0,0 @@ - class ProfilerView - attr :filer_manifest, :item_name, :manifest, :filer_conf, - :symbol, :caption, :summary, :icon, :date, :edit - def initialize filer_manifest, items, operators, paginate - @filer_manifest = filer_manifest - @items = items - @file_items = @items.map {|item| - FileItem.new self, @filer_manifest - } - end - - def render view - end - - def model_name - @item_name - end - - def model - model_name.classify.constantize - end - - end - - class ProfilerManager - class Profiler - def initialize item_name, item, operators, conf, manifest - @item_name = item_name - @item = item - @operators = operators - @conf = conf - @manifest = manifest - - @lists = @manifest.profiler(@item_name).lists - @belongs_to_conf = @manifest.profiler(@item_name).belongs_to - @has_many_conf = @manifest.profiler(@item_name).has_many - @has_one_conf = @manifest.profiler(@item_name).has_one - end - - def modelize str - str.classify.constantize - end - - def header_filer - @manifest.filer_managers[@item_name].open @item_name, [@item], @operators, nil - end - - def each_column - @conf['columns'].each do |column_name| - column = Column.new @item_name, column_name, @item, @operators, @manifest - yield column - end - end - - def parent_item parent_model, model_belongs_to_conf - r = nil - id_column = model_belongs_to_conf['id_column'] - begin - r = parent_model.show(@item.attributes[id_column], @operators) - rescue ActiveRecord::RecordNotFound, ActiveRecord::Forbidden - end - r - end - - def each_belongs_to - @belongs_to_conf.each do |association_model_name| - model_belongs_to_conf = @manifest.model(@item_name).belongs_to[association_model_name] - parent_model = self.modelize association_model_name - parent = self.parent_item parent_model, model_belongs_to_conf - if parent - parent_filer = @manifest.filer_managers[parent_model.item_name].open parent_model.item_name, [parent], @operators, nil - yield parent_filer - end - end - end - - def each_has_many - @has_many_conf.each do |profiler_list_name| - raise "undefined lists for #{profiler_list_name} in #{@lists}\n" unless @lists[profiler_list_name] - model_name = @lists[profiler_list_name]['model_name'] - list_name = @lists[profiler_list_name]['list_name'] - raise "undefined has_many list for #{model_name}::#{list_name}\nconf:#{@controller_conf}\n" unless @manifest.list_managers[model_name] - list = @manifest.list_managers[model_name].open(list_name, 1, 3, @operators) - items = list.items @item -#p [model_name, list_name, @item, list.class, list.includes, list.where(@item )] - has_many_filer = @manifest.filer_managers[model_name].open model_name, items, @operators, nil - model = model_name.classify.constantize - more_url = "/#{model.table_name}/#{list_name}/#{@item.id}" - yield has_many_filer, more_url - end - end - - def each_has_one - @has_one_conf.each do |profiler_list_name| - raise "undefined lists for #{profiler_list_name} in #{@lists}\n" unless @lists[profiler_list_name] - model_name = @lists[profiler_list_name]['model_name'] - list_name = @lists[profiler_list_name]['list_name'] - raise "undefined has_one list for #{model_name}::#{list_name}\nconf:#{@controller_conf}\n" unless @manifest.list_managers[model_name] - list = @manifest.list_managers[model_name].open(list_name, 1, 1, @operators) - items = list.items @item - has_one_filer = @manifest.filer_managers[model_name].open model_name, items, @operators, nil - yield has_one_filer - end - end - - end - - def initialize profiler_manifest - @profiler_manifest = profiler_manifest - @item_name = @profiler_manifest.item_name - @manifest = profiler_manifest.manifest - @profiler_conf = @profiler_manifest.conf - end - - end - diff --git a/lib/manifest/manifest.rb b/lib/manifest/manifest.rb index a871faaf..a2da8f80 100644 --- a/lib/manifest/manifest.rb +++ b/lib/manifest/manifest.rb @@ -18,11 +18,11 @@ module Manifest @controllers = Controller.manager(self, @manifest['controllers']) @models = Model.manager(self, @manifest['models']) @locals = @manifest['locals'] + @lists = List.manager(self, @locals['lists']) @filers = Filer.manager(self, @locals['filers']) @profilers = Profiler.manager(self, @locals['profilers']) @forms = Form.base_manager(self, @locals['forms']) @forms.merge(Form.extend_manager(self, @locals['forms'])) - @lists = List.manager(self, @locals['lists']) @system_resources.init add_action end diff --git a/lib/manifest/model.rb b/lib/manifest/model.rb index c2eb4c50..256b4d1f 100644 --- a/lib/manifest/model.rb +++ b/lib/manifest/model.rb @@ -34,10 +34,7 @@ module Manifest @model_manifest['attributes'].each {|attribute_name, attribute_manifest| @attributes[attribute_name] = ModelModule::Attribute.new(self, attribute_name, attribute_manifest) } - @associations = {} - @model_manifest['associations'].each {|association_name, association_manifest| - @associations[association_name] = ModelModule::Association.new(self, association_name, association_manifest) - } + @associations = ModelModule::Association.new(self, @model_manifest['associations']) @lists = {} @model_manifest['lists'].each {|list_name, list_manifest| @lists[list_name] = ModelModule::ListFactory.factory(self, list_name, list_manifest) diff --git a/lib/manifest/model/association.rb b/lib/manifest/model/association.rb index 6a806b19..f21d0820 100644 --- a/lib/manifest/model/association.rb +++ b/lib/manifest/model/association.rb @@ -4,11 +4,11 @@ require_dependency "manifest/model/association/has_one" module Manifest module ModelModule class Association - attr :model, :association_name, :association_manifest, + include AssociationModule + attr :model, :association_manifest, :belongs_to, :has_many, :has_one - def initialize model, association_name, association_manifest + def initialize model, association_manifest @model = model - @association_name = association_name @association_manifest = association_manifest self.set_default self.init diff --git a/lib/manifest/model/association/belongs_to.rb b/lib/manifest/model/association/belongs_to.rb index e01eae1a..20f50e85 100644 --- a/lib/manifest/model/association/belongs_to.rb +++ b/lib/manifest/model/association/belongs_to.rb @@ -22,6 +22,10 @@ module Manifest @id_column = @belongs_to_manifest['id_column'] end + def model + ::Manifest.item_name_to_model @model_name + end + def association_name @association.association_name end diff --git a/lib/manifest/model/association/has_many.rb b/lib/manifest/model/association/has_many.rb index 1fddab93..ce1ee6d3 100644 --- a/lib/manifest/model/association/has_many.rb +++ b/lib/manifest/model/association/has_many.rb @@ -23,6 +23,10 @@ module Manifest @through = @has_many_manifest['through'] end + def model + ::Manifest.item_name_to_model @model_name + end + def association_name @association.association_name end diff --git a/lib/manifest/model/association/has_one.rb b/lib/manifest/model/association/has_one.rb index 6f4e8744..1e270574 100644 --- a/lib/manifest/model/association/has_one.rb +++ b/lib/manifest/model/association/has_one.rb @@ -22,6 +22,10 @@ module Manifest @foreign_key = @has_one_manifest['foreign_key'] end + def model + ::Manifest.item_name_to_model @model_name + end + def association_name @association.association_name end diff --git a/lib/manifest/model/attribute.rb b/lib/manifest/model/attribute.rb index 22f9d704..0d9ab3e6 100644 --- a/lib/manifest/model/attribute.rb +++ b/lib/manifest/model/attribute.rb @@ -4,7 +4,7 @@ module Manifest class Attribute include AttributeModule attr :model, :attribute_name, :attribute_manifest, - :primary_key, :rules, :source + :type, :primary_key, :rules, :source def initialize model, attribute_name, attribute_manifest @model = model @attribute_name = attribute_name @@ -20,6 +20,7 @@ module Manifest end def init + @type = @attribute_manifest['type'] @primary_key = @attribute_manifest['primary_key'] @rules = @attribute_manifest['rules'] if @attribute_manifest['source'] diff --git a/lib/manifest/model/list/filter.rb b/lib/manifest/model/list/filter.rb index e79ca01d..a72a54a6 100644 --- a/lib/manifest/model/list/filter.rb +++ b/lib/manifest/model/list/filter.rb @@ -2,7 +2,7 @@ module Manifest module ModelModule module ListModule class FilterList < Base - attr :filter_key + attr :filter_key, :filter_item_name def set_default super @@ -12,6 +12,7 @@ module Manifest def init super + @filter_item_name = @args['filter_item_name'] @filter_key = @args['filter_key'] end diff --git a/lib/manifest/model/list/through_filter.rb b/lib/manifest/model/list/through_filter.rb index 9149e37f..185bed69 100644 --- a/lib/manifest/model/list/through_filter.rb +++ b/lib/manifest/model/list/through_filter.rb @@ -2,7 +2,7 @@ module Manifest module ModelModule module ListModule class ThroughFilterList < FilterList - attr :list, :list_name, :list_manifest + attr :through def set_default super @@ -10,18 +10,7 @@ module Manifest def init super - return - @through = @list_list_conf['through'] - end - - def includes - {@through => {@from => {}} } - end - - def where filter_item - w = @model.list_where - w += ' and ' unless w.blank? - [w + @through + '.' + @filter_key + ' = ?', filter_item.id] + @through = @args['through'] end end diff --git a/lib/manifest/profiler.rb b/lib/manifest/profiler.rb index 1eb54ff6..e5555cbf 100644 --- a/lib/manifest/profiler.rb +++ b/lib/manifest/profiler.rb @@ -13,7 +13,7 @@ module Manifest end attr :profiler_manifest, :item_name, :manifest, - :columns, :lists, :associations + :column_names, :lists, :associations def initialize manifest, item_name, profiler_manifest @manifest = manifest @item_name = item_name @@ -23,13 +23,13 @@ module Manifest end def set_default - @profiler_manifest['columns'] ||= [] + @profiler_manifest['column_names'] ||= [] @profiler_manifest['lists'] ||= {} @profiler_manifest['associations'] ||= {} end def init - @columns = @profiler_manifest['columns'] + @column_names = @profiler_manifest['column_names'] @lists = {} @profiler_manifest['lists'].each {|list_name, list_manifest| @lists[list_name] = ProfilerModule::List.new(self, list_name, list_manifest) @@ -37,8 +37,8 @@ module Manifest @associations = ProfilerModule::Association.new(self, @profiler_manifest['associations']) end - def open item, operators - ProfilerView.new @item_name, item, operators, @profiler_conf, @manifest + def each_column + @column_names end end diff --git a/lib/manifest/profiler/association.rb b/lib/manifest/profiler/association.rb index c07fc206..3dc1cf07 100644 --- a/lib/manifest/profiler/association.rb +++ b/lib/manifest/profiler/association.rb @@ -39,7 +39,7 @@ module Manifest @profiler.model_name end - def model_manifest + def profiler_manifest @profiler.profiler_manifest end diff --git a/lib/manifest/profiler/association/belongs_to.rb b/lib/manifest/profiler/association/belongs_to.rb index bc052a62..a76c3a5c 100644 --- a/lib/manifest/profiler/association/belongs_to.rb +++ b/lib/manifest/profiler/association/belongs_to.rb @@ -16,6 +16,10 @@ module Manifest def init end + def model + ::Manifest::item_name_to_model @model_name + end + def association_name @association.association_name end diff --git a/lib/manifest/profiler/association/has_many.rb b/lib/manifest/profiler/association/has_many.rb index 200cf6c5..bc9553b0 100644 --- a/lib/manifest/profiler/association/has_many.rb +++ b/lib/manifest/profiler/association/has_many.rb @@ -2,10 +2,11 @@ module Manifest module ProfilerModule module AssociationModule class HasMany - attr :association, :list_name - def initialize association, list_name + attr :association, :profiler_list_name, + :model_name, :list_name, :list + def initialize association, profiler_list_name @association = association - @list_name = list_name + @profiler_list_name = profiler_list_name self.set_default self.init end @@ -14,12 +15,40 @@ module Manifest end def init + if list_manifest = self.profiler.lists[@profiler_list_name] + @model_name = list_manifest.model_name + @list_name = list_manifest.list_name + else + n = @profiler_list_name.split '.' + if n.size > 1 + @model_name = n[0] + @list_name = n[1] + else + raise "undefined list for profilers > #{self.profiler.item_name} > lists > #{@my_name}\n" unless @list_manifest['model_name'] + end + end + @my_list = ::Manifest.manifest.lists[@model_name] + raise "undefined my_list for profilers > #{self.profiler.item_name} > lists > #{@my_name} ... #{@model_name}\n" unless @my_list + @list = @my_list[@list_name] + raise "undefined list for profilers > #{self.profiler.item_name} > lists > #{@my_name} ... #{@list_name}\n" unless @list + end + + def model + ::Manifest::item_name_to_model @model_name end def association_name @association.association_name end + def profiler + @association.profiler + end + + def profiler_manifest + @association.profiler_manifest + end + end end diff --git a/lib/manifest/profiler/association/has_one.rb b/lib/manifest/profiler/association/has_one.rb index d35011e7..5e65622a 100644 --- a/lib/manifest/profiler/association/has_one.rb +++ b/lib/manifest/profiler/association/has_one.rb @@ -16,6 +16,10 @@ module Manifest def init end + def model + ::Manifest::item_name_to_model @model_name + end + def association_name @association.association_name end diff --git a/lib/manifest/profiler/list.rb b/lib/manifest/profiler/list.rb index b566af0a..f9adef7b 100644 --- a/lib/manifest/profiler/list.rb +++ b/lib/manifest/profiler/list.rb @@ -13,8 +13,8 @@ module Manifest end def set_default - list_manifest['model_name'] ||= {} - list_manifest['list_name'] ||= {} + raise "undefined model_name for profilers > #{self.profiler_name} > lists > #{@my_name}\n" unless @list_manifest['model_name'] + raise "undefined list_name for profilers > #{self.profiler_name} > lists > #{@my_name}\n" unless @list_manifest['list_name'] end def init @@ -26,7 +26,7 @@ module Manifest @profiler.item_name end - def filer_manifest + def profiler_manifest @profiler.profiler_manifest end diff --git a/public/manifest.json b/public/manifest.json index dc6a6a5e..7856fc90 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -21,8 +21,7 @@ } }, "show": { - "type": "show", - "name": "show" + "type": "show" }, "count": { "type": "count", @@ -55,6 +54,9 @@ "by_scroll": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -80,6 +82,9 @@ "by_author": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -114,6 +119,9 @@ "list_name": "play" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -139,6 +147,9 @@ "by_sheet": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -176,6 +187,9 @@ "list_name": "play" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -207,6 +221,9 @@ "by_panel": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -241,6 +258,9 @@ "by_speech_balloon_template": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -275,6 +295,9 @@ "by_author": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -303,6 +326,9 @@ "by_author": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -328,6 +354,9 @@ "by_writing_format": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -347,6 +376,9 @@ "list_name": "public_list" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -369,6 +401,9 @@ "by_author": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -397,6 +432,9 @@ "by_author": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -419,6 +457,9 @@ "list_name": "private_list" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -442,6 +483,9 @@ "by_artist": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -464,6 +508,9 @@ "list_name": "public_list" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -483,6 +530,9 @@ "by_system_picture": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -502,6 +552,9 @@ "list_name": "public_list" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -524,6 +577,9 @@ "by_system_picture": { "type": "list" }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -600,6 +656,9 @@ "list_name": "ground_colors" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -622,6 +681,9 @@ "list_name": "resource_pictures" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -638,6 +700,9 @@ "list_name": "public_list" } }, + "show": { + "type": "show" + }, "count": { "type": "count", "args": { @@ -1485,7 +1550,12 @@ "type": "private" }, "by_scroll": { - "type": "through_filter" + "type": "through_filter", + "args": { + "filter_item_name": "scroll", + "through": "scroll_panels", + "filter_key": "scroll_id" + } }, "by_sheet": { "type": "through_filter" @@ -3229,7 +3299,7 @@ "list_name": "by_scroll" } }, - "columns": [ + "column_names": [ "id", "title", "description", @@ -3889,10 +3959,6 @@ }, "system_picture": { "lists": { - "speech_balloon_templates.by_system_picture": { - "model_name": "speech_balloon_template", - "list_name": "by_system_picture" - }, "licenses.by_system_picture": { "model_name": "license", "list_name": "by_system_picture" @@ -3911,7 +3977,6 @@ "associations": { "belongs_to": [], "has_many": [ - "speech_balloon_templates.by_system_picture", "licenses.by_system_picture" ], "has_one": [] -- 2.11.0