feat: admin interface shows number of quotes per player
This commit is contained in:
parent
f667f4cf00
commit
f2aa568b09
@ -17,7 +17,7 @@ export default {
|
||||
|
||||
<style lang="scss">
|
||||
.admin-tile {
|
||||
width: 300px;
|
||||
min-width: 240px;
|
||||
margin: 16px;
|
||||
|
||||
&__title {
|
||||
|
@ -26,14 +26,27 @@
|
||||
<td>Name:</td>
|
||||
<td>{{ gameinfo.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td># Players:</td>
|
||||
<td>{{ players.length }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</AdminTile>
|
||||
<AdminTile title="Players">
|
||||
<ul>
|
||||
<li>Player #1</li>
|
||||
<li>Player #2</li>
|
||||
<li>Player #3</li>
|
||||
</ul>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th># Quotes</th>
|
||||
<th>Score</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
<tr class="page-admin__player" @click="editPlayer(player.id)" v-for="player in players" :key="player.id">
|
||||
<td>{{ player.name }}</td>
|
||||
<td>{{ player.quotes.length }}</td>
|
||||
<td>{{ player.score }}</td>
|
||||
<td>{{ player.isPlaying ? (player.isIdle ? 'idle' : 'active') : '-'}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</AdminTile>
|
||||
</div>
|
||||
</template>
|
||||
@ -56,18 +69,28 @@ export default {
|
||||
},
|
||||
gameinfo() {
|
||||
return this.$store.state.engine.gameinfo || {}
|
||||
}
|
||||
},
|
||||
players() {
|
||||
const gameinfo = this.$store.state.engine.gameinfo || {}
|
||||
const players = [...gameinfo.players || []]
|
||||
return players.sort((a, b) => { return a.name.localeCompare(b.name) })
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
login() {
|
||||
this.$router.push({ path: '/' })
|
||||
},
|
||||
editPlayer(id) {
|
||||
alert(id)
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.page-admin {
|
||||
color: #ffffff;
|
||||
|
||||
&__tiles {
|
||||
display: flex;
|
||||
margin: 24px;
|
||||
@ -76,6 +99,12 @@ export default {
|
||||
&__back-button {
|
||||
margin: 16px;
|
||||
}
|
||||
color: #ffffff;
|
||||
|
||||
&__player {
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: #a0a0a0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -25,14 +25,7 @@ func (app *Application) GetQuotes(usr *user.User, w http.ResponseWriter, r *http
|
||||
return
|
||||
}
|
||||
|
||||
quotesInfo, err := gm.GetQuotesInfoByUser(usr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(w, "forbidden")
|
||||
return
|
||||
}
|
||||
quotesInfo := gm.GetQuotesInfoByUser(usr)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
jsonString, _ := json.Marshal(quotesInfo)
|
||||
fmt.Fprintf(w, string(jsonString))
|
||||
|
@ -3,11 +3,32 @@ package game
|
||||
import ()
|
||||
|
||||
func (gm *Game) GetGameInfo() *GameInfoJson {
|
||||
gameInfo := gm.initGameInfoJson()
|
||||
|
||||
for i, _ := range gameInfo.Players {
|
||||
gameInfo.Players[i].Quotes = gm.getQuotesInfoByUserId(gameInfo.Players[i].Id)
|
||||
}
|
||||
return gameInfo
|
||||
}
|
||||
|
||||
func (gm *Game) initGameInfoJson() *GameInfoJson {
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
gameInfo := GameInfoJson{
|
||||
Name: gm.name,
|
||||
Name: gm.name,
|
||||
Players: make([]PlayerInfoJson, 0),
|
||||
}
|
||||
|
||||
for _, player := range gm.players {
|
||||
gameInfo.Players = append(gameInfo.Players, PlayerInfoJson{
|
||||
Id: player.id,
|
||||
Name: player.name,
|
||||
Score: player.score,
|
||||
IsPlaying: player.isPlaying,
|
||||
IsIdle: player.isIdle,
|
||||
})
|
||||
}
|
||||
|
||||
return &gameInfo
|
||||
}
|
||||
|
@ -4,20 +4,15 @@ import (
|
||||
"sirlab.de/go/knyt/user"
|
||||
)
|
||||
|
||||
type Quote struct {
|
||||
Id string `json:"id"`
|
||||
Quote string `json:"quote"`
|
||||
func (gm *Game) GetQuotesInfoByUser(usr *user.User) *QuotesInfo {
|
||||
usrId := usr.GetId()
|
||||
return &QuotesInfo{Quotes: gm.getQuotesInfoByUserId(usrId)}
|
||||
}
|
||||
|
||||
type QuotesInfo struct {
|
||||
Quotes []Quote `json:"quotes"`
|
||||
}
|
||||
|
||||
func (gm *Game) GetQuotesInfoByUser(usr *user.User) (*QuotesInfo, error) {
|
||||
func (gm *Game) getQuotesInfoByUserId(usrId string) []Quote {
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
usrId := usr.GetId()
|
||||
quotes := make([]Quote, 0)
|
||||
for _, quote := range gm.quotes {
|
||||
if quote.GetSourceId() == usrId {
|
||||
@ -28,5 +23,5 @@ func (gm *Game) GetQuotesInfoByUser(usr *user.User) (*QuotesInfo, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return &QuotesInfo{Quotes: quotes}, nil
|
||||
return quotes
|
||||
}
|
||||
|
@ -70,9 +70,27 @@ type GameJson struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Quote struct {
|
||||
Id string `json:"id"`
|
||||
Quote string `json:"quote"`
|
||||
}
|
||||
|
||||
type QuotesInfo struct {
|
||||
Quotes []Quote `json:"quotes"`
|
||||
}
|
||||
|
||||
type PlayerInfoJson struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Score int `json:"score"`
|
||||
IsPlaying bool `json:"isPlaying"`
|
||||
IsIdle bool `json:"isIdle"`
|
||||
Quotes []Quote `json:"quotes"`
|
||||
}
|
||||
|
||||
type GameInfoJson struct {
|
||||
Name string `json:"name"`
|
||||
Players map[string]playerInfo `json:"players"`
|
||||
Name string `json:"name"`
|
||||
Players []PlayerInfoJson `json:"players"`
|
||||
}
|
||||
|
||||
type GameStateJson struct {
|
||||
|
Loading…
Reference in New Issue
Block a user