Fix some uploading stuff, rename some variables

This commit is contained in:
Adam Goldsmith 2019-01-01 17:43:57 +01:00
parent 96f1b728cb
commit d25da968c4
3 changed files with 26 additions and 27 deletions

View File

@ -1,11 +1,11 @@
<template>
<!-- style is inline for phantomjs -->
<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>
</span>
</div>
<div v-for="cardRow in chunkedCards">
<span v-for="card in cardRow" @click="$emit('input', card)">
<Hero v-bind="card.card" style="white-space: initial;"> </Hero>
</span>
</div>
</div>
</template>
@ -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));
},
},
}

View File

@ -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: {}},
};
},
@ -75,9 +76,9 @@
created() {
if (this.deckID !== 'new') {
fetch('/decks/' + this.deckID + '.json')
.then(r => r.json())
.then(j => this.deckInfo = j.input)
.catch((err) => console.log('did not get old JSON, starting new deck'));
.then(r => r.json())
.then(j => this.deckInfo = j)
.catch((err) => console.log('did not get old JSON, starting new deck'));
}
/* window.addEventListener(
@ -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));

View File

@ -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>');
}));
}