2018-10-19 05:15:28 +00:00
|
|
|
<template lang="html">
|
|
|
|
<div
|
2019-10-01 22:26:31 +00:00
|
|
|
class="game-board"
|
|
|
|
ref="gameBoard"
|
2019-01-24 06:16:08 +00:00
|
|
|
v-if="user && platform"
|
2018-10-19 05:15:28 +00:00
|
|
|
>
|
2019-02-15 21:57:11 +00:00
|
|
|
<game-board-placeholder :id="gameDetailId" v-if="loading" />
|
2018-11-27 06:45:37 +00:00
|
|
|
|
2019-02-08 06:13:48 +00:00
|
|
|
<modal
|
|
|
|
ref="game"
|
|
|
|
large
|
|
|
|
@close="closeGame"
|
|
|
|
>
|
2019-04-19 06:20:29 +00:00
|
|
|
<game-detail
|
|
|
|
v-if="gameDetailId"
|
2019-05-08 22:40:15 +00:00
|
|
|
slot="content"
|
2019-04-19 06:20:29 +00:00
|
|
|
:id="gameDetailId"
|
|
|
|
:list-id="gameDetailListIndex"
|
|
|
|
/>
|
2019-02-06 06:55:00 +00:00
|
|
|
</modal>
|
|
|
|
|
2019-02-08 06:15:16 +00:00
|
|
|
<modal
|
|
|
|
ref="tag"
|
2019-05-18 12:56:05 +00:00
|
|
|
:title="$t('tags.applyTag')"
|
|
|
|
:message="$t('tags.useTags')"
|
2019-02-08 06:15:16 +00:00
|
|
|
>
|
|
|
|
<div slot="content">
|
2019-05-08 22:40:15 +00:00
|
|
|
<div
|
|
|
|
class="tags"
|
|
|
|
v-for="(tag, name) in tags"
|
|
|
|
:key="name"
|
|
|
|
>
|
2019-04-26 06:18:53 +00:00
|
|
|
<tag
|
|
|
|
:label="name"
|
|
|
|
:hex="tag.hex"
|
|
|
|
:readonly="!tag.games.includes(gameTagsId)"
|
|
|
|
@action="tryAdd(tag.games, name)"
|
|
|
|
@close="removeTag(name)"
|
|
|
|
/>
|
2019-02-08 06:15:16 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</modal>
|
|
|
|
|
2018-12-19 16:30:22 +00:00
|
|
|
<template>
|
2018-11-17 22:21:50 +00:00
|
|
|
<list
|
|
|
|
:name="list.name"
|
2019-10-06 05:26:13 +00:00
|
|
|
:game-list="list.games"
|
2018-11-17 22:21:50 +00:00
|
|
|
:listIndex="listIndex"
|
|
|
|
:key="`${list.name}-${listIndex}`"
|
2019-01-11 20:20:21 +00:00
|
|
|
v-if="list && !loading"
|
2018-11-17 22:21:50 +00:00
|
|
|
v-for="(list, listIndex) in gameLists[platform.code]"
|
|
|
|
@end="dragEnd"
|
|
|
|
/>
|
|
|
|
|
2019-11-04 22:08:30 +00:00
|
|
|
<list-add />
|
2018-11-17 22:21:50 +00:00
|
|
|
</template>
|
2018-10-19 05:15:28 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-01-11 20:20:21 +00:00
|
|
|
import GameBoardPlaceholder from '@/components/GameBoard/GameBoardPlaceholder';
|
2019-08-06 22:45:59 +00:00
|
|
|
import Tag from '@/components/Tag';
|
2019-04-05 22:46:56 +00:00
|
|
|
import ListAdd from '@/components/Lists/ListAdd';
|
2019-08-06 22:45:59 +00:00
|
|
|
import Modal from '@/components/Modal';
|
2019-05-17 05:37:58 +00:00
|
|
|
import List from '@/components/Lists/List';
|
2019-10-09 16:30:07 +00:00
|
|
|
import GameDetail from '@/pages/GameDetail';
|
|
|
|
import { chunk } from 'lodash';
|
|
|
|
import { mapState } 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,
|
|
|
|
GameBoardPlaceholder,
|
|
|
|
ListAdd,
|
|
|
|
Tag,
|
|
|
|
GameDetail,
|
|
|
|
Modal,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dragging: false,
|
|
|
|
draggingId: null,
|
|
|
|
loading: false,
|
|
|
|
gameData: null,
|
|
|
|
gameDetailListIndex: null,
|
|
|
|
gameDetailId: null,
|
|
|
|
gameTagsId: null,
|
|
|
|
queryLimit: 500,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['user', 'gameLists', 'platform', 'tags', 'games']),
|
|
|
|
|
|
|
|
list() {
|
|
|
|
return this.gameLists && this.platform && this.gameLists[this.platform.code]
|
|
|
|
? this.gameLists[this.platform.code]
|
|
|
|
: null;
|
2018-10-19 05:15:28 +00:00
|
|
|
},
|
2019-11-08 19:56:03 +00:00
|
|
|
},
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
mounted() {
|
|
|
|
if (!this.platform) {
|
|
|
|
this.$router.push({ name: 'platforms' });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.load();
|
|
|
|
this.setPageTitle();
|
|
|
|
this.$bus.$on('OPEN_GAME', this.openGame);
|
|
|
|
this.$bus.$on('OPEN_TAGS', this.openTags);
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$bus.$off('OPEN_GAME');
|
|
|
|
this.$bus.$off('OPEN_TAGS');
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
tryAdd(games, tagName) {
|
|
|
|
if (!games.includes(this.gameTagsId)) {
|
|
|
|
this.addTag(tagName);
|
|
|
|
}
|
2018-10-19 05:15:28 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
addTag(tagName) {
|
|
|
|
this.$store.commit('ADD_GAME_TAG', { tagName, gameId: this.gameTagsId });
|
|
|
|
this.$bus.$emit('SAVE_TAGS', this.tags);
|
|
|
|
},
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
closeGame() {
|
|
|
|
this.setPageTitle();
|
|
|
|
this.gameDetailId = null;
|
|
|
|
this.$store.commit('CLEAR_ACTIVE_GAME');
|
2018-10-19 05:15:28 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
setPageTitle() {
|
|
|
|
document.title = this.platform
|
|
|
|
? `${this.platform.name} - Gamebrary`
|
|
|
|
: 'Gamebrary';
|
|
|
|
},
|
2019-02-06 06:55:00 +00:00
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
removeTag(tagName) {
|
|
|
|
this.$store.commit('REMOVE_GAME_TAG', { tagName, gameId: this.gameTagsId });
|
|
|
|
this.$bus.$emit('SAVE_TAGS', this.tags);
|
2019-02-06 06:55:00 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
openGame({ id, listId }) {
|
|
|
|
this.gameDetailId = id;
|
|
|
|
this.gameDetailListIndex = listId;
|
|
|
|
this.$refs.game.open();
|
2018-10-19 05:15:28 +00:00
|
|
|
},
|
|
|
|
|
2019-11-08 19:56:03 +00:00
|
|
|
openTags(id) {
|
|
|
|
this.gameTagsId = id;
|
|
|
|
this.$refs.tag.open(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
dragEnd() {
|
|
|
|
this.dragging = false;
|
|
|
|
this.draggingId = null;
|
|
|
|
this.updateLists();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateLists() {
|
|
|
|
this.$store.dispatch('SAVE_LIST', this.gameLists)
|
|
|
|
.then(() => {
|
|
|
|
this.$bus.$emit('TOAST', { message: 'List updated' });
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$bus.$emit('TOAST', { message: 'Authentication error', type: 'error' });
|
|
|
|
this.$router.push({ name: 'sessionExpired' });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
load() {
|
|
|
|
const flattenedList = this.list
|
|
|
|
? this.list.map(({ games }) => games).flat()
|
|
|
|
: [];
|
|
|
|
|
|
|
|
const dedupedList = Array.from(new Set(flattenedList));
|
|
|
|
|
|
|
|
return dedupedList.length > this.queryLimit
|
|
|
|
? this.loadGamesInChunks(dedupedList)
|
|
|
|
: this.loadGames(dedupedList);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadGames(gameList) {
|
|
|
|
if (gameList && gameList.length > 0) {
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
this.$store.dispatch('LOAD_GAMES', gameList.toString())
|
|
|
|
.then(() => {
|
|
|
|
this.loading = false;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$bus.$emit('TOAST', { message: 'Error loading games', type: 'error' });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
loadGamesInChunks(gameList) {
|
|
|
|
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>
|
2019-09-10 20:02:16 +00:00
|
|
|
@import "~styles/styles";
|
2018-10-19 05:15:28 +00:00
|
|
|
|
2019-10-01 22:26:31 +00:00
|
|
|
.game-board {
|
2018-11-17 22:21:50 +00:00
|
|
|
user-select: none;
|
2018-10-29 23:53:49 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: flex-start;
|
|
|
|
height: calc(100vh - 48px);
|
2019-02-21 19:29:17 +00:00
|
|
|
padding: 0 $gp;
|
2018-10-29 23:53:49 +00:00
|
|
|
box-sizing: border-box;
|
|
|
|
overflow-x: auto;
|
|
|
|
overflow-x: overlay;
|
|
|
|
display: flex;
|
2018-10-19 05:15:28 +00:00
|
|
|
}
|
2018-10-29 23:53:49 +00:00
|
|
|
|
|
|
|
.list-placeholder {
|
|
|
|
opacity: 0.25;
|
|
|
|
}
|
2018-10-19 05:15:28 +00:00
|
|
|
</style>
|