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,32 +88,50 @@ class FFTCGSESSION
|
|||
resolve digest
|
||||
|
||||
getGames: ->
|
||||
# function to return all active gameKeys
|
||||
activeGameKeys = (set, cursor) =>
|
||||
# start iteration
|
||||
set ?= new Set()
|
||||
cursor ?= '0'
|
||||
new Promise (resolve) =>
|
||||
# function to return all active gameKeys
|
||||
activeGameKeys = (set, cursor) =>
|
||||
# start iteration
|
||||
set ?= new Set()
|
||||
cursor ?= '0'
|
||||
|
||||
return new Promise (resolve, reject) =>
|
||||
# scan "active" gameKey
|
||||
@db.sscan (@gameKey 'active'), cursor, 'COUNT', '100', (err, res) ->
|
||||
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]
|
||||
for key in res[1]
|
||||
set.add key
|
||||
# add to results set
|
||||
cursor = res[0]
|
||||
for key in res[1]
|
||||
set.add key
|
||||
|
||||
if cursor == '0'
|
||||
# done on cursor = 0
|
||||
resolve set
|
||||
else
|
||||
# recursive call (resolve one step deeper)
|
||||
allGames set, cursor
|
||||
.then (set) ->
|
||||
if cursor == '0'
|
||||
# done on cursor = 0
|
||||
resolve set
|
||||
else
|
||||
# recursive call (resolve one step deeper)
|
||||
allGames set, cursor
|
||||
.then (set) ->
|
||||
resolve set
|
||||
|
||||
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
|
||||
|
||||
activeGameKeys().then (set) ->
|
||||
logger.info "game count: #{Array.from(set).length}"
|
||||
|
||||
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