-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Once pagination, sort, and search are fully implemented, I will break table out into its own component.
- Loading branch information
Showing
4 changed files
with
407 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as v from 'valibot'; | ||
|
||
export const paginateSchema = v.object({ | ||
page: v.number(), | ||
size: v.number() | ||
}); | ||
|
||
export type PaginateSchema = typeof paginateSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ortal/src/routes/(authenticated)/admin/workflows/[product_id]/transitions/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { prisma } from 'sil.appbuilder.portal.common'; | ||
import type { PageServerLoad, Actions } from './$types'; | ||
import { paginateSchema } from '$lib/table'; | ||
import { superValidate } from 'sveltekit-superforms'; | ||
import { valibot } from 'sveltekit-superforms/adapters'; | ||
|
||
export const load: PageServerLoad = async (event) => { | ||
const transitions = await prisma.productTransitions.findMany({ | ||
where: { | ||
ProductId: event.params.product_id, | ||
TransitionType: 1 | ||
}, | ||
select: { | ||
AllowedUserNames: true, | ||
InitialState: true, | ||
DestinationState: true, | ||
DateTransition: true, | ||
Command: true, | ||
Comment: true, | ||
}, | ||
take: 5 | ||
}); | ||
|
||
const count = await prisma.productTransitions.count({ | ||
where: { | ||
ProductId: event.params.product_id, | ||
TransitionType: 1 | ||
} | ||
}); | ||
|
||
return { | ||
transitions, | ||
count, | ||
form: await superValidate( | ||
{ | ||
page: 0, | ||
size: 5 | ||
}, | ||
valibot(paginateSchema) | ||
) | ||
}; | ||
}; | ||
|
||
export const actions: Actions = { | ||
page: async function (event) { | ||
|
||
const form = await superValidate(event.request, valibot(paginateSchema)); | ||
|
||
const transitions = await prisma.productTransitions.findMany({ | ||
where: { | ||
ProductId: event.params.product_id, | ||
TransitionType: 1 | ||
}, | ||
select: { | ||
AllowedUserNames: true, | ||
InitialState: true, | ||
DestinationState: true, | ||
DateTransition: true, | ||
Command: true, | ||
Comment: true, | ||
}, | ||
skip: form.data.size * form.data.page, | ||
take: form.data.size | ||
}); | ||
|
||
const count = await prisma.productTransitions.count({ | ||
where: { | ||
ProductId: event.params.product_id, | ||
TransitionType: 1 | ||
} | ||
}); | ||
|
||
//console.log({ form, query: { data: transitions, count }}); | ||
|
||
return { form, ok: form.valid, query: { data: transitions, count }}; | ||
} | ||
} |
Oops, something went wrong.