Fix some uploading stuff, rename some variables
This commit is contained in:
parent
1a22f4f67d
commit
3573db0567
20
src/Deck.vue
20
src/Deck.vue
@ -3,7 +3,7 @@
|
||||
<div style="white-space: nowrap;">
|
||||
<div v-for="cardRow in chunkedCards">
|
||||
<span v-for="card in cardRow" @click="$emit('input', card)">
|
||||
<Hero v-bind="card.card"> </Hero>
|
||||
<Hero v-bind="card.card" style="white-space: initial;"> </Hero>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@ -14,19 +14,17 @@
|
||||
|
||||
export default {
|
||||
name: 'Deck',
|
||||
props: ['deckInfo'],
|
||||
props: ['cards'],
|
||||
components: {Hero},
|
||||
|
||||
computed: {
|
||||
cards() {
|
||||
console.log
|
||||
allCards() {
|
||||
return Object
|
||||
.keys(this.deckInfo)
|
||||
.filter(cardType => cardType !== 'meta')
|
||||
.flatMap(cardType => this.deckInfo[cardType].flatMap((card, index) => {
|
||||
.keys(this.cards)
|
||||
.flatMap(cardType => this.cards[cardType].flatMap((card, index) => {
|
||||
let cardWrapper = {
|
||||
type: cardType,
|
||||
card: this.deckInfo[cardType][index],
|
||||
card: this.cards[cardType][index],
|
||||
props: Hero.props,
|
||||
};
|
||||
return Array(card.count || 1).fill(cardWrapper);
|
||||
@ -35,12 +33,12 @@
|
||||
|
||||
chunkedCards() {
|
||||
// find minimum box to fit cards
|
||||
let columns = Math.ceil(Math.sqrt(this.cards.length));
|
||||
let rows = Math.ceil(this.cards.length / columns) || 0;
|
||||
let columns = Math.ceil(Math.sqrt(this.allCards.length));
|
||||
let rows = Math.ceil(this.allCards.length / columns) || 0;
|
||||
return Array(rows)
|
||||
.fill()
|
||||
.map((_, index) => index * columns)
|
||||
.map(begin => this.cards.slice(begin, begin + columns));
|
||||
.map(begin => this.allCards.slice(begin, begin + columns));
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Deck ref="deck" :deckInfo="deckInfo" v-model="selected"> </Deck>
|
||||
<Deck ref="deck" :cards="deckInfo.cards" v-model="selected"> </Deck>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -62,7 +62,8 @@
|
||||
data() {
|
||||
return {
|
||||
selected: null,
|
||||
deckInfo: {meta: {name: "", type: ""}},
|
||||
deckInfo: {meta: {name: "", type: ""},
|
||||
cards: {}},
|
||||
};
|
||||
},
|
||||
|
||||
@ -76,7 +77,7 @@
|
||||
if (this.deckID !== 'new') {
|
||||
fetch('/decks/' + this.deckID + '.json')
|
||||
.then(r => r.json())
|
||||
.then(j => this.deckInfo = j.input)
|
||||
.then(j => this.deckInfo = j)
|
||||
.catch((err) => console.log('did not get old JSON, starting new deck'));
|
||||
}
|
||||
|
||||
@ -126,11 +127,10 @@
|
||||
method: 'post',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
id: this.deckID === 'new' ? undefined : this.deckID,
|
||||
deck: this.deckInfo,
|
||||
body: (new XMLSerializer()).serializeToString(this.$refs.deck.$el),
|
||||
})
|
||||
})
|
||||
_id: this.deckID === 'new' ? undefined : this.deckID,
|
||||
dom: (new XMLSerializer()).serializeToString(this.$refs.deck.$el),
|
||||
})})
|
||||
.then(r => r.json())
|
||||
.then(j => this.$router.replace('/edit/' + j.id))
|
||||
.catch(err => console.log('Failed to upload' + err));
|
||||
|
@ -35,8 +35,8 @@ function getDecksList(req, res) {
|
||||
}
|
||||
|
||||
function getInputJSON(req, res) {
|
||||
db.findOne({_id: req.params.deckID})
|
||||
.then(doc => res.json(doc.input))
|
||||
db.findOne({_id: req.params.deckID}, {image: 0})
|
||||
.then(doc => res.json(doc))
|
||||
.catch(err => res.status(404).end());
|
||||
}
|
||||
|
||||
@ -47,6 +47,7 @@ function getDeckImage(req, res) {
|
||||
}
|
||||
|
||||
function getTTSJSON(req, res) {
|
||||
// TODO: fix
|
||||
db.findOne({_id: req.params.deckID})
|
||||
.then(doc => {
|
||||
let deckIn = doc.deck;
|
||||
@ -115,6 +116,6 @@ function handleUpload(req, res) {
|
||||
}
|
||||
});
|
||||
page.property('zoomFactor', 2); // pretty arbitrary
|
||||
page.property('content', '<body style="margin:0;">' + json.body + '</body>');
|
||||
page.property('content', '<body style="margin:0;">' + json.dom + '</body>');
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user