pg_rails 7.0.7 → 7.0.8.pre.alpha.6

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -0
  3. data/pg_associable/app/assets/{css → stylesheets}/pg_associable.scss +40 -41
  4. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +36 -9
  5. data/pg_associable/app/helpers/pg_associable/helpers.rb +6 -3
  6. data/pg_associable/app/inputs/pg_associable_input.rb +53 -0
  7. data/pg_associable/app/javascript/asociable_controller.tsx +247 -0
  8. data/pg_associable/app/javascript/modal_controller.js +29 -0
  9. data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +9 -8
  10. data/pg_associable/app/views/pg_engine/base/_pg_associable_modal.html.slim +5 -32
  11. data/pg_associable/index.js +2 -4
  12. data/pg_associable/lib/pg_associable/engine.rb +0 -4
  13. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +49 -41
  14. data/pg_engine/app/controllers/pg_engine/resource_helper.rb +6 -2
  15. data/pg_engine/app/decorators/pg_engine/base_decorator.rb +2 -2
  16. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +2 -2
  17. data/pg_engine/app/helpers/pg_engine/form_helper.rb +70 -0
  18. data/pg_engine/app/helpers/pg_engine/route_helper.rb +14 -6
  19. data/pg_engine/app/views/admin/accounts/_form.html.slim +1 -1
  20. data/pg_engine/app/views/admin/user_accounts/_form.html.slim +3 -3
  21. data/pg_engine/app/views/admin/users/_form.html.slim +1 -1
  22. data/pg_engine/app/views/pg_engine/base/index.html.slim +3 -3
  23. data/pg_engine/config/initializers/active_admin.rb +1 -4
  24. data/pg_engine/config/simple_form/simple_form_bootstrap.rb +17 -9
  25. data/pg_engine/db/migrate/20240222115722_create_active_storage_tables.active_storage.rb +57 -0
  26. data/pg_engine/db/seeds.rb +7 -4
  27. data/pg_engine/lib/pg_engine/engine.rb +1 -1
  28. data/pg_engine/lib/pg_engine/route_helpers.rb +1 -0
  29. data/pg_engine/lib/pg_engine/utils/pdf_preview_generator.rb +50 -0
  30. data/pg_engine/lib/pg_engine.rb +3 -0
  31. data/pg_engine/lib/tasks/auto_anotar_modelos.rake +1 -1
  32. data/pg_engine/spec/fixtures/test.pdf +0 -0
  33. data/pg_engine/spec/pg_engine/pdf_preview_generator_spec.rb +12 -0
  34. data/pg_layout/app/assets/stylesheets/sidebar.scss +10 -2
  35. data/pg_layout/app/javascript/nested_controller.js +48 -0
  36. data/pg_layout/app/javascript/pg_form_controller.js +13 -0
  37. data/pg_layout/app/javascript/utils.ts +34 -0
  38. data/pg_layout/app/views/layouts/pg_layout/devise.html.slim +1 -1
  39. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +14 -10
  40. data/pg_layout/app/views/pg_layout/_flash.html.slim +2 -2
  41. data/pg_layout/app/views/pg_layout/_navbar.html.erb +10 -0
  42. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +3 -3
  43. data/pg_layout/index.js +4 -0
  44. data/pg_rails/lib/version.rb +1 -1
  45. data/pg_rails/scss/pg_rails.scss +1 -1
  46. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +3 -3
  47. metadata +15 -13
  48. data/pg_associable/app/assets/js/asociable_controller.js +0 -58
  49. data/pg_associable/app/assets/js/asociable_inline_controller.js +0 -142
  50. data/pg_associable/app/assets/js/modal_controller.js +0 -117
  51. data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +0 -39
  52. data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +0 -41
  53. data/pg_associable/app/views/pg_associable/_resultados.html.slim +0 -9
  54. data/pg_associable/lib/pg_associable/simple_form_initializer.rb +0 -34
  55. data/pg_associable/lib/tasks/pg_associable_tasks.rake +0 -4
