Private
Public Access
Añadidos cmabios para presentar imagenes en los permisos y grupos
This commit is contained in:
1 parent
e784fb6ec8
commit
00f140480d
20 files changed
+468
-57
No files matched your search
+16
-13
@@ -1,20 +1,23 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM node:22-alpine AS builder
|
||||
# Imagen oficial de Bun
|
||||
FROM oven/bun:latest
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
# Copiar manifiestos primero para aprovechar el cache de capas
|
||||
# (el lockfile es bun.lock en versiones nuevas, bun.lockb en las viejas)
|
||||
COPY package.json bun.lock* bun.lockb* ./
|
||||
|
||||
# Instalar dependencias
|
||||
RUN bun install
|
||||
|
||||
# Copiar el resto del código
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# ---
|
||||
FROM node:22-alpine
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/build ./build
|
||||
COPY --from=builder /app/package*.json ./
|
||||
RUN npm install --omit=dev
|
||||
# Generar .svelte-kit (tsconfig, types y generated/server/internal.js)
|
||||
RUN bunx svelte-kit sync
|
||||
|
||||
# Puerto del dev server
|
||||
EXPOSE 3000
|
||||
CMD ["node", "build"]
|
||||
|
||||
# Dev server con hot reload, escuchando en todas las interfaces
|
||||
CMD ["sh", "-c", "bunx svelte-kit sync && bun run dev --host 0.0.0.0 --port 3000"]
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
"name": "front",
|
||||
"dependencies": {
|
||||
"@sveltejs/adapter-node": "^5.5.7",
|
||||
"carbon-components-svelte": "0.110.0",
|
||||
"carbon-components-svelte": "^0.110.0",
|
||||
"carbon-icons-svelte": "^13.13.0",
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"dev": "vite dev --host",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<script lang="ts">
|
||||
import { Button, Search } from 'carbon-components-svelte';
|
||||
import IconPreview from '$lib/components/IconPreview.svelte';
|
||||
import { iconosCarbon } from '$lib/icons/iconosCarbon';
|
||||
|
||||
let {
|
||||
value = $bindable(''),
|
||||
label = 'Imagen / icono'
|
||||
}: {
|
||||
value: string;
|
||||
label?: string;
|
||||
} = $props();
|
||||
|
||||
let busqueda = $state('');
|
||||
|
||||
const iconosFiltrados = $derived(
|
||||
iconosCarbon.filter((icono) => icono.nombre.toLowerCase().includes(busqueda.toLowerCase()))
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="icono-field">
|
||||
<span class="cds--label">{label}</span>
|
||||
|
||||
<div class="icono-seleccionado">
|
||||
{#if value}
|
||||
<IconPreview nombre={value} size={24} />
|
||||
<span>{value}</span>
|
||||
<Button kind="ghost" size="small" onclick={() => (value = '')}>Quitar</Button>
|
||||
{:else}
|
||||
<span class="texto-secundario">Sin icono seleccionado</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<Search
|
||||
bind:value={busqueda}
|
||||
size="sm"
|
||||
labelText="Buscar icono"
|
||||
placeholder="Buscar icono de Carbon..."
|
||||
on:keydown={(e) => e.key === 'Enter' && e.preventDefault()}
|
||||
/>
|
||||
|
||||
<div class="icono-grid" role="listbox" aria-label="Iconos disponibles">
|
||||
{#each iconosFiltrados as icono (icono.nombre)}
|
||||
<button
|
||||
type="button"
|
||||
class:seleccionado={value === icono.nombre}
|
||||
role="option"
|
||||
aria-selected={value === icono.nombre}
|
||||
title={icono.nombre}
|
||||
onclick={() => (value = icono.nombre)}
|
||||
>
|
||||
<IconPreview nombre={icono.nombre} size={24} />
|
||||
<span>{icono.nombre}</span>
|
||||
</button>
|
||||
{:else}
|
||||
<p class="texto-secundario">No se encontraron iconos.</p>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.icono-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.icono-seleccionado {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
min-height: 2.5rem;
|
||||
}
|
||||
|
||||
.icono-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
|
||||
gap: 0.5rem;
|
||||
max-height: 15rem;
|
||||
overflow-y: auto;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.icono-grid button {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.75rem 0.5rem;
|
||||
border: 1px solid var(--cds-border-subtle-01);
|
||||
border-radius: 4px;
|
||||
background: var(--cds-layer-01);
|
||||
color: var(--cds-text-primary);
|
||||
cursor: pointer;
|
||||
font-size: 0.75rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.icono-grid button span {
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.icono-grid button:hover,
|
||||
.icono-grid button:focus-visible {
|
||||
border-color: var(--cds-border-interactive);
|
||||
}
|
||||
|
||||
.icono-grid button.seleccionado {
|
||||
border-color: var(--cds-border-interactive);
|
||||
background: var(--cds-layer-selected-01);
|
||||
}
|
||||
|
||||
.texto-secundario {
|
||||
color: var(--cds-text-secondary, #6f6f6f);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { obtenerIconoCarbon } from '$lib/icons/iconosCarbon';
|
||||
|
||||
let {
|
||||
nombre,
|
||||
size = 20
|
||||
}: {
|
||||
nombre?: string | null;
|
||||
size?: number;
|
||||
} = $props();
|
||||
|
||||
const Icono = $derived(obtenerIconoCarbon(nombre));
|
||||
|
||||
const esUrlDeImagen = $derived(
|
||||
!!nombre &&
|
||||
(nombre.startsWith('http://') ||
|
||||
nombre.startsWith('https://') ||
|
||||
nombre.startsWith('data:image/') ||
|
||||
nombre.startsWith('/'))
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if Icono}
|
||||
<Icono {size} />
|
||||
{:else if esUrlDeImagen}
|
||||
<img src={nombre} alt="" width={size} height={size} />
|
||||
{/if}
|
||||
@@ -0,0 +1,108 @@
|
||||
import type { Component } from 'svelte';
|
||||
import type { CarbonIconProps } from 'carbon-icons-svelte';
|
||||
|
||||
import Analytics from 'carbon-icons-svelte/lib/Analytics.svelte';
|
||||
import Api from 'carbon-icons-svelte/lib/Api.svelte';
|
||||
import Barcode from 'carbon-icons-svelte/lib/Barcode.svelte';
|
||||
import Bookmark from 'carbon-icons-svelte/lib/Bookmark.svelte';
|
||||
import Building from 'carbon-icons-svelte/lib/Building.svelte';
|
||||
import Catalog from 'carbon-icons-svelte/lib/Catalog.svelte';
|
||||
import Certificate from 'carbon-icons-svelte/lib/Certificate.svelte';
|
||||
import Checkmark from 'carbon-icons-svelte/lib/Checkmark.svelte';
|
||||
import CheckmarkFilled from 'carbon-icons-svelte/lib/CheckmarkFilled.svelte';
|
||||
import Cloud from 'carbon-icons-svelte/lib/Cloud.svelte';
|
||||
import ColorPalette from 'carbon-icons-svelte/lib/ColorPalette.svelte';
|
||||
import Dashboard from 'carbon-icons-svelte/lib/Dashboard.svelte';
|
||||
import DataBase from 'carbon-icons-svelte/lib/DataBase.svelte';
|
||||
import Enterprise from 'carbon-icons-svelte/lib/Enterprise.svelte';
|
||||
import Folder from 'carbon-icons-svelte/lib/Folder.svelte';
|
||||
import FolderShared from 'carbon-icons-svelte/lib/FolderShared.svelte';
|
||||
import Group from 'carbon-icons-svelte/lib/Group.svelte';
|
||||
import GroupAccess from 'carbon-icons-svelte/lib/GroupAccess.svelte';
|
||||
import GroupAccount from 'carbon-icons-svelte/lib/GroupAccount.svelte';
|
||||
import GroupSecurity from 'carbon-icons-svelte/lib/GroupSecurity.svelte';
|
||||
import Home from 'carbon-icons-svelte/lib/Home.svelte';
|
||||
import Identification from 'carbon-icons-svelte/lib/Identification.svelte';
|
||||
import Image from 'carbon-icons-svelte/lib/Image.svelte';
|
||||
import InventoryManagement from 'carbon-icons-svelte/lib/InventoryManagement.svelte';
|
||||
import Key from 'carbon-icons-svelte/lib/Key.svelte';
|
||||
import License from 'carbon-icons-svelte/lib/License.svelte';
|
||||
import Locked from 'carbon-icons-svelte/lib/Locked.svelte';
|
||||
import Menu from 'carbon-icons-svelte/lib/Menu.svelte';
|
||||
import Notification from 'carbon-icons-svelte/lib/Notification.svelte';
|
||||
import PaintBrush from 'carbon-icons-svelte/lib/PaintBrush.svelte';
|
||||
import Password from 'carbon-icons-svelte/lib/Password.svelte';
|
||||
import Report from 'carbon-icons-svelte/lib/Report.svelte';
|
||||
import Security from 'carbon-icons-svelte/lib/Security.svelte';
|
||||
import Settings from 'carbon-icons-svelte/lib/Settings.svelte';
|
||||
import ShoppingCart from 'carbon-icons-svelte/lib/ShoppingCart.svelte';
|
||||
import Star from 'carbon-icons-svelte/lib/Star.svelte';
|
||||
import Tag from 'carbon-icons-svelte/lib/Tag.svelte';
|
||||
import Tools from 'carbon-icons-svelte/lib/Tools.svelte';
|
||||
import Unlocked from 'carbon-icons-svelte/lib/Unlocked.svelte';
|
||||
import User from 'carbon-icons-svelte/lib/User.svelte';
|
||||
import UserAdmin from 'carbon-icons-svelte/lib/UserAdmin.svelte';
|
||||
import UserMultiple from 'carbon-icons-svelte/lib/UserMultiple.svelte';
|
||||
import UserProfile from 'carbon-icons-svelte/lib/UserProfile.svelte';
|
||||
import UserRole from 'carbon-icons-svelte/lib/UserRole.svelte';
|
||||
import View from 'carbon-icons-svelte/lib/View.svelte';
|
||||
|
||||
export interface IconoCarbon {
|
||||
nombre: string;
|
||||
componente: Component<CarbonIconProps>;
|
||||
}
|
||||
|
||||
export const iconosCarbon: IconoCarbon[] = [
|
||||
{ nombre: 'Group', componente: Group },
|
||||
{ nombre: 'GroupAccess', componente: GroupAccess },
|
||||
{ nombre: 'GroupAccount', componente: GroupAccount },
|
||||
{ nombre: 'GroupSecurity', componente: GroupSecurity },
|
||||
{ nombre: 'User', componente: User },
|
||||
{ nombre: 'UserMultiple', componente: UserMultiple },
|
||||
{ nombre: 'UserAdmin', componente: UserAdmin },
|
||||
{ nombre: 'UserRole', componente: UserRole },
|
||||
{ nombre: 'UserProfile', componente: UserProfile },
|
||||
{ nombre: 'Security', componente: Security },
|
||||
{ nombre: 'Settings', componente: Settings },
|
||||
{ nombre: 'Tools', componente: Tools },
|
||||
{ nombre: 'Dashboard', componente: Dashboard },
|
||||
{ nombre: 'Home', componente: Home },
|
||||
{ nombre: 'Menu', componente: Menu },
|
||||
{ nombre: 'Building', componente: Building },
|
||||
{ nombre: 'Enterprise', componente: Enterprise },
|
||||
{ nombre: 'Catalog', componente: Catalog },
|
||||
{ nombre: 'Folder', componente: Folder },
|
||||
{ nombre: 'FolderShared', componente: FolderShared },
|
||||
{ nombre: 'Tag', componente: Tag },
|
||||
{ nombre: 'Star', componente: Star },
|
||||
{ nombre: 'Bookmark', componente: Bookmark },
|
||||
{ nombre: 'Notification', componente: Notification },
|
||||
{ nombre: 'Key', componente: Key },
|
||||
{ nombre: 'Password', componente: Password },
|
||||
{ nombre: 'Locked', componente: Locked },
|
||||
{ nombre: 'Unlocked', componente: Unlocked },
|
||||
{ nombre: 'View', componente: View },
|
||||
{ nombre: 'PaintBrush', componente: PaintBrush },
|
||||
{ nombre: 'ColorPalette', componente: ColorPalette },
|
||||
{ nombre: 'Image', componente: Image },
|
||||
{ nombre: 'Identification', componente: Identification },
|
||||
{ nombre: 'License', componente: License },
|
||||
{ nombre: 'Certificate', componente: Certificate },
|
||||
{ nombre: 'Report', componente: Report },
|
||||
{ nombre: 'Analytics', componente: Analytics },
|
||||
{ nombre: 'DataBase', componente: DataBase },
|
||||
{ nombre: 'Cloud', componente: Cloud },
|
||||
{ nombre: 'Api', componente: Api },
|
||||
{ nombre: 'InventoryManagement', componente: InventoryManagement },
|
||||
{ nombre: 'ShoppingCart', componente: ShoppingCart },
|
||||
{ nombre: 'Barcode', componente: Barcode },
|
||||
{ nombre: 'Checkmark', componente: Checkmark },
|
||||
{ nombre: 'CheckmarkFilled', componente: CheckmarkFilled }
|
||||
];
|
||||
|
||||
const iconosPorNombre = new Map(iconosCarbon.map((icono) => [icono.nombre, icono.componente]));
|
||||
|
||||
export function obtenerIconoCarbon(nombre?: string | null): Component<CarbonIconProps> | undefined {
|
||||
if (!nombre) return undefined;
|
||||
return iconosPorNombre.get(nombre);
|
||||
}
|
||||
@@ -3,6 +3,10 @@ import { obtenerPermisos } from '$lib/hooks/obtenerPermisos';
|
||||
import type { Grupo, Permiso } from '../../types';
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
// El token de autenticación vive en localStorage, por lo que la carga debe
|
||||
// ejecutarse en el navegador y no durante el SSR.
|
||||
export const ssr = false;
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
let grupos: Grupo[] = [];
|
||||
let permisos: Permiso[] = [];
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { Modal, TextInput, TextArea } from 'carbon-components-svelte';
|
||||
import { Modal, TextArea, TextInput } from 'carbon-components-svelte';
|
||||
import IconPicker from '$lib/components/IconPicker.svelte';
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
editando = false,
|
||||
nombre = $bindable(''),
|
||||
descripcion = $bindable(''),
|
||||
imagen = $bindable(''),
|
||||
alGuardar,
|
||||
alCerrar
|
||||
}: {
|
||||
@@ -13,6 +15,7 @@
|
||||
editando?: boolean;
|
||||
nombre: string;
|
||||
descripcion: string;
|
||||
imagen: string;
|
||||
alGuardar?: () => void;
|
||||
alCerrar?: () => void;
|
||||
} = $props();
|
||||
@@ -21,12 +24,14 @@
|
||||
<form id="grupo-form" onsubmit={alGuardar}>
|
||||
<Modal
|
||||
bind:open
|
||||
size="lg"
|
||||
modalHeading={editando ? 'Editar Grupo' : 'Nuevo Grupo'}
|
||||
primaryButtonText={editando ? 'Guardar' : 'Crear'}
|
||||
secondaryButtonText="Cancelar"
|
||||
formId="grupo-form"
|
||||
on:click:button--secondary={() => alCerrar?.()}
|
||||
hasForm
|
||||
hasScrollingContent
|
||||
>
|
||||
<TextInput bind:value={nombre} labelText="Nombre" placeholder="ej: Administradores" />
|
||||
<TextArea
|
||||
@@ -34,5 +39,7 @@
|
||||
labelText="Descripción"
|
||||
placeholder="Descripción del grupo"
|
||||
/>
|
||||
|
||||
<IconPicker bind:value={imagen} label="Imagen / icono del grupo" />
|
||||
</Modal>
|
||||
</form>
|
||||
@@ -2,6 +2,7 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { resolve } from '$app/paths';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import IconPreview from '$lib/components/IconPreview.svelte';
|
||||
import type { Grupo } from '../../../types';
|
||||
import {
|
||||
Accordion,
|
||||
@@ -24,7 +25,12 @@
|
||||
>
|
||||
|
||||
<div class="group-header">
|
||||
<h1 class="page-title">{data.grupo.nombre}</h1>
|
||||
<h1 class="page-title">
|
||||
{#if data.grupo.imagen}
|
||||
<IconPreview nombre={data.grupo.imagen} size={32} />
|
||||
{/if}
|
||||
{data.grupo.nombre}
|
||||
</h1>
|
||||
{#if data.grupo.descripcion}
|
||||
<p class="text-secondary">{data.grupo.descripcion}</p>
|
||||
{/if}
|
||||
@@ -40,7 +46,12 @@
|
||||
<div
|
||||
class="permiso-item rounded ps-1! transition duration-200 ease-in-out hover:bg-white/5"
|
||||
>
|
||||
<span>{p.nombre}</span>
|
||||
<span class="permiso-nombre">
|
||||
{#if p.imagen}
|
||||
<IconPreview nombre={p.imagen} size={16} />
|
||||
{/if}
|
||||
{p.nombre}
|
||||
</span>
|
||||
<Tag type="blue">{p.alias}</Tag>
|
||||
</div>
|
||||
</ContainedListItem>
|
||||
@@ -61,6 +72,9 @@
|
||||
}
|
||||
|
||||
.page-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 1.75rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
@@ -96,6 +110,12 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.permiso-nombre {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
:global(.permiso-item .cds--tag) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ import { obtenerGrupo } from '$lib/hooks/obtenerGrupo';
|
||||
import type { Grupo } from '../../../types';
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
// El token de autenticación vive en localStorage, por lo que la carga debe
|
||||
// ejecutarse en el navegador y no durante el SSR.
|
||||
export const ssr = false;
|
||||
|
||||
export const load: PageLoad = async ({ params, fetch }) => {
|
||||
const id = Number(params.id);
|
||||
|
||||
|
||||
Vendored
+1
@@ -63,6 +63,7 @@ export interface Permiso {
|
||||
nombre: string;
|
||||
alias: string;
|
||||
descripcion?: string;
|
||||
imagen?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,19 @@ import tailwindcss from '@tailwindcss/vite';
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
// En Docker, el contenedor de Svelte no puede resolver "localhost" hacia nginx.
|
||||
// docker-compose define API_PROXY_TARGET=http://nginx:80.
|
||||
const nodeProcess = globalThis as {
|
||||
process?: { env?: Record<string, string | undefined> };
|
||||
};
|
||||
const apiProxyTarget = nodeProcess.process?.env?.API_PROXY_TARGET || 'http://localhost:80';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [tailwindcss(), sveltekit()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:80',
|
||||
target: apiProxyTarget,
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user