Skip to content

Commit

Permalink
Merge branch 'rgl538' into 'main'
Browse files Browse the repository at this point in the history
https://gitlab.com/pasosdeJesus/sivel2_gen/-/issues/538 Pasa funciones coffee de filtro a stimulus

See merge request pasosdeJesus/sivel2_gen!514
  • Loading branch information
vtamara committed Aug 26, 2024
2 parents b7aec3e + 26722a8 commit e36135e
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 97 deletions.
49 changes: 0 additions & 49 deletions app/assets/javascripts/sivel2_gen/motor.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,6 @@ enviaFormularioContarPost= (root) ->
root.elempe = []
)

$(document).on('click', 'button#boton_filtro_avanzado', (e) ->
if $(this).attr("aria-expanded") == 'true'
$('#botones_finfiltro').removeClass("float-end").addClass("d-flex justify-content-center")
else
$('#botones_finfiltro').removeClass("d-flex justify-content-center").addClass("float-end")
if $('#conscasos_q').is(':visible')
$('#conscasos_q').hide()
else
$('#conscasos_q').show()
)

Sivel2GenMotorEs6.iniciar()

# Elimina acto
Expand Down Expand Up @@ -785,44 +774,6 @@ enviaFormularioContarPost= (root) ->
return event.preventDefault()
)

$(document).on('change', '#filtro_tviolencia_id', (e) ->
tviolencia_id = $(this).val()
select = $(this)
if tviolencia_id != "Z"
b = root.puntomontaje + 'admin/categorias/filtratviolencia'
$.ajax({
url: b,
data: {tviolencia: tviolencia_id},
dataType: "json",
success: (datos) ->
div_padre = select.closest("div")
div_grid = div_padre.parent()
div_filtro = div_grid.parent().parent()
input_cat = div_filtro.find("select[id=filtro_categoria_id]")
Msip__Motor.configurarElementoTomSelect(input_cat.val(datos[0]))
error: (jqXHR, texto) ->
alert("Error: " + jqXHR.responseText)
})
)
$(document).on('change', '#filtro_categoria_id', (e) ->
categoria_id = $(this).val()
select = $(this)
b = root.puntomontaje + 'admin/categorias/filtratviolencia'
$.ajax({
url: b,
data: {categorias_seleccionadas: categoria_id},
dataType: "json",
success: (datos) ->
if datos[0] == false
div_padre = select.closest("div")
div_grid = div_padre.parent()
div_filtro = div_grid.parent().parent()
input_tipo = div_filtro.find("select[id=filtro_tviolencia_id]")
Msip__Motor.configurarElementoTomSelect(input_tipo.val("Z"))
error: (jqXHR, texto) ->
alert("Error: " + jqXHR.responseText)
})
)
return

@sivel2_gen_prepara_eventos_unicos = (root) ->
Expand Down
96 changes: 96 additions & 0 deletions app/javascript/controllers/filtro_avanzado_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Controller } from "@hotwired/stimulus"
// Maneja filrto avanzado de casos con stimulus

import Msip__Motor from "../msip/motor"

// Conecta con data-controller="sivel2-gen--filtro-avanzado"
export default class extends Controller {

static targets = [
"botonesFin"
]

connect() {
console.log("Conexion de controlador filtro avanzado establecida")
}

abrir(e){
if (e.target && e.target.id === 'boton_filtro_avanzado') {
var botonFiltro = e.target;

if (botonFiltro.getAttribute('aria-expanded') === 'true') {
this.botonesFinTarget.classList.remove('float-end');
this.botonesFinTarget.classList.add('d-flex', 'justify-content-center');
} else {
this.botonesFinTarget.classList.remove('d-flex', 'justify-content-center');
this.botonesFinTarget.classList.add('float-end');
}
}
}

filtrar_tviolencia(e){
if (e.target && e.target.id === 'filtro_tviolencia_id') {
var tviolencia_id = e.target.value;
var select = e.target;

if (tviolencia_id !== "Z") {
var url = window.puntomontaje + 'admin/categorias/filtratviolencia';

var xhr = new XMLHttpRequest();
xhr.open('GET', url + '?tviolencia=' + encodeURIComponent(tviolencia_id), true);
xhr.responseType = 'json';

xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var datos = xhr.response;
var div_padre = select.closest('div');
var div_grid = div_padre.parentElement;
var div_filtro = div_grid.parentElement.parentElement;
var input_cat = div_filtro.querySelector('select[id=filtro_categoria_id]');

//Msip__Motor.configurarElementoTomSelect(input_cat.value = datos[0]);
} else {
alert('Error: ' + xhr.responseText);
}
}
};

xhr.send();
}
}
}

filtrar_categoria(e){
if (e.target && e.target.id === 'filtro_categoria_id') {
var categoria_id = e.target.value;
var select = e.target;
var url = window.puntomontaje + 'admin/categorias/filtratviolencia';

var xhr = new XMLHttpRequest();
xhr.open('GET', url + '?categorias_seleccionadas=' + encodeURIComponent(categoria_id), true);
xhr.responseType = 'json';

xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var datos = xhr.response;
if (datos[0] === false) {
debugger
var div_padre = select.closest('div');
var div_grid = div_padre.parentElement;
var div_filtro = div_grid.parentElement.parentElement;
var input_tipo = div_filtro.querySelector('select[id=filtro_tviolencia_id]');
Msip__Motor.configurarElementoTomSelect(input_tipo.value = 'Z');
}
} else {
alert('Error: ' + xhr.responseText);
}
}
};

