2021-02-18 00:50:37 +00:00
|
|
|
<template lang="html">
|
2021-02-20 16:53:38 +00:00
|
|
|
<div class="wallpapers">
|
2021-02-21 18:17:58 +00:00
|
|
|
<preview-wallpaper-modal
|
|
|
|
:wallpaper="activeWallpaper"
|
2021-02-21 19:10:24 +00:00
|
|
|
:selectable="selectable"
|
|
|
|
@selected="selected"
|
2021-02-21 18:17:58 +00:00
|
|
|
/>
|
2021-02-21 18:13:06 +00:00
|
|
|
|
2021-02-18 00:50:37 +00:00
|
|
|
<b-card
|
|
|
|
v-for="wallpaper in wallpapers"
|
|
|
|
:key="wallpaper.name"
|
|
|
|
:img-src="wallpaper.url"
|
|
|
|
:img-alt="wallpaper.name"
|
|
|
|
img-top
|
|
|
|
img-width="180"
|
2021-03-11 00:06:47 +00:00
|
|
|
class="mb-3 mx-0 p-0 overflow-hidden word-wrap clickable"
|
2021-02-21 19:10:24 +00:00
|
|
|
@click="openModal(wallpaper)"
|
2021-02-18 00:50:37 +00:00
|
|
|
>
|
|
|
|
<h6>
|
|
|
|
{{ wallpaper.name }}
|
|
|
|
|
|
|
|
<b-badge v-if="wallpaper.metadata && wallpaper.metadata.size">
|
2021-02-22 17:33:22 +00:00
|
|
|
{{ formatSize(wallpaper) }}
|
2021-02-18 00:50:37 +00:00
|
|
|
</b-badge>
|
|
|
|
</h6>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
variant="danger"
|
2021-02-21 19:10:24 +00:00
|
|
|
@click.stop="confirmDeleteWallpaper(wallpaper)"
|
2021-02-18 00:50:37 +00:00
|
|
|
>
|
|
|
|
<i class="fas fa-trash-alt fa-fw" aria-hidden />
|
|
|
|
</b-button>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
v-if="selectable"
|
|
|
|
variant="primary"
|
2021-02-21 19:10:24 +00:00
|
|
|
@click.stop="selected(wallpaper)"
|
2021-02-18 00:50:37 +00:00
|
|
|
>
|
|
|
|
<i
|
|
|
|
v-if="saving"
|
|
|
|
class="fas fa-sync fa-spin fa-fw"
|
|
|
|
aria-hidden
|
|
|
|
/>
|
|
|
|
|
|
|
|
<span v-else>Select</span>
|
|
|
|
</b-button>
|
|
|
|
</b-card>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-02-21 18:13:06 +00:00
|
|
|
import PreviewWallpaperModal from '@/components/Wallpapers/PreviewWallpaperModal';
|
2021-02-22 17:33:22 +00:00
|
|
|
import { bytesToSize } from '@/utils';
|
2021-02-18 00:50:37 +00:00
|
|
|
import { mapState } from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
2021-02-21 18:13:06 +00:00
|
|
|
components: {
|
|
|
|
PreviewWallpaperModal,
|
|
|
|
},
|
|
|
|
|
2021-02-18 00:50:37 +00:00
|
|
|
props: {
|
|
|
|
selectable: Boolean,
|
|
|
|
saving: Boolean,
|
|
|
|
},
|
|
|
|
|
2021-02-21 18:13:06 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
activeWallpaper: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2021-02-18 00:50:37 +00:00
|
|
|
computed: {
|
|
|
|
...mapState(['wallpapers']),
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2021-02-21 18:13:06 +00:00
|
|
|
openModal(wallpaper) {
|
|
|
|
this.activeWallpaper = wallpaper;
|
|
|
|
this.$bvModal.show('previewWallpaper');
|
|
|
|
},
|
|
|
|
|
2021-02-21 19:10:24 +00:00
|
|
|
selected(wallpaper) {
|
2021-02-18 00:50:37 +00:00
|
|
|
if (this.selectable) {
|
|
|
|
this.$emit('selected', wallpaper);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-02-22 17:33:22 +00:00
|
|
|
formatSize(wallpaper) {
|
|
|
|
const size = wallpaper && wallpaper.metadata && wallpaper.metadata.size
|
|
|
|
? wallpaper.metadata.size
|
|
|
|
: 0;
|
2021-02-18 00:50:37 +00:00
|
|
|
|
2021-02-22 17:33:22 +00:00
|
|
|
return bytesToSize(size);
|
2021-02-18 00:50:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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', { variant: 'danger' });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$bvToast.toast('File deleted');
|
|
|
|
|
|
|
|
// const { board } = this;
|
|
|
|
// TODO: handle wallpapers in use
|
|
|
|
// if (board.wallpaper && this.board.wallpaper === file.path) {
|
2021-02-27 03:01:11 +00:00
|
|
|
// this.$bus.$emit('LOAD_BOARD_BACKGROUND');
|
2021-02-18 00:50:37 +00:00
|
|
|
// }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" rel="stylesheet/scss" scoped>
|
|
|
|
.wallpapers {
|
|
|
|
display: grid;
|
|
|
|
grid-column-gap: 1rem;
|
|
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
|
|
|
|
|
|
@media(max-width: 720px) {
|
2021-03-11 00:06:47 +00:00
|
|
|
grid-template-columns: 1fr;
|
2021-02-18 00:50:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|