履歴: ソフトウェア/rails/PaperTrail+ActiveScaffold
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 19 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2017/11/29 23:51:31 | ソフトウェア/rails/PaperTrail+ActiveScaffold 最新版 | 65,862 | +1 | -1 | 表示 | 表示中 | — |
| 2017/11/29 23:51:31 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 65,868 | +142 | -40 | 表示 | 差分 | 選択 |
| 2017/11/20 22:46:29 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 62,621 | +28 | -7 | 表示 | 差分 | 基準 |
| 2017/11/17 4:40:23 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 62,164 | +439 | -168 | 表示 | 差分 | 選択 |
| 2017/11/11 0:33:35 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 56,254 | +62 | -0 | 表示 | 差分 | 選択 |
| 2017/11/10 15:30:30 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 54,775 | +234 | -0 | 表示 | 差分 | 選択 |
| 2017/7/21 3:01:44 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 45,642 | +217 | -0 | 表示 | 差分 | 選択 |
| 2014/10/28 2:23:29 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,600 | +18 | -1 | 表示 | 差分 | 選択 |
| 2014/5/20 12:30:48 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,301 | +3 | -1 | 表示 | 差分 | 選択 |
| 2014/5/19 7:59:00 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,274 | +1 | -1 | 表示 | 差分 | 選択 |
| 2014/5/16 12:35:23 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,268 | +141 | -13 | 表示 | 差分 | 選択 |
| 2014/5/16 2:38:10 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 33,839 | +118 | -1 | 表示 | 差分 | 選択 |
| 2014/5/16 1:02:59 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 30,813 | +225 | -26 | 表示 | 差分 | 選択 |
| 2014/5/1 16:06:00 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 25,360 | +329 | -0 | 表示 | 差分 | 選択 |
| 2014/4/30 13:35:06 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 16,966 | +264 | -0 | 表示 | 差分 | 選択 |
| 2014/4/28 1:10:44 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 10,805 | +4 | -0 | 表示 | 差分 | 選択 |
| 2014/4/25 2:51:34 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 10,732 | +2 | -2 | 表示 | 差分 | 選択 |
| 2014/4/24 15:21:55 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 10,728 | +382 | -1 | 表示 | 差分 | 選択 |
| 2014/4/24 11:01:35 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 1,131 | — | — | 表示 | — | 選択 |
基準: ソフトウェア/rails/PaperTrail+ActiveScaffold (2017/11/20 22:46:29) → 比較: ソフトウェア/rails/PaperTrail+ActiveScaffold (2017/11/29 23:51:31) 最新版
@@ -1849,7 +1849,7 @@
#
# 2014.05.02 初期リリース
# 2014.05.16 build を実装した
- # 2017.11.21 Rails5 用に改訂
+ # 2017.11.29 Rails 5 用に改修 & route 定義だけで使えるようにした
#
module TrailedParanoidScaffold
@@ -1901,20 +1901,22 @@
conf.show.columns.add :created_at, :updated_at
conf.create.columns.exclude :histories, :deleted_at
conf.update.columns.exclude :histories, :deleted_at
- conf.list.columns.add :updated_at
+ conf.list.columns.exclude :deleted_at, :created_at, :updated_at
conf.action_links.add 'restore', :label => 'Restore', :type => :member,
:confirm => 'Are you sure you want to restore the record?',
:method => :put, :position => :false
conf.actions.exclude :deleted_records
- block.call(conf)
+ block.call(conf) if block
end
end
end
def self.included(base)
+
base.class_eval do
+
extend ClassMethods
-
+
# 削除を元に戻すアクション
def restore
do_restore
@@ -1978,7 +1980,8 @@
# histories の表示を "# 数字" にする
define_method("#{model_id}_histories_column") do |record, column|
- "# " + record.versions.size.to_s
+ ("# #{record.versions.size.to_s} @ #{l record.updated_at, format: :short}" +
+ ( record.versions.last.whodunnit ? "<br> by #{record.versions.last.whodunnit}" : '')).html_safe
end
end
end
@@ -2003,13 +2006,14 @@
# リストに表示する内容と順番を指定
conf.list.columns= [:item, :event, :created_at, :object_changes]
+ conf.list.sorting= { :created_at => :desc }
# 検索をしやすくする
conf.actions.exclude :search
conf.actions.add :field_search
- conf.field_search.columns = [:item_id,:event,:created_at]
+ conf.field_search.columns = [:event,:created_at,:object_changes]
- block.call(conf)
+ block.call(conf) if block
end
end
end
@@ -2020,11 +2024,6 @@
protected
- # 逆順で表示
- def custom_finder_options
- {reorder: "id DESC"}
- end
-
# 親クラスは削除済みのレコードも検索する
def nested_parent_record(crud = :read)
@nested_parent_record ||=
@@ -2082,37 +2081,71 @@
#
# の形で呼び出すことを想定している。
#
- def self.build(file, parent = ApplicationController, &block)
- file = File.expand_path(file).sub(/\.rb\z/,'')
- unless file =~ /([^\/]+?)(\/histories)?_(controller|helper)\z/
+ def self.build(file, parent = nil, &block)
+ file = File.expand_path(file).sub(/.*\/app\/(controllers|helpers)\//,'').sub(/\.rb\z/,'')
+ self.build_sub(file, parent, &block)
+ end
+
+ # admin/models_controller.rb
+ # admin/models_helper.rb
+ # admin/model/histories_controller.rb
+ # admin/model/histories_helper.rb
+ # のような文字列を渡す
+ def self.build_sub(file, parent = nil, &block)
+ unless file =~ /([^\/]+)(\/histories)?_(controller|helper)\z/
throw "unexpected file name #{file}"
end
# 必要な情報をファイル名から取り出す
- model = $1 # "model" or "models"
- histories = $2 # "histories" or nil
controller_or_helper = $3 # "controller" or "helper"
+ histories = $2 # "histories" or nil
+ model = $1 # "model"
model = model.singularize unless histories
-
- *path, name = file.
- sub(/.*\/app\/#{controller_or_helper}s\//,'').
- split(File::Separator).
- map{|s| s.classify}
- # 無名クラス・モジュールを作成
- if controller_or_helper == "controller"
- new_class = Class.new(parent)
- else
- new_class = Module.new()
- end
+ *path, name = file.split(File::Separator).map{|s| s.classify}
# Admin::ModelsController
# Admin::ModelsHelper
# Admin::Model::HistoriesController
# Admin::Model::HistoriesHelper
- # といった定数に結びつける
- path.reduce(Object){|obj, p| obj.const_get(p, false)}.const_set name, new_class
-
+ # といった定数に結びつけたい
+ # このとき Controller は AdminController を継承する
+
+ # そのために Admin や AdminController のようなモジュールや
+ # クラスを定義する
+
+ # c = controller, n = namespace
+ c, n = path.reduce([ApplicationController, Object]){|list, p|
+ c, n = list
+
+ if controller_or_helper == "controller"
+ c = if Object.const_defined? (p + 'Controller'), false
+ Object.const_get (p + 'Controller'), false
+ else
+ Object.const_set p + 'Controller', Class.new(c)
+ end
+ end
+
+ n = if n.const_defined? p, false
+ n.const_get(p, false)
+ else
+ n.const_set p, Module.new()
+ end
+ [c, n]
+ }
+
+ # ApplicationController を参照すると Helper が読み込まれるので
+ # 必要な Controller, Helper をその前に登録する
+
+ if controller_or_helper == "controller"
+ new_class = Class.new(c)
+ else
+ new_class = Module.new()
+ end
+
+ #
+ n.const_set name, new_class
+
# 新しく作ったクラス・モジュールに必要な機能を追加
new_class.class_eval do
# TrailedParanoidScaffold::Controller
@@ -2164,18 +2197,78 @@
end
# 与えられたブロックをクラス・モジュールのスコープで評価
- new_class.class_eval &block
+ new_class.class_eval &block if block
end
end
+ # 必要な Model / Controller / Helper が定義されていなければ定義する
+ def self.build_all(path)
+ path =~ /^\/((.*)\/)?([^\/]+)$/
+ model = $3
+ path = $1 || ''
+
+ # Model::History
+ TrailedParanoidScaffold::unless_defined(model + '/history') do |name|
+ model.classify.constantize.class_eval do
+ include TrailedParanoidScaffold::Model
+ end
+ end
+
+ # Model::HistoriesHelper
+ unless_defined(path + model + '/histories_helper') do |name|
+ TrailedParanoidScaffold.build_sub(name) { }
+ end
+
+ # ModelsHelper
+ TrailedParanoidScaffold::unless_defined(path + model.pluralize + '_helper') do |name|
+ TrailedParanoidScaffold.build_sub(name) { }
+ end
+
+ # ModelsController
+ unless_defined(model.pluralize + '_controller') do |name|
+ TrailedParanoidScaffold.build_sub(path + name) do |conf|
+ # 自動的には読み込まれないため手動でヘルパーを読み込む
+ add_template_helper (path + model.pluralize + '_helper').classify.constantize
+
+ # active_scaffold を呼ぶ
+ active_scaffold @active_scaffold_model
+ end
+ end
+
+ # Model::HistoriesController
+ unless_defined(model + '/histories_controller') do |name|
+ TrailedParanoidScaffold.build_sub(path + name) do |conf|
+ # 自動的には読み込まれないため手動でヘルパーを読み込む
+ add_template_helper (path + model + '/histories_helper').classify.constantize
+
+ # active_scaffold を呼ぶ
+ active_scaffold @active_scaffold_model
+ end
+ end
+ end
+
+ # id.classify で指定された定数が見つからなければ与えられたブロックを実行する
+ # ブロックには指定された定数が渡される
+ def self.unless_defined(id)
+ defined = false
+ begin
+ id.classify.constantize
+ # was defined
+ defined = true
+ rescue NameError
+ # was not defined
+ end
+
+ yield id unless defined
+ end
+
end
module ActionDispatch
module Routing
class Mapper
module Base
-
# trails_paranoid_scaffold 用の as_routes
#
# options には、
@@ -2209,7 +2302,9 @@
resources :histories, histories_resources do
as_routes histories_routes
end
-
+
+ # 必要な Controller / Helper を定義する
+ TrailedParanoidScaffold::build_all(( @scope[:path] || '' ) + '/' + @scope[:controller].singularize)
end
end
@@ -2217,11 +2312,7 @@
end
end
-app/models/test.rb
- LANG:ruby
- class Test < ApplicationRecord
- include TrailedParanoidScaffold::Model
- end
+paranoid のためのカラムを追加
LANG:console
$ rails generate migration AddDeletedAtToTests deleted_at:datetime:index
@@ -2234,28 +2325,40 @@
as_tpsf_routes
end
+これだけで動くようにした。
+
+History や Controller, Helper は定義されていなければ勝手に定義する。
+
+** Controller や Helper に手を加えたい場合 [#o890da96]
+
app/controllers/tests_controller.rb
LANG:ruby
TrailedParanoidScaffold::build(__FILE__) do
active_scaffold @active_scaffold_model do |conf|
+ # ここに active_scaffold の column 定義など
end
+ # ここに追加の action など
end
app/helpers/tests_helper.rb
LANG:ruby
TrailedParanoidScaffold::build(__FILE__) do
+ # ここに追加の設定を
end
app/controllers/test/histories_controller.rb
LANG:ruby
TrailedParanoidScaffold::build(__FILE__) do
active_scaffold @active_scaffold_model do |conf|
+ # ここに active_scaffold の column 定義など
end
+ # ここに追加の action など
end
app/helpers/test/histories_helper.rb
LANG:ruby
TrailedParanoidScaffold::build(__FILE__) do
+ # ここに追加の設定を
end
@@ -2283,5 +2386,4 @@
* 質問・コメント [#t616f744]
-#article_kcaptcha
-
+#article();