2020-08-25 23:37:33 +00:00
|
|
|
<template lang="html">
|
2020-09-28 23:25:36 +00:00
|
|
|
<div>
|
2020-09-26 00:09:20 +00:00
|
|
|
<b-jumbotron
|
2020-10-05 18:42:04 +00:00
|
|
|
:header="$t('wallpapers.title')"
|
|
|
|
:lead="$t('wallpapers.subtitle')"
|
2020-09-26 00:09:20 +00:00
|
|
|
header-level="5"
|
|
|
|
fluid
|
|
|
|
/>
|
|
|
|
<!-- TODO: show space used -->
|
|
|
|
<!-- TODO: allow to apply wallpaper to board from here -->
|
|
|
|
<b-container>
|
2020-10-05 18:42:04 +00:00
|
|
|
<!-- TODO: convert to form -->
|
|
|
|
<!-- TODO: translate "browse" -->
|
|
|
|
<!-- TODO: display file names -->
|
|
|
|
<b-row class="mb-3">
|
2020-08-25 23:37:33 +00:00
|
|
|
<b-col cols="12" lg="6">
|
|
|
|
<b-form-group
|
2020-10-05 18:42:04 +00:00
|
|
|
:label="$t('wallpapers.form.label')"
|
|
|
|
:description="$t('wallpapers.form.helperText')"
|
2020-08-25 23:37:33 +00:00
|
|
|
>
|
|
|
|
<b-form-file
|
|
|
|
v-model="file"
|
|
|
|
accept="image/*"
|
2020-10-05 18:42:04 +00:00
|
|
|
:placeholder="$t('wallpapers.form.placeholder')"
|
2020-08-25 23:37:33 +00:00
|
|
|
/>
|
|
|
|
</b-form-group>
|
|
|
|
|
|
|
|
<b-alert v-if="isDuplicate && !saving" show variant="warning">
|
2020-10-05 18:42:04 +00:00
|
|
|
{{ $t('wallpapers.form.duplicateMessage', { fileName: file.name }) }}
|
2020-08-25 23:37:33 +00:00
|
|
|
</b-alert>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
@click="uploadWallpaper"
|
|
|
|
variant="primary"
|
|
|
|
:disabled="!Boolean(file) || saving || isDuplicate"
|
|
|
|
>
|
|
|
|
<b-spinner small v-if="saving" />
|
2020-10-05 18:42:04 +00:00
|
|
|
<span v-else>{{ $t('wallpapers.form.upload') }}</span>
|
2020-08-25 23:37:33 +00:00
|
|
|
</b-button>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
|
|
|
|
<b-form-row v-if="wallpapers.length">
|
|
|
|
<b-col cols="12">
|
2020-10-05 18:42:04 +00:00
|
|
|
<h5>{{ $t('wallpapers.list.title') }}</h5>
|
2020-08-25 23:37:33 +00:00
|
|
|
</b-col>
|
|
|
|
|
|
|
|
<b-col
|
|
|
|
v-for="wallpaper in wallpapers"
|
|
|
|
:key="wallpaper.name"
|
|
|
|
cols="6"
|
|
|
|
sm="4"
|
|
|
|
lg="3"
|
|
|
|
>
|
|
|
|
<b-card
|
|
|
|
class="mb-2"
|
|
|
|
header-class="py-0 px-2"
|
|
|
|
body-class="d-flex p-0 text-center justify-content-center align-items-center"
|
|
|
|
header-tag="small"
|
|
|
|
>
|
|
|
|
<b-img
|
|
|
|
:src="wallpaper.url"
|
|
|
|
:alt="wallpaper.name"
|
|
|
|
fluid
|
|
|
|
/>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
class="position-absolute delete-file"
|
|
|
|
variant="danger"
|
|
|
|
size="sm"
|
|
|
|
@click="confirmDeleteWallpaper(wallpaper)"
|
|
|
|
>
|
2020-10-08 17:55:26 +00:00
|
|
|
<icon name="trash" white />
|
2020-08-25 23:37:33 +00:00
|
|
|
</b-button>
|
|
|
|
</b-card>
|
|
|
|
</b-col>
|
|
|
|
</b-form-row>
|
|
|
|
|
|
|
|
<b-alert show v-else>You don't have any wallpapers.</b-alert>
|
2020-09-26 00:09:20 +00:00
|
|
|
</b-container>
|
2020-09-28 23:25:36 +00:00
|
|
|
</div>
|
2020-08-25 23:37:33 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapState } from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
file: null,
|
|
|
|
saving: false,
|
|
|
|
loading: false,
|
|
|
|
wallpaperUrls: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
...mapState(['user', 'board', 'wallpapers']),
|
|
|
|
|
|
|
|
existingFiles() {
|
|
|
|
return this.wallpapers.map(({ name }) => name);
|
|
|
|
},
|
|
|
|
|
|
|
|
isDuplicate() {
|
|
|
|
const { file, existingFiles } = this;
|
|
|
|
|
|
|
|
return file && file.name && existingFiles.includes(file.name);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
async uploadWallpaper() {
|
|
|
|
const { file } = this;
|
|
|
|
this.saving = true;
|
|
|
|
|
|
|
|
await this.$store.dispatch('UPLOAD_WALLPAPER', file)
|
|
|
|
.catch(() => {
|
|
|
|
this.saving = false;
|
|
|
|
this.$bvToast.toast('There was an error uploading wallpaper', { title: 'Error', variant: 'danger' });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.file = null;
|
|
|
|
this.saving = false;
|
|
|
|
this.$bvToast.toast(file.name, { title: 'File uploaded', variant: 'success' });
|
|
|
|
this.$bus.$emit('WALLPAPER_UPLOADED');
|
|
|
|
},
|
|
|
|
|
|
|
|
confirmDeleteWallpaper(file) {
|
|
|
|
this.$bvModal.msgBoxConfirm('Wallpaper will be permanently removed', {
|
|
|
|
title: 'Are you sure you want to delete this file?',
|
|
|
|
okVariant: 'danger',
|
|
|
|
okTitle: 'Yes',
|
|
|
|
})
|
|
|
|
.then((value) => {
|
|
|
|
if (value) {
|
|
|
|
this.deleteFile(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteFile(file) {
|
|
|
|
await this.$store.dispatch('DELETE_WALLPAPER', file)
|
|
|
|
.catch(() => {
|
|
|
|
this.$bvToast.toast('There was an error deleting wallpaper', { title: 'Error', variant: 'danger' });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$bvToast.toast(file.name, { title: 'File deleted', variant: 'success' });
|
|
|
|
|
|
|
|
// const { board } = this;
|
|
|
|
// TODO: handle wallpapers in use
|
|
|
|
// if (board.wallpaper && this.board.wallpaper === file.path) {
|
|
|
|
// this.$bus.$emit('RELOAD_WALLPAPER');
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" rel="stylesheet/scss" scoped>
|
|
|
|
.delete-file {
|
|
|
|
bottom: .5rem;
|
|
|
|
right: .5rem;
|
|
|
|
}
|
|
|
|
</style>
|