@@ -0,0 +1,13 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export default class extends Controller {
4
+ connect () {
5
+ this.element.querySelectorAll('.form-select, .form-control').forEach((slct) => {
6
+ slct.addEventListener('change', (e) => {
7
+ if (e.target.value) {
8
+ slct.classList.remove('is-invalid')
9
+ }
10
+ })
11
+ })
12
+ }
13
+ }
@@ -0,0 +1,34 @@
1
+ export function round (value) {
2
+ return Math.round(value * 100) / 100
3
+ }
4
+
5
+ export function printCurrency (value, moneda) {
6
+ return monedaSimbolo(moneda) + numberWithDots(round(value).toFixed(2).replace('.', ','))
7
+ }
8
+
9
+ export function showPercentage (value) {
10
+ return '% ' + value
11
+ }
12
+
13
+ export function monedaSimbolo (moneda) {
14
+ switch (moneda) {
15
+ case 'pesos':
16
+ return '$ '
17
+ case 'dolares':
18
+ return 'U$S '
19
+ case 'euros':
20
+ return '€ '
21
+ case 'reales':
22
+ return 'R$ '
23
+ case 'pesos_chilenos':
24
+ return 'CLP '
25
+ case 'pesos_mexicanos':
26
+ return 'MXN '
27
+ default:
28
+ return '$ '
29
+ }
30
+ }
31
+
32
+ export function numberWithDots (x) {
33
+ return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.')
34
+ }
@@ -19,6 +19,6 @@ html
19
19
 
20
20
  css:
21
21
  .pg-form {
22
- max-width: 300px;
22
+ max-width: 22em;
23
23
  margin: auto;
24
24
  }
@@ -3,6 +3,11 @@ html
3
3
  head
4
4
  title = Rails.application.class.module_parent_name
5
5
  meta name="viewport" content="width=device-width,initial-scale=1"
6
+ / meta name="turbo-cache-control" content="no-cache"
7
+ / meta name="turbo-refresh-method" content="morph"
8
+ / meta name="turbo-refresh-scroll" content="preserve"
9
+ / meta name="turbo-prefetch" content="true"
10
+ meta name="view-transition" content="same-origin"
6
11
  = csrf_meta_tags
7
12
  = csp_meta_tag
8
13
 
@@ -12,19 +17,18 @@ html
12
17
  .with-sidebar
13
18
  = render partial: 'pg_layout/sidebar'
14
19
  div
20
+ .position-relative.d-flex.justify-content-around
21
+ #flash.flash.position-absolute.z-1.mt-1
22
+ = render partial: 'pg_layout/flash'
15
23
  = render partial: 'pg_layout/navbar'
16
24
  div
17
- .text-center
18
- #flash.flash.d-inline-block
19
- = render partial: 'pg_layout/flash'
20
25
  - if user_signed_in?
21
- .d-flex.px-3.align-items-center.justify-content-between.d-print-none
22
- div
23
- / <!-- <h1 class="h3 mb-0 text-gray-800"><%= content_for(:title) %></h1> -->
24
- nav aria-label="breadcrumb"
25
- = render_breadcrumbs
26
- / = render_breadcrumbs builder: ::Bootstrap4BreadcrumbsBuilder
27
- .btn-toolbar.py-2
26
+ .d-flex.align-items-center.justify-content-between.px-3.py-1.d-print-none[
27
+ style="min-height: 2.5em;"]
28
+ nav aria-label="breadcrumb"
29
+ = render_breadcrumbs
30
+ / = render_breadcrumbs builder: ::Bootstrap4BreadcrumbsBuilder
31
+ .btn-toolbar
28
32
  = yield(:actions)
29
33
  hr.my-0
30
34
  = yield
@@ -4,7 +4,7 @@
4
4
  / slim-lint:enable LineLength
5
5
 
6
6
  - flash_to_show.each do |flash_type, message|
7
- .toast(class="bg-#{flash_type_to_class(flash_type)}-subtle" role="alert"
8
- aria-live="assertive" aria-atomic="true")
7
+ .toast(class="bg-#{flash_type_to_class(flash_type)}-subtle" role="alert" data-bs-autohide="true"
8
+ data-turbo-temporary="true" aria-live="assertive" aria-atomic="true")
9
9
  .toast-body
10
10
  = message
@@ -24,6 +24,16 @@
24
24
  </li>
25
25
  </ul>
26
26
  </li>
27
+ <% @navbar.sidebar.each do |entry| %>
28
+ <% next if @navbar.hide_entry?(entry) %>
29
+ <% random_id = rand(99999).to_s %>
30
+ <li class="nav-item d-md-none">
31
+ <a class="nav-link" href="<%= entry[:path] %>" role="button">
32
+ <%= entry[:title] %>
33
+ </a>
34
+ </li>
35
+ <% end %>
36
+
27
37
  <% else %>
28
38
  <li class="nav-item">
29
39
  <%= link_to 'ingresar', new_user_session_path, class: 'nav-link' %>
