2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
|
|
|
<div class="ncvczrfv"
|
2020-10-17 13:12:00 +02:00
|
|
|
:class="{ isSelected }"
|
2020-01-29 20:37:25 +01:00
|
|
|
@click="onClick"
|
2020-10-17 13:12:00 +02:00
|
|
|
@contextmenu.stop="onContextmenu"
|
2020-01-29 20:37:25 +01:00
|
|
|
draggable="true"
|
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
:title="title"
|
|
|
|
>
|
2020-12-19 02:55:52 +01:00
|
|
|
<div class="label" v-if="$i.avatarId == file.id">
|
2021-11-11 18:02:25 +01:00
|
|
|
<img src="/client-assets/label.svg"/>
|
2020-12-26 02:47:36 +01:00
|
|
|
<p>{{ $ts.avatar }}</p>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2020-12-19 02:55:52 +01:00
|
|
|
<div class="label" v-if="$i.bannerId == file.id">
|
2021-11-11 18:02:25 +01:00
|
|
|
<img src="/client-assets/label.svg"/>
|
2020-12-26 02:47:36 +01:00
|
|
|
<p>{{ $ts.banner }}</p>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
<div class="label red" v-if="file.isSensitive">
|
2021-11-11 18:02:25 +01:00
|
|
|
<img src="/client-assets/label-red.svg"/>
|
2020-12-26 02:47:36 +01:00
|
|
|
<p>{{ $ts.nsfw }}</p>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/>
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
<p class="name">
|
|
|
|
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }}</span>
|
|
|
|
<span class="ext" v-if="file.name.lastIndexOf('.') != -1">{{ file.name.substr(file.name.lastIndexOf('.')) }}</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { defineComponent } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
2020-10-17 13:12:00 +02:00
|
|
|
import MkDriveFileThumbnail from './drive-file-thumbnail.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import bytes from '@/filters/bytes';
|
|
|
|
import * as os from '@/os';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-04-21 17:34:56 +02:00
|
|
|
components: {
|
2020-10-17 13:12:00 +02:00
|
|
|
MkDriveFileThumbnail
|
2020-04-21 17:34:56 +02:00
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-21 17:34:56 +02:00
|
|
|
isSelected: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
selectMode: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
emits: ['chosen'],
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isDragging: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-04-21 17:34:56 +02:00
|
|
|
// TODO: parentへの参照を無くす
|
2020-01-29 20:37:25 +01:00
|
|
|
browser(): any {
|
|
|
|
return this.$parent;
|
|
|
|
},
|
|
|
|
title(): string {
|
2020-10-17 13:12:00 +02:00
|
|
|
return `${this.file.name}\n${this.file.type} ${bytes(this.file.size)}`;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-10-17 13:12:00 +02:00
|
|
|
getMenu() {
|
|
|
|
return [{
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.rename,
|
2021-04-25 15:32:46 +02:00
|
|
|
icon: 'fas fa-i-cursor',
|
2020-10-17 13:12:00 +02:00
|
|
|
action: this.rename
|
|
|
|
}, {
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.file.isSensitive ? this.$ts.unmarkAsSensitive : this.$ts.markAsSensitive,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: this.file.isSensitive ? 'fas fa-eye' : 'fas fa-eye-slash',
|
2020-10-17 13:12:00 +02:00
|
|
|
action: this.toggleSensitive
|
2021-05-28 02:38:09 +02:00
|
|
|
}, {
|
|
|
|
text: this.$ts.describeFile,
|
|
|
|
icon: 'fas fa-i-cursor',
|
|
|
|
action: this.describe
|
2020-10-17 13:12:00 +02:00
|
|
|
}, null, {
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.copyUrl,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-link',
|
2020-10-17 13:12:00 +02:00
|
|
|
action: this.copyUrl
|
|
|
|
}, {
|
|
|
|
type: 'a',
|
|
|
|
href: this.file.url,
|
|
|
|
target: '_blank',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.download,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-download',
|
2020-10-17 13:12:00 +02:00
|
|
|
download: this.file.name
|
|
|
|
}, null, {
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.delete,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-trash-alt',
|
2020-10-17 13:12:00 +02:00
|
|
|
danger: true,
|
|
|
|
action: this.deleteFile
|
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
onClick(ev) {
|
|
|
|
if (this.selectMode) {
|
2020-04-21 17:34:56 +02:00
|
|
|
this.$emit('chosen', this.file);
|
2020-01-29 20:37:25 +01:00
|
|
|
} else {
|
2021-08-08 05:19:10 +02:00
|
|
|
os.popupMenu(this.getMenu(), ev.currentTarget || ev.target);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
onContextmenu(e) {
|
|
|
|
os.contextMenu(this.getMenu(), e);
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
onDragstart(e) {
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
2020-10-17 13:12:00 +02:00
|
|
|
e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(this.file));
|
2020-01-29 20:37:25 +01:00
|
|
|
this.isDragging = true;
|
|
|
|
|
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
|
|
|
this.browser.isDragSource = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragend(e) {
|
|
|
|
this.isDragging = false;
|
|
|
|
this.browser.isDragSource = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
rename() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.dialog({
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.renameFile,
|
2020-01-29 20:37:25 +01:00
|
|
|
input: {
|
2020-12-26 02:47:36 +01:00
|
|
|
placeholder: this.$ts.inputNewFileName,
|
2020-01-29 20:37:25 +01:00
|
|
|
default: this.file.name,
|
|
|
|
allowEmpty: false
|
|
|
|
}
|
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('drive/files/update', {
|
2020-01-29 20:37:25 +01:00
|
|
|
fileId: this.file.id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-05-28 02:38:09 +02:00
|
|
|
describe() {
|
2021-11-11 18:02:25 +01:00
|
|
|
os.popup(import('@/components/media-caption.vue'), {
|
2021-05-28 02:38:09 +02:00
|
|
|
title: this.$ts.describeFile,
|
|
|
|
input: {
|
|
|
|
placeholder: this.$ts.inputNewDescription,
|
|
|
|
default: this.file.comment !== null ? this.file.comment : '',
|
|
|
|
},
|
|
|
|
image: this.file
|
|
|
|
}, {
|
|
|
|
done: result => {
|
|
|
|
if (!result || result.canceled) return;
|
|
|
|
let comment = result.result;
|
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: this.file.id,
|
|
|
|
comment: comment.length == 0 ? null : comment
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 'closed');
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
toggleSensitive() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('drive/files/update', {
|
2020-01-29 20:37:25 +01:00
|
|
|
fileId: this.file.id,
|
|
|
|
isSensitive: !this.file.isSensitive
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
copyUrl() {
|
|
|
|
copyToClipboard(this.file.url);
|
2020-10-17 13:12:00 +02:00
|
|
|
os.success();
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
setAsAvatar() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.updateAvatar(this.file);
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
setAsBanner() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.updateBanner(this.file);
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
addApp() {
|
|
|
|
alert('not implemented yet');
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteFile() {
|
2020-10-17 13:12:00 +02:00
|
|
|
const { canceled } = await os.dialog({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('driveFileDeleteConfirm', { name: this.file.name }),
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('drive/files/delete', {
|
2020-01-29 20:37:25 +01:00
|
|
|
fileId: this.file.id
|
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
bytes
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ncvczrfv {
|
|
|
|
position: relative;
|
|
|
|
padding: 8px 0 0 0;
|
|
|
|
min-height: 180px;
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
&, * {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
&:hover {
|
|
|
|
background: rgba(#000, 0.05);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b65a5;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #c12113;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: rgba(#000, 0.1);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b588c;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #ce2212;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
&.isSelected {
|
2020-01-29 20:37:25 +01:00
|
|
|
background: var(--accent);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--accentLighten);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: var(--accentDarken);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
pointer-events: none;
|
|
|
|
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
background: #0c7ac9;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
top: 0;
|
|
|
|
left: 57px;
|
|
|
|
width: 28px;
|
|
|
|
height: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
top: 57px;
|
|
|
|
left: 0;
|
|
|
|
width: 8px;
|
|
|
|
height: 28px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #c12113;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> img {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> p {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 3;
|
|
|
|
top: 19px;
|
|
|
|
left: -28px;
|
|
|
|
width: 120px;
|
|
|
|
margin: 0;
|
|
|
|
text-align: center;
|
|
|
|
line-height: 28px;
|
|
|
|
color: #fff;
|
|
|
|
transform: rotate(-45deg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
2021-04-10 05:40:50 +02:00
|
|
|
width: 110px;
|
|
|
|
height: 110px;
|
2020-01-29 20:37:25 +01:00
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
margin: 4px 0 0 0;
|
|
|
|
font-size: 0.8em;
|
|
|
|
text-align: center;
|
|
|
|
word-break: break-all;
|
|
|
|
color: var(--fg);
|
2021-03-02 14:57:16 +01:00
|
|
|
overflow: hidden;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
> .ext {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|