pg_rails 7.0.6 → 7.0.8.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/pg_associable/app/assets/{css → stylesheets}/pg_associable.scss +1 -1
  4. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +2 -19
  5. data/pg_associable/app/helpers/pg_associable/helpers.rb +2 -1
  6. data/pg_associable/app/inputs/pg_associable_input.rb +53 -0
  7. data/pg_associable/app/javascript/asociable_controller.tsx +171 -0
  8. data/pg_associable/app/{assets/js → javascript}/modal_controller.js +6 -3
  9. data/pg_associable/app/views/pg_associable/_resultados.html.slim +3 -1
  10. data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +5 -2
  11. data/pg_associable/index.js +2 -4
  12. data/pg_associable/lib/pg_associable/engine.rb +0 -8
  13. data/pg_associable/spec/pg_associable/helpers_spec.rb +4 -3
  14. data/pg_engine/app/admin/accounts.rb +25 -0
  15. data/pg_engine/{lib/templates/activeadmin → app/admin}/audits.rb +3 -3
  16. data/pg_engine/app/admin/dashboard.rb +34 -0
  17. data/pg_engine/app/admin/user_accounts.rb +26 -0
  18. data/pg_engine/{lib/templates/activeadmin → app/admin}/users.rb +1 -2
  19. data/pg_engine/app/assets/javascripts/active_admin.js +1 -0
  20. data/pg_engine/app/assets/stylesheets/active_admin.scss +17 -0
  21. data/pg_engine/app/controllers/admin/accounts_controller.rb +33 -0
  22. data/pg_engine/app/controllers/admin/user_accounts_controller.rb +33 -0
  23. data/pg_engine/app/controllers/admin/users_controller.rb +47 -0
  24. data/pg_engine/app/controllers/pg_engine/resource_helper.rb +1 -0
  25. data/pg_engine/app/decorators/account_decorator.rb +16 -0
  26. data/pg_engine/app/decorators/user_account_decorator.rb +19 -0
  27. data/pg_engine/app/decorators/user_decorator.rb +20 -0
  28. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +1 -1
  29. data/pg_engine/app/models/account.rb +39 -0
  30. data/pg_engine/app/models/user.rb +61 -0
  31. data/pg_engine/app/models/user_account.rb +46 -0
  32. data/pg_engine/app/policies/account_policy.rb +31 -0
  33. data/pg_engine/app/policies/pg_engine/application_policy.rb +1 -1
  34. data/pg_engine/app/policies/user_account_policy.rb +31 -0
  35. data/pg_engine/app/policies/user_policy.rb +31 -0
  36. data/pg_engine/app/views/admin/accounts/_account.html.slim +1 -0
  37. data/pg_engine/app/views/admin/accounts/_form.html.slim +12 -0
  38. data/pg_engine/app/views/admin/accounts/edit.html.slim +5 -0
  39. data/pg_engine/app/views/admin/accounts/new.html.slim +5 -0
  40. data/pg_engine/app/views/admin/accounts/show.html.slim +27 -0
  41. data/pg_engine/app/views/admin/user_accounts/_form.html.slim +12 -0
  42. data/pg_engine/app/views/admin/user_accounts/_user_account.html.slim +1 -0
  43. data/pg_engine/app/views/admin/user_accounts/edit.html.slim +5 -0
  44. data/pg_engine/app/views/admin/user_accounts/new.html.slim +5 -0
  45. data/pg_engine/app/views/admin/user_accounts/show.html.slim +24 -0
  46. data/pg_engine/app/views/admin/users/_form.html.slim +12 -0
  47. data/pg_engine/app/views/admin/users/_user.html.slim +1 -0
  48. data/pg_engine/app/views/admin/users/edit.html.slim +5 -0
  49. data/pg_engine/app/views/admin/users/new.html.slim +5 -0
  50. data/pg_engine/app/views/admin/users/show.html.slim +27 -0
  51. data/pg_engine/config/initializers/active_admin.rb +352 -0
  52. data/pg_engine/config/initializers/devise.rb +313 -0
  53. data/pg_engine/config/locales/devise.en.yml +65 -0
  54. data/pg_engine/config/routes.rb +11 -0
  55. data/pg_engine/db/migrate/20240205194218_devise_create_users.rb +47 -0
  56. data/pg_engine/db/migrate/20240208234111_unaccent.rb +5 -0
  57. data/pg_engine/db/migrate/20240208234901_install_audited.rb +32 -0
  58. data/pg_engine/db/migrate/20240210025702_create_active_admin_comments.rb +16 -0
  59. data/pg_engine/db/migrate/20240211152951_create_accounts.rb +24 -0
  60. data/pg_engine/db/migrate/20240211153049_create_user_accounts.rb +20 -0
  61. data/pg_engine/db/seeds.rb +8 -0
  62. data/pg_engine/lib/pg_engine/engine.rb +16 -2
  63. data/pg_engine/lib/tasks/auto_anotar_modelos.rake +1 -1
  64. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +206 -0
  65. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +189 -0
  66. data/pg_engine/spec/controllers/admin/users_controller_spec.rb +180 -0
  67. data/pg_engine/spec/factories/accounts.rb +11 -0
  68. data/pg_engine/spec/factories/user_accounts.rb +21 -0
  69. data/pg_engine/spec/factories/users.rb +59 -0
  70. data/pg_engine/spec/models/account_spec.rb +13 -0
  71. data/pg_engine/spec/models/user_account_spec.rb +13 -0
  72. data/pg_engine/spec/models/user_spec.rb +13 -0
  73. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +1 -0
  74. data/pg_layout/app/views/pg_layout/_flash.html.slim +1 -1
  75. data/pg_layout/lib/pg_layout/engine.rb +0 -1
  76. data/pg_rails/lib/version.rb +1 -1
  77. data/pg_rails/scss/pg_rails.scss +1 -1
  78. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +1 -1
  79. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +4 -4
  80. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +1 -1
  81. data/pg_scaffold/spec/generators_spec.rb +1 -1
  82. metadata +62 -14
  83. data/pg_associable/app/assets/js/asociable_controller.js +0 -58
  84. data/pg_associable/app/assets/js/asociable_inline_controller.js +0 -142
  85. data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +0 -39
  86. data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +0 -41
  87. data/pg_associable/lib/pg_associable/simple_form_initializer.rb +0 -34
  88. data/pg_associable/lib/tasks/pg_associable_tasks.rake +0 -4