xhr.send();
}
}

}
7 changes: 6 additions & 1 deletion app/views/sivel2_gen/casos/_filtro_avanzado.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
selected: "Z",
label: false,
include_blank: false
input_html: {
"data-action": "change->sivel2-gen--filtro-avanzado#filtrar_tviolencia",
}
%>

</div>
Expand All @@ -169,7 +172,9 @@
},
value_method: :id,
:include_hidden => false,
input_html: { :class => "tom-select", multiple: true },
input_html: { :class => "tom-select",
"data-action": "change->sivel2-gen--filtro-avanzado#filtrar_categoria",
multiple: true },
label: false
%>
</div>
Expand Down
95 changes: 48 additions & 47 deletions app/views/sivel2_gen/casos/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,60 @@
{ remote: true,
url: sivel2_gen.casos_path,
method: "get" } do |f|
%>
<div class="container">
<div class="row align-items-center">
<div class="offset-md-0 col-md-1">
<% if @conscaso.size > 0 && current_usuario &&
can?(:new, Sivel2Gen::Caso) %>
<%= render partial: 'msip/modelos/boton_nuevo',
locals: {ruta: sivel2_gen.new_caso_path} %>
<% end %>
</div>
<div class="offset-md-3 col-md-1">
Casos: <span id="numconscaso"><%= @conscaso.count %></span>
</div>
<div class="offset-md-2 col-md-2">
<%= f.input :q,
label: false,
placeholder: 'Búsqueda aproximada'
%>
</div>
<div class="col">
<button type='buton'
class="btn btn-default btn-sm float-end"
role="button"
data-bs-toggle="collapse"
data-bs-target="#filtro_avanzado"
aria-expanded="false"
aria-controls="filtro_avanzado"
id="boton_filtro_avanzado">
Búsqueda Avanzada
</button>
</div>
%>
<div class="container" data-controller="sivel2-gen--filtro-avanzado">
<div class="row align-items-center">
<div class="offset-md-0 col-md-1">
<% if @conscaso.size > 0 && current_usuario &&
can?(:new, Sivel2Gen::Caso) %>
<%= render partial: 'msip/modelos/boton_nuevo',
locals: {ruta: sivel2_gen.new_caso_path} %>
<% end %>
</div>
<div class="offset-md-3 col-md-1">
Casos: <span id="numconscaso"><%= @conscaso.count %></span>
</div>
<div class="row">
<div class="offset-md-0 col-md-12">
<div class="collapse" id="filtro_avanzado">
</br>
<%= render partial: 'filtro_avanzado', locals: {f: f} %>
</div>
<div class="offset-md-2 col-md-2">
<%= f.input :q,
label: false,
placeholder: 'Búsqueda aproximada'
%>
</div>
<div class="col">
<button type='button'
class="btn btn-default btn-sm float-end"
role="button"
data-action="click->sivel2-gen--filtro-avanzado#abrir"
data-bs-toggle="collapse"
data-bs-target="#filtro_avanzado"
aria-expanded="false"
aria-controls="filtro_avanzado"
id="boton_filtro_avanzado">
Búsqueda Avanzada
</button>
</div>
</div>
<div class="row">
<div class="offset-md-0 col-md-12">
<div class="collapse" id="filtro_avanzado">
</br>
<%= render partial: 'filtro_avanzado', locals: {f: f} %>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="float-end" id="botones_finfiltro">
<%= f.button :submit, 'Filtrar', id: 'sivel2_gen-filtrar-casos',
class: 'btn btn-default',
'data-turbo': false %>
<button class="btn btn-default" type="reset">
Limpiar
</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="float-end" id="botones_finfiltro" data-sivel2-gen--filtro-avanzado-target="botonesFin">
<%= f.button :submit, 'Filtrar', id: 'sivel2_gen-filtrar-casos',
class: 'btn btn-default',
'data-turbo': false %>
<button class="btn btn-default" type="reset">
Limpiar
</button>
</div>
</div>
</div>
</div>
<% end %>

<div id="casos">
Expand Down
3 changes: 3 additions & 0 deletions test/dummy/app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ application.register("sivel2-gen--edad", Sivel2Gen__EdadController)
import Sivel2Gen__EnviarFichaCasoController from "./sivel2_gen/enviar_ficha_caso_controller"
application.register("sivel2-gen--enviar-ficha-caso", Sivel2Gen__EnviarFichaCasoController)

import Sivel2Gen__FiltroAvanzadoController from "./sivel2_gen/filtro_avanzado_controller"
application.register("sivel2-gen--filtro-avanzado", Sivel2Gen__FiltroAvanzadoController)

import Sivel2Gen__MapaosmController from "./sivel2_gen/mapaosm_controller"
application.register("sivel2-gen--mapaosm", Sivel2Gen__MapaosmController)

Expand Down

0 comments on commit e36135e

Please sign in to comment.