Private
Public Access
añadido fuzzy search en grupos
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
c93199b636
commit
72f55e6773
4 files changed
+29
-29
No files matched your search
+2
-29
@@ -2,7 +2,6 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"sort"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"repuestera_back/dto"
|
"repuestera_back/dto"
|
||||||
@@ -55,7 +54,7 @@ func ConstruirSesion(usuarioID, empresaID uint) (*dto.AuthResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
empresaRol := membresia.Rol
|
empresaRol := membresia.Rol
|
||||||
permisos, err := PermisosDeMiembro(usuarioID, empresaID, membresia.Rol)
|
permisos, err := PermisosDeMiembro(usuarioID, empresaID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -105,24 +104,13 @@ func ConstruirSesion(usuarioID, empresaID uint) (*dto.AuthResponse, error) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PermisosDeMiembro(usuarioID, empresaID uint, rol models_seguridad.RolEmpresa) ([]uint, error) {
|
func PermisosDeMiembro(usuarioID, empresaID uint) ([]uint, error) {
|
||||||
usuario, err := r.ObtenerRepositorios().Usuario.PrecargarGruposPermisosDeEmpresa(usuarioID, empresaID)
|
usuario, err := r.ObtenerRepositorios().Usuario.PrecargarGruposPermisosDeEmpresa(usuarioID, empresaID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
permisos := utils.PermisosDeUsuario(usuario)
|
permisos := utils.PermisosDeUsuario(usuario)
|
||||||
if rol == models_seguridad.RolOwner {
|
|
||||||
permisos2, err := r.ObtenerRepositorios().Permiso.ObtenerTodos()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ids := make([]uint, 0, len(permisos2))
|
|
||||||
for n := range permisos2 {
|
|
||||||
ids = append(ids, permisos2[n].ID)
|
|
||||||
}
|
|
||||||
permisos = anexarUnicos(permisos, ids)
|
|
||||||
}
|
|
||||||
return permisos, nil
|
return permisos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,18 +153,3 @@ func EmpresaDeUsuario(usuarioID, empresaID uint) (*models_seguridad.Empresa, mod
|
|||||||
}
|
}
|
||||||
return empresa, membresia.Rol, nil
|
return empresa, membresia.Rol, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func anexarUnicos(base []uint, extras []uint) []uint {
|
|
||||||
vistos := make(map[uint]bool, len(base)+len(extras))
|
|
||||||
for _, id := range base {
|
|
||||||
vistos[id] = true
|
|
||||||
}
|
|
||||||
for _, id := range extras {
|
|
||||||
if !vistos[id] {
|
|
||||||
base = append(base, id)
|
|
||||||
vistos[id] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Slice(base, func(i, j int) bool { return base[i] < base[j] })
|
|
||||||
return base
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Búsqueda difusa simple: devuelve true si todos los caracteres de `consulta`
|
||||||
|
// aparecen en `texto` en el mismo orden (sin necesidad de ser contiguos).
|
||||||
|
export function fuzzyMatch(texto: string, consulta: string): boolean {
|
||||||
|
if (!consulta) return true;
|
||||||
|
const t = (texto ?? '').toLowerCase();
|
||||||
|
const q = consulta.toLowerCase();
|
||||||
|
let ti = 0;
|
||||||
|
for (let qi = 0; qi < q.length; qi++) {
|
||||||
|
const ch = q[qi];
|
||||||
|
ti = t.indexOf(ch, ti);
|
||||||
|
if (ti === -1) return false;
|
||||||
|
ti++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ComboBox, Modal } from 'carbon-components-svelte';
|
import { ComboBox, Modal } from 'carbon-components-svelte';
|
||||||
|
import { fuzzyMatch } from '$lib/utils/fuzzy';
|
||||||
import type { Permiso } from '../../types';
|
import type { Permiso } from '../../types';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -20,6 +21,10 @@
|
|||||||
if (!itemSeleccionado) return;
|
if (!itemSeleccionado) return;
|
||||||
alSeleccionar?.(itemSeleccionado);
|
alSeleccionar?.(itemSeleccionado);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filtrar(item: { id: number; text: string }, valor: string) {
|
||||||
|
return fuzzyMatch(item.text, valor);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form id="permiso-form" onsubmit={enviar}>
|
<form id="permiso-form" onsubmit={enviar}>
|
||||||
@@ -39,6 +44,7 @@
|
|||||||
labelText="Seleccionar permiso"
|
labelText="Seleccionar permiso"
|
||||||
items={permisosDisponibles.map((p) => ({ id: p.id, text: `${p.nombre} (${p.alias})` }))}
|
items={permisosDisponibles.map((p) => ({ id: p.id, text: `${p.nombre} (${p.alias})` }))}
|
||||||
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
||||||
|
shouldFilterItem={filtrar}
|
||||||
on:select={(e) => (itemSeleccionado = e.detail.selectedItem)}
|
on:select={(e) => (itemSeleccionado = e.detail.selectedItem)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ComboBox, Modal } from 'carbon-components-svelte';
|
import { ComboBox, Modal } from 'carbon-components-svelte';
|
||||||
|
import { fuzzyMatch } from '$lib/utils/fuzzy';
|
||||||
import type { Grupo } from '../../types';
|
import type { Grupo } from '../../types';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -20,6 +21,10 @@
|
|||||||
if (!itemSeleccionado) return;
|
if (!itemSeleccionado) return;
|
||||||
alSeleccionar?.(itemSeleccionado);
|
alSeleccionar?.(itemSeleccionado);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filtrar(item: { id: number; text: string }, valor: string) {
|
||||||
|
return fuzzyMatch(item.text, valor);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form id="subgrupo-form" onsubmit={enviar}>
|
<form id="subgrupo-form" onsubmit={enviar}>
|
||||||
@@ -39,6 +44,7 @@
|
|||||||
labelText="Seleccionar subgrupo"
|
labelText="Seleccionar subgrupo"
|
||||||
items={gruposDisponibles.map((g) => ({ id: g.id, text: g.nombre }))}
|
items={gruposDisponibles.map((g) => ({ id: g.id, text: g.nombre }))}
|
||||||
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
itemToString={(item: { id: number; text: string } | null) => (item ? item.text : '')}
|
||||||
|
shouldFilterItem={filtrar}
|
||||||
on:select={(e) => (itemSeleccionado = e.detail.selectedItem)}
|
on:select={(e) => (itemSeleccionado = e.detail.selectedItem)}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in new issue
Block a user