rows_controller 2.2.2 → 3.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ddc0bace86fc0866651fa9a9a7db8e2680954dfca498d1e166ced15c1ad97a7
4
- data.tar.gz: 6c1302388c207f4b558754bbccb0fbfd437623cd807d98008ff6a8f8d51e5bcb
3
+ metadata.gz: 9414a13edbb916cc607c39536a62b3642ada61cee3c0cb26361fa759b192acfa
4
+ data.tar.gz: 615a5cf379ea71ae26ec8904ac3221712e45670efcd6a5e3cd303b67be835738
5
5
  SHA512:
6
- metadata.gz: 629d50095b51ab86a72dad57ff842c26c98b08dc58b5237431c5df736d7bc19765adb5cc31eae662b2a15296e9beeb143ec6c94cfe7fb5e6c07e8ed07634ef1e
7
- data.tar.gz: 65dd1a78bb87ded0a88abe36524d199aff6db89fe00fea93bebf28188614b85f380b89022f248454b2d86b42f26a5d1b609c47e0cd196041b51d48c1c95890cf
6
+ metadata.gz: 32f61e6e683933e0d81c87127a9bf9beaf24bb611f68c051974f65b3b830ee9ec5cbfc3c38e1632206422277befa6cd1511c2334f63c6042d2a4124e098d5fc9
7
+ data.tar.gz: 7c4ae08f41e3c196a7adea824b674cf3d4bed5883ff24377aacd7d76ed4a209ea598e28c9a1dc2bc77b16c9b68758a8fc0176bd627c15e093a9d4393b9b82051
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2009-2018 Dittmar Krall http://matique.de
1
+ Copyright (c) 2012-2021 Dittmar Krall - www.matique.com
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  RowsController
2
2
  ==============
