Add pagination to ISAC registries
This commit is contained in:
@@ -4,14 +4,17 @@ import { getDatabase } from '$lib/server/database';
|
||||
import { fail } from '@sveltejs/kit';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
import { getPagination } from '$lib/server/pagination';
|
||||
|
||||
type SharedEffect = { statId: string; valueI: number; valueII: number };
|
||||
|
||||
export const load: PageServerLoad = async ({ cookies }) => {
|
||||
export const load: PageServerLoad = async ({ cookies, url }) => {
|
||||
await requirePermission(await getSessionUser(cookies), 'data.manage');
|
||||
const db = await getDatabase();
|
||||
const totalRow = await (await db.prepare('SELECT COUNT(*) AS total FROM talents')).get();
|
||||
const pagination = getPagination(url, Number(totalRow?.total ?? 0));
|
||||
const [talents, tiers, triggers, links, effects, stats, templates, weaponScopes, weaponSlots] = await Promise.all([
|
||||
(await db.prepare('SELECT * FROM talents ORDER BY active DESC,name COLLATE NOCASE')).all(),
|
||||
(await db.prepare('SELECT * FROM talents ORDER BY active DESC,name COLLATE NOCASE LIMIT ? OFFSET ?')).all(pagination.perPage, pagination.offset),
|
||||
(await db.prepare('SELECT id,talent_id,tier,description FROM talent_tiers')).all(),
|
||||
(await db.prepare('SELECT * FROM talent_triggers ORDER BY active DESC,name COLLATE NOCASE')).all(),
|
||||
(await db.prepare('SELECT talent_tier_id,trigger_id FROM talent_tier_triggers')).all(),
|
||||
@@ -21,6 +24,17 @@ export const load: PageServerLoad = async ({ cookies }) => {
|
||||
(await db.prepare('SELECT talent_id,scope FROM talent_weapon_scopes')).all(),
|
||||
(await db.prepare('SELECT talent_id,slot FROM weapon_talent_slots')).all()
|
||||
]);
|
||||
const [triggerSummary, slotSummary, exoticSummary, gearSummary] = await Promise.all([
|
||||
(await db.prepare('SELECT COUNT(*) AS total FROM talent_triggers')).get(),
|
||||
(await db.prepare(`SELECT
|
||||
SUM(CASE WHEN slot=1 THEN 1 ELSE 0 END) AS slot1,
|
||||
SUM(CASE WHEN slot=2 THEN 1 ELSE 0 END) AS slot2 FROM weapon_talent_slots`)).get(),
|
||||
(await db.prepare("SELECT COUNT(*) AS total FROM talent_weapon_scopes WHERE scope='Exotic'")).get(),
|
||||
(await db.prepare(`SELECT
|
||||
SUM(CASE WHEN category='Backpack' THEN 1 ELSE 0 END) AS backpack,
|
||||
SUM(CASE WHEN category IN ('Vest','Body Armor') THEN 1 ELSE 0 END) AS body_armor
|
||||
FROM talents`)).get()
|
||||
]);
|
||||
return {
|
||||
talents: talents.map((talent) => ({
|
||||
...talent,
|
||||
@@ -43,7 +57,17 @@ export const load: PageServerLoad = async ({ cookies }) => {
|
||||
}))
|
||||
})),
|
||||
triggers,
|
||||
stats
|
||||
stats,
|
||||
summary: {
|
||||
total: Number(totalRow?.total ?? 0),
|
||||
triggers: Number(triggerSummary?.total ?? 0),
|
||||
slot1: Number(slotSummary?.slot1 ?? 0),
|
||||
slot2: Number(slotSummary?.slot2 ?? 0),
|
||||
exotic: Number(exoticSummary?.total ?? 0),
|
||||
backpack: Number(gearSummary?.backpack ?? 0),
|
||||
bodyArmor: Number(gearSummary?.body_armor ?? 0)
|
||||
},
|
||||
pagination
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user