Private
Public Access
algunos refactors y arregle el tema de que no se eliminaban los
subgrupos
This commit is contained in:
1 parent
ab88be0ba5
commit
df2412f29a
25 files changed
+406
-252
No files matched your search
@@ -3,7 +3,6 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"repuestera_back/dto"
|
|
||||||
r "repuestera_back/repositorios"
|
r "repuestera_back/repositorios"
|
||||||
"repuestera_back/utils"
|
"repuestera_back/utils"
|
||||||
|
|
||||||
@@ -12,7 +11,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CambiarContraseña(c *gin.Context) {
|
func CambiarContraseña(c *gin.Context) {
|
||||||
var req dto.CambiarContraseñaRequest
|
var req struct {
|
||||||
|
UserID uint `json:"user_id"`
|
||||||
|
OldPassword string `json:"old_password"`
|
||||||
|
NewPassword string `json:"new_password" binding:"required"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Login(c *gin.Context) {
|
func Login(c *gin.Context) {
|
||||||
var req dto.LoginRequest
|
var req struct {
|
||||||
|
Email string `json:"email" binding:"required,email"`
|
||||||
|
Password string `json:"password" binding:"required"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Refresh(c *gin.Context) {
|
func Refresh(c *gin.Context) {
|
||||||
var req dto.RefreshRequest
|
var req struct {
|
||||||
|
RefreshToken string `json:"refresh_token" binding:"required"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Register(c *gin.Context) {
|
func Register(c *gin.Context) {
|
||||||
var req dto.RegisterRequest
|
var req struct {
|
||||||
|
Email string `json:"email" binding:"required,email"`
|
||||||
|
Password string `json:"password" binding:"required,min=6"`
|
||||||
|
Name string `json:"name" binding:"required"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package grupo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"repuestera_back/dto"
|
|
||||||
r "repuestera_back/repositorios"
|
r "repuestera_back/repositorios"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AgregarGrupoAUsuario(c *gin.Context) {
|
func AgregarGrupoAUsuario(c *gin.Context) {
|
||||||
var req dto.GrupoUsuarioRelacion
|
var req struct {
|
||||||
|
GrupoID uint `json:"grupo_id" binding:"required"`
|
||||||
|
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package grupo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"repuestera_back/dto"
|
|
||||||
r "repuestera_back/repositorios"
|
r "repuestera_back/repositorios"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -10,7 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func AgregarPermisoAGrupo(c *gin.Context) {
|
func AgregarPermisoAGrupo(c *gin.Context) {
|
||||||
var req dto.GrupoPermisoRequest
|
var req struct {
|
||||||
|
PermisoID uint `json:"permission_id"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package grupo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"repuestera_back/dto"
|
|
||||||
r "repuestera_back/repositorios"
|
r "repuestera_back/repositorios"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -10,7 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func AgregarSubGrupo(c *gin.Context) {
|
func AgregarSubGrupo(c *gin.Context) {
|
||||||
var req dto.GrupoHijoRequest
|
var req struct {
|
||||||
|
ChildGroupID uint `json:"child_group_id"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package grupo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"repuestera_back/dto"
|
|
||||||
r "repuestera_back/repositorios"
|
r "repuestera_back/repositorios"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func QuitarGrupoAUsuario(c *gin.Context) {
|
func QuitarGrupoAUsuario(c *gin.Context) {
|
||||||
var req dto.GrupoUsuarioRelacion
|
var req struct {
|
||||||
|
GrupoID uint `json:"grupo_id" binding:"required"`
|
||||||
|
UsuarioID uint `json:"usuario_id" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package grupo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"repuestera_back/dto"
|
|
||||||
r "repuestera_back/repositorios"
|
r "repuestera_back/repositorios"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -10,7 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func QuitarPermisoAGrupo(c *gin.Context) {
|
func QuitarPermisoAGrupo(c *gin.Context) {
|
||||||
var req dto.GrupoPermisoRequest
|
var req struct {
|
||||||
|
PermisoID uint `json:"permission_id"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package grupo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"repuestera_back/dto"
|
|
||||||
r "repuestera_back/repositorios"
|
r "repuestera_back/repositorios"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -10,7 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func QuitarSubGrupo(c *gin.Context) {
|
func QuitarSubGrupo(c *gin.Context) {
|
||||||
var req dto.GrupoHijoRequest
|
var req struct {
|
||||||
|
ChildGroupID uint `json:"child_group_id"`
|
||||||
|
}
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
package repuestos
|
package repuestos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"repuestera_back/models"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
r "repuestera_back/repositorios"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CrearRepuesto(c *gin.Context){
|
|
||||||
|
|
||||||
|
|
||||||
|
func CrearRepuesto(c *gin.Context){
|
||||||
|
var repuesto models.Repuesto
|
||||||
|
if err := c.ShouldBindJSON(&repuesto); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.ObtenerRepositorios().Repuesto.Crear(&repuesto); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusCreated, repuesto)
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,18 @@
|
|||||||
package repuestos
|
package repuestos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
r "repuestera_back/repositorios"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ObtenerRepuestos(c *gin.Context){
|
func ObtenerRepuestos(c *gin.Context){
|
||||||
|
repuestos, err := r.ObtenerRepositorios().Repuesto.ObtenerTodos()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, repuestos)
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,5 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
type LoginRequest struct {
|
|
||||||
Email string `json:"email" binding:"required,email"`
|
|
||||||
Password string `json:"password" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RegisterRequest struct {
|
|
||||||
Email string `json:"email" binding:"required,email"`
|
|
||||||
Password string `json:"password" binding:"required,min=6"`
|
|
||||||
Name string `json:"name" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TokenResponse struct {
|
type TokenResponse struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken string `json:"refresh_token"`
|
||||||
@@ -29,13 +18,3 @@ type MeResponse struct {
|
|||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefreshRequest struct {
|
|
||||||
RefreshToken string `json:"refresh_token" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CambiarContraseñaRequest struct {
|
|
||||||
UserID uint `json:"user_id"`
|
|
||||||
OldPassword string `json:"old_password"`
|
|
||||||
NewPassword string `json:"new_password" binding:"required"`
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,5 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
type GrupoPermisoRequest struct {
|
|
||||||
PermisoID uint `json:"permission_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GrupoHijoRequest struct {
|
|
||||||
ChildGroupID uint `json:"child_group_id"`
|
|
||||||
}
|
|
||||||
type GrupoSimpleDTO struct {
|
type GrupoSimpleDTO struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Nombre string `json:"nombre"`
|
Nombre string `json:"nombre"`
|
||||||
@@ -26,12 +19,3 @@ type GruposYPermisosResponse struct {
|
|||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Groups []GrupoSimpleDTO `json:"groups"`
|
Groups []GrupoSimpleDTO `json:"groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GrupoUsuarioRelacion struct {
|
|
||||||
GrupoID uint `json:"grupo_id" binding:"required"`
|
|
||||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UsuarioIDRequest struct{
|
|
||||||
UsuarioID uint `json:"usuario_id" binding:"required"`
|
|
||||||
}
|
|
||||||
@@ -148,16 +148,24 @@ func (r *repositorioGrupo) AgregarSubGrupo(padreID, hijoID uint) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *repositorioGrupo) QuitarSubGrupo(padreID, hijoID uint) error {
|
func (r *repositorioGrupo) QuitarSubGrupo(padreID, hijoID uint) error {
|
||||||
|
// var padre models_seguridad.Grupo
|
||||||
|
// if err := r.db.Preload("Grupos").First(&padre, padreID).Error; err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
var padre models_seguridad.Grupo
|
var padre models_seguridad.Grupo
|
||||||
if err := r.db.Preload("Grupos").First(&padre, padreID).Error; err != nil {
|
if err := r.db.Preload("Grupos").First(&padre, padreID).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var nuevos []models_seguridad.Grupo
|
|
||||||
for _, g := range padre.Grupos {
|
return r.db.Model(&padre).Association("Grupos").Delete(&models_seguridad.Grupo{ID: hijoID})
|
||||||
if g.ID != hijoID {
|
|
||||||
nuevos = append(nuevos, g)
|
// var nuevos []models_seguridad.Grupo
|
||||||
}
|
// for _, g := range padre.Grupos {
|
||||||
}
|
// if g.ID != hijoID {
|
||||||
padre.Grupos = nuevos
|
// nuevos = append(nuevos, g)
|
||||||
return r.db.Save(&padre).Error
|
// }
|
||||||
|
// }
|
||||||
|
// padre.Grupos = nuevos
|
||||||
|
// return r.db.Save(&padre).Error
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,8 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function obtenerGrupos(): Promise<Grupo[]> {
|
export async function obtenerGrupos(fetch?: Function): Promise<Grupo[]> {
|
||||||
|
if (!fetch) fetch = window.fetch;
|
||||||
const response = await fetch(`${API_URL}/grupos`, {
|
const response = await fetch(`${API_URL}/grupos`, {
|
||||||
headers: { Authorization: `Bearer ${getToken()}` }
|
headers: { Authorization: `Bearer ${getToken()}` }
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function obtenerPermisos(): Promise<Permiso[]> {
|
export async function obtenerPermisos(fetch?: Function): Promise<Permiso[]> {
|
||||||
|
if (!fetch) fetch = window.fetch;
|
||||||
const response = await fetch(`${API_URL}/permisos`, {
|
const response = await fetch(`${API_URL}/permisos`, {
|
||||||
headers: { Authorization: `Bearer ${getToken()}` }
|
headers: { Authorization: `Bearer ${getToken()}` }
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,42 +1,32 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import { Button, DataTableSkeleton, InlineNotification, Table, TableBody, TableCell, TableContainer, TableHead, TableHeader, TableRow } from 'carbon-components-svelte';
|
||||||
Button,
|
import { invalidate } from '$app/navigation';
|
||||||
ComboBox,
|
|
||||||
DataTableSkeleton,
|
|
||||||
InlineNotification,
|
|
||||||
Modal,
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableContainer,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
TextInput,
|
|
||||||
TextArea
|
|
||||||
} from 'carbon-components-svelte';
|
|
||||||
import Header from '$lib/components/Header.svelte';
|
import Header from '$lib/components/Header.svelte';
|
||||||
import Toast from '$lib/components/Toast.svelte';
|
import Toast from '$lib/components/Toast.svelte';
|
||||||
|
import GrupoFormModal from './GrupoFormModal.svelte';
|
||||||
|
import DeleteGrupoModal from './DeleteGrupoModal.svelte';
|
||||||
|
import AgregarPermisoModal from './AgregarPermisoModal.svelte';
|
||||||
|
import AgregarSubgrupoModal from './AgregarSubgrupoModal.svelte';
|
||||||
|
import QuitarSubgrupoModal from './QuitarSubgrupoModal.svelte';
|
||||||
import {
|
import {
|
||||||
obtenerGrupos,
|
|
||||||
crearGrupo,
|
crearGrupo,
|
||||||
actualizarGrupo,
|
actualizarGrupo,
|
||||||
eliminarGrupo,
|
eliminarGrupo,
|
||||||
obtenerPermisos,
|
|
||||||
asignarPermisoAGrupo,
|
asignarPermisoAGrupo,
|
||||||
quitarPermisoAGrupo,
|
quitarPermisoAGrupo,
|
||||||
agregarSubGrupo,
|
agregarSubGrupo,
|
||||||
quitarSubGrupo
|
quitarSubGrupo
|
||||||
} from '$lib/api';
|
} from '$lib/api';
|
||||||
import type { Grupo, Permiso } from '../../types';
|
import type { Grupo } from '../../types';
|
||||||
|
import type { PageData } from './$types';
|
||||||
import Add from 'carbon-icons-svelte/lib/Add.svelte';
|
import Add from 'carbon-icons-svelte/lib/Add.svelte';
|
||||||
import Edit from 'carbon-icons-svelte/lib/Edit.svelte';
|
import Edit from 'carbon-icons-svelte/lib/Edit.svelte';
|
||||||
import TrashCan from 'carbon-icons-svelte/lib/TrashCan.svelte';
|
import TrashCan from 'carbon-icons-svelte/lib/TrashCan.svelte';
|
||||||
import Close from 'carbon-icons-svelte/lib/Close.svelte';
|
import Close from 'carbon-icons-svelte/lib/Close.svelte';
|
||||||
|
|
||||||
let grupos: Grupo[] = $state([]);
|
let { data }: { data: PageData } = $props();
|
||||||
let allPermisos: Permiso[] = $state([]);
|
|
||||||
let loading = $state(true);
|
let loading = $state(false);
|
||||||
let error = $state('');
|
let error = $state('');
|
||||||
|
|
||||||
let modalOpen = $state(false);
|
let modalOpen = $state(false);
|
||||||
@@ -53,8 +43,9 @@
|
|||||||
|
|
||||||
let permisoModalOpen = $state(false);
|
let permisoModalOpen = $state(false);
|
||||||
let subgrupoModalOpen = $state(false);
|
let subgrupoModalOpen = $state(false);
|
||||||
let selectedPermisoItem = $state<{ id: number; text: string } | null>(null);
|
let quitarSubgrupoModalOpen = $state(false);
|
||||||
let selectedSubgrupoItem = $state<{ id: number; text: string } | null>(null);
|
let quitarSubgrupoId = $state(0);
|
||||||
|
let quitarSubgrupoNombre = $state('');
|
||||||
|
|
||||||
let successMsg = $state('');
|
let successMsg = $state('');
|
||||||
let errorMsg = $state('');
|
let errorMsg = $state('');
|
||||||
@@ -66,48 +57,6 @@
|
|||||||
{ key: 'descripcion' as const, value: 'Descripción' }
|
{ key: 'descripcion' as const, value: 'Descripción' }
|
||||||
];
|
];
|
||||||
|
|
||||||
async function cargarGrupos() {
|
|
||||||
loading = true;
|
|
||||||
error = '';
|
|
||||||
try {
|
|
||||||
grupos = await obtenerGrupos();
|
|
||||||
} catch (e) {
|
|
||||||
error = e instanceof Error ? e.message : 'Error al cargar grupos';
|
|
||||||
} finally {
|
|
||||||
loading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function cargarPermisos() {
|
|
||||||
try {
|
|
||||||
allPermisos = await obtenerPermisos();
|
|
||||||
} catch {
|
|
||||||
// silently fail, permisos list is not critical
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function abrirModalCrear() {
|
|
||||||
modalEditando = false;
|
|
||||||
formId = 0;
|
|
||||||
formNombre = '';
|
|
||||||
formDescripcion = '';
|
|
||||||
modalOpen = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function abrirModalEditar(g: Grupo) {
|
|
||||||
modalEditando = true;
|
|
||||||
formId = g.id;
|
|
||||||
formNombre = g.nombre;
|
|
||||||
formDescripcion = g.descripcion ?? '';
|
|
||||||
modalOpen = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function abrirModalEliminar(g: Grupo) {
|
|
||||||
deleteId = g.id;
|
|
||||||
deleteNombre = g.nombre;
|
|
||||||
deleteModalOpen = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function seleccionarGrupo(g: Grupo) {
|
function seleccionarGrupo(g: Grupo) {
|
||||||
selectedGrupo = selectedGrupo?.id === g.id ? null : g;
|
selectedGrupo = selectedGrupo?.id === g.id ? null : g;
|
||||||
}
|
}
|
||||||
@@ -121,12 +70,20 @@
|
|||||||
}, 4000);
|
}, 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSecondary() {
|
async function recargar() {
|
||||||
modalOpen = false;
|
loading = true;
|
||||||
|
error = '';
|
||||||
|
try {
|
||||||
|
await invalidate(() => true);
|
||||||
|
if (selectedGrupo) {
|
||||||
|
const updated = data.grupos.find((g) => g.id === selectedGrupo!.id);
|
||||||
|
if (updated) selectedGrupo = updated;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
error = e instanceof Error ? e.message : 'Error al recargar';
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDeleteSecondary() {
|
|
||||||
deleteModalOpen = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function guardarGrupo() {
|
async function guardarGrupo() {
|
||||||
@@ -154,7 +111,7 @@
|
|||||||
}
|
}
|
||||||
modalOpen = false;
|
modalOpen = false;
|
||||||
selectedGrupo = null;
|
selectedGrupo = null;
|
||||||
await cargarGrupos();
|
await recargar();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg = e instanceof Error ? e.message : 'Error al guardar grupo';
|
errorMsg = e instanceof Error ? e.message : 'Error al guardar grupo';
|
||||||
notifOpen = true;
|
notifOpen = true;
|
||||||
@@ -170,7 +127,7 @@
|
|||||||
deleteModalOpen = false;
|
deleteModalOpen = false;
|
||||||
selectedGrupo = null;
|
selectedGrupo = null;
|
||||||
mostrarNotificacion('Grupo eliminado', '');
|
mostrarNotificacion('Grupo eliminado', '');
|
||||||
await cargarGrupos();
|
await recargar();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg = e instanceof Error ? e.message : 'Error al eliminar grupo';
|
errorMsg = e instanceof Error ? e.message : 'Error al eliminar grupo';
|
||||||
notifOpen = true;
|
notifOpen = true;
|
||||||
@@ -180,25 +137,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function abrirModalAgregarPermiso() {
|
async function agregarPermiso(item: { id: number; text: string }) {
|
||||||
selectedPermisoItem = null;
|
if (!selectedGrupo) return;
|
||||||
permisoModalOpen = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function abrirModalAgregarSubgrupo() {
|
|
||||||
selectedSubgrupoItem = null;
|
|
||||||
subgrupoModalOpen = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function agregarPermiso() {
|
|
||||||
if (!selectedGrupo || !selectedPermisoItem) return;
|
|
||||||
try {
|
try {
|
||||||
await asignarPermisoAGrupo(selectedGrupo.id, selectedPermisoItem.id);
|
await asignarPermisoAGrupo(selectedGrupo.id, item.id);
|
||||||
mostrarNotificacion('Permiso asignado', '');
|
mostrarNotificacion('Permiso asignado', '');
|
||||||
permisoModalOpen = false;
|
permisoModalOpen = false;
|
||||||
await cargarGrupos();
|
await recargar();
|
||||||
const updated = grupos.find((g) => g.id === selectedGrupo!.id);
|
|
||||||
if (updated) selectedGrupo = updated;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg = e instanceof Error ? e.message : 'Error al asignar permiso';
|
errorMsg = e instanceof Error ? e.message : 'Error al asignar permiso';
|
||||||
notifOpen = true;
|
notifOpen = true;
|
||||||
@@ -213,9 +158,7 @@
|
|||||||
try {
|
try {
|
||||||
await quitarPermisoAGrupo(selectedGrupo.id, permisoId);
|
await quitarPermisoAGrupo(selectedGrupo.id, permisoId);
|
||||||
mostrarNotificacion('Permiso quitado', '');
|
mostrarNotificacion('Permiso quitado', '');
|
||||||
await cargarGrupos();
|
await recargar();
|
||||||
const updated = grupos.find((g) => g.id === selectedGrupo!.id);
|
|
||||||
if (updated) selectedGrupo = updated;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg = e instanceof Error ? e.message : 'Error al quitar permiso';
|
errorMsg = e instanceof Error ? e.message : 'Error al quitar permiso';
|
||||||
notifOpen = true;
|
notifOpen = true;
|
||||||
@@ -225,15 +168,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function agregarSubgrupo() {
|
async function agregarSubgrupo(item: { id: number; text: string }) {
|
||||||
if (!selectedGrupo || !selectedSubgrupoItem) return;
|
if (!selectedGrupo) return;
|
||||||
try {
|
try {
|
||||||
await agregarSubGrupo(selectedGrupo.id, selectedSubgrupoItem.id);
|
await agregarSubGrupo(selectedGrupo.id, item.id);
|
||||||
mostrarNotificacion('Subgrupo agregado', '');
|
mostrarNotificacion('Subgrupo agregado', '');
|
||||||
subgrupoModalOpen = false;
|
subgrupoModalOpen = false;
|
||||||
await cargarGrupos();
|
await recargar();
|
||||||
const updated = grupos.find((g) => g.id === selectedGrupo!.id);
|
|
||||||
if (updated) selectedGrupo = updated;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg = e instanceof Error ? e.message : 'Error al agregar subgrupo';
|
errorMsg = e instanceof Error ? e.message : 'Error al agregar subgrupo';
|
||||||
notifOpen = true;
|
notifOpen = true;
|
||||||
@@ -243,14 +184,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function quitarSubgrupo(childGroupId: number) {
|
async function confirmarQuitarSubgrupo() {
|
||||||
if (!selectedGrupo) return;
|
if (!selectedGrupo) return;
|
||||||
try {
|
try {
|
||||||
await quitarSubGrupo(selectedGrupo.id, childGroupId);
|
await quitarSubGrupo(selectedGrupo.id, quitarSubgrupoId);
|
||||||
mostrarNotificacion('Subgrupo quitado', '');
|
mostrarNotificacion('Subgrupo quitado', '');
|
||||||
await cargarGrupos();
|
quitarSubgrupoModalOpen = false;
|
||||||
const updated = grupos.find((g) => g.id === selectedGrupo!.id);
|
await recargar();
|
||||||
if (updated) selectedGrupo = updated;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg = e instanceof Error ? e.message : 'Error al quitar subgrupo';
|
errorMsg = e instanceof Error ? e.message : 'Error al quitar subgrupo';
|
||||||
notifOpen = true;
|
notifOpen = true;
|
||||||
@@ -261,20 +201,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let permisosDisponibles = $derived(
|
let permisosDisponibles = $derived(
|
||||||
allPermisos.filter((p) => !selectedGrupo?.permisos?.some((sp) => sp.id === p.id))
|
data.permisos.filter((p) => !selectedGrupo?.permisos?.some((sp) => sp.id === p.id))
|
||||||
);
|
);
|
||||||
|
|
||||||
let gruposDisponibles = $derived(
|
let gruposDisponibles = $derived(
|
||||||
grupos.filter(
|
data.grupos.filter(
|
||||||
(g) =>
|
(g) =>
|
||||||
g.id !== selectedGrupo?.id && !selectedGrupo?.grupos_hijos?.some((sg) => sg.id === g.id)
|
g.id !== selectedGrupo?.id && !selectedGrupo?.grupos_hijos?.some((sg) => sg.id === g.id)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
cargarGrupos();
|
|
||||||
cargarPermisos();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Header />
|
<Header />
|
||||||
@@ -282,7 +217,7 @@
|
|||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<h1 class="page-title">Gestión de Grupos</h1>
|
<h1 class="page-title">Gestión de Grupos</h1>
|
||||||
<Button onclick={abrirModalCrear} icon={Add}>Nuevo Grupo</Button>
|
<Button onclick={() => { modalEditando = false; formId = 0; formNombre = ''; formDescripcion = ''; modalOpen = true; }} icon={Add}>Nuevo Grupo</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if error}
|
{#if error}
|
||||||
@@ -303,7 +238,7 @@
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{#each grupos as g (g.id)}
|
{#each data.grupos as g (g.id)}
|
||||||
<TableRow
|
<TableRow
|
||||||
class="selected-row={selectedGrupo?.id === g.id}"
|
class="selected-row={selectedGrupo?.id === g.id}"
|
||||||
onclick={() => seleccionarGrupo(g)}
|
onclick={() => seleccionarGrupo(g)}
|
||||||
@@ -315,14 +250,14 @@
|
|||||||
<TableCell>{String(g[header.key] ?? '-')}</TableCell>
|
<TableCell>{String(g[header.key] ?? '-')}</TableCell>
|
||||||
{/each}
|
{/each}
|
||||||
<TableCell class="acciones-cell">
|
<TableCell class="acciones-cell">
|
||||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => abrirModalEditar(g)}>
|
<Button kind="ghost" size="small" icon={Edit} onclick={() => { modalEditando = true; formId = g.id; formNombre = g.nombre; formDescripcion = g.descripcion ?? ''; modalOpen = true; }}>
|
||||||
Editar
|
Editar
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
kind="ghost"
|
kind="ghost"
|
||||||
size="small"
|
size="small"
|
||||||
icon={TrashCan}
|
icon={TrashCan}
|
||||||
onclick={() => abrirModalEliminar(g)}
|
onclick={() => { deleteId = g.id; deleteNombre = g.nombre; deleteModalOpen = true; }}
|
||||||
>
|
>
|
||||||
Eliminar
|
Eliminar
|
||||||
</Button>
|
</Button>
|
||||||
@@ -348,7 +283,7 @@
|
|||||||
<div class="detail-col">
|
<div class="detail-col">
|
||||||
<div class="detail-col-header">
|
<div class="detail-col-header">
|
||||||
<h3>Permisos</h3>
|
<h3>Permisos</h3>
|
||||||
<Button kind="ghost" size="small" icon={Add} onclick={abrirModalAgregarPermiso}>
|
<Button kind="ghost" size="small" icon={Add} onclick={() => permisoModalOpen = true}>
|
||||||
Agregar
|
Agregar
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -389,7 +324,7 @@
|
|||||||
<div class="detail-col">
|
<div class="detail-col">
|
||||||
<div class="detail-col-header">
|
<div class="detail-col-header">
|
||||||
<h3>Subgrupos</h3>
|
<h3>Subgrupos</h3>
|
||||||
<Button kind="ghost" size="small" icon={Add} onclick={abrirModalAgregarSubgrupo}>
|
<Button kind="ghost" size="small" icon={Add} onclick={() => subgrupoModalOpen = true}>
|
||||||
Agregar
|
Agregar
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -412,7 +347,7 @@
|
|||||||
kind="ghost"
|
kind="ghost"
|
||||||
size="small"
|
size="small"
|
||||||
icon={Close}
|
icon={Close}
|
||||||
onclick={() => quitarSubgrupo(sg.id)}
|
onclick={() => { quitarSubgrupoId = sg.id; quitarSubgrupoNombre = sg.nombre; quitarSubgrupoModalOpen = true; }}
|
||||||
>
|
>
|
||||||
Quitar
|
Quitar
|
||||||
</Button>
|
</Button>
|
||||||
@@ -431,85 +366,42 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="grupo-form" onsubmit={guardarGrupo}>
|
<GrupoFormModal
|
||||||
<Modal
|
|
||||||
bind:open={modalOpen}
|
bind:open={modalOpen}
|
||||||
modalHeading={modalEditando ? 'Editar Grupo' : 'Nuevo Grupo'}
|
editando={modalEditando}
|
||||||
primaryButtonText={modalEditando ? 'Guardar' : 'Crear'}
|
bind:nombre={formNombre}
|
||||||
secondaryButtonText="Cancelar"
|
bind:descripcion={formDescripcion}
|
||||||
formId="grupo-form"
|
alGuardar={guardarGrupo}
|
||||||
on:click:button--secondary={handleSecondary}
|
alCerrar={() => (modalOpen = false)}
|
||||||
hasForm
|
|
||||||
>
|
|
||||||
<TextInput bind:value={formNombre} labelText="Nombre" placeholder="ej: Administradores" />
|
|
||||||
<TextArea
|
|
||||||
bind:value={formDescripcion}
|
|
||||||
labelText="Descripción"
|
|
||||||
placeholder="Descripción del grupo"
|
|
||||||
/>
|
/>
|
||||||
</Modal>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="delete-form" onsubmit={confirmarEliminar}>
|
<DeleteGrupoModal
|
||||||
<Modal
|
|
||||||
bind:open={deleteModalOpen}
|
bind:open={deleteModalOpen}
|
||||||
modalHeading="Eliminar Grupo"
|
nombre={deleteNombre}
|
||||||
primaryButtonText="Eliminar"
|
alConfirmar={confirmarEliminar}
|
||||||
secondaryButtonText="Cancelar"
|
alCerrar={() => (deleteModalOpen = false)}
|
||||||
formId="delete-form"
|
/>
|
||||||
hasForm
|
|
||||||
on:click:button--secondary={handleDeleteSecondary}
|
|
||||||
danger
|
|
||||||
>
|
|
||||||
<p>¿Estás seguro de que querés eliminar el grupo <strong>{deleteNombre}</strong>?</p>
|
|
||||||
</Modal>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="permiso-form" onsubmit={agregarPermiso}>
|
<AgregarPermisoModal
|
||||||
<Modal
|
|
||||||
bind:open={permisoModalOpen}
|
bind:open={permisoModalOpen}
|
||||||
modalHeading="Agregar Permiso"
|
{permisosDisponibles}
|
||||||
primaryButtonText="Agregar"
|
alSeleccionar={agregarPermiso}
|
||||||
secondaryButtonText="Cancelar"
|
alCerrar={() => (permisoModalOpen = false)}
|
||||||
formId="permiso-form"
|
|
||||||
hasForm
|
|
||||||
on:click:button--secondary={() => (permisoModalOpen = false)}
|
|
||||||
>
|
|
||||||
{#if permisosDisponibles.length === 0}
|
|
||||||
<p class="text-secondary">No hay permisos disponibles para agregar.</p>
|
|
||||||
{:else}
|
|
||||||
<ComboBox
|
|
||||||
labelText="Seleccionar permiso"
|
|
||||||
items={permisosDisponibles.map((p) => ({ id: p.id, text: `${p.nombre} (${p.alias})` }))}
|
|
||||||
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
|
||||||
on:select={(e) => (selectedPermisoItem = e.detail.selectedItem)}
|
|
||||||
/>
|
/>
|
||||||
{/if}
|
|
||||||
</Modal>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="subgrupo-form" onsubmit={agregarSubgrupo}>
|
<AgregarSubgrupoModal
|
||||||
<Modal
|
|
||||||
bind:open={subgrupoModalOpen}
|
bind:open={subgrupoModalOpen}
|
||||||
modalHeading="Agregar Subgrupo"
|
{gruposDisponibles}
|
||||||
primaryButtonText="Agregar"
|
alSeleccionar={agregarSubgrupo}
|
||||||
secondaryButtonText="Cancelar"
|
alCerrar={() => (subgrupoModalOpen = false)}
|
||||||
formId="subgrupo-form"
|
/>
|
||||||
hasForm
|
|
||||||
on:click:button--secondary={() => (subgrupoModalOpen = false)}
|
<QuitarSubgrupoModal
|
||||||
>
|
bind:open={quitarSubgrupoModalOpen}
|
||||||
{#if gruposDisponibles.length === 0}
|
nombre={quitarSubgrupoNombre}
|
||||||
<p class="text-secondary">No hay grupos disponibles para agregar como subgrupo.</p>
|
alConfirmar={confirmarQuitarSubgrupo}
|
||||||
{:else}
|
alCerrar={() => (quitarSubgrupoModalOpen = false)}
|
||||||
<ComboBox
|
|
||||||
labelText="Seleccionar subgrupo"
|
|
||||||
items={gruposDisponibles.map((g) => ({ id: g.id, text: g.nombre }))}
|
|
||||||
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
|
||||||
on:select={(e) => (selectedSubgrupoItem = e.detail.selectedItem)}
|
|
||||||
/>
|
/>
|
||||||
{/if}
|
|
||||||
</Modal>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<Toast
|
<Toast
|
||||||
kind={successMsg ? 'success' : 'error'}
|
kind={successMsg ? 'success' : 'error'}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { obtenerGrupos, obtenerPermisos } from '$lib/api';
|
||||||
|
import type { Grupo, Permiso } from '../../types';
|
||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
let grupos: Grupo[] = [];
|
||||||
|
let permisos: Permiso[] = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
grupos = await obtenerGrupos(fetch);
|
||||||
|
} catch {
|
||||||
|
// token might not be available on server
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
permisos = await obtenerPermisos(fetch);
|
||||||
|
} catch {
|
||||||
|
// token might not be available on server
|
||||||
|
}
|
||||||
|
|
||||||
|
return { grupos, permisos };
|
||||||
|
};
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { ComboBox, Modal } from 'carbon-components-svelte';
|
||||||
|
import type { Permiso } from '../../types';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(false),
|
||||||
|
permisosDisponibles = [],
|
||||||
|
alSeleccionar,
|
||||||
|
alCerrar
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
permisosDisponibles: Permiso[];
|
||||||
|
alSeleccionar?: (item: { id: number; text: string }) => void;
|
||||||
|
alCerrar?: () => void;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
let itemSeleccionado: { id: number; text: string } | null = $state(null);
|
||||||
|
|
||||||
|
function enviar() {
|
||||||
|
if (!itemSeleccionado) return;
|
||||||
|
alSeleccionar?.(itemSeleccionado);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form id="permiso-form" onsubmit={enviar}>
|
||||||
|
<Modal
|
||||||
|
bind:open
|
||||||
|
modalHeading="Agregar Permiso"
|
||||||
|
primaryButtonText="Agregar"
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
formId="permiso-form"
|
||||||
|
hasForm
|
||||||
|
on:click:button--secondary={() => alCerrar?.()}
|
||||||
|
>
|
||||||
|
{#if permisosDisponibles.length === 0}
|
||||||
|
<p class="text-secondary">No hay permisos disponibles para agregar.</p>
|
||||||
|
{:else}
|
||||||
|
<ComboBox
|
||||||
|
labelText="Seleccionar permiso"
|
||||||
|
items={permisosDisponibles.map((p) => ({ id: p.id, text: `${p.nombre} (${p.alias})` }))}
|
||||||
|
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
||||||
|
on:select={(e) => (itemSeleccionado = e.detail.selectedItem)}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { ComboBox, Modal } from 'carbon-components-svelte';
|
||||||
|
import type { Grupo } from '../../types';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(false),
|
||||||
|
gruposDisponibles = [],
|
||||||
|
alSeleccionar,
|
||||||
|
alCerrar
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
gruposDisponibles: Grupo[];
|
||||||
|
alSeleccionar?: (item: { id: number; text: string }) => void;
|
||||||
|
alCerrar?: () => void;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
let itemSeleccionado: { id: number; text: string } | null = $state(null);
|
||||||
|
|
||||||
|
function enviar() {
|
||||||
|
if (!itemSeleccionado) return;
|
||||||
|
alSeleccionar?.(itemSeleccionado);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form id="subgrupo-form" onsubmit={enviar}>
|
||||||
|
<Modal
|
||||||
|
bind:open
|
||||||
|
modalHeading="Agregar Subgrupo"
|
||||||
|
primaryButtonText="Agregar"
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
formId="subgrupo-form"
|
||||||
|
hasForm
|
||||||
|
on:click:button--secondary={() => alCerrar?.()}
|
||||||
|
>
|
||||||
|
{#if gruposDisponibles.length === 0}
|
||||||
|
<p class="text-secondary">No hay grupos disponibles para agregar como subgrupo.</p>
|
||||||
|
{:else}
|
||||||
|
<ComboBox
|
||||||
|
labelText="Seleccionar subgrupo"
|
||||||
|
items={gruposDisponibles.map((g) => ({ id: g.id, text: g.nombre }))}
|
||||||
|
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
||||||
|
on:select={(e) => (itemSeleccionado = e.detail.selectedItem)}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Modal } from 'carbon-components-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(false),
|
||||||
|
nombre = '',
|
||||||
|
alConfirmar,
|
||||||
|
alCerrar
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
nombre?: string;
|
||||||
|
alConfirmar?: () => void;
|
||||||
|
alCerrar?: () => void;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form id="delete-form" onsubmit={alConfirmar}>
|
||||||
|
<Modal
|
||||||
|
bind:open
|
||||||
|
modalHeading="Eliminar Grupo"
|
||||||
|
primaryButtonText="Eliminar"
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
formId="delete-form"
|
||||||
|
hasForm
|
||||||
|
on:click:button--secondary={() => alCerrar?.()}
|
||||||
|
danger
|
||||||
|
>
|
||||||
|
<p>¿Estás seguro de que querés eliminar el grupo <strong>{nombre}</strong>?</p>
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Modal, TextInput, TextArea } from 'carbon-components-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(false),
|
||||||
|
editando = false,
|
||||||
|
nombre = $bindable(''),
|
||||||
|
descripcion = $bindable(''),
|
||||||
|
alGuardar,
|
||||||
|
alCerrar
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
editando?: boolean;
|
||||||
|
nombre: string;
|
||||||
|
descripcion: string;
|
||||||
|
alGuardar?: () => void;
|
||||||
|
alCerrar?: () => void;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form id="grupo-form" onsubmit={alGuardar}>
|
||||||
|
<Modal
|
||||||
|
bind:open
|
||||||
|
modalHeading={editando ? 'Editar Grupo' : 'Nuevo Grupo'}
|
||||||
|
primaryButtonText={editando ? 'Guardar' : 'Crear'}
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
formId="grupo-form"
|
||||||
|
on:click:button--secondary={() => alCerrar?.()}
|
||||||
|
hasForm
|
||||||
|
>
|
||||||
|
<TextInput bind:value={nombre} labelText="Nombre" placeholder="ej: Administradores" />
|
||||||
|
<TextArea
|
||||||
|
bind:value={descripcion}
|
||||||
|
labelText="Descripción"
|
||||||
|
placeholder="Descripción del grupo"
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Modal } from 'carbon-components-svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
open = $bindable(false),
|
||||||
|
nombre = '',
|
||||||
|
alConfirmar,
|
||||||
|
alCerrar
|
||||||
|
}: {
|
||||||
|
open: boolean;
|
||||||
|
nombre?: string;
|
||||||
|
alConfirmar?: () => void;
|
||||||
|
alCerrar?: () => void;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form id="quitar-subgrupo-form" onsubmit={alConfirmar}>
|
||||||
|
<Modal
|
||||||
|
bind:open
|
||||||
|
modalHeading="Quitar Subgrupo"
|
||||||
|
primaryButtonText="Quitar"
|
||||||
|
secondaryButtonText="Cancelar"
|
||||||
|
formId="quitar-subgrupo-form"
|
||||||
|
hasForm
|
||||||
|
on:click:button--secondary={() => alCerrar?.()}
|
||||||
|
danger
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
¿Estás seguro de que querés quitar el subgrupo <strong>{nombre}</strong>?
|
||||||
|
</p>
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<script>
|
||||||
|
import { Modal } from 'carbon-components-svelte';
|
||||||
|
|
||||||
|
let { show } = $props();
|
||||||
|
|
||||||
|
let error = $state('');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form
|
||||||
|
id="crearRepuestoForm"
|
||||||
|
onsubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Modal
|
||||||
|
formId="crearRepuestoForm"
|
||||||
|
bind:open={show}
|
||||||
|
modalHeading="Registrar Repuesto"
|
||||||
|
primaryButtonText="Registrar"
|
||||||
|
secondaryButtonText="Cerrar"
|
||||||
|
on:click:button--secondary={handleClose}
|
||||||
|
>
|
||||||
|
{#if error}
|
||||||
|
<div class="error-msg">{error}</div>
|
||||||
|
{/if}
|
||||||
|
<TextInput name="nombre" type="text" labelText="Nombre: " bind:value={usuario.name} />
|
||||||
|
<TextInput name="email" type="text" labelText="Email" bind:value={usuario.email} />
|
||||||
|
</Modal>
|
||||||
|
</form>
|
||||||
Reference in new issue
Block a user