3
3
  [![Gem Version](https://badge.fury.io/rb/rows_controller.svg)](https://badge.fury.io/rb/rows_controller)
4
- [![Build Status](https://travis-ci.org/matique/rows_controller.png?branch=master)](https://travis-ci.org/matique/rows_controller)
5
4
 
6
5
  DRYs Rails controllers. Imagine replacing that @order by 'resource' in the
7
6
  controllers/views and, imho, an area for DRYing appears.
@@ -26,8 +25,8 @@ use:
26
25
 
27
26
  I.e. RowsController defines all the usual methods (index, show, edit,...).
28
27
 
29
- The methods may be redefined in OrdersController overwriting the
30
- methods from RowsController.
28
+ The methods may be redefined in OrdersController
29
+ (overwrites methods from RowsController).
31
30
 
32
31
  Low level methods like 'resources' may be redefined as well.
33
32
  An example:
@@ -70,6 +69,12 @@ be changed by e.g.:
70
69
  The model class can be retrieved with the helper model_class.
71
70
 
72
71
 
72
+ Rails 6
73
+ -------
74
+
75
+ This gem is intended for Rails 6.
76
+ Older Rails versions may use "gem 'rows_controller', '= 2.2.2'".
77
+
73
78
  Rails 5
74
79
  -------
75
80
 
@@ -118,7 +123,7 @@ As usual:
118
123
 
119
124
  gem 'rows_controller' # in Gemfile
120
125
  bundle
121
- ( cd spec/dummy; rake db:create db:migrate )
126
+ ( cd spec/dummy; rake db:create db:migrate ) # not required for Rails 6
122
127
  rake
123
128
 
124
129
 
@@ -131,4 +136,4 @@ Look for:
131
136
  - inherited_resources
132
137
  - decent_exposure
133
138
 
134
- Copyright (c) 2009-2017 [Dittmar Krall], released under the MIT license.
139
+ Copyright (c) 2009-2020 [Dittmar Krall], released under the MIT license.
@@ -77,7 +77,7 @@ class RowsController < ApplicationController
77
77
  if params[:commit] == 'OK'
78
78
  redirect_to action: :index
79
79
  else
80
- redirect_to action: 'edit', id: resource.id
80
+ redirect_to action: 'edit', id: resource.id
81
81
  end
82
82
  }
83
83
  format.json { render action: 'show',
@@ -3,6 +3,7 @@ ruby:
3
3
  # Column :multi_selection generates a check_box
4
4
 
5
5
  cnt = 0
6
+ odd_even = %w[odd even]
6
7
 
7
8
  table.rows-list
8
9
  thead
@@ -12,7 +13,7 @@ table.rows-list
12
13
  tbody
13
14
  - resources.each do |resource|
14
15
  - cnt += 1
15
- tr id="row_#{resource.id}" class="#{%w{odd even}.at(cnt % 2)}"
16
+ tr id="row_#{resource.id}" class="#{odd_even.at(cnt % 2)}"
16
17
  = render 'list_row', resource: resource, columns: columns
17
18
  td
18
19
  = render 'row_buttons', row: resource
@@ -1,5 +1,5 @@
1
1
  / Default list footer presenting a 'Create' button linked to action new.
2
2
  / May be overwriten for e.g. pagination
3
3
 
4
- div.list-footer
4
+ .list-footer
5
5
  = link_to t('button.create').html_safe, url_for(action: :new), class: 'button'
@@ -4,4 +4,3 @@
4
4
 
5
5
  - columns.each do |column|
6
6
  th = column == :multi_selection ? '' : t("header.#{column}")
7
-
@@ -1,14 +1,14 @@
1
1
  ruby:
2
2
  # Fills the last column of the list with "buttons".
3
3
  # Requires row current_controller (supplied by Rails)
4
- if defined?(current_controller)
5
- url = "/#{current_controller}/#{row.id}"
6
- else
7
- url = url_for row
8
- end
4
+ url = if defined?(current_controller)
5
+ "/#{current_controller}/#{row.id}"
6
+ else
7
+ url_for row
8
+ end
9
9
 
10
- = link_to t('button.show').html_safe, url
11
- = link_to t('button.edit').html_safe, url + '/edit'
10
+ = link_to t('button.show').html_safe, url
11
+ = link_to t('button.edit').html_safe, "#{url}/edit"
12
12
  = link_to t('button.delete').html_safe, url,
13
13
  remote: true,
14
- data: { confirm: 'Are you sure?' }, method: :delete
14
+ data: {confirm: 'Are you sure?'}, method: :delete
@@ -10,7 +10,7 @@ ruby:
10
10
  left ||= nil
11
11
  right ||= nil
12
12
 
13
- div.rows-submit style="width:100%"
13
+ .rows-submit style="width:100%"
14
14
  input style="display:none" type="submit" name="commit" value="OK"
15
15
  p style="float:left"
16
16
  = render '/rows/submit_part', content: :submit_left, names: left
@@ -4,7 +4,8 @@ ruby:
4
4
  # partial 'form' template
5
5
 
6
6
  content_for(:submit_left) {
7
- link_to t('button.back').html_safe, "/#{controller_name}", class: 'button' }
7
+ link_to t('button.back').html_safe, "/#{controller_name}", class: 'button'
8
+ }
8
9
 
9
10
  fieldset class="wide mask" id=model_symbol
10
11
  legend = t('ui.editing', model: model_name).html_safe
@@ -14,4 +15,4 @@ fieldset class="wide mask" id=model_symbol
14
15
  /"/#{controller_name}/update/#{@row.id}"
15
16
  = form_for resource, url: "/#{controller_name}/#{@row.id}", html: {multipart: @multipart} do |f|
16
17
  = render 'form', f: f
17
- = render '/rows/submit', right: ['update', 'OK']
18
+ = render '/rows/submit', right: %w[update OK]
@@ -1,8 +1,8 @@
1
- - # Template for RowsController (index)
2
- - # Requires resources model_name resource_columns
1
+ / Template for RowsController (index)
2
+ / Requires resources model_name resource_columns
3
3
 
4
- - if resources.length > 0
5
- h1 = t('ui.listing', model: model_name).html_safe
4
+ - if resources.length.positive?
5
+ h1 = t('ui.listing', model: model_name).html_safe
6
6
  = render '/rows/list', resources: resources, columns: resource_columns
7
7
  - else
8
8
  h1 = t('ui.empty_list', model: model_name).html_safe
@@ -4,7 +4,8 @@ ruby:
4
4
  # partial 'form' template
5
5
 
6
6
  content_for(:submit_left) {
7
- link_to t('button.back').html_safe, "/#{controller_name}", class: 'button' }
7
+ link_to t('button.back').html_safe, "/#{controller_name}", class: 'button'
8
+ }
8
9
 
9
10
  fieldset.wide class="mask" id=model_symbol
10
11
  legend = t('ui.new', model: model_name).html_safe
@@ -13,4 +14,4 @@ fieldset.wide class="mask" id=model_symbol
13
14
  - @multipart ||= false
14
15
  = form_for resource, html: {multipart: @multipart} do |f|
15
16
  = render 'form', f: f
16
- = render '/rows/submit', right: ['create', 'OK']
17
+ = render '/rows/submit', right: %w[create OK]
@@ -4,9 +4,11 @@ ruby:
4
4
  # partial 'form' template
5
5
 
6
6
  content_for(:submit_left) {
7
- link_to t('button.back').html_safe, url_for(action: :index), class: 'button' }
7
+ link_to t('button.back').html_safe, url_for(action: :index), class: 'button'
8
+ }
8
9
  content_for(:submit_right) {
9
- link_to t('button.edit').html_safe, url_for(action: :edit), class: 'button' }
10
+ link_to t('button.edit').html_safe, url_for(action: :edit), class: 'button'
11
+ }
10
12
 
