rows_controller 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/rows_controller.rb +5 -2
- data/app/controllers/rows_controller.rb.bak +91 -0
- data/app/controllers/rows_ext_controller.rb +4 -1
- data/app/controllers/rows_ext_controller.rb.bak +18 -0
- data/lib/rows/engine.rb +2 -0
- data/lib/rows/engine.rb.bak +4 -0
- data/lib/rows/model.rb +6 -4
- data/lib/rows/model.rb.bak +32 -0
- data/lib/rows/resources.rb +8 -3
- data/lib/rows/resources.rb.bak +80 -0
- data/lib/rows/utils.rb +6 -4
- data/lib/rows/utils.rb.bak +20 -0
- data/lib/rows/version.rb +4 -1
- data/lib/rows/version.rb.bak +7 -0
- data/lib/rows_controller.rb +4 -2
- data/lib/rows_controller.rb.bak +8 -0
- metadata +21 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ddc0bace86fc0866651fa9a9a7db8e2680954dfca498d1e166ced15c1ad97a7
|
4
|
+
data.tar.gz: 6c1302388c207f4b558754bbccb0fbfd437623cd807d98008ff6a8f8d51e5bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 629d50095b51ab86a72dad57ff842c26c98b08dc58b5237431c5df736d7bc19765adb5cc31eae662b2a15296e9beeb143ec6c94cfe7fb5e6c07e8ed07634ef1e
|
7
|
+
data.tar.gz: 65dd1a78bb87ded0a88abe36524d199aff6db89fe00fea93bebf28188614b85f380b89022f248454b2d86b42f26a5d1b609c47e0cd196041b51d48c1c95890cf
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rows/resources'
|
2
4
|
require 'rows/model'
|
3
5
|
require 'rows/utils'
|
@@ -56,7 +58,8 @@ class RowsController < ApplicationController
|
|
56
58
|
def destroy
|
57
59
|
set_resource
|
58
60
|
resource_destroy
|
59
|
-
|
61
|
+
msg = t('ui.destroyed', model: model_name).html_safe
|
62
|
+
flash[:notice] = msg unless request.xhr?
|
60
63
|
respond_to do |format|
|
61
64
|
format.html { redirect_to action: :index }
|
62
65
|
format.js { render template: 'rows/destroy', layout: false }
|
@@ -67,7 +70,7 @@ class RowsController < ApplicationController
|
|
67
70
|
private
|
68
71
|
def create_update(which, msg)
|
69
72
|
respond_to do |format|
|
70
|
-
if
|
73
|
+
if send(which)
|
71
74
|
format.html {
|
72
75
|
flash[:notice] = t(msg, scope: :ui, model: model_name,
|
73
76
|
default: "%{model} was successfully #{msg}.").html_safe
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rows/resources'
|
2
|
+
require 'rows/model'
|
3
|
+
require 'rows/utils'
|
4
|
+
|
5
|
+
class RowsController < ApplicationController
|
6
|
+
helper_method :set_resource, :set_resources, :resource, :resources
|
7
|
+
helper_method :resource_columns, :resource_format
|
8
|
+
helper_method :model_class, :model_name
|
9
|
+
helper_method :model_symbol, :model_symbol_plural
|
10
|
+
|
11
|
+
include Rows::Model
|
12
|
+
include Rows::Resources
|
13
|
+
include Rows::Utils
|
14
|
+
|
15
|
+
def self.model_class(model_class = nil)
|
16
|
+
@_model_class ||= nil
|
17
|
+
unless model_class.nil?
|
18
|
+
@_model_class = model_class
|
19
|
+
@_model_class = model_class.constantize if model_class.is_a?(String)
|
20
|
+
end
|
21
|
+
@_model_class
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /:resources[.json]
|
25
|
+
def index
|
26
|
+
set_resources
|
27
|
+
end
|
28
|
+
|
29
|
+
# GET /:resource/:id[.json]
|
30
|
+
def show
|
31
|
+
set_resource
|
32
|
+
end
|
33
|
+
|
34
|
+
# GET /:resource/new
|
35
|
+
def new
|
36
|
+
resource_new
|
37
|
+
end
|
38
|
+
|
39
|
+
# GET /:resource/:id/edit
|
40
|
+
def edit
|
41
|
+
set_resource
|
42
|
+
end
|
43
|
+
|
44
|
+
# POST /:resources[.json]
|
45
|
+
def create
|
46
|
+
create_update(:resource_create, 'created')
|
47
|
+
end
|
48
|
+
|
49
|
+
# PATCH/PUT /:resources/:id[.json]
|
50
|
+
def update
|
51
|
+
set_resource
|
52
|
+
create_update(:resource_update, 'updated')
|
53
|
+
end
|
54
|
+
|
55
|
+
# DELETE /:resources/:id[.json]
|
56
|
+
def destroy
|
57
|
+
set_resource
|
58
|
+
resource_destroy
|
59
|
+
flash[:notice] = t('ui.destroyed', model: model_name).html_safe unless request.xhr?
|
60
|
+
respond_to do |format|
|
61
|
+
format.html { redirect_to action: :index }
|
62
|
+
format.js { render template: 'rows/destroy', layout: false }
|
63
|
+
format.json { head :no_content }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def create_update(which, msg)
|
69
|
+
respond_to do |format|
|
70
|
+
if self.send(which)
|
71
|
+
format.html {
|
72
|
+
flash[:notice] = t(msg, scope: :ui, model: model_name,
|
73
|
+
default: "%{model} was successfully #{msg}.").html_safe
|
74
|
+
if params[:commit] == 'OK'
|
75
|
+
redirect_to action: :index
|
76
|
+
else
|
77
|
+
redirect_to action: 'edit', id: resource.id
|
78
|
+
end
|
79
|
+
}
|
80
|
+
format.json { render action: 'show',
|
81
|
+
status: msg == 'created' ? :created : :ok,
|
82
|
+
location: resource }
|
83
|
+
else ## failed
|
84
|
+
format.html { render action: msg == 'created' ? :new : :edit }
|
85
|
+
format.json { render json: resource.errors,
|
86
|
+
status: :unprocessable_entity }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Extensions
|
1
4
|
class RowsExtController < RowsController
|
2
5
|
|
3
6
|
def copy
|
4
7
|
set_resource resource.dup
|
5
8
|
resource.id = nil
|
6
9
|
respond_to do |format|
|
7
|
-
format.html { render :
|
10
|
+
format.html { render action: :new }
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class RowsExtController < RowsController
|
2
|
+
|
3
|
+
def copy
|
4
|
+
set_resource resource.dup
|
5
|
+
resource.id = nil
|
6
|
+
respond_to do |format|
|
7
|
+
format.html { render :action => :new }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def multi_deletion
|
12
|
+
items = params[:multi_tick] || []
|
13
|
+
items -= ['']
|
14
|
+
items.map { |id| model_class.find_by_id(id.to_i).destroy }
|
15
|
+
redirect_to action: :index
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/rows/engine.rb
CHANGED
data/lib/rows/model.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rows::Model
|
2
4
|
|
3
5
|
def model_class
|
4
|
-
@_model_class
|
5
|
-
|
6
|
+
@_model_class ||= self.class.model_class ||
|
7
|
+
params[:controller].singularize.camelize.constantize
|
6
8
|
end
|
7
9
|
|
8
10
|
if Rails::VERSION::MAJOR > 3
|
9
11
|
def model_name
|
10
|
-
@_model_name
|
12
|
+
@_model_name ||= model_class.model_name.name
|
11
13
|
end
|
12
14
|
|
13
15
|
def model_symbol
|
@@ -19,7 +21,7 @@ module Rows::Model
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def model_symbol
|
22
|
-
@_model_symbol ||= model_name.underscore.gsub(
|
24
|
+
@_model_symbol ||= model_name.underscore.gsub(%r{/}, '_')
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rows::Model
|
4
|
+
|
5
|
+
def model_class
|
6
|
+
@_model_class ||= self.class.model_class ||
|
7
|
+
params[:controller].singularize.camelize.constantize
|
8
|
+
end
|
9
|
+
|
10
|
+
if Rails::VERSION::MAJOR > 3
|
11
|
+
def model_name
|
12
|
+
@_model_name ||= model_class.model_name.name
|
13
|
+
end
|
14
|
+
|
15
|
+
def model_symbol
|
16
|
+
@_model_symbol ||= model_class.model_name.singular
|
17
|
+
end
|
18
|
+
else
|
19
|
+
def model_name
|
20
|
+
@_model_name ||= model_class.name
|
21
|
+
end
|
22
|
+
|
23
|
+
def model_symbol
|
24
|
+
@_model_symbol ||= model_name.underscore.gsub( %r{/}, '_' )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def model_symbol_plural
|
29
|
+
@_model_symbol_plural ||= model_symbol.pluralize
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/rows/resources.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rows::Resources
|
2
4
|
|
3
5
|
def set_resources(rows = nil)
|
@@ -52,14 +54,17 @@ module Rows::Resources
|
|
52
54
|
def resource_columns
|
53
55
|
return model_class.column_headers if model_class.respond_to?(:column_headers)
|
54
56
|
return ['to_s'] unless model_class.respond_to?(:content_columns)
|
55
|
-
|
57
|
+
|
58
|
+
# ['id'] + model_class.content_columns.collect { |c| c.name }
|
59
|
+
['id'] + model_class.content_columns.collect(&:name)
|
56
60
|
end
|
57
61
|
|
58
62
|
def resource_whitelist
|
59
63
|
raise "RowsController requires private method 'resource_whitelist' in controller <#{params[:controller]}>"
|
60
64
|
end
|
61
65
|
|
62
|
-
# Never trust parameters from the scary internet, only allow the
|
66
|
+
# Never trust parameters from the scary internet, only allow the
|
67
|
+
# white list through.
|
63
68
|
def resource_params
|
64
69
|
permits = resource_whitelist
|
65
70
|
if params.respond_to?(:require)
|
@@ -68,7 +73,7 @@ module Rows::Resources
|
|
68
73
|
pars = params[model_symbol] || {}
|
69
74
|
pars.keys.each { |x|
|
70
75
|
x = x.to_sym
|
71
|
-
|
76
|
+
unless permits.include?(x) || permits.include?({ x => [] })
|
72
77
|
pars.delete(x)
|
73
78
|
p "** WARNING: model <#{model_name}> dropping params <#{x}>"
|
74
79
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Rows::Resources
|
2
|
+
|
3
|
+
def set_resources(rows = nil)
|
4
|
+
rows ||= model_class.all
|
5
|
+
instance_variable_set("@#{model_symbol_plural}", rows)
|
6
|
+
@rows = rows
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_resource(row = nil)
|
10
|
+
row ||= model_class.find_by_id(params[:id].to_i)
|
11
|
+
instance_variable_set("@#{model_symbol}", row)
|
12
|
+
@row = row
|
13
|
+
end
|
14
|
+
|
15
|
+
def resources
|
16
|
+
@rows ||= set_resources
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource
|
20
|
+
@row ||= set_resource
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
# low level resource methods
|
25
|
+
# can be monkey patched
|
26
|
+
def resource_new
|
27
|
+
if params[model_symbol]
|
28
|
+
set_resource model_class.new(resource_params)
|
29
|
+
else
|
30
|
+
set_resource model_class.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def resource_create
|
35
|
+
resource_new
|
36
|
+
resource.save
|
37
|
+
end
|
38
|
+
|
39
|
+
def resource_update
|
40
|
+
if Rails::VERSION::MAJOR >= 4
|
41
|
+
# return true unless params[model_symbol]
|
42
|
+
resource.update(resource_params)
|
43
|
+
else
|
44
|
+
resource.update_attributes(resource_params)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def resource_destroy
|
49
|
+
resource.destroy
|
50
|
+
end
|
51
|
+
|
52
|
+
def resource_columns
|
53
|
+
return model_class.column_headers if model_class.respond_to?(:column_headers)
|
54
|
+
return ['to_s'] unless model_class.respond_to?(:content_columns)
|
55
|
+
['id'] + model_class.content_columns.collect{|c| c.name }
|
56
|
+
end
|
57
|
+
|
58
|
+
def resource_whitelist
|
59
|
+
raise "RowsController requires private method 'resource_whitelist' in controller <#{params[:controller]}>"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
63
|
+
def resource_params
|
64
|
+
permits = resource_whitelist
|
65
|
+
if params.respond_to?(:require)
|
66
|
+
params.require(model_symbol).permit(permits)
|
67
|
+
else
|
68
|
+
pars = params[model_symbol] || {}
|
69
|
+
pars.keys.each { |x|
|
70
|
+
x = x.to_sym
|
71
|
+
unless permits.include?(x) || permits.include?({x => []})
|
72
|
+
pars.delete(x)
|
73
|
+
p "** WARNING: model <#{model_name}> dropping params <#{x}>"
|
74
|
+
end
|
75
|
+
}
|
76
|
+
pars
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/lib/rows/utils.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rows::Utils
|
2
4
|
|
3
5
|
# formatting
|
4
6
|
def resource_format(x)
|
5
7
|
return '--'.html_safe if x.nil?
|
6
8
|
bool = x.class == Time || x.class == Date || x.class == DateTime ||
|
7
|
-
|
9
|
+
x.class == ActiveSupport::TimeWithZone
|
8
10
|
return x.strftime('%d.%m.%Y').html_safe if bool
|
9
11
|
# return I18n.l(x) if bool
|
10
12
|
# return x.to_s.html_safe if x.class == Fixnum
|
11
|
-
return x.to_s.html_safe if x.
|
13
|
+
return x.to_s.html_safe if x.is_a?(Integer)
|
12
14
|
return 'X'.html_safe if x.class == TrueClass
|
13
15
|
return ' '.html_safe if x.class == FalseClass
|
14
16
|
return x.call if x.class == Proc
|
15
17
|
return '---'.html_safe if x.empty?
|
16
|
-
|
17
|
-
|
18
|
+
|
19
|
+
x.to_s.gsub(/\r*\n/, '<br/>')
|
18
20
|
end
|
19
21
|
|
20
22
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rows::Utils
|
2
|
+
|
3
|
+
# formatting
|
4
|
+
def resource_format(x)
|
5
|
+
return '--'.html_safe if x.nil?
|
6
|
+
bool = x.class == Time || x.class == Date || x.class == DateTime ||
|
7
|
+
x.class == ActiveSupport::TimeWithZone
|
8
|
+
return x.strftime('%d.%m.%Y').html_safe if bool
|
9
|
+
# return I18n.l(x) if bool
|
10
|
+
# return x.to_s.html_safe if x.class == Fixnum
|
11
|
+
return x.to_s.html_safe if x.kind_of?(Integer)
|
12
|
+
return 'X'.html_safe if x.class == TrueClass
|
13
|
+
return ' '.html_safe if x.class == FalseClass
|
14
|
+
return x.call if x.class == Proc
|
15
|
+
return '---'.html_safe if x.empty?
|
16
|
+
str = x.to_s
|
17
|
+
return str.gsub(/\r*\n/, '<br/>')
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/rows/version.rb
CHANGED
data/lib/rows_controller.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rows/engine'
|
2
4
|
|
3
5
|
module Rows
|
4
6
|
end
|
5
7
|
|
6
|
-
I18n.load_path << File.expand_path('
|
7
|
-
I18n.load_path << File.expand_path('
|
8
|
+
I18n.load_path << File.expand_path('rows/locales/en.yml', __dir__)
|
9
|
+
I18n.load_path << File.expand_path('rows/locales/de.yml', __dir__)
|
8
10
|
I18n.reload!
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rows_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: appraisal
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12'
|
55
55
|
description: YourController < RowsController ( < ApplicationController).
|
56
56
|
email:
|
57
57
|
- dittmar.krall@matique.de
|
@@ -62,7 +62,9 @@ files:
|
|
62
62
|
- MIT-LICENSE
|
63
63
|
- README.md
|
64
64
|
- app/controllers/rows_controller.rb
|
65
|
+
- app/controllers/rows_controller.rb.bak
|
65
66
|
- app/controllers/rows_ext_controller.rb
|
67
|
+
- app/controllers/rows_ext_controller.rb.bak
|
66
68
|
- app/views/rows/_form.slim
|
67
69
|
- app/views/rows/_list.slim
|
68
70
|
- app/views/rows/_list_footer.slim
|
@@ -79,13 +81,19 @@ files:
|
|
79
81
|
- app/views/shared/_error_explanation.slim
|
80
82
|
- app/views/shared/_show_flash.slim
|
81
83
|
- lib/rows/engine.rb
|
84
|
+
- lib/rows/engine.rb.bak
|
82
85
|
- lib/rows/locales/de.yml
|
83
86
|
- lib/rows/locales/en.yml
|
84
87
|
- lib/rows/model.rb
|
88
|
+
- lib/rows/model.rb.bak
|
85
89
|
- lib/rows/resources.rb
|
90
|
+
- lib/rows/resources.rb.bak
|
86
91
|
- lib/rows/utils.rb
|
92
|
+
- lib/rows/utils.rb.bak
|
87
93
|
- lib/rows/version.rb
|
94
|
+
- lib/rows/version.rb.bak
|
88
95
|
- lib/rows_controller.rb
|
96
|
+
- lib/rows_controller.rb.bak
|
89
97
|
homepage: http://matique.de
|
90
98
|
licenses:
|
91
99
|
- MIT
|