crude games list
This commit is contained in:
parent
b56aedbca6
commit
e963576e46
7 changed files with 141 additions and 22 deletions
26
backend/routes/games/list.coffee
Normal file
26
backend/routes/games/list.coffee
Normal file
|
@ -0,0 +1,26 @@
|
|||
logger = (require 'logging').default '/games/list'
|
||||
|
||||
# session storage (volatile data)
|
||||
session = (require '../../session')
|
||||
|
||||
module.exports =
|
||||
url: '/games/list'
|
||||
method: 'POST'
|
||||
# schema: (require './info.schema')
|
||||
|
||||
handler: (request, reply) ->
|
||||
session.check request.body.session ? ""
|
||||
.then (userid) ->
|
||||
# active session found, get associated user
|
||||
session.getGames()
|
||||
.then (games) ->
|
||||
logger.debug "OK '#{userid}' got games"
|
||||
reply.send
|
||||
success: true
|
||||
games: games
|
||||
|
||||
.catch ->
|
||||
# no session found
|
||||
logger.info "FAIL '#{request.body.session}' session not found"
|
||||
reply.send
|
||||
success: false
|
|
@ -28,6 +28,8 @@ fastify.route (require "./routes/#{route}") for route in [
|
|||
'decks/modify'
|
||||
# delete deck
|
||||
'decks/delete'
|
||||
# list games
|
||||
'games/list'
|
||||
]
|
||||
|
||||
# request logging
|
||||
|
|
|
@ -88,6 +88,7 @@ class FFTCGSESSION
|
|||
resolve digest
|
||||
|
||||
getGames: ->
|
||||
new Promise (resolve) =>
|
||||
# function to return all active gameKeys
|
||||
activeGameKeys = (set, cursor) =>
|
||||
# start iteration
|
||||
|
@ -97,6 +98,8 @@ class FFTCGSESSION
|
|||
return new Promise (resolve, reject) =>
|
||||
# scan "active" gameKey
|
||||
@db.sscan (@gameKey 'active'), cursor, 'COUNT', '100', (err, res) ->
|
||||
if err
|
||||
reject null
|
||||
|
||||
# add to results set
|
||||
cursor = res[0]
|
||||
|
@ -112,8 +115,23 @@ class FFTCGSESSION
|
|||
.then (set) ->
|
||||
resolve set
|
||||
|
||||
activeGameKeys().then (set) ->
|
||||
logger.info "game count: #{Array.from(set).length}"
|
||||
activeGameKeys()
|
||||
.then (set) =>
|
||||
activeGames = []
|
||||
|
||||
for key in Array.from set
|
||||
activeGames.push new Promise (resolve) =>
|
||||
@db.hget key, 'owner', (err, res) ->
|
||||
if(err)
|
||||
resolve null
|
||||
|
||||
resolve res
|
||||
|
||||
Promise.all activeGames
|
||||
.then (activeGames) ->
|
||||
console.log activeGames
|
||||
resolve activeGames
|
||||
|
||||
|
||||
joinGame: (digest, userid) ->
|
||||
new Promise (resolve, reject) =>
|
||||
|
|
36
frontend/src/components/GamesList.vue
Normal file
36
frontend/src/components/GamesList.vue
Normal file
|
@ -0,0 +1,36 @@
|
|||
<template>
|
||||
<div>
|
||||
<div v-for="game in games" :key="game">
|
||||
{{ game }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from '@/plugins/axios'
|
||||
|
||||
export default {
|
||||
name: 'GamesList',
|
||||
|
||||
props: {
|
||||
session: String
|
||||
},
|
||||
|
||||
asyncComputed: {
|
||||
games: {
|
||||
get() {
|
||||
return axios
|
||||
.post('/games/list', {
|
||||
session: this.session
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
return response.data.games
|
||||
}
|
||||
})
|
||||
},
|
||||
default: []
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -4,7 +4,9 @@
|
|||
<v-icon>view_carousel</v-icon> Decks
|
||||
</v-btn>
|
||||
|
||||
<v-btn flat> <v-icon>play_arrow</v-icon> Play </v-btn>
|
||||
<v-btn flat :to="{ name: 'games' }">
|
||||
<v-icon>play_arrow</v-icon> Play
|
||||
</v-btn>
|
||||
|
||||
<v-btn flat :to="{ name: 'usercp' }">
|
||||
<v-icon>person</v-icon> {{ user.login }}
|
||||
|
|
|
@ -28,6 +28,12 @@ export default new Router({
|
|||
component: () =>
|
||||
import(/* webpackChunkName: "deckcp" */ './views/DeckCP.vue')
|
||||
},
|
||||
{
|
||||
path: '/games',
|
||||
name: 'games',
|
||||
component: () =>
|
||||
import(/* webpackChunkName: "games" */ './views/Games.vue')
|
||||
},
|
||||
{
|
||||
path: '/game',
|
||||
name: 'game',
|
||||
|
|
29
frontend/src/views/Games.vue
Normal file
29
frontend/src/views/Games.vue
Normal file
|
@ -0,0 +1,29 @@
|
|||
<template>
|
||||
<v-content>
|
||||
<HeaderIntern v-model="session" @user="user = $event" />
|
||||
|
||||
<v-container v-if="user">
|
||||
<h2 class="headline">Open Tables</h2>
|
||||
<GamesList :session="session" />
|
||||
</v-container>
|
||||
</v-content>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HeaderIntern from '@/components/HeaderIntern.vue'
|
||||
import GamesList from '@/components/GamesList.vue'
|
||||
|
||||
export default {
|
||||
name: 'Games',
|
||||
|
||||
components: {
|
||||
HeaderIntern,
|
||||
GamesList
|
||||
},
|
||||
|
||||
data: () => ({
|
||||
session: null,
|
||||
user: null
|
||||
})
|
||||
}
|
||||
</script>
|
Reference in a new issue