fix/INP-filtros-y-modal
This commit is contained in:
@@ -13,6 +13,7 @@ router = TenantCRUDRoutes(
|
|||||||
tags=["a76.general_catalogs.inpc"],
|
tags=["a76.general_catalogs.inpc"],
|
||||||
resource_name="INPC",
|
resource_name="INPC",
|
||||||
enable_list=True,
|
enable_list=True,
|
||||||
|
enable_filters=True,
|
||||||
# Permisos
|
# Permisos
|
||||||
list_permissions=["cat_inpc.view"],
|
list_permissions=["cat_inpc.view"],
|
||||||
get_permissions=["cat_inpc.view"],
|
get_permissions=["cat_inpc.view"],
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ class INPCService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if filters:
|
if filters:
|
||||||
# Add filters here if needed
|
if filters.get("year"):
|
||||||
pass
|
query = query.filter(INPC.year == filters["year"])
|
||||||
|
if filters.get("month"):
|
||||||
|
query = query.filter(INPC.month == filters["month"])
|
||||||
|
|
||||||
total = query.count()
|
total = query.count()
|
||||||
items = query.offset(skip).limit(limit).all()
|
items = query.offset(skip).limit(limit).all()
|
||||||
|
|||||||
@@ -34,11 +34,22 @@ export async function getINPCs(
|
|||||||
companyId: number,
|
companyId: number,
|
||||||
filters: Record<string, any> = {}
|
filters: Record<string, any> = {}
|
||||||
): Promise<ApiResponse<INPCListResponse>> {
|
): Promise<ApiResponse<INPCListResponse>> {
|
||||||
|
const cleanFilters = Object.fromEntries(
|
||||||
|
Object.entries(filters).filter(([, value]) => {
|
||||||
|
if (value === undefined || value === null) return false;
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
const trimmed = value.trim();
|
||||||
|
return trimmed !== '' && trimmed.toLowerCase() !== 'undefined';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
page: page.toString(),
|
page: page.toString(),
|
||||||
page_size: pageSize.toString(),
|
page_size: pageSize.toString(),
|
||||||
company_id: companyId.toString(),
|
company_id: companyId.toString(),
|
||||||
...filters
|
...cleanFilters
|
||||||
});
|
});
|
||||||
|
|
||||||
return await api.get(`/v1/a76/inpc/?${params.toString()}`);
|
return await api.get(`/v1/a76/inpc/?${params.toString()}`);
|
||||||
|
|||||||
@@ -86,7 +86,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Dialog.Root bind:open>
|
<Dialog.Root bind:open>
|
||||||
<Dialog.Content class="sm:max-w-[500px]">
|
<Dialog.Content
|
||||||
|
class="sm:max-w-[500px]"
|
||||||
|
onInteractOutside={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
<Dialog.Header>
|
<Dialog.Header>
|
||||||
<Dialog.Title>{title}</Dialog.Title>
|
<Dialog.Title>{title}</Dialog.Title>
|
||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
import * as Card from '$lib/components/ui/card';
|
import * as Card from '$lib/components/ui/card';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { Input } from '$lib/components/ui/input';
|
import { Input } from '$lib/components/ui/input';
|
||||||
import { Pencil, Plus, Trash2, RefreshCw } from 'lucide-svelte';
|
import { Pencil, Plus, Trash2 } from 'lucide-svelte';
|
||||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||||
import { obtenerAtajosListaINPC } from '$lib/config/shortcuts/dashboard/general_catalogs/inpc/list';
|
import { obtenerAtajosListaINPC } from '$lib/config/shortcuts/dashboard/general_catalogs/inpc/list';
|
||||||
import { inpcApi, type INPC } from '$lib/api/dashboard/a76/general_catalogs/inpc';
|
import { inpcApi, type INPC } from '$lib/api/dashboard/a76/general_catalogs/inpc';
|
||||||
@@ -88,10 +88,11 @@
|
|||||||
page: '1',
|
page: '1',
|
||||||
page_size: pageSize.toString()
|
page_size: pageSize.toString()
|
||||||
});
|
});
|
||||||
if (response.data) {
|
const payload = (response as any).items ? response : (response as any).data;
|
||||||
allItems = response.data.items;
|
if (payload?.items) {
|
||||||
currentPage = 1;
|
allItems = payload.items;
|
||||||
totalItems = response.data.total;
|
currentPage = payload.page || 1;
|
||||||
|
totalItems = payload.total;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = 'Error aplicando filtros';
|
error = 'Error aplicando filtros';
|
||||||
@@ -118,11 +119,14 @@
|
|||||||
page: (currentPage + 1).toString(),
|
page: (currentPage + 1).toString(),
|
||||||
page_size: pageSize.toString()
|
page_size: pageSize.toString()
|
||||||
});
|
});
|
||||||
if (response.data?.items) {
|
const payload = (response as any).items ? response : (response as any).data;
|
||||||
allItems = [...allItems, ...response.data.items];
|
if (payload?.items) {
|
||||||
currentPage += 1;
|
allItems = [...allItems, ...payload.items];
|
||||||
totalItems = response.data.total;
|
currentPage = payload.page || currentPage + 1;
|
||||||
|
totalItems = payload.total;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
error = 'Error cargando mas datos';
|
||||||
} finally {
|
} finally {
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
@@ -139,11 +143,14 @@
|
|||||||
page: '1',
|
page: '1',
|
||||||
page_size: pageSize.toString()
|
page_size: pageSize.toString()
|
||||||
});
|
});
|
||||||
if (response.data) {
|
const payload = (response as any).items ? response : (response as any).data;
|
||||||
allItems = response.data.items;
|
if (payload?.items) {
|
||||||
currentPage = 1;
|
allItems = payload.items;
|
||||||
totalItems = response.data.total;
|
currentPage = payload.page || 1;
|
||||||
|
totalItems = payload.total;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
error = 'Error al recargar datos';
|
||||||
} finally {
|
} finally {
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
@@ -168,9 +175,6 @@
|
|||||||
<p class="text-muted-foreground">{m['common.sub_inpc']()}</p>
|
<p class="text-muted-foreground">{m['common.sub_inpc']()}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
<Button variant="outline" size="sm" class="h-9" onclick={reloadData}>
|
|
||||||
<RefreshCw class="mr-2 h-4 w-4" /> {m['common.btn_refresh']()}
|
|
||||||
</Button>
|
|
||||||
{#if !isError && canCreate}
|
{#if !isError && canCreate}
|
||||||
<Button
|
<Button
|
||||||
class="h-9"
|
class="h-9"
|
||||||
|
|||||||
Reference in New Issue
Block a user