11
13
  fieldset.show class="wide mask" id=model_symbol
12
14
  legend = t('ui.showing', model: model_name).html_safe
@@ -1,9 +1,9 @@
1
1
  / # Generates error messages
2
2
  / # requires resource
3
3
 
4
- - if resource && resource.respond_to?(:errors) && resource.errors.any?
5
- div#error_explanation
6
- h2 #{pluralize(resource.errors.count, "error")} prohibited this template from being saved:
4
+ - if resource.respond_to?(:errors) && resource.errors.any?
5
+ #error_explanation
6
+ h2 #{pluralize(resource.errors.count, 'error')} prohibited this template from being saved:
7
7
 
8
8
  ul
9
9
  - resource.errors.full_messages.each do |msg|
data/lib/rows/engine.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: true
1
+ # rubocop: disable all
2
2
 
3
3
  module Rows
4
4
  class Engine < ::Rails::Engine
data/lib/rows/model.rb CHANGED
@@ -1,32 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rows::Model
4
-
5
4
  def model_class
6
5
  @_model_class ||= self.class.model_class ||
7
- params[:controller].singularize.camelize.constantize
6
+ Kernel.const_get(params[:controller].classify)
8
7
  end
9
8
 
10
- if Rails::VERSION::MAJOR > 3
11
- def model_name
12
- @_model_name ||= model_class.model_name.name
13
- end
9
+ if Rails::VERSION::MAJOR > 3
10
+ def model_name
11
+ @_model_name ||= model_class.model_name.name
12
+ end
14
13
 
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
14
+ def model_symbol
15
+ @_model_symbol ||= model_class.model_name.singular
16
+ end
17
+ else
18
+ def model_name
19
+ @_model_name ||= model_class.name
20
+ end
22
21
 
23
- def model_symbol
24
- @_model_symbol ||= model_name.underscore.gsub(%r{/}, '_')
22
+ def model_symbol
23
+ @_model_symbol ||= model_name.underscore.tr('/', '_')
24
+ end
25
25
  end
26
- end
27
26
 
28
27
  def model_symbol_plural
29
28
  @_model_symbol_plural ||= model_symbol.pluralize
30
29
  end
31
-
32
30
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rows::Resources
4
-
5
4
  def set_resources(rows = nil)
6
5
  rows ||= model_class.all
7
6
  instance_variable_set("@#{model_symbol_plural}", rows)
@@ -23,8 +22,8 @@ module Rows::Resources
23
22
  end
24
23
 
25
24
  private
26
- # low level resource methods
27
- # can be monkey patched
25
+ # low level resource methods
26
+ # can be monkey patched
28
27
  def resource_new
29
28
  if params[model_symbol]
30
29
  set_resource model_class.new(resource_params)
@@ -40,7 +39,7 @@ module Rows::Resources
40
39
 