@@ -1,8 +1,8 @@
1
1
  <div id="sidebar" class="<%= @navbar_opened_class %> flex-shrink-0 bg-gradient d-none d-<%= @breakpoint_navbar_expand %>-block">
2
2
  <% if user_signed_in? %>
3
- <div class="sidebar--large-items" style="position:fixed">
3
+ <div class="sidebar--large-items">
4
4
  <hr>
5
- <div class="sidebar--small-items">
5
+ <%# <div class="sidebar--small-items">
6
6
  <ul class="list-unstyled ps-0">
7
7
  <li class="mb-1 text-center">
8
8
  <a href="javascript:void(0)" class="nav-link" data-bs-toggle="tooltip" data-bs-title="Agenda">
@@ -10,7 +10,7 @@
10
10
  </a>
11
11
  </li>
12
12
  </ul>
13
- </div>
13
+ </div> %>
14
14
  <div class="sidebar--large-items">
15
15
  <ul class="list-unstyled ps-0">
16
16
  <% @navbar.sidebar.each do |entry| %>
data/pg_layout/index.js CHANGED
@@ -1,9 +1,13 @@
1
1
  // Controllers
2
2
  import NavbarController from './app/javascript/navbar_controller'
3
+ import NestedController from './app/javascript/nested_controller'
4
+ import PgFormController from './app/javascript/pg_form_controller'
3
5
  // Bootstrap's toasts
4
6
  import * as bootstrap from 'bootstrap'
5
7
 
6
8
  window.Stimulus.register('navbar', NavbarController)
9
+ window.Stimulus.register('nested', NestedController)
10
+ window.Stimulus.register('pg_form', PgFormController)
7
11
 
