From 328ff509e392faf16d68b3e3d079617cc2514edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 9 Oct 2025 15:40:42 +0200 Subject: [PATCH] trabajando en el wizard del presupuesto --- .../presupuesto/PresupuestoController.java | 63 +++++++++++++++++-- .../PresupuestoDatatableService.java | 2 +- src/main/resources/i18n/app_es.properties | 4 +- .../resources/i18n/presupuesto_es.properties | 3 + src/main/resources/static/assets/css/app.css | 22 +++---- src/main/resources/static/assets/js/app.js | 18 +++++- .../pages/imprimelibros/presupuestos/list.js | 7 +++ .../presupuestos/presupuesto-form.html | 56 +++++++++++++++++ .../presupuestos/presupuesto-list.html | 24 ++++--- 9 files changed, 173 insertions(+), 26 deletions(-) create mode 100644 src/main/resources/templates/imprimelibros/presupuestos/presupuesto-form.html diff --git a/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java b/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java index 321d936..ac38d57 100644 --- a/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java +++ b/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoController.java @@ -5,6 +5,7 @@ import org.springframework.ui.Model; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -16,15 +17,17 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.http.MediaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.type.TypeReference; - +import com.imprimelibros.erp.configurationERP.VariableService; import com.imprimelibros.erp.datatables.*; import com.imprimelibros.erp.externalApi.skApiClient; import com.imprimelibros.erp.i18n.TranslationService; @@ -41,6 +44,8 @@ import jakarta.validation.Valid; @RequestMapping("/presupuesto") public class PresupuestoController { + private final PresupuestoRepository presupuestoRepository; + @Autowired protected PresupuestoService presupuestoService; @@ -53,12 +58,16 @@ public class PresupuestoController { private final ObjectMapper objectMapper; private final TranslationService translationService; private final PresupuestoDatatableService dtService; + private final VariableService variableService; public PresupuestoController(ObjectMapper objectMapper, TranslationService translationService, - PresupuestoDatatableService dtService) { + PresupuestoDatatableService dtService, PresupuestoRepository presupuestoRepository, + VariableService variableService) { this.objectMapper = objectMapper; this.translationService = translationService; this.dtService = dtService; + this.presupuestoRepository = presupuestoRepository; + this.variableService = variableService; } @PostMapping("/public/validar/datos-generales") @@ -421,7 +430,7 @@ public class PresupuestoController { // MÉTODOS PARA USUARIOS AUTENTICADOS // ============================================= @GetMapping - public String getPresupuestoView(Model model, Authentication authentication, Locale locale) { + public String getPresupuestoList(Model model, Authentication authentication, Locale locale) { List keys = List.of(); @@ -431,9 +440,55 @@ public class PresupuestoController { return "imprimelibros/presupuestos/presupuesto-list"; } + @GetMapping(value = { "/edit/{id}", "/view/{id}" }) + public String getPresupuestoEditForm( + @PathVariable(name = "id", required = true) Long id, + RedirectAttributes redirectAttributes, + Model model, + Authentication authentication, + Locale locale) { + + List keys = List.of( + "presupuesto.plantilla-cubierta", + "presupuesto.plantilla-cubierta-text", + "presupuesto.impresion-cubierta", + "presupuesto.impresion-cubierta-help"); + + Map translations = translationService.getTranslations(locale, keys); + model.addAttribute("languageBundle", translations); + model.addAttribute("pod", variableService.getValorEntero("POD")); + model.addAttribute("ancho_alto_min", variableService.getValorEntero("ancho_alto_min")); + model.addAttribute("ancho_alto_max", variableService.getValorEntero("ancho_alto_max")); + + // Buscar el presupuesto + Optional presupuestoOpt = presupuestoRepository.findById(id); + boolean isUser = authentication.getAuthorities().stream() + .anyMatch(a -> a.getAuthority().equals("ROLE_USER")); + + if (isUser) { + // Si es usuario, solo puede ver sus propios presupuestos + String username = authentication.getName(); + if (!presupuestoOpt.get().getUser().getUserName().equals(username)) { + presupuestoOpt = Optional.empty(); + } + } + + if (presupuestoOpt.isEmpty()) { + // Añadir mensaje flash para mostrar alerta + redirectAttributes.addFlashAttribute("errorMessage", + messageSource.getMessage("presupuesto.errores.presupuesto-no-existe", new Object[] { id }, locale)); + // Redirigir a la vista de lista + return "redirect:/presupuesto"; + } + + // Si existe, lo añadimos al modelo + model.addAttribute("presupuesto", presupuestoOpt.get()); + return "imprimelibros/presupuestos/presupuesto-form"; + } + @GetMapping(value = "/datatable/anonimos", produces = "application/json") @ResponseBody - public DataTablesResponse> datatableAnonimos( + public DataTablesResponse> datatableAnonimos( HttpServletRequest request, Authentication auth, Locale locale) { DataTablesRequest dt = DataTablesParser.from(request); diff --git a/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoDatatableService.java b/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoDatatableService.java index 041cbee..de4774a 100644 --- a/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoDatatableService.java +++ b/src/main/java/com/imprimelibros/erp/presupuesto/PresupuestoDatatableService.java @@ -177,7 +177,7 @@ public class PresupuestoDatatableService { m.put("actions", "
" + "" + + + "\" class=\"link-success btn-edit-anonimo fs-15\">" + "" + diff --git a/src/main/resources/i18n/app_es.properties b/src/main/resources/i18n/app_es.properties index 0fff1f0..073a9a5 100644 --- a/src/main/resources/i18n/app_es.properties +++ b/src/main/resources/i18n/app_es.properties @@ -16,4 +16,6 @@ app.logout=Cerrar sesión app.sidebar.inicio=Inicio app.sidebar.presupuestos=Presupuestos app.sidebar.configuracion=Configuración -app.sidebar.usuarios=Usuarios \ No newline at end of file +app.sidebar.usuarios=Usuarios + +app.errors.403=No tienes permiso para acceder a esta página. \ No newline at end of file diff --git a/src/main/resources/i18n/presupuesto_es.properties b/src/main/resources/i18n/presupuesto_es.properties index 651734a..c691497 100644 --- a/src/main/resources/i18n/presupuesto_es.properties +++ b/src/main/resources/i18n/presupuesto_es.properties @@ -1,4 +1,5 @@ presupuesto.title=Presupuestos +presupuesto.editar.title=Editar presupuesto presupuesto.datos-generales=Datos Generales presupuesto.interior=Interior presupuesto.cubierta=Cubierta @@ -287,5 +288,7 @@ presupuesto.errores.papel-cubierta=Seleccione el tipo de papel para la cubierta presupuesto.errores.gramaje-cubierta=Seleccione el gramaje del papel para la cubierta presupuesto.errores.acabado-cubierta=Seleccione el acabado de la cubierta +presupuesto.errores.presupuesto-no-existe=El presupuesto con ID {0} no existe. + presupuesto.errores.presupuesto-maquetacion=No se pudo calcular el presupuesto de maquetación. presupuesto.errores.presupuesto-marcapaginas=No se pudo calcular el presupuesto de marcapáginas. \ No newline at end of file diff --git a/src/main/resources/static/assets/css/app.css b/src/main/resources/static/assets/css/app.css index 8475747..efffc86 100644 --- a/src/main/resources/static/assets/css/app.css +++ b/src/main/resources/static/assets/css/app.css @@ -1780,15 +1780,15 @@ File: Main Css File } [data-layout=semibox] .main-content { margin-left: calc(250px + 25px); - padding: 0 6%; + padding: 0 2%; } [data-layout=semibox] .footer { - left: calc(250px + 6% + 1.5rem + 25px); - right: calc(6% + 1.5rem); + left: calc(250px + 2% + 1.5rem + 25px); + right: calc(2% + 1.5rem); } [data-layout=semibox] #page-topbar { - left: calc(250px + 6% + 1.5rem + 25px); - right: calc(6% + 1.5rem); + left: calc(250px + 2% + 1.5rem + 25px); + right: calc(2% + 1.5rem); top: 25px; border-radius: 0.25rem; -webkit-transition: all 0.5s ease; @@ -1801,10 +1801,10 @@ File: Main Css File margin-left: calc(180px + 25px); } [data-layout=semibox][data-sidebar-size=md] #page-topbar { - left: calc(180px + 6% + 1.5rem + 25px); + left: calc(180px + 2% + 1.5rem + 25px); } [data-layout=semibox][data-sidebar-size=md] .footer { - left: calc(180px + 6% + 1.5rem + 25px); + left: calc(180px + 2% + 1.5rem + 25px); } [data-layout=semibox][data-sidebar-size=sm] .main-content { margin-left: calc(70px + 25px); @@ -1813,19 +1813,19 @@ File: Main Css File top: 25px; } [data-layout=semibox][data-sidebar-size=sm] #page-topbar { - left: calc(70px + 6% + 1.5rem + 25px); + left: calc(70px + 2% + 1.5rem + 25px); } [data-layout=semibox][data-sidebar-size=sm] .footer { - left: calc(70px + 6% + 1.5rem + 25px); + left: calc(70px + 2% + 1.5rem + 25px); } [data-layout=semibox][data-sidebar-size=sm-hover] .main-content { margin-left: calc(70px + 25px); } [data-layout=semibox][data-sidebar-size=sm-hover] #page-topbar { - left: calc(70px + 6% + 1.5rem + 25px); + left: calc(70px + 2% + 1.5rem + 25px); } [data-layout=semibox][data-sidebar-size=sm-hover] .footer { - left: calc(70px + 6% + 1.5rem + 25px); + left: calc(70px + 2% + 1.5rem + 25px); } } [data-layout=semibox] .mx-n4 { diff --git a/src/main/resources/static/assets/js/app.js b/src/main/resources/static/assets/js/app.js index 15cfd89..521d5cc 100644 --- a/src/main/resources/static/assets/js/app.js +++ b/src/main/resources/static/assets/js/app.js @@ -22,7 +22,7 @@ if (!lang || lang === getCurrentLang()) return; // Guarda la preferencia (opcional) - try { localStorage.setItem("language", lang); } catch {} + try { localStorage.setItem("language", lang); } catch { } // Redirige con ?lang=... para que Spring cambie el Locale y renderice en ese idioma const url = new URL(location.href); @@ -48,6 +48,22 @@ url.searchParams.set("lang", saved); location.replace(url); // alinea y no deja historial extra } + + initsAlert(); + } + + function initsAlert() { + var alerts = document.querySelectorAll('.alert.alert-dismissible'); + alerts.forEach(function (el) { + // Solo si está visible + if (el.classList.contains('show')) { + setTimeout(function () { + // Usa la API de Bootstrap para cerrar con transición + var bsAlert = bootstrap.Alert.getOrCreateInstance(el); + bsAlert.close(); + }, 5000); + } + }); } document.addEventListener("DOMContentLoaded", initLanguage); diff --git a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestos/list.js b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestos/list.js index 36278af..c45ea46 100644 --- a/src/main/resources/static/assets/js/pages/imprimelibros/presupuestos/list.js +++ b/src/main/resources/static/assets/js/pages/imprimelibros/presupuestos/list.js @@ -66,6 +66,13 @@ ], }); + $('#presupuestos-anonimos-datatable').on('click', '.btn-edit-anonimo', function (e) { + e.preventDefault(); + const id = $(this).data('id'); + if (id) { + window.location.href = '/presupuesto/view/' + id; + } + }); })(); diff --git a/src/main/resources/templates/imprimelibros/presupuestos/presupuesto-form.html b/src/main/resources/templates/imprimelibros/presupuestos/presupuesto-form.html new file mode 100644 index 0000000..fe88e19 --- /dev/null +++ b/src/main/resources/templates/imprimelibros/presupuestos/presupuesto-form.html @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + +
+
+ + +
+ + +
+ +
+ +
+ +
+
+
+
+ + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/imprimelibros/presupuestos/presupuesto-list.html b/src/main/resources/templates/imprimelibros/presupuestos/presupuesto-list.html index 4f2680d..8541660 100644 --- a/src/main/resources/templates/imprimelibros/presupuestos/presupuesto-list.html +++ b/src/main/resources/templates/imprimelibros/presupuestos/presupuesto-list.html @@ -21,16 +21,24 @@
- +
+ +
+ +