pg_rails 7.0.3 → 7.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8cb512a5e5483d9560982aebe0f68c8934f7c6fa63497a2e3701adf7b33ac7b
4
- data.tar.gz: ce68d888d08bdbab4ed1e537d1f5d40b94d45c5a2f4d89f0ce99f65e3b9760ad
3
+ metadata.gz: d63547ea3619de2194b7906e2344df8fe1ff049cd3b066ba1adcb61cf1ae8102
4
+ data.tar.gz: 5845c9d534c94be6ddb71823271d21f3d2c28615ba5d70d5a874478799d48eeb
5
5
  SHA512:
6
- metadata.gz: 3fb3e9557497c249a2960b61996a8e76e5075fab812753d6c09f7215b6155a928d6914a49b431c05a0869a3bc0cc78cfece7f895a4c6f47112a853834b77a122
7
- data.tar.gz: 1aa9067316fa32c9aab7cec6aece106e5dbc5f7f89c257d27ccc003c7d497f11fb0af275ca6e3b254d545da261d160876b54486bf429350e29e7d78e1860a1e0
6
+ metadata.gz: b7611fd24a756c4a7c6e8573f67b48dd0e9598839065feef9ac6345e8e09e0b71087db795647524f6f8bd9734fe67c6da54d4305391306441eddcaf6b0120937
7
+ data.tar.gz: 204dc0788a96e724b67038d0c89e1a8cecf69a1a4fd8f8ada7d105289ed0615641eed73e8353cf85acea3be573332d05583070650740c37ed53d891c2ec30579
@@ -26,21 +26,20 @@ export default class extends Controller {
26
26
  }
27
27
  }
28
28
  const input = this.element.querySelector('input[type=text]')
29
- if(input.value) {
29
+ if (input.value) {
30
30
  this.element.classList.add('filled')
31
31
  }
32
-
33
32
  }
34
33
 
35
-
36
34
  selectItem (e) {
37
35
  // TODO: text en data
38
36
  this.completarCampo(e.target.dataset.id, e.target.text)
39
37
  }
