Add new deck
This commit is contained in:
parent
38b92829cd
commit
0475e45275
6 changed files with 123 additions and 48 deletions
34
backend/routes/decks/add.coffee
Normal file
34
backend/routes/decks/add.coffee
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
logger = (require 'logging').default '/decks/add'
|
||||||
|
|
||||||
|
# session storage (volatile data)
|
||||||
|
session = (require '../../session')
|
||||||
|
# fftcg.db (persistent data)
|
||||||
|
fftcgdb = (require '../../db')
|
||||||
|
|
||||||
|
module.exports =
|
||||||
|
url: '/decks/add'
|
||||||
|
method: 'POST'
|
||||||
|
# schema: (require './modify.schema')
|
||||||
|
|
||||||
|
handler: (request, reply) ->
|
||||||
|
session.check request.body.session ? ""
|
||||||
|
.then (userid) ->
|
||||||
|
# active session found, get associated user
|
||||||
|
fftcgdb.addDeck (userid), (request.body.deckCards)
|
||||||
|
.then (deckID) ->
|
||||||
|
logger.info "OK user '#{userid}' added deck '#{deckID}'"
|
||||||
|
reply.send
|
||||||
|
success: true
|
||||||
|
deck: deckID
|
||||||
|
|
||||||
|
.catch (err) ->
|
||||||
|
# couldnt get user details
|
||||||
|
logger.warn "FAIL '#{err}' for user id '#{userid}'"
|
||||||
|
reply.send
|
||||||
|
success: false
|
||||||
|
|
||||||
|
.catch ->
|
||||||
|
# no session found
|
||||||
|
logger.info "FAIL '#{request.body.session}' session not found"
|
||||||
|
reply.send
|
||||||
|
success: false
|
|
@ -22,6 +22,8 @@ fastify.route (require "./routes/#{route}") for route in [
|
||||||
'user/register'
|
'user/register'
|
||||||
# list decks
|
# list decks
|
||||||
'decks/list'
|
'decks/list'
|
||||||
|
# add deck
|
||||||
|
'decks/add'
|
||||||
# modify deck
|
# modify deck
|
||||||
'decks/modify'
|
'decks/modify'
|
||||||
]
|
]
|
||||||
|
|
|
@ -46,7 +46,8 @@ export default class {
|
||||||
let cardLines = str.match(cardLinesRE)
|
let cardLines = str.match(cardLinesRE)
|
||||||
let cardCounts = {}
|
let cardCounts = {}
|
||||||
|
|
||||||
cardLines.forEach(cardLine => {
|
if (cardLines) {
|
||||||
|
for (let cardLine of cardLines) {
|
||||||
// extract serial (guaranteed to be in here!)
|
// extract serial (guaranteed to be in here!)
|
||||||
let serialRE = /\b(\d+)-0*(\d{1,3})[A-Z]?\b/i
|
let serialRE = /\b(\d+)-0*(\d{1,3})[A-Z]?\b/i
|
||||||
let serial = serialRE.exec(cardLine)
|
let serial = serialRE.exec(cardLine)
|
||||||
|
@ -84,7 +85,8 @@ export default class {
|
||||||
cardCounts[serial] = 0
|
cardCounts[serial] = 0
|
||||||
}
|
}
|
||||||
cardCounts[serial] += count
|
cardCounts[serial] += count
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// push card data into deck
|
// push card data into deck
|
||||||
this.cards = []
|
this.cards = []
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
<template>
|
<template>
|
||||||
<v-expansion-panel>
|
<v-expansion-panel v-model="open">
|
||||||
<Deck
|
<Deck
|
||||||
v-for="deck in linked"
|
v-for="deck in linked"
|
||||||
:deck="deck"
|
:deck="deck"
|
||||||
:key="deck.id"
|
:key="deck.id"
|
||||||
@change="refresh_decks"
|
@change="refresh_decks"
|
||||||
/>
|
/>
|
||||||
<NewDeck />
|
<NewDeck
|
||||||
|
@change="
|
||||||
|
open = null
|
||||||
|
refresh_decks()
|
||||||
|
"
|
||||||
|
/>
|
||||||
</v-expansion-panel>
|
</v-expansion-panel>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -26,6 +31,10 @@ export default {
|
||||||
NewDeck
|
NewDeck
|
||||||
},
|
},
|
||||||
|
|
||||||
|
data: () => ({
|
||||||
|
open: null
|
||||||
|
}),
|
||||||
|
|
||||||
asyncComputed: {
|
asyncComputed: {
|
||||||
decks: {
|
decks: {
|
||||||
get() {
|
get() {
|
||||||
|
|
|
@ -6,13 +6,16 @@
|
||||||
|
|
||||||
<v-container>
|
<v-container>
|
||||||
<v-card flat>
|
<v-card flat>
|
||||||
<DeckEditor />
|
<DeckEditor ref="editor" @save="save_deck" />
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-container>
|
</v-container>
|
||||||
</v-expansion-panel-content>
|
</v-expansion-panel-content>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import * as Cookies from 'js-cookie'
|
||||||
|
import axios from '@/plugins/axios'
|
||||||
|
|
||||||
import DeckEditor from './forms/DeckEditor.vue'
|
import DeckEditor from './forms/DeckEditor.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -20,6 +23,26 @@ export default {
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
DeckEditor
|
DeckEditor
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
session: () => Cookies.get('session')
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
save_deck(new_deck) {
|
||||||
|
axios
|
||||||
|
.post('/decks/add', {
|
||||||
|
session: this.session,
|
||||||
|
deckCards: new_deck.plainObject()
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.data.success) {
|
||||||
|
this.$emit('change')
|
||||||
|
this.$refs.editor.clear()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -49,23 +49,28 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
data: () => ({
|
data: () => ({
|
||||||
check: {
|
check: null,
|
||||||
count: 50,
|
new_deck: null
|
||||||
maximum: 0,
|
|
||||||
checked: false
|
|
||||||
},
|
|
||||||
new_deck: {}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.new_deck = new Deck(0)
|
this.clear()
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
clear() {
|
||||||
|
this.check = {
|
||||||
|
count: 50,
|
||||||
|
maximum: 0,
|
||||||
|
checked: false
|
||||||
|
}
|
||||||
|
|
||||||
|
this.new_deck = new Deck(0)
|
||||||
if (this.deck)
|
if (this.deck)
|
||||||
// this.deck should already be populated!
|
// this.deck should already be populated!
|
||||||
this.new_deck.from_object(this.deck)
|
this.new_deck.from_object(this.deck)
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
|
||||||
validate() {
|
validate() {
|
||||||
this.new_deck.from_deckList(this.$refs.deckList.lazyValue)
|
this.new_deck.from_deckList(this.$refs.deckList.lazyValue)
|
||||||
this.new_deck.populate()
|
this.new_deck.populate()
|
||||||
|
@ -75,9 +80,9 @@ export default {
|
||||||
|
|
||||||
// find most frequent card
|
// find most frequent card
|
||||||
this.check.maximum = 0
|
this.check.maximum = 0
|
||||||
this.new_deck.cards.forEach(card => {
|
for (let card of this.new_deck.cards) {
|
||||||
if (card.count > this.check.maximum) this.check.maximum = card.count
|
if (card.count > this.check.maximum) this.check.maximum = card.count
|
||||||
})
|
}
|
||||||
|
|
||||||
// deck has now been checked
|
// deck has now been checked
|
||||||
this.check.checked = true
|
this.check.checked = true
|
||||||
|
|
Reference in a new issue