Skip to content

Commit

Permalink
Merge branch 'rgl518' into 'main'
Browse files Browse the repository at this point in the history
Rgl518 - Ya funciona Anexos con Turbo

See merge request pasosdeJesus/sivel2_gen!467
  • Loading branch information
vtamara committed Aug 5, 2023
2 parents 6f3e964 + eb6f2cc commit 2c2be1c
Show file tree
Hide file tree
Showing 19 changed files with 1,582 additions and 236 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GIT

GIT
remote: https://gitlab.com/pasosdeJesus/msip.git
revision: 92cd4c9c67935d4743612e4ec2184a20b8d84e82
revision: a3a4e8281a75ca159151d7edf78840aeea308869
branch: main
specs:
msip (2.2.0.beta4)
Expand Down Expand Up @@ -237,14 +237,14 @@ GEM
mime-types-data (3.2023.0218.1)
mini_mime (1.1.2)
mini_portile2 (2.8.4)
minitest (5.18.1)
minitest (5.19.0)
minitest-reporters (1.6.0)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
msgpack (1.7.2)
net-imap (0.3.6)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
Expand Down Expand Up @@ -280,7 +280,7 @@ GEM
puma (6.3.0)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.6)
Expand All @@ -301,7 +301,7 @@ GEM
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.1.1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
Expand Down Expand Up @@ -418,7 +418,7 @@ GEM
will_paginate (3.3.1)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.9)
zeitwerk (2.6.11)

PLATFORMS
x86_64-openbsd
Expand Down Expand Up @@ -481,4 +481,4 @@ DEPENDENCIES
will_paginate

BUNDLED WITH
2.4.17
2.4.18
10 changes: 10 additions & 0 deletions app/controllers/msip/anexos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'date'
require 'sivel2_gen/concerns/controllers/anexos_controller'

module Msip
class AnexosController < Msip::ModelosController

load_and_authorize_resource class: Msip::Anexo
include Sivel2Gen::Concerns::Controllers::AnexosController
end
end
8 changes: 8 additions & 0 deletions app/controllers/sivel2_gen/anexo_casos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'sivel2_gen/concerns/controllers/anexo_casos_controller'

module Sivel2Gen
class AnexoCasosController < ApplicationController
load_and_authorize_resource class: Sivel2Gen::AnexoCaso
include Sivel2Gen::Concerns::Controllers::AnexoCasosController
end
end
1 change: 0 additions & 1 deletion app/models/msip/anexo.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

require 'sivel2_gen/concerns/models/anexo'

module Msip
Expand Down
1 change: 1 addition & 0 deletions app/models/sivel2_gen/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def self.initialize_sivel2_gen(habilidad, usuario = nil)
habilidad.can :descarga_anexo, Msip::Anexo
habilidad.can :mostrar_portada, Msip::Anexo
habilidad.can :abre_anexo, Msip::Anexo
habilidad.can :manage, Sivel2Gen::AnexoCaso


habilidad.can :contar, Msip::Ubicacion
Expand Down
17 changes: 17 additions & 0 deletions app/views/sivel2_gen/anexo_casos/create.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= simple_form_for @caso , multipart: true do |form| %>
<%= form.simple_fields_for :anexo_caso,
child_index: params[:index] do |ca_form| %>
<%= turbo_stream.replace "agregar-anexo-caso" do %>
<%= form.submit "Añadir Anexo",
formaction: sivel2_gen.crear_anexo_caso_path(ca_form.index.to_i + 1),
formmethod: :post,
formnovalidate: true,
class: 'btn btn-sm btn-primary agregar-ca',
id: "agregar-anexo-caso" %>
<% end %>
<%= turbo_stream.append "anexo_casos_marco" do %>
<%= render "/sivel2_gen/casos/anexo_caso_campos", f: ca_form %>
<% end %>
<% end %>
<% end %>
9 changes: 9 additions & 0 deletions app/views/sivel2_gen/anexo_casos/destroy.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= fields model: @caso do |form| %>
<%= form.simple_fields_for :anexo_caso,
child_index: params[:index] do |ca_form| %>
<%= turbo_frame_tag "anexo_caso_#{ca_form.index}" do %>
<%= ca_form.hidden_field :id, value: params[:id] %>
<%= ca_form.hidden_field :_destroy, value: true %>
<% end %>
<% end %>
<% end %>
87 changes: 49 additions & 38 deletions app/views/sivel2_gen/casos/_anexo_caso_campos.html.erb
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
<div class='control-group nested-fields'>
<div class="controls">
<% f.object.msip_anexo = Msip::Anexo.new if !f.object.msip_anexo %>
<%= turbo_frame_tag "anexo_caso_#{f.index}" do %>
<div class='control-group nested-fields'>
<div class="controls">
<% if f.object.msip_anexo.nil? %>
<% f.object.msip_anexo = Msip::Anexo.new %>
<% end %>
<%= f.simple_fields_for :msip_anexo, :html => {:multipart => true} do |a| %>
<div class="row">
<div class="col-md-6">
<%= a.input :id, as: :hidden %>
<%= f.input :fecha,
:input_html => { type: "date" },
:as => :string,
:label => "Fecha" %>
</div>

