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