2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
|
|
|
<div class="ncvczrfv"
|
2020-10-17 14:12:00 +03:00
|
|
|
:class="{ isSelected }"
|
2021-11-19 12:36:12 +02:00
|
|
|
draggable="true"
|
|
|
|
:title="title"
|
2020-01-29 21:37:25 +02:00
|
|
|
@click="onClick"
|
2020-10-17 14:12:00 +03:00
|
|
|
@contextmenu.stop="onContextmenu"
|
2020-01-29 21:37:25 +02:00
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-if="$i.avatarId == file.id" class="label">
|
2021-11-11 19:02:25 +02:00
|
|
|
<img src="/client-assets/label.svg"/>
|
2020-12-26 03:47:36 +02:00
|
|
|
<p>{{ $ts.avatar }}</p>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-if="$i.bannerId == file.id" class="label">
|
2021-11-11 19:02:25 +02:00
|
|
|
<img src="/client-assets/label.svg"/>
|
2020-12-26 03:47:36 +02:00
|
|
|
<p>{{ $ts.banner }}</p>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
2021-11-19 12:36:12 +02:00
|
|
|
<div v-if="file.isSensitive" class="label red">
|
2021-11-11 19:02:25 +02:00
|
|
|
<img src="/client-assets/label-red.svg"/>
|
2020-12-26 03:47:36 +02:00
|
|
|
<p>{{ $ts.nsfw }}</p>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
<MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/>
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
<p class="name">
|
|
|
|
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }}</span>
|
2021-11-19 12:36:12 +02:00
|
|
|
<span v-if="file.name.lastIndexOf('.') != -1" class="ext">{{ file.name.substr(file.name.lastIndexOf('.')) }}</span>
|
2020-01-29 21:37:25 +02:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 14:12:00 +03:00
|
|
|
import { defineComponent } from 'vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
2020-10-17 14:12:00 +03:00
|
|
|
import MkDriveFileThumbnail from './drive-file-thumbnail.vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import bytes from '@/filters/bytes';
|
|
|
|
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-04-21 18:34:56 +03:00
|
|
|
components: {
|
2020-10-17 14:12:00 +03:00
|
|
|
MkDriveFileThumbnail
|
2020-04-21 18:34:56 +03:00
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-21 18:34:56 +03:00
|
|
|
isSelected: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-01-29 21:37:25 +02:00
|
|
|
selectMode: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
emits: ['chosen'],
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isDragging: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-04-21 18:34:56 +03:00
|
|
|
// TODO: parentへの参照を無くす
|
2020-01-29 21:37:25 +02:00
|
|
|
browser(): any {
|
|
|
|
return this.$parent;
|
|
|
|
},
|
|
|
|
title(): string {
|
2020-10-17 14:12:00 +03:00
|
|
|
return `${this.file.name}\n${this.file.type} ${bytes(this.file.size)}`;
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-10-17 14:12:00 +03:00
|
|
|
getMenu() {
|
|
|
|
return [{
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.rename,
|
2021-04-25 16:32:46 +03:00
|
|
|
icon: 'fas fa-i-cursor',
|
2020-10-17 14:12:00 +03:00
|
|
|
action: this.rename
|
|
|
|
}, {
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.file.isSensitive ? this.$ts.unmarkAsSensitive : this.$ts.markAsSensitive,
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: this.file.isSensitive ? 'fas fa-eye' : 'fas fa-eye-slash',
|
2020-10-17 14:12:00 +03:00
|
|
|
action: this.toggleSensitive
|
2021-05-28 03:38:09 +03:00
|
|
|
}, {
|
|
|
|
text: this.$ts.describeFile,
|
|
|
|
icon: 'fas fa-i-cursor',
|
|
|
|
action: this.describe
|
2020-10-17 14:12:00 +03:00
|
|
|
}, null, {
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.copyUrl,
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-link',
|
2020-10-17 14:12:00 +03:00
|
|
|
action: this.copyUrl
|
|
|
|
}, {
|
|
|
|
type: 'a',
|
|
|
|
href: this.file.url,
|
|
|
|
target: '_blank',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.download,
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-download',
|
2020-10-17 14:12:00 +03:00
|
|
|
download: this.file.name
|
|
|
|
}, null, {
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.delete,
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-trash-alt',
|
2020-10-17 14:12:00 +03:00
|
|
|
danger: true,
|
|
|
|
action: this.deleteFile
|
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
onClick(ev) {
|
|
|
|
if (this.selectMode) {
|
2020-04-21 18:34:56 +03:00
|
|
|
this.$emit('chosen', this.file);
|
2020-01-29 21:37:25 +02:00
|
|
|
} else {
|
2021-08-08 06:19:10 +03:00
|
|
|
os.popupMenu(this.getMenu(), ev.currentTarget || ev.target);
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
onContextmenu(e) {
|
|
|
|
os.contextMenu(this.getMenu(), e);
|
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
onDragstart(e) {
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
2020-10-17 14:12:00 +03:00
|
|
|
e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(this.file));
|
2020-01-29 21:37:25 +02:00
|
|
|
this.isDragging = true;
|
|
|
|
|
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
|
|
|
this.browser.isDragSource = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragend(e) {
|
|
|
|
this.isDragging = false;
|
|
|
|
this.browser.isDragSource = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
rename() {
|
2021-11-18 11:45:58 +02:00
|
|
|
os.inputText({
|
2020-12-26 03:47:36 +02:00
|
|
|
title: this.$ts.renameFile,
|
2021-11-18 11:45:58 +02:00
|
|
|
placeholder: this.$ts.inputNewFileName,
|
|
|
|
default: this.file.name,
|
|
|
|
allowEmpty: false
|
2020-01-29 21:37:25 +02:00
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
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: this.file.id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-05-28 03:38:09 +03:00
|
|
|
describe() {
|
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: 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 21:37:25 +02:00
|
|
|
toggleSensitive() {
|
2020-10-17 14:12:00 +03:00
|
|
|
os.api('drive/files/update', {
|
2020-01-29 21:37:25 +02:00
|
|
|
fileId: this.file.id,
|
|
|
|
isSensitive: !this.file.isSensitive
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
copyUrl() {
|
|
|
|
copyToClipboard(this.file.url);
|
2020-10-17 14:12:00 +03:00
|
|
|
os.success();
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
addApp() {
|
|
|
|
alert('not implemented yet');
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteFile() {
|
2021-11-18 11:45:58 +02:00
|
|
|
const { canceled } = await os.confirm({
|
2020-01-29 21:37:25 +02:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('driveFileDeleteConfirm', { name: this.file.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
os.api('drive/files/delete', {
|
2020-01-29 21:37:25 +02:00
|
|
|
fileId: this.file.id
|
|
|
|
});
|
2020-10-17 14:12:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
bytes
|
2020-01-29 21:37:25 +02: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 14:12:00 +03:00
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2020-01-29 21:37:25 +02: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 14:12:00 +03:00
|
|
|
&.isSelected {
|
2020-01-29 21:37:25 +02: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 06:40:50 +03:00
|
|
|
width: 110px;
|
|
|
|
height: 110px;
|
2020-01-29 21:37:25 +02: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 15:57:16 +02:00
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
> .ext {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|