38
+
40
39
  completarCampo (id, text) {
41
40
  const textField = this.element.querySelector('input[type=text]')
42
41
  const hiddenField = this.element.querySelector('input[type=hidden]')
43
- if( id === undefined ) {
42
+ if (id === undefined) {
44
43
  id = null
45
44
  }
46
45
  hiddenField.value = id
@@ -22,86 +22,88 @@ export default class extends Controller {
22
22
  this.element.querySelector('.pencil').onclick = (e) => {
23
23
  that.input.focus()
24
24
  }
25
- if(this.input.value) {
25
+ if (this.input.value) {
26
26
  this.element.classList.add('filled')
27
27
  }
28
28
 
29
- let debounce = function(callback, wait) {
30
- let timerId;
29
+ const debounce = function (callback, wait) {
30
+ let timerId
31
31
  return (...args) => {
32
- clearTimeout(timerId);
32
+ clearTimeout(timerId)
33
33
  timerId = setTimeout(() => {
34
- callback(...args);
35
- }, wait);
36
- };
34
+ callback(...args)
35
+ }, wait)
36
+ }
37
37
  }
38
38
  const doSearchBounce = debounce((force) => {
39
39
  that.doSearch(force)
40
40
  }, 200)
41
41
 
42
42
  this.input.addEventListener('blur', (e) => {
43
- this.input.placeholder = ""
43
+ this.input.placeholder = ''
44
44
  })
45
45
  this.input.onfocus = (e) => {
46
46
  this.input.select()
47
- if(this.input.value.length == 0) {
47
+ if (this.input.value.length === 0) {
48
48
  this.escribiAlgo()
49
49
  }
50
50
  }
51
51
  this.input.onkeyup = (e) => {
52
- if(this.input.value.length == 0) {
52
+ if (this.input.value.length === 0) {
53
53
  this.escribiAlgo()
54
54
  }
55
- if(e.keyCode == 13) {
55
+ if (e.keyCode === 13) {
56
56
  doSearchBounce(true)
57
57
  } else {
58
58
  doSearchBounce()
59
59
  }
60
60
  }
61
61
  this.input.onkeydown = (e) => {
62
- if(e.keyCode == 13) {
63
- e.preventDefault();
64
- return false;
62
+ if (e.keyCode === 13) {
63
+ e.preventDefault()
64
+ return false
65
65
  }
66
66
  }
67
67
  }
68
- buscando() {
68
+
69
+ buscando () {
69
70
  this.result.innerHTML = `
70
71
  <div class="resultados" tabindex="-1">
71
72
  <div class="fst-italic text-secondary">Buscando...</div>
72
73
  </div>
73
74
  `
74
75
  }
75
- escribiAlgo() {
76
- this.input.placeholder = "Escribí algo para buscar"
76
+
77
+ escribiAlgo () {
78
+ this.input.placeholder = 'Escribí algo para buscar'
77
79
  }
78
80
 
79
- doSearch(force = false) {
80
- if(!force && this.input.value.length < 3) {
81
+ doSearch (force = false) {
82
+ if (!force && this.input.value.length < 3) {
81
83
  return
82
84
  }
83
- if(!force && this.input.value == this.lastValue) {
85
+ if (!force && this.input.value === this.lastValue) {
84
86
  return
85
87
  }
86
88
  this.lastValue = this.input.value
87
89
 
88
- let timerId = setTimeout(() => {
90
+ const timerId = setTimeout(() => {
89
91
  this.buscando()
90
92
  }, 200)
91
- document.addEventListener("turbo:before-stream-render", function(e) {
93
+ document.addEventListener('turbo:before-stream-render', function (e) {
92
94
  clearTimeout(timerId)
93
95
  })
94
- let url = `${this.input.dataset.url}?id=${this.elemId}`
96
+ const url = `${this.input.dataset.url}?id=${this.elemId}`
95
97
  const form = document.createElement('form')
96
98
  form.setAttribute('method', 'post')
97
99
  form.setAttribute('action', url)
98
100
  form.setAttribute('data-turbo-stream', true)
99
- let partial = document.createElement('input')
101
+ const partial = document.createElement('input')
100
102
  partial.setAttribute('type', 'hidden')
101
103
  partial.setAttribute('name', 'partial')
102
104
  partial.setAttribute('value', 'pg_associable/resultados_inline')
103
105
  form.appendChild(partial)
104
- let query = document.createElement('input')
106
+ const query = document.createElement('input')
105
107
  query.setAttribute('type', 'hidden')
106
108
  query.setAttribute('name', 'query')
107
109
  query.setAttribute('value', this.input.value)
@@ -114,7 +116,7 @@ export default class extends Controller {
114
116
  completarCampo (id, text) {
115
117
  const textField = this.element.querySelector('input[type=text]')
116
118
  const hiddenField = this.element.querySelector('input[type=hidden]')
117
- if( id === undefined ) {
119
+ if (id === undefined) {
118
120
  id = null
119
121
  }
120
122
  hiddenField.value = id
@@ -134,7 +136,6 @@ export default class extends Controller {
134
136
  this.result.innerHTML = ''
135
137
  }
136
138
 
137
-
138
139
  disconnect (e) {
139
140
  console.log('disconnect asociable_inline')
140
141
  }
@@ -3,10 +3,9 @@ import * as bootstrap from 'bootstrap'
3
3
 
4
4
  export default class extends Controller {
5
5
  static outlets = ['asociable']
6
- static targets = ['response', 'result']
6
+ static targets = ['response', 'result', 'searchInput', 'searchForm']
7
7
 
8
8
  modalPuntero = null
9
- input = null
10
9
  lastValue = ''
11
10
 
12
11
  connect (e) {
@@ -15,28 +14,33 @@ export default class extends Controller {
15
14
  this.modalPuntero = new bootstrap.Modal(modal)
16
15
  this.modalPuntero.show()
17
16
 
18
- this.input = this.element.querySelector('input[type=text]')
17
+ if (this.searchInputTargets.length > 0) {
18
+ this.bindSearchInput()
19
+ }
20
+ }
19
21
 
20
- let debounce = function(callback, wait) {
21
- let timerId;
22
- return (...args) => {
23
- clearTimeout(timerId);
24
- timerId = setTimeout(() => {
25
- callback(...args);
26
- }, wait);
27
- };
22
+ debounce (callback, wait) {
23
+ let timerId
24
+ return (...args) => {
25
+ clearTimeout(timerId)
26
+ timerId = setTimeout(() => {
27
+ callback(...args)
28
+ }, wait)
28
29
  }
29
- const doSearchBounce = debounce((force) => {
30
+ }
31
+
32
+ bindSearchInput () {
33
+ const doSearchBounce = this.debounce((force) => {
30
34
  this.doSearch(force)
31
35
  }, 200)
32
- this.input.onkeydown = (e) => {
33
- if(e.keyCode == 13) {
34
- e.preventDefault();
35
- return false;
36
+ this.searchInputTarget.onkeydown = (e) => {
37
+ if (e.keyCode === 13) {
38
+ e.preventDefault()
39
+ return false
36
40
  }
37
41
  }
38
- this.input.onkeyup = (e) => {
39
- if(e.keyCode == 13) {
42
+ this.searchInputTarget.onkeyup = (e) => {
43
+ if (e.keyCode === 13) {
40
44
  doSearchBounce(true)
41
45
  } else {
42
46
  doSearchBounce()
@@ -44,7 +48,7 @@ export default class extends Controller {
44
48
  }
45
49
  }
46
50
 
47
- buscando() {
51
+ buscando () {
48
52
  this.resultTarget.innerHTML = `
49
53
  <ul class="resultados list-group list-group-flush" tabindex="-1">
50
54
  <li class="list-group-item">
@@ -53,40 +57,23 @@ export default class extends Controller {
53
57
  </ul>
54
58
  `
55
59
  }
56
- doSearch(force = false) {
57
- if(!force && this.input.value.length < 3) {
60
+
61
+ doSearch (force = false) {
62
+ if (!force && this.searchInputTarget.value.length < 3) {
58
63
  return
59
64
  }
60
- if(!force && this.input.value == this.lastValue) {
65
+ if (!force && this.searchInputTarget.value === this.lastValue) {
61
66
  return
62
67
  }
63
- this.lastValue = this.input.value
68
+ this.lastValue = this.searchInputTarget.value
64
69
 
65
- let timerId = setTimeout(() => {
70
+ const timerId = setTimeout(() => {
66
71
  this.buscando()
67
72
  }, 200)
68
- document.addEventListener("turbo:before-stream-render", function(e) {
73
+ document.addEventListener('turbo:before-stream-render', function (e) {
69
74
  clearTimeout(timerId)
70
75
  })
71
- this.element.querySelector('form').requestSubmit()
72
- // let url = `${this.input.dataset.url}?id=${this.elemId}`
73
- // const form = document.createElement('form')
74
- // form.setAttribute('method', 'post')
75
- // form.setAttribute('action', url)
76
- // form.setAttribute('data-turbo-stream', true)
77
- // let partial = document.createElement('input')
78
- // partial.setAttribute('type', 'hidden')
79
- // partial.setAttribute('name', 'partial')
80
- // partial.setAttribute('value', 'pg_associable/resultados_inline')
81
- // form.appendChild(partial)
82
- // let query = document.createElement('input')
83
- // query.setAttribute('type', 'hidden')
84
- // query.setAttribute('name', 'query')
85
- // query.setAttribute('value', this.input.value)
86
- // form.appendChild(query)
87
- // document.body.prepend(form)
88
- // form.requestSubmit()
89
- // form.remove()
76
+ this.searchFormTarget.requestSubmit()
90
77
  }
91
78
 
92
79
  selectItem (e) {
@@ -10,7 +10,7 @@ module PgAssociable
10
10
 
11
11
  def pg_respond_buscar
12
12
  partial = params[:partial] || 'pg_associable/resultados'
13
- @collection = policy_scope(@clase_modelo).query(params[:query]).limit(6)
13
+ @collection = policy_scope(@clase_modelo).kept.query(params[:query]).limit(6)
14
14
  render turbo_stream:
15
15
  turbo_stream.update("resultados-#{params[:id]}",
16
16
  partial:, locals: { collection: @collection })
@@ -11,17 +11,19 @@
11
11
  a.btn-close[type="button" data-bs-dismiss="modal" aria-label="Close"]
12
12
  .modal-body
13
13
  .show-on-select-item
14
- - if @clase_modelo.count.zero?
14
+ - if policy_scope(@clase_modelo).kept.count.zero?
15
15
  p No hay #{@clase_modelo.nombre_plural.downcase} aún
16
16
  = link_to "Crear el primer #{@clase_modelo.nombre_singular.downcase}",
17
17
  'javascript:void(0)', data: { action: 'modal#toggleCrearElegir' }
18
18
  - else
19
19
  = form_tag namespaced_path(@clase_modelo, prefix: :buscar),
20
+ data: { 'modal-target': 'searchForm' },
20
21
  method: :post, class: 'pg-form buscar' do
21
22
  = hidden_field_tag :id, params[:id]
22
23
  = text_field_tag :query, '', class: 'form-control',
23
24
  placeholder: 'Escribí algo para buscar',
24
- autocomplete: 'off'
25
+ autocomplete: 'off',
26
+ data: { 'modal-target': 'searchInput' }
25
27
  / = button_tag 'Buscar'
26
28
  .resultados-wrapper id="resultados-#{params[:id]}" data-modal-target="result"
27
29
  #pg-associable-form.show-on-new-item
@@ -1,34 +1,59 @@
1
- # frozen_string_literal: true
2
-
3
- # # frozen_string_literal: true
4
-
1
+ # NOTE: only doing this in development as some production environments (Heroku)
2
+ # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
3
+ # NOTE: to have a dev-mode tool do its thing in production.
5
4
  if Rails.env.development?
6
- Annotate.set_defaults(
7
- # 'show_migration' => 'true',
8
- 'show_foreign_keys' => 'true',
9
- 'show_indexes' => 'true',
10
- 'exclude_controllers' => 'true',
11
- 'exclude_helpers' => 'true',
12
- 'exclude_tests' => 'true',
13
- 'classified_sort' => 'true',
14
- 'with_comment' => 'true',
15
-
16
- 'models' => 'true'
17
- )
18
-
19
- # Annotate models
20
- task annotate: :environment do
21
- puts 'Annotating models...'
22
- system 'bundle exec annotate'
5
+ require 'annotate'
6
+ task :set_annotation_options do
7
+ # You can override any of these by setting an environment variable of the
8
+ # same name.
9
+ Annotate.set_defaults(
10
+ 'active_admin' => 'false',
11
+ 'additional_file_patterns' => [],
12
+ 'routes' => 'true',
13
+ 'models' => 'true',
14
+ 'position_in_routes' => 'before',
15
+ 'position_in_class' => 'before',
16
+ 'position_in_test' => 'before',
17
+ 'position_in_fixture' => 'before',
18
+ 'position_in_factory' => 'before',
19
+ 'position_in_serializer' => 'before',
20
+ 'show_foreign_keys' => 'true',
21
+ 'show_complete_foreign_keys' => 'false',
22
+ 'show_indexes' => 'true',
23
+ 'simple_indexes' => 'false',
24
+ 'model_dir' => 'app/models',
25
+ 'root_dir' => '',
26
+ 'include_version' => 'false',
27
+ 'require' => '',
28
+ 'exclude_tests' => 'true',
29
+ 'exclude_fixtures' => 'true',
30
+ 'exclude_factories' => 'true',
31
+ 'exclude_serializers' => 'true',
32
+ 'exclude_scaffolds' => 'true',
33
+ 'exclude_controllers' => 'true',
34
+ 'exclude_helpers' => 'true',
35
+ 'exclude_sti_subclasses' => 'false',
36
+ 'ignore_model_sub_dir' => 'false',
37
+ 'ignore_columns' => nil,
38
+ 'ignore_routes' => nil,
39
+ 'ignore_unknown_models' => 'false',
40
+ # 'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>',
41
+ # 'hide_default_column_types' => '<%= AnnotateModels::NO_DEFAULT_COL_TYPES.join(",") %>',
42
+ 'skip_on_db_migrate' => 'false',
43
+ 'format_bare' => 'true',
44
+ 'format_rdoc' => 'false',
45
+ 'format_yard' => 'false',
46
+ 'format_markdown' => 'false',
47
+ 'sort' => 'false',
48
+ 'force' => 'false',
49
+ 'frozen' => 'false',
50
+ 'classified_sort' => 'true',
51
+ 'trace' => 'false',
52
+ 'wrapper_open' => nil,
53
+ 'wrapper_close' => nil,
54
+ 'with_comment' => 'true'
55
+ )
23
56
  end
24
57
 
25
- # Run annotate task after db:migrate
26
- # and db:rollback tasks
27
- Rake::Task['db:migrate'].enhance do
28
- Rake::Task['annotate'].invoke
29
- end
30
-
31
- Rake::Task['db:rollback'].enhance do
32
- Rake::Task['annotate'].invoke
33
- end
58
+ Annotate.load_tasks
34
59
  end
data/pg_layout/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  // Controllers
2
2
  import NavbarController from './app/javascript/navbar_controller'
3
- window.Stimulus.register('navbar', NavbarController)
4
-
5
3
  // Bootstrap's toasts
6
4
  import * as bootstrap from 'bootstrap'
5
+
6
+ window.Stimulus.register('navbar', NavbarController)
7
+
7
8
  document.addEventListener('turbo:load', function () {
8
9
  const toastElList = document.querySelectorAll('.toast:not(.hide):not(.show)')
9
10
  Array.from(toastElList).map(toastEl => new bootstrap.Toast(toastEl).show())
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.3'
4
+ VERSION = '7.0.5'
5
5
  end
@@ -20,7 +20,7 @@ class PgResourceRouteGenerator < Rails::Generators::NamedBase
20
20
  return if options[:actions].present?
21
21
 
22
22
  route_s = <<~RUBY
23
- PgEngine.resource_route(self, :#{file_name.pluralize})
23
+ pg_resource(:#{file_name.pluralize})
24
24
  RUBY
25
25
  route route_s, namespace: regular_class_path
26
26
  end
@@ -57,9 +57,11 @@ class PgScaffoldGenerator < Rails::Generators::NamedBase
57
57
 
58
58
  def parent_controller
59
59
  parts = controller_class_name.split('::')
60
- return "#{parts.first}Controller" if parts.length > 1 && (get_class "#{parts.first}Controller")
60
+ namesp = namespace.present? ? "#{namespace}::" : ''
61
+ cont_name = "#{namesp}#{parts.first}Controller"
62
+ return cont_name if parts.length > 1 && get_class(cont_name)
61
63
 
62
- raise "#{parts.first}Controller not exists"
64
+ raise "#{cont_name} not exists"
63
65
  end
64
66
 
65
67
  def atributos_a_filtrar
@@ -2,19 +2,20 @@
2
2
 
3
3
  # generado con pg_rails
4
4
 
5
- <% if namespaced? -%>
5
+ <% if false && namespaced? -%>
6
6
  require_dependency "<%= namespaced_path %>/application_controller"
7
7
 
8
8
  <% end -%>
9
+ <% module_namespacing do -%>
9
10
  <% module_namespacing_2 do -%>
10
11
  class <%= controller_class_name.split('::').last %>Controller < <%= parent_controller %>
11
- before_action { @clase_modelo = <%= class_name %> }
12
+ before_action { @clase_modelo = <%= class_name.split('::').last %> }
12
13
 
13
- before_action(only: :index) { authorize <%= class_name %> }
14
+ before_action(only: :index) { authorize <%= class_name.split('::').last %> }
14
15
 
15
16
  before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
16
17
 
17
- add_breadcrumb <%= class_name %>.nombre_plural, :<%= plural_route_name %>_path
18
+ add_breadcrumb <%= class_name.split('::').last %>.nombre_plural, :<%= plural_route_name %>_path
18
19
 
19
20
  private
20
21
 
@@ -35,3 +36,4 @@ class <%= controller_class_name.split('::').last %>Controller < <%= parent_contr
35
36
  end
36
37
  end
37
38
  <% end -%>
39
+ <% end -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.3
4
+ version: 7.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails goodies.
14
14
  email: