diff --git a/src/Deck.vue b/src/Deck.vue index a46fe9b..618c385 100644 --- a/src/Deck.vue +++ b/src/Deck.vue @@ -1,11 +1,11 @@ @@ -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)); }, }, } diff --git a/src/Editor.vue b/src/Editor.vue index 5987026..2f4ae4c 100644 --- a/src/Editor.vue +++ b/src/Editor.vue @@ -47,7 +47,7 @@ - + @@ -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)); diff --git a/src/server.js b/src/server.js index 96825a4..113a9de 100644 --- a/src/server.js +++ b/src/server.js @@ -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', '' + json.body + ''); + page.property('content', '' + json.dom + ''); })); }