2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-show="files.length != 0" class="skeikyzd">
|
|
|
|
<XDraggable v-model="_files" class="files" item-key="id" animation="150" delay="100" delay-on-touch-only="true">
|
2020-12-05 05:50:09 +02:00
|
|
|
<template #item="{element}">
|
|
|
|
<div @click="showFileMenu(element, $event)" @contextmenu.prevent="showFileMenu(element, $event)">
|
|
|
|
<MkDriveFileThumbnail :data-id="element.id" class="thumbnail" :file="element" fit="cover"/>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-if="element.isSensitive" class="sensitive">
|
2021-04-20 17:22:59 +03:00
|
|
|
<i class="fas fa-exclamation-triangle icon"></i>
|
2020-12-05 05:50:09 +02:00
|
|
|
</div>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
2020-12-05 05:50:09 +02:00
|
|
|
</template>
|
2020-10-17 14:12:00 +03:00
|
|
|
</XDraggable>
|
2022-01-21 11:27:33 +02:00
|
|
|
<p class="remain">{{ 16 - files.length }}/16</p>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 14:12:00 +03:00
|
|
|
import { defineComponent, defineAsyncComponent } from 'vue';
|
|
|
|
import MkDriveFileThumbnail from './drive-file-thumbnail.vue'
|
2021-11-11 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
export default defineComponent({
|
2020-01-29 21:37:25 +02:00
|
|
|
components: {
|
2020-12-05 05:50:09 +02:00
|
|
|
XDraggable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2020-10-17 14:12:00 +03:00
|
|
|
MkDriveFileThumbnail
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
files: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
detachMediaFn: {
|
|
|
|
type: Function,
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-12-05 05:50:09 +02:00
|
|
|
emits: ['updated', 'detach', 'changeSensitive', 'changeName'],
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2020-02-04 02:20:10 +02:00
|
|
|
menu: null as Promise<null> | null,
|
2020-01-29 21:37:25 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-12-05 05:50:09 +02:00
|
|
|
computed: {
|
|
|
|
_files: {
|
|
|
|
get() {
|
|
|
|
return this.files;
|
|
|
|
},
|
|
|
|
set(value) {
|
|
|
|
this.$emit('updated', value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
methods: {
|
|
|
|
detachMedia(id) {
|
|
|
|
if (this.detachMediaFn) {
|
|
|
|
this.detachMediaFn(id);
|
2020-10-17 14:12:00 +03:00
|
|
|
} else {
|
|
|
|
this.$emit('detach', id);
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleSensitive(file) {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.api('drive/files/update', {
|
2020-01-29 21:37:25 +02:00
|
|
|
fileId: file.id,
|
|
|
|
isSensitive: !file.isSensitive
|
|
|
|
}).then(() => {
|
2020-12-05 05:50:09 +02:00
|
|
|
this.$emit('changeSensitive', file, !file.isSensitive);
|
2020-01-29 21:37:25 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
async rename(file) {
|
2021-11-18 11:45:58 +02:00
|
|
|
const { canceled, result } = await os.inputText({
|
2020-12-26 03:47:36 +02:00
|
|
|
title: this.$ts.enterFileName,
|
2021-11-18 11:45:58 +02:00
|
|
|
default: file.name,
|
2020-01-29 21:37:25 +02:00
|
|
|
allowEmpty: false
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-10-17 14:12:00 +03:00
|
|
|
os.api('drive/files/update', {
|
2020-01-29 21:37:25 +02:00
|
|
|
fileId: file.id,
|
|
|
|
name: result
|
|
|
|
}).then(() => {
|
2020-12-05 05:50:09 +02:00
|
|
|
this.$emit('changeName', file, result);
|
2020-01-29 21:37:25 +02:00
|
|
|
file.name = result;
|
|
|
|
});
|
|
|
|
},
|
2021-05-28 03:38:09 +03:00
|
|
|
|
|
|
|
async describe(file) {
|
2021-11-11 19:02:25 +02:00
|
|
|
os.popup(import("@/components/media-caption.vue"), {
|
2021-05-28 03:38:09 +03:00
|
|
|
title: this.$ts.describeFile,
|
|
|
|
input: {
|
|
|
|
placeholder: this.$ts.inputNewDescription,
|
|
|
|
default: file.comment !== null ? file.comment : "",
|
|
|
|
},
|
|
|
|
image: file
|
|
|
|
}, {
|
|
|
|
done: result => {
|
|
|
|
if (!result || result.canceled) return;
|
2022-01-21 10:43:51 +02:00
|
|
|
let comment = result.result.length == 0 ? null : result.result;
|
2021-05-28 03:38:09 +03:00
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: file.id,
|
2022-01-21 10:43:51 +02:00
|
|
|
comment: comment,
|
|
|
|
}).then(() => {
|
|
|
|
file.comment = comment;
|
2021-05-28 03:38:09 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 'closed');
|
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
showFileMenu(file, ev: MouseEvent) {
|
2020-02-04 02:20:10 +02:00
|
|
|
if (this.menu) return;
|
2021-08-08 06:19:10 +03:00
|
|
|
this.menu = os.popupMenu([{
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.renameFile,
|
2021-04-25 16:32:46 +03:00
|
|
|
icon: 'fas fa-i-cursor',
|
2020-10-17 14:12:00 +03:00
|
|
|
action: () => { this.rename(file) }
|
|
|
|
}, {
|
2020-12-26 03:47:36 +02:00
|
|
|
text: file.isSensitive ? this.$ts.unmarkAsSensitive : this.$ts.markAsSensitive,
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: file.isSensitive ? 'fas fa-eye-slash' : 'fas fa-eye',
|
2020-10-17 14:12:00 +03:00
|
|
|
action: () => { this.toggleSensitive(file) }
|
2021-05-28 03:38:09 +03:00
|
|
|
}, {
|
|
|
|
text: this.$ts.describeFile,
|
|
|
|
icon: 'fas fa-i-cursor',
|
|
|
|
action: () => { this.describe(file) }
|
2020-10-17 14:12:00 +03:00
|
|
|
}, {
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.attachCancel,
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-times-circle',
|
2020-10-17 14:12:00 +03:00
|
|
|
action: () => { this.detachMedia(file.id) }
|
2022-01-28 04:53:12 +02:00
|
|
|
}], ev.currentTarget ?? ev.target).then(() => this.menu = null);
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.skeikyzd {
|
2020-10-17 14:12:00 +03:00
|
|
|
padding: 8px 16px;
|
2020-01-29 21:37:25 +02:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .files {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
|
|
> div {
|
|
|
|
position: relative;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
2020-10-17 14:12:00 +03:00
|
|
|
margin-right: 4px;
|
|
|
|
border-radius: 4px;
|
2021-03-02 15:57:16 +02:00
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
cursor: move;
|
|
|
|
|
|
|
|
&:hover > .remove {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
z-index: 1;
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .sensitive {
|
|
|
|
display: flex;
|
|
|
|
position: absolute;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: 2;
|
|
|
|
background: rgba(17, 17, 17, .7);
|
|
|
|
color: #fff;
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remain {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 8px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|