2018-10-19 05:15:28 +00:00
|
|
|
<template lang="html">
|
2020-10-14 21:53:57 +00:00
|
|
|
<div
|
2020-11-18 05:55:35 +00:00
|
|
|
:class="['board py-2', boardBackground, { dragging, 'empty': isEmptyBoard }]"
|
2020-12-18 04:44:40 +00:00
|
|
|
:style="boardStyles"
|
2020-10-14 21:53:57 +00:00
|
|
|
>
|
2020-08-15 00:00:55 +00:00
|
|
|
<board-placeholder v-if="loading" />
|
2019-11-21 21:44:51 +00:00
|
|
|
|
2021-02-03 04:57:19 +00:00
|
|
|
<template v-else-if="showBoard">
|
2020-08-18 18:56:10 +00:00
|
|
|
<list
|
2020-08-21 06:49:49 +00:00
|
|
|
v-for="(list, listIndex) in board.lists"
|
2020-08-21 06:13:45 +00:00
|
|
|
:list="list"
|
2020-08-21 06:49:49 +00:00
|
|
|
:listIndex="listIndex"
|
2020-08-21 06:13:45 +00:00
|
|
|
:key="list.name"
|
2020-08-18 18:56:10 +00:00
|
|
|
/>
|
2019-11-08 20:34:06 +00:00
|
|
|
|
2021-02-19 22:58:05 +00:00
|
|
|
<div class="d-flex flex-column pr-2">
|
|
|
|
<b-button
|
|
|
|
:variant="nightMode ? 'dark' : 'light'"
|
|
|
|
size="sm"
|
|
|
|
class="mb-2"
|
|
|
|
v-b-modal:add-list
|
|
|
|
>
|
|
|
|
<i class="fas fa-plus fa-fw" aria-hidden />
|
|
|
|
</b-button>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
:variant="nightMode ? 'dark' : 'light'"
|
|
|
|
size="sm"
|
|
|
|
v-b-modal:edit-board
|
|
|
|
>
|
|
|
|
<i class="fas fa-cog fa-fw" aria-hidden />
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
|
2020-10-14 00:37:32 +00:00
|
|
|
<empty-board v-if="isEmptyBoard" class="mr-3" />
|
|
|
|
|
2021-01-25 21:04:37 +00:00
|
|
|
<add-list-modal />
|
2021-02-03 23:38:37 +00:00
|
|
|
<edit-board-modal />
|
2020-08-26 21:22:21 +00:00
|
|
|
</template>
|
2021-02-03 04:57:19 +00:00
|
|
|
|
|
|
|
<b-alert
|
|
|
|
v-else
|
|
|
|
variant="warning"
|
|
|
|
show
|
|
|
|
>
|
|
|
|
<span>Private Board</span>
|
|
|
|
</b-alert>
|
2019-11-08 20:34:06 +00:00
|
|
|
</div>
|
2018-10-19 05:15:28 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-02-18 00:51:37 +00:00
|
|
|
import EditBoardModal from '@/components/Board/EditBoardModal';
|
2020-08-15 00:00:55 +00:00
|
|
|
import BoardPlaceholder from '@/components/Board/BoardPlaceholder';
|
2020-10-14 00:37:32 +00:00
|
|
|
import EmptyBoard from '@/components/Board/EmptyBoard';
|
2021-01-25 21:04:37 +00:00
|
|
|
import AddListModal from '@/components/Board/AddListModal';
|
2019-05-17 05:37:58 +00:00
|
|
|
import List from '@/components/Lists/List';
|
2020-08-21 06:13:45 +00:00
|
|
|
import chunk from 'lodash.chunk';
|
2020-10-14 21:53:57 +00:00
|
|
|
import { mapState, mapGetters } from 'vuex';
|
2018-10-19 05:15:28 +00:00
|
|
|
import draggable from 'vuedraggable';
|
2018-10-25 06:33:15 +00:00
|
|
|
|
2018-10-19 05:15:28 +00:00
|
|
|
export default {
|
2019-11-08 19:56:03 +00:00
|
|
|
components: {
|
|
|
|
draggable,
|
|
|
|
List,
|
2020-08-15 00:00:55 +00:00
|
|
|
BoardPlaceholder,
|
2020-10-14 00:37:32 +00:00
|
|
|
EmptyBoard,
|
2021-01-25 21:04:37 +00:00
|
|
|
AddListModal,
|
2021-02-03 23:38:37 +00:00
|
|
|
EditBoardModal,
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2020-08-18 18:56:10 +00:00
|
|
|
loading: true,
|
2019-11-08 19:56:03 +00:00
|
|
|
queryLimit: 500,
|
2020-08-26 16:13:04 +00:00
|
|
|
wallpaperUrl: null,
|
2019-11-08 19:56:03 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-08-28 21:56:20 +00:00
|
|
|
...mapState(['user', 'dragging', 'board', 'wallpapers']),
|
2020-10-14 21:53:57 +00:00
|
|
|
...mapGetters(['nightMode']),
|
2020-08-25 04:23:22 +00:00
|
|
|
|
2021-02-03 04:57:19 +00:00
|
|
|
showBoard() {
|
|
|
|
const { isPublicRoute, board } = this;
|
|
|
|
const isPublicBoard = isPublicRoute && board.isPublic;
|
|
|
|
|
|
|
|
return this.user || isPublicBoard;
|
|
|
|
},
|
|
|
|
|
2020-12-18 04:44:40 +00:00
|
|
|
boardStyles() {
|
2021-02-03 21:54:47 +00:00
|
|
|
if (!this.showBoard) {
|
2021-02-03 22:34:22 +00:00
|
|
|
return '';
|
2021-02-03 21:54:47 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 17:19:12 +00:00
|
|
|
if (this.board.backgroundUrl) {
|
|
|
|
return `background-image: url('${this.board.backgroundUrl}');`;
|
|
|
|
}
|
|
|
|
|
2020-12-18 04:44:40 +00:00
|
|
|
if (this.wallpaperUrl) {
|
2020-12-21 18:09:19 +00:00
|
|
|
return `background-image: url('${this.wallpaperUrl}');`;
|
2020-12-18 04:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: use optional chaining
|
2020-12-18 04:46:31 +00:00
|
|
|
return this.board && this.board.backgroundColor
|
|
|
|
? `background-color: ${this.board.backgroundColor};`
|
|
|
|
: null;
|
2020-08-25 04:23:22 +00:00
|
|
|
},
|
2020-09-01 17:47:56 +00:00
|
|
|
|
|
|
|
boardId() {
|
|
|
|
return this.$route.params.id;
|
|
|
|
},
|
2020-10-05 18:42:28 +00:00
|
|
|
|
2020-10-14 00:37:32 +00:00
|
|
|
isEmptyBoard() {
|
|
|
|
// TODO: use optional chaining
|
|
|
|
return this.board && this.board.lists && this.board.lists.length === 0;
|
|
|
|
},
|
|
|
|
|
2021-02-03 04:57:19 +00:00
|
|
|
isPublicRoute() {
|
2020-10-14 00:37:32 +00:00
|
|
|
// TODO: use optional chaining
|
2020-10-05 18:42:28 +00:00
|
|
|
return this.$route.meta && this.$route.meta.public;
|
|
|
|
},
|
2020-10-14 21:53:57 +00:00
|
|
|
|
|
|
|
boardBackground() {
|
2020-12-18 04:44:40 +00:00
|
|
|
if (this.board.backgroundColor) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-10-14 21:53:57 +00:00
|
|
|
return this.nightMode
|
|
|
|
? 'bg-dark'
|
|
|
|
: 'bg-light';
|
|
|
|
},
|
2020-09-01 17:47:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
boardId(value) {
|
|
|
|
if (value) {
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
},
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2020-10-05 18:42:28 +00:00
|
|
|
async mounted() {
|
2021-02-03 04:57:19 +00:00
|
|
|
if (this.isPublicRoute) {
|
2020-10-05 18:42:28 +00:00
|
|
|
await this.loadPublicBoard(this.boardId);
|
|
|
|
|
2021-02-03 04:57:19 +00:00
|
|
|
if (this.showBoard) {
|
|
|
|
this.loadBoardGames();
|
|
|
|
this.setWallpaper();
|
|
|
|
}
|
2020-10-05 18:42:28 +00:00
|
|
|
} else {
|
|
|
|
this.load();
|
|
|
|
}
|
2020-08-26 16:13:04 +00:00
|
|
|
|
2020-08-28 21:56:20 +00:00
|
|
|
this.$bus.$on('RELOAD_WALLPAPER', this.setWallpaper);
|
2020-08-25 04:23:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroyed() {
|
|
|
|
this.$store.commit('CLEAR_BOARD');
|
2020-08-26 16:13:04 +00:00
|
|
|
this.$bus.$off('RELOAD_WALLPAPER');
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-08-18 18:56:10 +00:00
|
|
|
load() {
|
2020-09-01 17:47:56 +00:00
|
|
|
if (this.boardId && this.user) {
|
|
|
|
this.loadBoard(this.boardId);
|
2020-08-18 18:56:10 +00:00
|
|
|
} else {
|
|
|
|
this.$router.push({ name: 'dashboard' });
|
|
|
|
}
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
|
|
|
|
2020-08-18 18:56:10 +00:00
|
|
|
async loadBoard(id) {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
await this.$store.dispatch('LOAD_BOARD', id)
|
|
|
|
.catch(() => {
|
|
|
|
this.$router.replace({ path: '/' });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.loadBoardGames();
|
2020-08-28 21:56:20 +00:00
|
|
|
this.setWallpaper();
|
2020-08-26 16:13:04 +00:00
|
|
|
},
|
|
|
|
|
2020-10-05 18:42:28 +00:00
|
|
|
async loadPublicBoard(id) {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
await this.$store.dispatch('LOAD_PUBIC_BOARD', id)
|
|
|
|
.catch(() => {
|
|
|
|
// this.$router.replace({ path: '/' });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.loadBoardGames();
|
2021-02-18 17:19:12 +00:00
|
|
|
// TODO: null check, define backgrounds priority
|
2020-10-05 18:42:28 +00:00
|
|
|
this.setWallpaper();
|
|
|
|
},
|
|
|
|
|
2020-08-28 21:56:20 +00:00
|
|
|
async setWallpaper() {
|
|
|
|
const { wallpaper } = this.board;
|
|
|
|
|
|
|
|
const wallpaperObject = wallpaper && this.wallpapers.length
|
|
|
|
? this.wallpapers.find(({ fullPath }) => fullPath === wallpaper)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
this.wallpaperUrl = wallpaperObject && wallpaperObject.url
|
|
|
|
? wallpaperObject.url
|
|
|
|
: null;
|
2020-08-18 18:56:10 +00:00
|
|
|
},
|
2019-11-08 19:56:03 +00:00
|
|
|
|
2020-08-18 18:56:10 +00:00
|
|
|
loadBoardGames() {
|
|
|
|
const { lists } = this.board;
|
2019-12-13 07:07:15 +00:00
|
|
|
|
2020-08-25 23:37:33 +00:00
|
|
|
if (lists && lists.length === 0) {
|
2020-08-22 18:58:44 +00:00
|
|
|
this.$bvModal.show('add-list');
|
2019-12-13 07:07:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 06:13:45 +00:00
|
|
|
const boardGames = Array.from(new Set(lists.map(({ games }) => games).flat()));
|
2019-11-08 19:56:03 +00:00
|
|
|
|
2020-08-21 06:13:45 +00:00
|
|
|
if (boardGames.length === 0) {
|
|
|
|
this.loading = false;
|
2020-08-18 18:56:10 +00:00
|
|
|
|
2020-08-21 06:13:45 +00:00
|
|
|
return boardGames;
|
|
|
|
}
|
2020-08-18 21:35:32 +00:00
|
|
|
|
2020-08-21 06:13:45 +00:00
|
|
|
return boardGames.length > this.queryLimit
|
|
|
|
? this.loadGamesInChunks(boardGames)
|
|
|
|
: this.loadGames(boardGames);
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
|
|
|
|
2020-08-21 06:13:45 +00:00
|
|
|
async loadGames(gameList) {
|
|
|
|
this.loading = true;
|
|
|
|
|
2020-11-07 05:49:18 +00:00
|
|
|
await this.$store.dispatch('LOAD_GAMES', gameList.toString())
|
2020-08-21 06:13:45 +00:00
|
|
|
.catch(() => {
|
2020-12-10 05:26:57 +00:00
|
|
|
this.$bvToast.toast('Error loading games', { variant: 'error' });
|
2020-08-21 06:13:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.loading = false;
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
loadGamesInChunks(gameList) {
|
2020-08-21 06:13:45 +00:00
|
|
|
const chunkedGameList = chunk(gameList, this.queryLimit);
|
|
|
|
|
|
|
|
chunkedGameList.forEach((gameListChunk) => {
|
|
|
|
this.loadGames(gameListChunk);
|
|
|
|
});
|
2018-10-19 05:15:28 +00:00
|
|
|
},
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
2018-10-19 05:15:28 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" rel="stylesheet/scss" scoped>
|
2020-08-15 00:00:55 +00:00
|
|
|
.board {
|
2019-11-14 21:10:10 +00:00
|
|
|
user-select: none;
|
|
|
|
display: flex;
|
2020-08-25 04:23:22 +00:00
|
|
|
background-size: cover;
|
2019-11-14 21:10:10 +00:00
|
|
|
align-items: flex-start;
|
2020-08-25 04:23:22 +00:00
|
|
|
height: 100vh;
|
2020-09-26 00:09:20 +00:00
|
|
|
width: 100%;
|
2021-02-03 04:56:37 +00:00
|
|
|
padding-left: calc(58px + .5rem);
|
2019-11-14 21:10:10 +00:00
|
|
|
box-sizing: border-box;
|
|
|
|
overflow-x: auto;
|
|
|
|
overflow-x: overlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
.list-placeholder {
|
|
|
|
opacity: 0.25;
|
|
|
|
}
|
2018-10-19 05:15:28 +00:00
|
|
|
</style>
|