@@ -1,142 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus'
2
-
3
- export default class extends Controller {
4
- static outlets = ['modal']
5
-
6
- result = null
7
- elemId = null
8
- input = null
9
- lastValue = ''
10
- connect (e) {
11
- console.log('connect asociable_inline')
12
- const that = this
13
- // ID único para identificar el campo y el modal
14
- this.input = this.element.querySelector('input[type=text]')
15
- this.elemId = Math.trunc(Math.random() * 1000000000)
16
- this.element.classList.add(`asociable-${this.elemId}`)
17
- this.result = document.createElement('div')
18
- this.result.setAttribute('id', `resultados-${this.elemId}`)
19
- this.result.classList.add('resultados-wrapper')
20
- this.input.parentNode.appendChild(this.result)
21
- this.input.parentNode.appendChild(this.result)
22
- this.element.querySelector('.pencil').onclick = (e) => {
23
- that.input.focus()
24
- }
25
- if (this.input.value) {
26
- this.element.classList.add('filled')
27
- }
28
-
29
- const debounce = function (callback, wait) {
30
- let timerId
31
- return (...args) => {
32
- clearTimeout(timerId)
33
- timerId = setTimeout(() => {
34
- callback(...args)
35
- }, wait)
36
- }
37
- }
38
- const doSearchBounce = debounce((force) => {
39
- that.doSearch(force)
40
- }, 200)
41
-
42
- this.input.addEventListener('blur', (e) => {
43
- this.input.placeholder = ''
44
- })
45
- this.input.onfocus = (e) => {
46
- this.input.select()
47
- if (this.input.value.length === 0) {
48
- this.escribiAlgo()
49
- }
50
- }
51
- this.input.onkeyup = (e) => {
52
- if (this.input.value.length === 0) {
53
- this.escribiAlgo()
54
- }
55
- if (e.keyCode === 13) {
56
- doSearchBounce(true)
57
- } else {
58
- doSearchBounce()
59
- }
60
- }
61
- this.input.onkeydown = (e) => {
62
- if (e.keyCode === 13) {
63
- e.preventDefault()
64
- return false
65
- }
66
- }
67
- }
68
-
69
- buscando () {
70
- this.result.innerHTML = `
71
- <div class="resultados" tabindex="-1">
72
- <div class="fst-italic text-secondary">Buscando...</div>
73
- </div>
74
- `
75
- }
76
-
77
- escribiAlgo () {
78
- this.input.placeholder = 'Escribí algo para buscar'
79
- }
80
-
81
- doSearch (force = false) {
82
- if (!force && this.input.value.length < 3) {
83
- return
84
- }
85
- if (!force && this.input.value === this.lastValue) {
86
- return
87
- }
88
- this.lastValue = this.input.value
89
-
90
- const timerId = setTimeout(() => {
91
- this.buscando()
92
- }, 200)
93
- document.addEventListener('turbo:before-stream-render', function (e) {
94
- clearTimeout(timerId)
95
- })
96
- const url = `${this.input.dataset.url}?id=${this.elemId}`
97
- const form = document.createElement('form')
98
- form.setAttribute('method', 'post')
99
- form.setAttribute('action', url)
100
- form.setAttribute('data-turbo-stream', true)
101
- const partial = document.createElement('input')
102
- partial.setAttribute('type', 'hidden')
103
- partial.setAttribute('name', 'partial')
104
- partial.setAttribute('value', 'pg_associable/resultados_inline')
105
- form.appendChild(partial)
106
- const query = document.createElement('input')
107
- query.setAttribute('type', 'hidden')
108
- query.setAttribute('name', 'query')
109
- query.setAttribute('value', this.input.value)
110
- form.appendChild(query)
111
- document.body.prepend(form)
112
- form.requestSubmit()
113
- form.remove()
114
- }
115
-
116
- completarCampo (id, text) {
117
- const textField = this.element.querySelector('input[type=text]')
118
- const hiddenField = this.element.querySelector('input[type=hidden]')
119
- if (id === undefined) {
120
- id = null
121
- }
122
- hiddenField.value = id
123
- if (id) {
124
- textField.value = text
125
- this.element.classList.add('filled')
126
- } else {
127
- this.element.classList.remove('filled')
128
- textField.value = null
129
- }
130
- }
131
-
132
- selectItem (e) {
133
- console.log('select')
134
- // TODO: text en data
135
- this.completarCampo(e.target.dataset.id, e.target.text)
136
- this.result.innerHTML = ''
137
- }
138
-
139
- disconnect (e) {
140
- console.log('disconnect asociable_inline')
141
- }
142
- }
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgAssociable
4
- class PgAssociableInlineInput < SimpleForm::Inputs::StringInput
5
- include ActionView::Helpers::FormTagHelper
6
-
7
- def hidden_input(wrapper_options = {})
8
- merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
- # merged_input_options = merge_wrapper_options(merged_input_options, { class: 'oculto' })
10
- @builder.hidden_field(attribute_name, merged_input_options)
11
- end
12
-
13
- def search_form(wrapper_options = nil)
14
- unless string?
15
- input_html_classes.unshift('string')
16
- # input_html_options[:type] ||= input_type if html5?
17
- end
18
- input_html_options[:type] = 'text'
19
- input_html_options[:data] = { url: options[:url_search] }
20
- input_html_options[:class] = 'form-control'
21
- input_html_options[:placeholder] = ''
22
-
23
- merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
24
-
25
- text_field_tag(nil, object.send(reflection.name).to_s, merged_input_options)
26
- end
27
-
28
- def limpiar(_wrapper_options = nil)
29
- content_tag('a', href: 'javascript:void(0)', class: 'limpiar', title: 'Limpiar', tabindex: '0',
30
- data: { action: 'asociable_inline#selectItem' }) do
31
- '<i class="bi bi-x-lg"></i>'.html_safe
32
- end
33
- end
34
-
35
- def pencil(_wrapper_options = nil)
36
- '<i tabindex="-1" class="bi bi-pencil pencil"></i>'.html_safe
37
- end
38
- end
39
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PgAssociable
4
- class PgAssociableInput < SimpleForm::Inputs::StringInput
5
- include ActionView::Helpers::FormTagHelper
6
-
7
- def hidden_input(wrapper_options = {})
8
- merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
- # merged_input_options = merge_wrapper_options(merged_input_options, { class: 'oculto' })
10
- @builder.hidden_field(attribute_name, merged_input_options)
11
- end
12
-
13
- def input(wrapper_options = nil)
14
- unless string?
15
- input_html_classes.unshift('string')
16
- # input_html_options[:type] ||= input_type if html5?
17
- end
18
- input_html_options[:type] = 'text'
19
-
20
- merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
21
- merged_input_options = merge_wrapper_options(merged_input_options, { class: 'keep-disabled' })
22
-
23
- text_field_tag(nil, object.send(reflection.name).to_s, merged_input_options)
24
- end
25
-
26
- def modal_link(_wrapper_options = nil)
27
- "<a href=\"#{options[:url_modal]}\" class=\"modal-link d-inline-block\" data-turbo-stream style=\"position:absolute; left:0; right:0; top:0; bottom:0;\"></a>".html_safe
28
- end
29
-
30
- def limpiar(_wrapper_options = nil)
31
- content_tag('a', href: 'javascript:void(0)', class: 'limpiar', title: 'Limpiar', tabindex: '0',
32
- data: { action: 'asociable#selectItem' }) do
33
- '<i class="bi bi-x-lg"></i>'.html_safe
34
- end
35
- end
36
-
37
- def pencil(_wrapper_options = nil)
38
- '<i tabindex="-1" class="bi bi-pencil pencil"></i>'.html_safe
39
- end
40
- end
41
- end
@@ -1,34 +0,0 @@
1
- SimpleForm.setup do |config|
2
- config.wrappers :pg_associable, tag: 'div', class: 'pg_associable mb-3', html: { data: { controller: 'asociable', 'asociable-modal-outlet': '.modal' } },
3
- error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
4
- b.use :html5
5
- b.optional :readonly
6
- b.use :label, class: 'form-label'
7
- b.use :hidden_input
8
- b.wrapper tag: 'div', class: 'position-relative' do |ba|
9
- ba.use :input, class: 'form-control', disabled: true, placeholder: 'Clic para seleccionar...',
10
- error_class: 'is-invalid'
11
- ba.use :pencil
12
- ba.use :modal_link
13
- ba.use :limpiar
14
- end
15
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
16
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
17
- end
18
-
19
- config.wrappers :pg_associable_inline, tag: 'div', class: 'pg_associable_inline mb-3', html: { data: { controller: 'asociable_inline' } },
20
- error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
21
- b.use :html5
22
- b.optional :readonly
23
- b.use :label, class: 'form-label'
24
- b.use :hidden_input
25
- b.wrapper tag: 'div', class: 'search-box position-relative' do |ba|
26
- ba.use :search_form, error_class: 'is-invalid'
27
- ba.use :limpiar
28
- ba.use :pencil
29
- # ba.use :input, class: 'form-control', placeholder: 'Buscar...'
30
- end
31
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
32
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
33
- end
34
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :pg_associable do
3
- # # Task goes here
4
- # end