crude games list

This commit is contained in:
Jörn-Michael Miehe 2019-06-04 17:00:09 +02:00
parent b56aedbca6
commit e963576e46
7 changed files with 141 additions and 22 deletions

View 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

View file

@ -28,6 +28,8 @@ fastify.route (require "./routes/#{route}") for route in [
'decks/modify' 'decks/modify'
# delete deck # delete deck
'decks/delete' 'decks/delete'
# list games
'games/list'
] ]
# request logging # request logging

View file

@ -88,6 +88,7 @@ class FFTCGSESSION
resolve digest resolve digest
getGames: -> getGames: ->
new Promise (resolve) =>
# function to return all active gameKeys # function to return all active gameKeys
activeGameKeys = (set, cursor) => activeGameKeys = (set, cursor) =>
# start iteration # start iteration
@ -97,6 +98,8 @@ class FFTCGSESSION
return new Promise (resolve, reject) => return new Promise (resolve, reject) =>
# scan "active" gameKey # scan "active" gameKey
@db.sscan (@gameKey 'active'), cursor, 'COUNT', '100', (err, res) -> @db.sscan (@gameKey 'active'), cursor, 'COUNT', '100', (err, res) ->
if err
reject null
# add to results set # add to results set
cursor = res[0] cursor = res[0]
@ -112,8 +115,23 @@ class FFTCGSESSION
.then (set) -> .then (set) ->
resolve set resolve set
activeGameKeys().then (set) -> activeGameKeys()
logger.info "game count: #{Array.from(set).length}" .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) -> joinGame: (digest, userid) ->
new Promise (resolve, reject) => new Promise (resolve, reject) =>

View 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>

View file

@ -4,7 +4,9 @@
<v-icon>view_carousel</v-icon> Decks <v-icon>view_carousel</v-icon> Decks
</v-btn> </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-btn flat :to="{ name: 'usercp' }">
<v-icon>person</v-icon> {{ user.login }} <v-icon>person</v-icon> {{ user.login }}

View file

@ -28,6 +28,12 @@ export default new Router({
component: () => component: () =>
import(/* webpackChunkName: "deckcp" */ './views/DeckCP.vue') import(/* webpackChunkName: "deckcp" */ './views/DeckCP.vue')
}, },
{
path: '/games',
name: 'games',
component: () =>
import(/* webpackChunkName: "games" */ './views/Games.vue')
},
{ {
path: '/game', path: '/game',
name: 'game', name: 'game',

View 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>