gamebrary/src/components/Board/CreateBoard.vue

199 lines
4.8 KiB
Vue
Raw Normal View History

2020-08-18 18:56:10 +00:00
<template lang="html">
2020-08-22 12:24:24 +00:00
<b-button
2020-10-21 19:02:32 +00:00
:variant="nightMode ? 'light' : 'primary'"
2020-08-22 12:24:24 +00:00
v-b-modal:create-board
>
2020-10-05 18:42:04 +00:00
{{ $t('boards.create') }}
2020-08-18 18:56:10 +00:00
<b-modal
id="create-board"
2020-10-14 00:08:56 +00:00
:header-bg-variant="nightMode ? 'dark' : null"
:header-text-variant="nightMode ? 'white' : null"
:body-bg-variant="nightMode ? 'dark' : null"
:body-text-variant="nightMode ? 'white' : null"
2020-08-22 12:24:24 +00:00
@show="resetBoard"
2020-08-18 18:56:10 +00:00
@hidden="resetBoard"
>
2020-10-14 00:35:40 +00:00
<template v-slot:modal-header="{ close }">
<modal-header
2020-10-14 21:47:02 +00:00
:title="$t('boards.create')"
@close="close"
/>
2020-10-14 00:35:40 +00:00
</template>
2020-08-18 18:56:10 +00:00
<form ref="createBoardForm" @submit.stop.prevent="submit">
<b-form-group
label="Board name"
label-for="name"
>
<b-form-input
id="name"
v-model="board.name"
2020-11-21 06:23:40 +00:00
placeholder="e.g. PS4 collection, Nintendo Switch, Xbox..."
2020-08-25 04:23:22 +00:00
autofocus
2020-08-18 18:56:10 +00:00
required
/>
</b-form-group>
<b-form-group
2020-08-25 06:26:10 +00:00
label="Board description"
2020-08-18 18:56:10 +00:00
label-for="description"
description="Optional"
>
<b-form-textarea
v-model="board.description"
maxlength="280"
2020-08-26 16:28:58 +00:00
rows="2"
2020-08-18 18:56:10 +00:00
/>
</b-form-group>
2020-08-26 16:28:58 +00:00
<platform-picker
v-model="board.platforms"
/>
<hr />
2020-08-18 18:56:10 +00:00
<b-form-group label="Board template">
<b-form-radio-group
v-model="selectedTemplate"
:options="boardTemplatesOptions"
buttons
name="radios-btn-default"
description="Optional"
/>
<b-row v-if="selectedTemplate" class="mt-3">
<b-col v-for="column in boardTemplates[selectedTemplate]" :key="column">
<b-card
:header="column"
header-tag="header"
header-class="p-1 pl-2"
hide-footer
/>
</b-col>
</b-row>
</b-form-group>
2020-11-22 03:31:18 +00:00
</form>
2020-08-18 18:56:10 +00:00
2020-11-22 03:31:18 +00:00
<template v-slot:modal-footer="{ cancel }">
<b-button @click="cancel" variant="light">
2020-08-18 18:56:10 +00:00
Cancel
2020-11-22 03:31:18 +00:00
</b-button>
2020-08-18 18:56:10 +00:00
<b-button
variant="primary"
2020-11-21 06:32:43 +00:00
:disabled="saving"
2020-08-18 18:56:10 +00:00
@click="submit"
>
<b-spinner small v-if="saving" />
2020-11-21 06:23:40 +00:00
<span v-else>Create board</span>
2020-08-18 18:56:10 +00:00
</b-button>
2020-11-22 03:31:18 +00:00
</template>
2020-08-18 18:56:10 +00:00
</b-modal>
</b-button>
</template>
<script>
2020-08-22 18:59:58 +00:00
import PlatformPicker from '@/components/Board/PlatformPicker';
2020-10-14 00:08:56 +00:00
import { mapGetters } from 'vuex';
2020-08-22 18:59:58 +00:00
2020-08-18 18:56:10 +00:00
export default {
2020-08-22 18:59:58 +00:00
components: {
PlatformPicker,
},
2020-08-18 18:56:10 +00:00
data() {
return {
board: {},
platformCategories: {
1: 'console',
2: 'arcade',
3: 'platform',
4: 'operating_system',
5: 'portable_console',
6: 'computer',
},
saving: false,
selectedTemplate: null,
boardTemplatesOptions: [
{ value: null, text: 'Blank' },
{ value: 'standard', text: 'Standard' },
{ value: 'detailed', text: 'Detailed' },
{ value: 'completionist', text: 'Completionist' },
],
boardTemplates: {
standard: ['Owned', 'Wishlist'],
detailed: ['Physical', 'Digital', 'Wishlist'],
completionist: ['Owned', 'Playing', 'Completed'],
},
};
},
2020-10-14 00:08:56 +00:00
computed: {
...mapGetters(['nightMode']),
},
2020-08-18 18:56:10 +00:00
methods: {
resetBoard() {
this.board = {
name: null,
description: null,
theme: null,
2020-08-25 04:23:22 +00:00
wallpaper: null,
2020-08-18 18:56:10 +00:00
platforms: [],
lists: [],
};
},
submit(e) {
e.preventDefault();
if (this.$refs.createBoardForm.checkValidity()) {
this.createBoard();
}
},
async createBoard() {
const { selectedTemplate, boardTemplates, board } = this;
2020-08-23 07:34:16 +00:00
if (board.platforms.length === 0) {
return this.$bvToast.toast('Please select at least 1 platform', { title: 'Error', variant: 'error' });
}
2020-08-18 18:56:10 +00:00
this.saving = true;
const lists = selectedTemplate && boardTemplates[selectedTemplate]
? boardTemplates[selectedTemplate].map((name) => {
const list = {
name,
games: [],
settings: {},
};
return list;
})
2020-08-25 06:21:44 +00:00
: [{
name: 'List name here',
games: [],
settings: {},
}];
2020-08-18 18:56:10 +00:00
const payload = {
...board,
lists,
};
await this.$store.dispatch('CREATE_BOARD', payload)
.catch(() => {
this.saving = false;
2020-08-23 07:34:16 +00:00
this.$bvToast.toast('There was an error creating board', { title: 'Error', variant: 'error' });
2020-08-18 18:56:10 +00:00
});
this.saving = false;
this.$bvToast.toast('Board crated', { title: 'Success', variant: 'success' });
2020-08-24 16:44:45 +00:00
return this.$bvModal.hide('create-board');
2020-08-18 18:56:10 +00:00
},
},
};
</script>