<%= f.simple_fields_for :msip_anexo do |a| %>

<div class="row">
<div class="col-md-6">
<%= f.input :fecha_localizada,
:input_html => { "data-behaviour" => "datepicker" },
:as => :string, :label => "Fecha" %>
<div class="col-md-6">
<% if !a.object || !a.object.adjunto_file_name || !a.object.id %>
<%= a.input :adjunto, as: :file,
label: 'Archivo',
data: {
disable_with: false } %>
<% else %>
<div class="msip_anexo_adjunto">
<label for="msip_anexo_attributes_<%=a.object.id%>_adjunto">
Archivo
</label>
<a id="msip_anexo_attributes_<%=a.object.id%>_adjunto"
href="<%= msip.descarga_anexo_path(a.object.id) %>"
style="text-decoration:none"
data-turbo='false'>
<%= a.object.adjunto_file_name %>
</a>
</div>
<% end %>
</div>
</div>

<div class="col-md-6">
<% if !a.object || !a.object.adjunto_file_name || !a.object.id %>
<%= a.input :adjunto, as: :file, label: 'Archivo' %>
<% else %>
<div class="msip_anexo_adjunto">
<label for="msip_anexo_attributes_<%=a.object.id%>_adjunto">
Archivo
</label>
<a id="msip_anexo_attributes_<%=a.object.id%>_adjunto"
href="<%= msip.descarga_anexo_path(a.object.id) %>"
style="text-decoration:none"
data-turbo='false'>
<%= a.object.adjunto_file_name %>
</a>
</div>
<% end %>
</div>

</div>

<%= a.input :descripcion %>
<%= a.input :descripcion %>
<%= a.input :id, as: :hidden %>
<% end %> <!-- f.simple_fields_for :msip_anexo -->

<%= a.input :id, as: :hidden %>
<% end %> <!-- f.simple_fields_for :msip_anexo -->
<%= link_to_remove_association "Eliminar Anexo", f,
:class => 'btn btn-sm btn-danger',
style: 'margin-bottom: 1em'
%>
<%= f.submit "Eliminar",
formaction: eliminar_anexo_caso_path(id: f.object.id, index: f.index),
formmethod: :delete,
formnovalidate: true,
class: 'btn btn-sm btn-danger',
data: {
turbo_frame: "anexo_caso_#{f.index}",
disable_with: false
} %>
</div>
</div>
</div>
<% end %>
22 changes: 15 additions & 7 deletions app/views/sivel2_gen/casos/_anexos.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<%= f.simple_fields_for :anexo_caso do |anexo| %>
<%= render 'sivel2_gen/casos/anexo_caso_campos', :f => anexo %>
<% end %>
<div id="anexo_casos_marco">
<%= f.simple_fields_for :anexo_caso, child_index: params[:index] do |anexo| %>
<%= render 'sivel2_gen/casos/anexo_caso_campos', :f => anexo %>
<% end %>
</div>

