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