41
40
  def resource_update
42
41
  if Rails::VERSION::MAJOR >= 4
43
- # return true unless params[model_symbol]
42
+ # return true unless params[model_symbol]
44
43
  resource.update(resource_params)
45
44
  else
46
45
  resource.update_attributes(resource_params)
@@ -52,10 +51,9 @@ module Rows::Resources
52
51
  end
53
52
 
54
53
  def resource_columns
55
- return model_class.column_headers if model_class.respond_to?(:column_headers)
56
- return ['to_s'] unless model_class.respond_to?(:content_columns)
54
+ return model_class.column_headers if model_class.respond_to?(:column_headers)
55
+ return ['to_s'] unless model_class.respond_to?(:content_columns)
57
56
 
58
- # ['id'] + model_class.content_columns.collect { |c| c.name }
59
57
  ['id'] + model_class.content_columns.collect(&:name)
60
58
  end
61
59
 
@@ -71,15 +69,15 @@ module Rows::Resources
71
69
  params.require(model_symbol).permit(permits)
72
70
  else
73
71
  pars = params[model_symbol] || {}
74
- pars.keys.each { |x|
75
- x = x.to_sym
76
- unless permits.include?(x) || permits.include?({ x => [] })
77
- pars.delete(x)
78
- p "** WARNING: model <#{model_name}> dropping params <#{x}>"
79
- end
72
+ # pars.keys.each { |x|
73
+ pars.each_key { |x|
74
+ x = x.to_sym
75
+ unless permits.include?(x) || permits.include?({x => []})
76
+ pars.delete(x)
77
+ p "** WARNING: model <#{model_name}> dropping params <#{x}>"
78
+ end
80
79
  }
81
80
  pars
82
81
  end
83
82
  end
84
-
85
83
  end
data/lib/rows/utils.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
+ # rubocop: disable all
2
3
 
3
4
  module Rows::Utils
4
-
5
- # formatting
5
+ # formatting
6
6
  def resource_format(x)
7
7
  return '--'.html_safe if x.nil?
8
+
8
9
  bool = x.class == Time || x.class == Date || x.class == DateTime ||
9
10
  x.class == ActiveSupport::TimeWithZone
10
- return x.strftime('%d.%m.%Y').html_safe if bool
11
- # return I18n.l(x) if bool
12
- # return x.to_s.html_safe if x.class == Fixnum
11
+ return x.strftime('%d.%m.%Y').html_safe if bool
12
+
13
+ # return I18n.l(x) if bool
14
+ # return x.to_s.html_safe if x.class == Fixnum
13
15
  return x.to_s.html_safe if x.is_a?(Integer)
14
16
  return 'X'.html_safe if x.class == TrueClass
15
17
  return '&ensp;'.html_safe if x.class == FalseClass
@@ -18,5 +20,4 @@ module Rows::Utils
18
20
 
19
21
  x.to_s.gsub(/\r*\n/, '<br/>')
20
22
  end
21
-
22
23
  end
data/lib/rows/version.rb CHANGED
@@ -1,7 +1,13 @@
1
- # frozen_string_literal: true
1
+ # rubocop: disable all
2
2
 
3
3
  module Rows
4
- VERSION = '2.2.2' # 2019-05-06
5
- # VERSION = '2.2.1' # 2019-02-18
6
- # VERSION = '2.2.0'
4
+ VERSION = '3.0.5' # 2021-06-24
5
+ # VERSION = '3.0.3' # 2020-07-14
6
+ # VERSION = '3.0.2' # 2020-04-27
7
+ # VERSION = '3.0.1' # 2020-03-01
8
+ # VERSION = '3.0.0' # 2019-10-03
9
+ # VERSION = '2.2.3' # 2019-10-03
10
+ # VERSION = '2.2.2' # 2019-05-06
11
+ # VERSION = '2.2.1' # 2019-02-18
12
+ # VERSION = '2.2.0'
7
13
  end
@@ -1,7 +1,13 @@
1
- # frozen_string_literal: true
1
+ # rubocop: disable all
2
2
 
3
3
  module Rows
4
- # VERSION = '2.2.2' # 2019-05-06
5
- VERSION = '2.2.1' # 2019-02-18
6
- # VERSION = '2.2.0'
4
+ VERSION = '3.0.4' # 2021-06-24
5
+ # VERSION = '3.0.3' # 2020-07-14
6
+ # VERSION = '3.0.2' # 2020-04-27
7
+ # VERSION = '3.0.1' # 2020-03-01
8
+ # VERSION = '3.0.0' # 2019-10-03
9
+ # VERSION = '2.2.3' # 2019-10-03
10
+ # VERSION = '2.2.2' # 2019-05-06
11
+ # VERSION = '2.2.1' # 2019-02-18
12
+ # VERSION = '2.2.0'
7
13
  end
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: true
1
+ # rubocop: disable all
2
2
 
3
3
  require 'rows/engine'
4
4
 
metadata CHANGED
@@ -1,31 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rows_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 3.0.5
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-03-06 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: appraisal
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
- - - "~>"
45
+ - - ">="
18
46
  - !ruby/object:Gem::Version
19
- version: '2'
47
+ version: '0'
20
48
  type: :development
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
- - - "~>"
52
+ - - ">="
25
53
  - !ruby/object:Gem::Version
26
- version: '2'
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: bundler
56
+ name: combustion
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - ">="
@@ -39,19 +67,33 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: rake
70
+ name: minitest
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - "~>"
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
- version: '12'
75
+ version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - "~>"
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
- version: '12'
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: YourController < RowsController ( < ApplicationController).
56
98
  email:
57
99
  - dittmar.krall@matique.de
@@ -62,9 +104,7 @@ files:
62
104
  - MIT-LICENSE
63
105
  - README.md
64
106
  - app/controllers/rows_controller.rb
65
- - app/controllers/rows_controller.rb.bak
66
107
  - app/controllers/rows_ext_controller.rb
67
- - app/controllers/rows_ext_controller.rb.bak
68
108
  - app/views/rows/_form.slim
69
109
  - app/views/rows/_list.slim
70
110
  - app/views/rows/_list_footer.slim
@@ -81,23 +121,19 @@ files:
81
121
  - app/views/shared/_error_explanation.slim
82
122
  - app/views/shared/_show_flash.slim
83
123
  - lib/rows/engine.rb
84
- - lib/rows/engine.rb.bak
85
124
  - lib/rows/locales/de.yml
86
125
  - lib/rows/locales/en.yml
87
126
  - lib/rows/model.rb
88
- - lib/rows/model.rb.bak
89
127
  - lib/rows/resources.rb
90
- - lib/rows/resources.rb.bak
91
128
  - lib/rows/utils.rb
92
- - lib/rows/utils.rb.bak
93
129
  - lib/rows/version.rb
94
130
  - lib/rows/version.rb.bak
95
131
  - lib/rows_controller.rb
96
- - lib/rows_controller.rb.bak
97
132
  homepage: http://matique.de
98
133
  licenses:
99
134
  - MIT
100
- metadata: {}
135
+ metadata:
136
+ source_code_uri: https://github.com/matique/rows_controller
101
137
  post_install_message:
102
138
  rdoc_options: []
103
139
  require_paths:
@@ -113,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
149
  - !ruby/object:Gem::Version
114
150
  version: '0'
115
151
  requirements: []
116
- rubygems_version: 3.0.1
152
+ rubygems_version: 3.2.6
117
153
  signing_key:
118
154
  specification_version: 4
119
155
  summary: RowsController DRYs your controllers.
@@ -1,91 +0,0 @@
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,18 +0,0 @@
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
@@ -1,4 +0,0 @@
1
- module Rows
2
- class Engine < ::Rails::Engine
3
- end
4
- end
@@ -1,32 +0,0 @@
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
@@ -1,80 +0,0 @@
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
@@ -1,20 +0,0 @@
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 '&ensp;'.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
@@ -1,8 +0,0 @@
1
- require 'rows/engine'
2
-
3
- module Rows
4
- end
5
-
6
- I18n.load_path << File.expand_path('../rows/locales/en.yml', __FILE__)
7
- I18n.load_path << File.expand_path('../rows/locales/de.yml', __FILE__)
8
- I18n.reload!