2018-02-23 19:46:09 +02:00
|
|
|
<template>
|
|
|
|
<div class="mkw-photo-stream" :class="$style.root" :data-melt="props.design == 2">
|
|
|
|
<mk-widget-container :show-header="props.design == 0" :naked="props.design == 2">
|
2018-11-08 20:44:35 +02:00
|
|
|
<template slot="header"><fa icon="camera"/>{{ $t('title') }}</template>
|
2018-02-23 19:46:09 +02:00
|
|
|
|
2018-11-13 15:45:28 +02:00
|
|
|
<p :class="$style.fetching" v-if="fetching"><fa icon="spinner" pulse fixed-width/>{{ $t('@.loading') }}<mk-ellipsis/></p>
|
2018-02-23 19:46:09 +02:00
|
|
|
<div :class="$style.stream" v-if="!fetching && images.length > 0">
|
2019-02-04 23:22:39 +02:00
|
|
|
<div v-for="(image, i) in images" :key="i"
|
2018-11-13 08:01:05 +02:00
|
|
|
:class="$style.img"
|
2019-02-04 23:22:39 +02:00
|
|
|
:style="`background-image: url(${thumbnail(image)})`"
|
2018-11-13 08:01:05 +02:00
|
|
|
draggable="true"
|
|
|
|
@dragstart="onDragstart(image, $event)"
|
|
|
|
></div>
|
2018-02-23 19:46:09 +02:00
|
|
|
</div>
|
2018-11-08 20:44:35 +02:00
|
|
|
<p :class="$style.empty" v-if="!fetching && images.length == 0">{{ $t('no-photos') }}</p>
|
2018-02-23 19:46:09 +02:00
|
|
|
</mk-widget-container>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2018-02-24 17:18:09 +02:00
|
|
|
import define from '../../../common/define-widget';
|
2018-11-08 20:44:35 +02:00
|
|
|
import i18n from '../../../i18n';
|
2019-02-04 23:22:39 +02:00
|
|
|
import { getStaticImageUrl } from '../../scripts/get-static-image-url';
|
2018-11-08 20:44:35 +02:00
|
|
|
|
2018-02-23 19:46:09 +02:00
|
|
|
export default define({
|
|
|
|
name: 'photo-stream',
|
|
|
|
props: () => ({
|
|
|
|
design: 0
|
|
|
|
})
|
|
|
|
}).extend({
|
2018-11-08 20:44:35 +02:00
|
|
|
i18n: i18n('common/views/widgets/photo-stream.vue'),
|
|
|
|
|
2018-02-23 19:46:09 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
images: [],
|
|
|
|
fetching: true,
|
2018-10-07 05:06:17 +03:00
|
|
|
connection: null
|
2018-02-23 19:46:09 +02:00
|
|
|
};
|
|
|
|
},
|
2018-11-13 08:01:05 +02:00
|
|
|
|
2018-02-23 19:46:09 +02:00
|
|
|
mounted() {
|
2018-11-09 01:13:34 +02:00
|
|
|
this.connection = this.$root.stream.useSharedConnection('main');
|
2018-02-23 19:46:09 +02:00
|
|
|
|
2018-10-07 05:06:17 +03:00
|
|
|
this.connection.on('driveFileCreated', this.onDriveFileCreated);
|
2018-02-23 19:46:09 +02:00
|
|
|
|
2018-11-09 01:13:34 +02:00
|
|
|
this.$root.api('drive/stream', {
|
2018-02-23 19:46:09 +02:00
|
|
|
type: 'image/*',
|
|
|
|
limit: 9
|
|
|
|
}).then(images => {
|
|
|
|
this.images = images;
|
|
|
|
this.fetching = false;
|
|
|
|
});
|
|
|
|
},
|
2018-11-13 08:01:05 +02:00
|
|
|
|
2018-02-23 19:46:09 +02:00
|
|
|
beforeDestroy() {
|
2018-10-07 05:06:17 +03:00
|
|
|
this.connection.dispose();
|
2018-02-23 19:46:09 +02:00
|
|
|
},
|
2018-11-13 08:01:05 +02:00
|
|
|
|
2018-02-23 19:46:09 +02:00
|
|
|
methods: {
|
|
|
|
onDriveFileCreated(file) {
|
|
|
|
if (/^image\/.+$/.test(file.type)) {
|
|
|
|
this.images.unshift(file);
|
|
|
|
if (this.images.length > 9) this.images.pop();
|
|
|
|
}
|
|
|
|
},
|
2018-11-13 08:01:05 +02:00
|
|
|
|
2018-02-23 19:46:09 +02:00
|
|
|
func() {
|
|
|
|
if (this.props.design == 2) {
|
|
|
|
this.props.design = 0;
|
|
|
|
} else {
|
|
|
|
this.props.design++;
|
|
|
|
}
|
2018-04-29 11:17:15 +03:00
|
|
|
|
|
|
|
this.save();
|
2018-11-13 08:01:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onDragstart(file, e) {
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
|
|
|
e.dataTransfer.setData('mk_drive_file', JSON.stringify(file));
|
|
|
|
},
|
2019-02-04 23:22:39 +02:00
|
|
|
|
|
|
|
thumbnail(image: any): string {
|
|
|
|
return this.$store.state.device.disableShowingAnimatedImages
|
|
|
|
? getStaticImageUrl(image.thumbnailUrl)
|
|
|
|
: image.thumbnailUrl;
|
|
|
|
},
|
2018-02-23 19:46:09 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" module>
|
|
|
|
.root[data-melt]
|
|
|
|
.stream
|
|
|
|
padding 0
|
|
|
|
|
|
|
|
.img
|
|
|
|
border solid 4px transparent
|
|
|
|
border-radius 8px
|
|
|
|
|
|
|
|
.stream
|
|
|
|
display flex
|
|
|
|
justify-content center
|
|
|
|
flex-wrap wrap
|
|
|
|
padding 8px
|
|
|
|
|
|
|
|
.img
|
|
|
|
flex 1 1 33%
|
|
|
|
width 33%
|
|
|
|
height 80px
|
|
|
|
background-position center center
|
|
|
|
background-size cover
|
|
|
|
border solid 2px transparent
|
|
|
|
border-radius 4px
|
|
|
|
|
|
|
|
.fetching
|
|
|
|
.empty
|
|
|
|
margin 0
|
|
|
|
padding 16px
|
|
|
|
text-align center
|
|
|
|
color #aaa
|
|
|
|
|
2018-11-05 18:40:11 +02:00
|
|
|
> [data-icon]
|
2018-02-23 19:46:09 +02:00
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
</style>
|