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