<div class="links">
<%= link_to_add_association 'Añadir Anexo', f, :anexo_caso,
partial: 'sivel2_gen/casos/anexo_caso_campos',
:class => 'btn btn-sm btn-primary'
%>
<%= f.submit "Añadir Anexo",
formaction: sivel2_gen.crear_anexo_caso_path(index: @caso.anexo_caso.size),
formmethod: :post,
formnovalidate: true,
class: 'btn btn-sm btn-primary agregar-ca',
name: "agregar-anexo-caso",
id: "agregar-anexo-caso",
data: {
disable_with: false } %>
</div>
1 change: 1 addition & 0 deletions app/views/sivel2_gen/casos/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<% @pestanas_formulariocaso = controller.pestanas_formulariocaso %>
<%= simple_form_for @caso,
url: sivel2_gen.casos_path(@caso).sub(/\./,"/"),
multipart: true,
html: {
class: 'form-horizontal',
"data-controller": "msip--bitacoraap",
Expand Down
1 change: 1 addition & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
inflect.irregular 'caso_fuenteprensa', 'caso_fuentesprensa' # Tocó porque no permite otro plural
inflect.irregular 'caso_fotra', 'caso_fotras' # Tocó porque no permite otro plural
inflect.irregular 'caso_presponsable', 'caso_presponsables' # Tocó porque no permite otro plural
inflect.irregular 'caso_anexo', 'caso_anexos' # Tocó porque no permite otro plural
inflect.irregular 'clase', 'clases'
inflect.irregular 'contextovictima', 'contextosvictima'
inflect.irregular 'estadocivil', 'estadosciviles'
Expand Down
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
end
end

resources :anexo_casos, only: [], param: :index do
member do
delete '(:id)', to: "anexo_casos#destroy", as: "eliminar"
post '/' => "anexo_casos#create", as: "crear"
end
end

resources :caso_fuentesprensa, only: [], param: :index do
member do
delete '(:id)', to: "caso_fuentesprensa#destroy", as: "eliminar"
Expand Down
50 changes: 50 additions & 0 deletions lib/sivel2_gen/concerns/controllers/anexo_casos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'date'

module Sivel2Gen
module Concerns
module Controllers
module AnexoCasosController
extend ActiveSupport::Concern

included do
include ActionView::Helpers::AssetUrlHelper

load_and_authorize_resource class: Sivel2Gen::AnexoCaso

before_action :prepara_caso

def clase
"Sivel2Gen::AnexoCaso"
end


def nuevo
end

def destroy
end

def create
end

def update
end

def set_anexo_caso
@anexocaso = Sivel2Gen::AnexoCaso.find(params[:id])
@registro = @anexocaso
end

private

def prepara_caso
@caso = Sivel2Gen::Caso.new(
anexo_caso: [Sivel2Gen::AnexoCaso.new])
end
end # included

end
end
end
end

30 changes: 30 additions & 0 deletions lib/sivel2_gen/concerns/controllers/anexos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

require 'msip/concerns/controllers/anexos_controller'
require 'date'

module Sivel2Gen
module Concerns
module Controllers
module AnexosController
extend ActiveSupport::Concern

included do
include Msip::Concerns::Controllers::AnexosController

def remplazar_antes_salvar_v
true
end

def remplazar_despues_salvar_v
true
end

end # included


class_methods do
end # class_methods
end
end
end
end
2 changes: 2 additions & 0 deletions lib/sivel2_gen/concerns/controllers/casos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ def update_gen
if params[:_msip_enviarautomatico] == "1"
params_finales = caso_params.except(
:caso_etiqueta_attributes,
:caso_anexo_attributes,
:caso_fuenteprensa_attributes,
:caso_fotra_attributes,
:caso_presponsable_attributes
Expand Down Expand Up @@ -1209,6 +1210,7 @@ def lista_params_sivel2_gen
:anexo_caso_attributes => [
:id,
:caso_id,
:anexo_id,
:fecha,
:fecha_localizada,
:_destroy,
Expand Down
3 changes: 2 additions & 1 deletion lib/sivel2_gen/concerns/models/anexo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ module Anexo
include Msip::Concerns::Models::Anexo

included do

has_many :anexo_caso, foreign_key: "anexo_id",
validate: true, class_name: 'Sivel2Gen::AnexoCaso'
has_many :caso, class_name: 'Sivel2Gen::Caso',
through: :anexo_caso
through: :anexo_caso, inverse_of: :msip_anexo
end

module ClassMethods
Expand Down
2 changes: 2 additions & 0 deletions lib/sivel2_gen/concerns/models/anexo_caso.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module AnexoCaso
include Msip::Localizacion
include Msip::FormatoFechaHelper

self.table_name = 'sivel2_gen_anexo_caso'

belongs_to :caso, foreign_key: "caso_id", validate: true,
class_name: "Sivel2Gen::Caso", inverse_of: :anexo_caso,
optional: false
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 @@ -4,6 +4,9 @@

import { application } from "./application"

import Msip__BitacoraapController from "./msip/bitacoraap_controller"
application.register("msip--bitacoraap", Msip__BitacoraapController)

import Msip__CancelarVacioEsEliminarController from "./msip/cancelar_vacio_es_eliminar_controller"
application.register("msip--cancelar-vacio-es-eliminar", Msip__CancelarVacioEsEliminarController)

Expand Down
Loading

0 comments on commit 2c2be1c

Please sign in to comment.