From 1544117aae850eb16287b1003073e34489ef280b Mon Sep 17 00:00:00 2001 From: iamBadgers Date: Sun, 9 Jun 2024 19:11:41 -0700 Subject: [PATCH] Update the character list to use the server side table stuff --- backend/src/characterservice.ts | 9 +-- frontend/src/types.ts | 4 +- frontend/src/vues/CharacterDetails.vue | 9 ++- frontend/src/vues/CharacterList.vue | 82 +++++++++++++++----------- frontend/src/vues/GameDetails.vue | 8 +-- 5 files changed, 65 insertions(+), 47 deletions(-) diff --git a/backend/src/characterservice.ts b/backend/src/characterservice.ts index a4c0340..ed9425b 100644 --- a/backend/src/characterservice.ts +++ b/backend/src/characterservice.ts @@ -33,14 +33,15 @@ export function addCharacterApis(app, jsonParser) { order: orderBy, where: filter }) - const pageCount = Math.ceil( - (await Character.count({ + const totalCount = await Character.count({ where: filter - })) / count + }) + const pageCount = Math.ceil( + totalCount / count ) res.setHeader('Content-Type', 'application/json') - res.send({ characterData, pageCount }) + res.send({ characterData, pageCount, totalCount }) } catch (e) { if (e instanceof ParsingError) { res.status(400).send('Could not parse filter.') diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 42760dc..8c9b699 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -28,7 +28,7 @@ export interface GameStats { Events: number AverageIP: number AverageEB: number - TotalIP: number, + TotalIP: number TotalEB: number } @@ -43,7 +43,7 @@ export interface GameCharacter { characterName: string gameId: number gameTite: string - pickedCharacter?:Character + pickedCharacter?: Character appliedCharacter?: Character } diff --git a/frontend/src/vues/CharacterDetails.vue b/frontend/src/vues/CharacterDetails.vue index 669d095..27d98ad 100644 --- a/frontend/src/vues/CharacterDetails.vue +++ b/frontend/src/vues/CharacterDetails.vue @@ -48,9 +48,14 @@ const route = useRoute() const characterId = ref(route.params.characterId) const character = ref({ - id: 0, characterName: "", playerName: "", role: "", status: "", lastGame: 0 + id: 0, + characterName: '', + playerName: '', + role: '', + status: '', + lastGame: 0 }) -const games = ref({played:[], applied: []}) +const games = ref({ played: [], applied: [] }) const earnedEB = ref(0) const earnedIP = ref(0) const gamesPlayedCount = ref(0) diff --git a/frontend/src/vues/CharacterList.vue b/frontend/src/vues/CharacterList.vue index 4110fbc..9c2fb39 100644 --- a/frontend/src/vues/CharacterList.vue +++ b/frontend/src/vues/CharacterList.vue @@ -6,33 +6,25 @@ v-model="filtervalue" > - - - - ID - Character - Role - Player - Status - Last Game - - - - - - {{ character.id }} - - - {{ character.characterName }} - - {{ character.role }} - {{ character.playerName }} - {{ character.status }} - {{ character.lastGame }} - 0 - - - + + + + + + ([]) const pageCount = ref(1) const page = ref(1) +const resultePerPage = ref(10) -let count = 10 +const count = ref(10) const filtervalue = ref('') -async function loadData() { +async function loadItems({ page, itemsPerPage, sortBy }) { + let sortString = 'id' + if (sortBy[0]) { + console.log(sortBy[0].key) + console.log(sortBy[0].order) + sortString = `${sortBy[0].key} ${sortBy[0].order}` + } + const response = await axios.post('/api/character', { - page: `${page.value - 1}`, - count: `10`, - orderBy: 'id', - filter: filtervalue.value ? `characterName:"${filtervalue.value}"` : '' + page: `${page - 1}`, + count: `${itemsPerPage}`, + orderBy: sortString, + filter: filtervalue.value ? `characterName:${filtervalue.value}` : '' }) + + console.log(response) characters.value = response.data.characterData pageCount.value = response.data.pageCount + count.value = response.data.totalCount } function setPage(targetPage: number) { @@ -83,7 +95,7 @@ watch(route, (newValue, oldValue) => { page.value = Number(route.query.page) } page.value = Number(route.query.page) - loadData() + loadItems({page: page.value, itemsPerPage: resultePerPage.value, sortBy:[]}) }) let debounce: ReturnType @@ -104,6 +116,6 @@ onMounted(async () => { if (route.query.filter) { filtervalue.value = route.query.filter.toString() } - loadData() + loadItems({page: page.value, itemsPerPage: resultePerPage.value, sortBy:[]}) }) diff --git a/frontend/src/vues/GameDetails.vue b/frontend/src/vues/GameDetails.vue index 713d438..9391c4e 100644 --- a/frontend/src/vues/GameDetails.vue +++ b/frontend/src/vues/GameDetails.vue @@ -100,12 +100,12 @@ const appHeaders: ReadonlyHeaders = [ const gameId = ref(route.params.gameId) const game = ref({ id: 0, - title: "", - gamemaster: "", + title: '', + gamemaster: '', payoutEB: 0, payoutIP: 0, - payoutLoot: "", - status: "", + payoutLoot: '', + status: '', postdate: 0 }) const picks = ref([])