8
12
  document.addEventListener('turbo:load', function () {
9
13
  const toastElList = document.querySelectorAll('.toast:not(.hide):not(.show)')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.7'
4
+ VERSION = '7.0.8-alpha.6'
5
5
  end
@@ -1,3 +1,3 @@
1
1
  @import './../../pg_engine/app/assets/stylesheets/pg_rails_b5';
2
- @import './../../pg_associable/app/assets/css/pg_associable';
2
+ @import './../../pg_associable/app/assets/stylesheets/pg_associable';
3
3
  @import './../../pg_layout/app/assets/stylesheets/sidebar';
@@ -1,12 +1,12 @@
1
1
  / # locals: (object: nil, asociable: false)
2
2
 
3
- div style="max-width: 300px"
4
- = pg_form_for(@<%= singular_name %> || object) do |f|
3
+ div style="max-width: 22em" data-controller="pg_form"
4
+ = pg_form_for(@<%= singular_name %> || object, asociable:)) do |f|
5
5
  = f.mensajes_de_error
6
6
 
7
7
  = hidden_field_tag :asociable, true if asociable
8
8
  <%- attributes.each do |attribute| -%>
9
- = f.<%= attribute.reference? ? :pg_associable_inline : :input %> :<%= attribute.name %>
9
+ = f.<%= attribute.reference? ? :pg_associable : :input %> :<%= attribute.name %>
10
10
  <%- end -%>
11
11
  .mt-2
12
12
  = f.button :submit
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.7
4
+ version: 7.0.8.pre.alpha.6
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-11 00:00:00.000000000 Z
11
+ date: 2024-02-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails goodies.
14
14
  email:
@@ -19,22 +19,17 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - MIT-LICENSE
21
21
  - README.md
22
- - pg_associable/app/assets/css/pg_associable.scss
23
- - pg_associable/app/assets/js/asociable_controller.js
24
- - pg_associable/app/assets/js/asociable_inline_controller.js
25
- - pg_associable/app/assets/js/modal_controller.js
22
+ - pg_associable/app/assets/stylesheets/pg_associable.scss
26
23
  - pg_associable/app/helpers/pg_associable/form_builder_methods.rb
27
24
  - pg_associable/app/helpers/pg_associable/helpers.rb
28
- - pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb
29
- - pg_associable/app/inputs/pg_associable/pg_associable_input.rb
30
- - pg_associable/app/views/pg_associable/_resultados.html.slim
25
+ - pg_associable/app/inputs/pg_associable_input.rb
26
+ - pg_associable/app/javascript/asociable_controller.tsx
27
+ - pg_associable/app/javascript/modal_controller.js
31
28
  - pg_associable/app/views/pg_associable/_resultados_inline.html.slim
32
29
  - pg_associable/app/views/pg_engine/base/_pg_associable_modal.html.slim
33
30
  - pg_associable/index.js
34
31
  - pg_associable/lib/pg_associable.rb
35
32
  - pg_associable/lib/pg_associable/engine.rb
36
- - pg_associable/lib/pg_associable/simple_form_initializer.rb
37
- - pg_associable/lib/tasks/pg_associable_tasks.rake
38
33
  - pg_associable/spec/pg_associable/helpers_spec.rb
39
34
  - pg_engine/app/admin/accounts.rb
40
35
  - pg_engine/app/admin/audits.rb
@@ -102,12 +97,14 @@ files:
102
97
  - pg_engine/db/migrate/20240210025702_create_active_admin_comments.rb
103
98
  - pg_engine/db/migrate/20240211152951_create_accounts.rb
104
99
  - pg_engine/db/migrate/20240211153049_create_user_accounts.rb
100
+ - pg_engine/db/migrate/20240222115722_create_active_storage_tables.active_storage.rb
105
101
  - pg_engine/db/seeds.rb
106
102
  - pg_engine/lib/pg_engine.rb
107
103
  - pg_engine/lib/pg_engine/configuracion.rb
108
104
  - pg_engine/lib/pg_engine/core_ext.rb
109
105
  - pg_engine/lib/pg_engine/engine.rb
110
106
  - pg_engine/lib/pg_engine/route_helpers.rb
107
+ - pg_engine/lib/pg_engine/utils/pdf_preview_generator.rb
111
108
  - pg_engine/lib/pg_engine/utils/pg_logger.rb
112
109
  - pg_engine/lib/tasks/auto_anotar_modelos.rake
113
110
  - pg_engine/spec/controllers/admin/accounts_controller_spec.rb
@@ -116,12 +113,17 @@ files:
116
113
  - pg_engine/spec/factories/accounts.rb
117
114
  - pg_engine/spec/factories/user_accounts.rb
118
115
  - pg_engine/spec/factories/users.rb
116
+ - pg_engine/spec/fixtures/test.pdf
119
117
  - pg_engine/spec/models/account_spec.rb
120
118
  - pg_engine/spec/models/user_account_spec.rb
121
119
  - pg_engine/spec/models/user_spec.rb
120
+ - pg_engine/spec/pg_engine/pdf_preview_generator_spec.rb
122
121
  - pg_layout/app/assets/stylesheets/sidebar.scss
123
122
  - pg_layout/app/javascript/cookies.js
124
123
  - pg_layout/app/javascript/navbar_controller.js
124
+ - pg_layout/app/javascript/nested_controller.js
125
+ - pg_layout/app/javascript/pg_form_controller.js
126
+ - pg_layout/app/javascript/utils.ts
125
127
  - pg_layout/app/lib/navbar.rb
126
128
  - pg_layout/app/views/devise/confirmations/new.html.erb
127
129
  - pg_layout/app/views/devise/mailer/confirmation_instructions.html.erb
@@ -220,9 +222,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
222
  version: '3.0'
221
223
  required_rubygems_version: !ruby/object:Gem::Requirement
222
224
  requirements:
223
- - - ">="
225
+ - - ">"
224
226
  - !ruby/object:Gem::Version
225
- version: '0'
227
+ version: 1.3.1
226
228
  requirements: []
227
229
  rubygems_version: 3.3.22
228
230
  signing_key:
@@ -1,58 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus'
2
-
3
- export default class extends Controller {
4
- static outlets = ['modal']
5
-
6
- lastValue = null
7
-
8
- connect (e) {
9
- console.log('connect asociable')
10
-
11
- // ID único para identificar el campo y el modal
12
- const elemId = Math.trunc(Math.random() * 1000000000)
13
- this.element.setAttribute('data-asociable-modal-outlet', `.modal-${elemId}`)
14
- this.element.classList.add(`asociable-${elemId}`)
15
-
16
- const that = this
17
- const modalLink = this.targets.element.querySelector('.modal-link')
18
- const path = modalLink.attributes.href.value
19
- modalLink.setAttribute('href', `${path}?id=${elemId}`)
20
- modalLink.onclick = (e) => {
21
- // Si ya hay un modal abierto lo abro y evito que se haga el get
22
- // Si no, dejo que se ejecute el comportamiento por default
23
- if (that.modalOutlets.length > 0) {
24
- e.preventDefault()
25
- that.modalOutlet.openModal()
26
- }
27
- }
28
- const input = this.element.querySelector('input[type=text]')
29
- if (input.value) {
30
- this.element.classList.add('filled')
31
- }
32
- }
33
-
34
- selectItem (e) {
35
- // TODO: text en data
36
- this.completarCampo(e.target.dataset.id, e.target.text)
37
- }
38
-
39
- completarCampo (id, text) {
40
- const textField = this.element.querySelector('input[type=text]')
41
- const hiddenField = this.element.querySelector('input[type=hidden]')
42
- if (id === undefined) {
43
- id = null
44
- }
45
- hiddenField.value = id
46
- if (id) {
47
- textField.value = text
48
- this.element.classList.add('filled')
49
- } else {
50
- textField.value = null
51
- this.element.classList.remove('filled')
52
- }
53
- }
54
-
55
- disconnect (e) {
56
- console.log('disconnect asociable')
57
- }
58
- }
@@ -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,117 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus'
2
- import * as bootstrap from 'bootstrap'
3
-
4
- export default class extends Controller {
5
- static outlets = ['asociable']
6
- static targets = ['response', 'result', 'searchInput', 'searchForm']
7
-
8
- modalPuntero = null
9
- lastValue = ''
10
-
11
- connect (e) {
12
- console.log('ModalController connected')
13
- const modal = this.targets.element
14
- this.modalPuntero = new bootstrap.Modal(modal)
15
- this.modalPuntero.show()
16
-
17
- if (this.searchInputTargets.length > 0) {
18
- this.bindSearchInput()
19
- }
20
- }
21
-
22
- debounce (callback, wait) {
23
- let timerId
24
- return (...args) => {
25
- clearTimeout(timerId)
26
- timerId = setTimeout(() => {
27
- callback(...args)
28
- }, wait)
29
- }
30
- }
31
-
32
- bindSearchInput () {
33
- const doSearchBounce = this.debounce((force) => {
34
- this.doSearch(force)
35
- }, 200)
36
- this.searchInputTarget.onkeydown = (e) => {
37
- if (e.keyCode === 13) {
38
- e.preventDefault()
39
- return false
40
- }
41
- }
42
- this.searchInputTarget.onkeyup = (e) => {
43
- if (e.keyCode === 13) {
44
- doSearchBounce(true)
45
- } else {
46
- doSearchBounce()
47
- }
48
- }
49
- }
50
-
51
- buscando () {
52
- this.resultTarget.innerHTML = `
53
- <ul class="resultados list-group list-group-flush" tabindex="-1">
54
- <li class="list-group-item">
55
- <span class="fst-italic text-secondary">Buscando...</span>
56
- </li>
57
- </ul>
58
- `
59
- }
60
-
61
- doSearch (force = false) {
62
- if (!force && this.searchInputTarget.value.length < 3) {
63
- return
64
- }
65
- if (!force && this.searchInputTarget.value === this.lastValue) {
66
- return
67
- }
68
- this.lastValue = this.searchInputTarget.value
69
-
70
- const timerId = setTimeout(() => {
71
- this.buscando()
72
- }, 200)
73
- document.addEventListener('turbo:before-stream-render', function (e) {
74
- clearTimeout(timerId)
75
- })
76
- this.searchFormTarget.requestSubmit()
77
- }
78
-
79
- selectItem (e) {
80
- const asociable = this.asociableOutlet
81
- // TODO: text en data
82
- asociable.completarCampo(e.target.dataset.id, e.target.text)
83
- this.remove()
84
- }
85
-
86
- responseTargetConnected (e) {
87
- const newObject = JSON.parse(e.dataset.response)
88
- const asociable = this.asociableOutlet
89
- asociable.completarCampo(newObject.id, newObject.to_s)
90
- this.remove()
91
- }
92
-
93
- remove () {
94
- this.targets.element.remove()
95
- }
96
-
97
- openModal () {
98
- this.modalPuntero.show()
99
- }
100
-
101
- toggleCrearElegir (e) {
102
- const content = this.element.querySelector('.modal-content')
103
- const state = content.dataset.state
104
- const newValue = state === 'new-item' ? 'select-item' : 'new-item'
105
- content.setAttribute('data-state', newValue)
106
- }
107
-
108
- disconnect (e) {
109
- console.log('ModalController disconnected')
110
- this.modalPuntero.dispose()
111
- document.querySelectorAll('.modal-backdrop').forEach(e => { e.remove() })
112
- }
113
-
114
- buscar () {
115
- alert('buscar')
116
- }
117
- }
@@ -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