This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/frontend/src/components/DeckList.vue

82 lines
1.4 KiB
Vue
Raw Normal View History

2019-05-14 15:59:36 +00:00
<template>
2019-05-24 11:30:26 +00:00
<v-expansion-panel v-model="open">
2019-05-23 11:58:59 +00:00
<Deck
2019-05-23 16:11:39 +00:00
v-for="deck in linked"
2019-05-23 11:58:59 +00:00
:deck="deck"
:key="deck.id"
@change="refresh_decks"
/>
2019-05-24 11:30:26 +00:00
<NewDeck
@change="
open = null
refresh_decks()
"
/>
2019-05-14 15:59:36 +00:00
</v-expansion-panel>
</template>
<script>
import * as Cookies from 'js-cookie'
import axios from '@/plugins/axios'
2019-05-23 16:11:39 +00:00
import DeckJS from '@/classes/Deck'
2019-05-14 15:59:36 +00:00
2019-05-14 23:13:44 +00:00
import Deck from './Deck.vue'
2019-05-23 16:11:39 +00:00
import NewDeck from './NewDeck.vue'
2019-05-14 15:59:36 +00:00
export default {
name: 'DeckList',
components: {
2019-05-23 16:11:39 +00:00
Deck,
NewDeck
2019-05-14 15:59:36 +00:00
},
2019-05-24 11:30:26 +00:00
data: () => ({
open: null
}),
asyncComputed: {
decks: {
get() {
return axios
.post('/decks/list', {
session: this.session
})
.then(response => {
if (response.data.success) {
return response.data.decks
}
})
},
default: []
}
},
2019-05-14 15:59:36 +00:00
computed: {
session: () => Cookies.get('session'),
2019-05-23 16:11:39 +00:00
linked() {
2019-05-14 15:59:36 +00:00
let result = []
2019-05-23 16:11:39 +00:00
for (let plainDeck of this.decks) {
2019-05-24 09:25:35 +00:00
let deck = new DeckJS(plainDeck.id)
deck.from_object(plainDeck.content)
2019-05-23 16:11:39 +00:00
deck.populate()
2019-05-14 15:59:36 +00:00
2019-05-23 16:11:39 +00:00
result.push(deck)
2019-05-14 15:59:36 +00:00
}
2019-05-27 11:51:24 +00:00
result.sort((deck_l, deck_r) => deck_l.name.localeCompare(deck_r.name))
2019-05-14 15:59:36 +00:00
return result
}
2019-05-23 11:58:59 +00:00
},
methods: {
refresh_decks() {
this.$asyncComputed.decks.update()
}
2019-05-14 15:59:36 +00:00
}
}
</script>