gamebrary/src/components/Settings/BoardSettings.vue

364 lines
9.5 KiB
Vue
Raw Normal View History

2020-08-15 00:02:34 +00:00
<template lang="html">
2020-08-25 04:23:22 +00:00
<b-button
v-b-modal:board-settings
2020-09-24 04:15:31 +00:00
v-b-tooltip.hover.left
title="Board settings"
2020-08-25 04:23:22 +00:00
class="mt-3"
2021-01-04 20:54:05 +00:00
variant="light"
2020-10-08 17:55:26 +00:00
size="sm"
2020-08-25 04:23:22 +00:00
ref="addList"
>
<i class="fas fa-cog fa-fw" aria-hidden />
2020-08-15 00:02:34 +00:00
<b-modal
id="board-settings"
2020-08-26 17:34:23 +00:00
size="lg"
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"
:footer-bg-variant="nightMode ? 'dark' : null"
:footer-text-variant="nightMode ? 'white' : null"
2020-10-14 21:48:27 +00:00
footer-class="d-flex justify-content-between"
2020-08-25 04:23:22 +00:00
@show="init"
@hide="hide"
2020-08-15 00:02:34 +00:00
>
2020-10-14 00:36:41 +00:00
<template v-slot:modal-header="{ close }">
<modal-header
2020-10-14 21:48:27 +00:00
:title="$t('board.settings.title')"
@close="close"
/>
2020-10-14 00:36:41 +00:00
</template>
2020-08-25 04:23:22 +00:00
<form ref="boardSettingsForm" @submit.stop.prevent="submit">
2020-10-14 23:20:25 +00:00
<b-row>
2020-12-28 16:12:39 +00:00
<b-col lg="6">
2020-10-14 23:20:25 +00:00
<b-form-group
:label="$t('board.settings.nameLabel')"
label-for="name"
2020-08-15 00:02:34 +00:00
>
2020-10-14 23:20:25 +00:00
<b-form-input
id="name"
v-model="name"
required
/>
</b-form-group>
<b-form-group
:label="$t('board.settings.descriptionLabel')"
label-for="description"
>
<b-form-textarea
id="description"
v-model="description"
maxlength="280"
rows="3"
/>
</b-form-group>
2020-12-18 04:44:07 +00:00
<b-form-group
label="Board background color"
label-for="backgroundColor"
>
<b-form-input
id="backgroundColor"
class="color-picker"
v-model="backgroundColor"
type="color"
/>
<b-form-text
v-if="backgroundColor"
id="input-live-help"
>
{{ backgroundColor }}
</b-form-text>
</b-form-group>
2020-11-23 23:28:43 +00:00
<b-button
v-b-modal.editPlatforms
:variant="noPlatformsSelected ? 'warning' : 'secondary'"
>
Platforms {{ noPlatformsSelected ? null : `(${board.platforms.length})` }}
</b-button>
<b-modal
id="editPlatforms"
2021-01-04 21:30:19 +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"
:footer-bg-variant="nightMode ? 'dark' : null"
:footer-text-variant="nightMode ? 'white' : null"
2020-11-23 23:28:43 +00:00
hide-footer
>
<template v-slot:modal-header="{ close }">
<modal-header
title="Board platforms"
@close="close"
/>
</template>
<b-alert :show="noPlatformsSelected" variant="warning">
Please select at least 1 platform
</b-alert>
<platform-picker v-model="board.platforms" />
</b-modal>
2020-10-14 23:20:25 +00:00
</b-col>
2020-12-28 16:12:39 +00:00
<b-col class="mt-4 mt-lg-0">
2020-10-14 23:20:25 +00:00
<b-form-group
:label="$t('board.settings.wallpaper')"
class="mb-0"
/>
<b-dropdown
id="wallpaper"
v-if="wallpapers.length"
text="Select wallpaper"
boundary="viewport"
>
<b-dropdown-item
v-for="file in wallpapers"
:key="file.name"
@click="setWallpaper(file.fullPath)"
>
<b-img
thumbnail
:src="file.url"
:alt="file.name"
width="200"
fluid
/>
</b-dropdown-item>
</b-dropdown>
<b-button
v-if="wallpaper"
2020-10-14 23:20:25 +00:00
variant="danger"
class="mx-2"
@click="removeWallpaper"
>
2020-10-14 21:48:27 +00:00
{{ $t('board.settings.removeWallpaper') }}
2020-10-14 23:20:25 +00:00
</b-button>
<b-alert :show="!wallpapers.length">
{{ $t('board.settings.noWallpapers') }}
<br />
<b-button :to="{ name: 'wallpapers' }" class="mt-3">
{{ $t('board.settings.uploadWallpaper') }}
</b-button>
</b-alert>
<b-img
v-if="wallpaperUrl"
thumbnail
class="my-3"
:src="wallpaperUrl"
fluid
/>
</b-col>
</b-row>
2020-08-25 04:23:22 +00:00
</form>
2020-10-14 23:20:25 +00:00
<template v-slot:modal-footer="{ cancel }">
<b-button
variant="danger"
2020-08-25 04:23:22 +00:00
@click="confirmDelete"
>
2020-10-14 21:48:27 +00:00
{{ $t('board.settings.deleteBoard') }}
</b-button>
2020-08-25 04:23:22 +00:00
2020-10-14 23:20:25 +00:00
<div>
<b-button
variant="light"
:disabled="saving"
class="mx-2"
@click="cancel"
>
{{ $t('global.cancel') }}
</b-button>
<b-button
variant="primary"
2020-11-23 23:28:43 +00:00
:disabled="saving || noPlatformsSelected"
2020-10-14 23:20:25 +00:00
@click="saveSettings"
>
<b-spinner small v-if="saving" />
<span v-else>{{ $t('global.save') }}</span>
</b-button>
</div>
</template>
2020-08-15 00:02:34 +00:00
</b-modal>
2020-08-25 04:23:22 +00:00
</b-button>
2020-08-15 00:02:34 +00:00
</template>
<script>
2020-10-14 00:08:56 +00:00
import { mapState, mapGetters } from 'vuex';
2020-08-25 04:23:22 +00:00
import PlatformPicker from '@/components/Board/PlatformPicker';
2020-08-15 00:02:34 +00:00
export default {
components: {
2020-08-25 04:23:22 +00:00
PlatformPicker,
2020-08-15 00:02:34 +00:00
},
data() {
return {
saving: false,
2020-08-25 04:23:22 +00:00
description: null,
2020-12-18 04:44:07 +00:00
backgroundColor: null,
2020-08-25 04:23:22 +00:00
name: null,
platforms: null,
theme: null,
wallpaper: null,
2020-08-26 16:13:04 +00:00
wallpaperUrl: null,
2020-08-15 00:02:34 +00:00
};
},
computed: {
2020-08-26 00:06:49 +00:00
...mapState(['board', 'user', 'wallpapers']),
2020-10-14 00:08:56 +00:00
...mapGetters(['nightMode']),
2020-11-23 23:28:43 +00:00
noPlatformsSelected() {
return this.board.platforms.length === 0;
2020-11-23 23:38:04 +00:00
},
2020-08-15 00:02:34 +00:00
},
methods: {
hide() {
this.$bus.$off('WALLPAPER_UPLOADED', this.loadWallpapers);
},
2020-08-25 04:23:22 +00:00
async loadWallpapers() {
2020-08-26 00:06:49 +00:00
await this.$store.dispatch('LOAD_WALLPAPERS')
.catch(() => {
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('There was an error loading wallpapers', { variant: 'danger' });
2020-08-26 00:06:49 +00:00
});
2020-08-25 04:23:22 +00:00
},
removeWallpaper() {
this.wallpaper = null;
2020-10-14 23:20:25 +00:00
this.wallpaperUrl = null;
2020-08-15 00:02:34 +00:00
},
async setWallpaper(wallpaper) {
2020-08-26 16:13:04 +00:00
this.wallpaper = wallpaper;
this.wallpaperUrl = await this.$store.dispatch('LOAD_WALLPAPER', wallpaper);
this.$bus.$emit('RELOAD_WALLPAPER');
2020-08-25 04:23:22 +00:00
},
submit(e) {
e.preventDefault();
2020-08-26 00:06:49 +00:00
if (this.$refs.boardSettingsForm.checkValidity()) {
this.saveSettings();
2020-08-25 04:23:22 +00:00
}
},
async init() {
this.$bus.$on('WALLPAPER_UPLOADED', this.loadWallpapers);
2020-08-25 04:23:22 +00:00
const { board } = this;
this.description = board.description;
this.name = board.name;
this.platforms = board.platforms;
2020-12-18 04:44:07 +00:00
this.backgroundColor = board.backgroundColor || null;
2020-08-25 04:23:22 +00:00
this.theme = board.theme || 'default';
this.wallpaper = board.wallpaper;
2020-08-26 16:13:04 +00:00
if (this.wallpaper) {
this.wallpaperUrl = await this.$store.dispatch('LOAD_WALLPAPER', this.wallpaper);
}
2020-08-25 04:23:22 +00:00
},
confirmDelete() {
this.$bvModal.msgBoxConfirm('Are you sure you want to delete this board?', {
title: 'Delete board',
2020-08-15 00:02:34 +00:00
okVariant: 'danger',
2021-01-04 21:30:19 +00:00
headerBgVariant: this.nightMode ? 'dark' : null,
headerTextVariant: this.nightMode ? 'white' : null,
bodyBgVariant: this.nightMode ? 'dark' : null,
bodyTextVariant: this.nightMode ? 'white' : null,
footerBgVariant: this.nightMode ? 'dark' : null,
footerTextVariant: this.nightMode ? 'white' : null,
2020-08-25 04:23:22 +00:00
okTitle: 'Yes, delete board',
2020-08-15 00:02:34 +00:00
})
.then((value) => {
if (value) {
this.deleteBoard();
}
});
},
2020-08-25 04:23:22 +00:00
async deleteBoard() {
this.loading = true;
2020-08-15 00:02:34 +00:00
2020-08-25 04:23:22 +00:00
await this.$store.dispatch('DELETE_BOARD', this.board.id)
2020-08-15 00:02:34 +00:00
.catch(() => {
2020-08-25 04:23:22 +00:00
this.loading = false;
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('There was an error deleting board', { variant: 'error' });
2020-08-15 00:02:34 +00:00
});
2020-08-25 04:23:22 +00:00
this.loading = false;
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('Board removed');
2020-09-28 23:26:19 +00:00
this.$router.push({ name: 'dashboard' });
2020-08-15 00:02:34 +00:00
},
2020-08-25 04:23:22 +00:00
async saveSettings() {
this.saving = true;
const wallpaperChanged = this.board.wallpaper !== this.wallpaper;
const { board } = this;
const payload = {
...board,
description: this.description,
name: this.name,
platforms: this.platforms,
2020-12-18 04:44:07 +00:00
backgroundColor: this.backgroundColor,
2020-08-25 04:23:22 +00:00
theme: this.theme,
wallpaper: this.wallpaper,
};
this.$store.commit('SET_BOARD', payload);
if (board.name !== this.name) {
this.$store.commit('UPDATE_BOARD_NAME', payload);
}
2020-08-25 04:23:22 +00:00
await this.$store.dispatch('SAVE_BOARD')
.catch(() => {
this.saving = false;
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('There was an error renaming list', { variant: 'danger' });
2020-08-25 04:23:22 +00:00
});
this.saving = false;
2020-12-10 05:26:57 +00:00
this.$bvToast.toast('Board settings saved');
2020-08-25 04:23:22 +00:00
this.$bvModal.hide('board-settings');
if (wallpaperChanged) {
this.$bus.$emit('RELOAD_WALLPAPER');
}
},
2020-08-15 00:02:34 +00:00
},
};
</script>
2020-08-25 04:23:22 +00:00
<style lang="scss" rel="stylesheet/scss">
.dropdown-menu {
max-height: 400px;
max-width: 360px;
overflow: auto;
}
2020-12-18 04:44:07 +00:00
.color-picker {
width: 38px;
}
2020-08-15 00:02:34 +00:00
</style>