2018-02-14 10:03:48 +00:00
|
|
|
<template>
|
2020-01-29 19:37:25 +00:00
|
|
|
<div class="rghtznwe"
|
2018-02-14 10:03:48 +00:00
|
|
|
:data-draghover="draghover"
|
|
|
|
@click="onClick"
|
|
|
|
@mouseover="onMouseover"
|
|
|
|
@mouseout="onMouseout"
|
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@dragenter.prevent="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.prevent.stop="onDrop"
|
|
|
|
draggable="true"
|
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
:title="title"
|
|
|
|
>
|
|
|
|
<p class="name">
|
2020-01-29 19:37:25 +00:00
|
|
|
<template v-if="hover"><fa :icon="faFolderOpen" fixed-width/></template>
|
|
|
|
<template v-if="!hover"><fa :icon="faFolder" fixed-width/></template>
|
2018-02-14 10:03:48 +00:00
|
|
|
{{ folder.name }}
|
|
|
|
</p>
|
2019-07-07 19:17:53 +00:00
|
|
|
<p class="upload" v-if="$store.state.settings.uploadFolder == folder.id">
|
2020-02-08 04:06:09 +00:00
|
|
|
{{ $t('uploadFolder') }}
|
2019-07-07 19:17:53 +00:00
|
|
|
</p>
|
2020-04-21 15:34:56 +00:00
|
|
|
<button v-if="selectMode" class="checkbox _button" :class="{ checked: isSelected }" @click.prevent.stop="checkboxClicked"></button>
|
2018-02-14 10:03:48 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2020-01-29 19:37:25 +00:00
|
|
|
import { faFolder, faFolderOpen } from '@fortawesome/free-regular-svg-icons';
|
2018-02-14 10:03:48 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2020-01-29 19:37:25 +00:00
|
|
|
props: {
|
|
|
|
folder: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
2020-04-21 15:34:56 +00:00
|
|
|
},
|
|
|
|
isSelected: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
selectMode: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-14 10:03:48 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
hover: false,
|
|
|
|
draghover: false,
|
|
|
|
isDragging: false,
|
2020-01-29 19:37:25 +00:00
|
|
|
faFolder, faFolderOpen
|
2018-02-14 10:03:48 +00:00
|
|
|
};
|
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2018-02-14 10:03:48 +00:00
|
|
|
computed: {
|
2018-02-18 03:35:18 +00:00
|
|
|
browser(): any {
|
|
|
|
return this.$parent;
|
|
|
|
},
|
2018-02-14 10:03:48 +00:00
|
|
|
title(): string {
|
|
|
|
return this.folder.name;
|
|
|
|
}
|
|
|
|
},
|
2020-04-21 15:34:56 +00:00
|
|
|
|
2018-02-14 10:03:48 +00:00
|
|
|
methods: {
|
2020-04-21 15:34:56 +00:00
|
|
|
checkboxClicked(e) {
|
|
|
|
this.$emit('chosen', this.folder);
|
|
|
|
},
|
|
|
|
|
2018-02-14 10:03:48 +00:00
|
|
|
onClick() {
|
|
|
|
this.browser.move(this.folder);
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseover() {
|
|
|
|
this.hover = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseout() {
|
|
|
|
this.hover = false
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragover(e) {
|
2018-02-26 21:25:17 +00:00
|
|
|
// 自分自身がドラッグされている場合
|
|
|
|
if (this.isDragging) {
|
2018-02-14 10:03:48 +00:00
|
|
|
// 自分自身にはドロップさせない
|
|
|
|
e.dataTransfer.dropEffect = 'none';
|
2018-02-26 21:25:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isFile = e.dataTransfer.items[0].kind == 'file';
|
|
|
|
const isDriveFile = e.dataTransfer.types[0] == 'mk_drive_file';
|
|
|
|
const isDriveFolder = e.dataTransfer.types[0] == 'mk_drive_folder';
|
|
|
|
|
|
|
|
if (isFile || isDriveFile || isDriveFolder) {
|
|
|
|
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
|
|
|
|
} else {
|
|
|
|
e.dataTransfer.dropEffect = 'none';
|
2018-02-14 10:03:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragenter() {
|
|
|
|
if (!this.isDragging) this.draghover = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragleave() {
|
|
|
|
this.draghover = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop(e) {
|
|
|
|
this.draghover = false;
|
|
|
|
|
|
|
|
// ファイルだったら
|
|
|
|
if (e.dataTransfer.files.length > 0) {
|
2018-12-11 11:36:55 +00:00
|
|
|
for (const file of Array.from(e.dataTransfer.files)) {
|
2018-02-14 10:03:48 +00:00
|
|
|
this.browser.upload(file, this.folder);
|
2018-12-11 11:36:55 +00:00
|
|
|
}
|
2018-02-26 21:25:17 +00:00
|
|
|
return;
|
2018-02-22 22:56:35 +00:00
|
|
|
}
|
2018-02-14 10:03:48 +00:00
|
|
|
|
2018-02-26 21:25:17 +00:00
|
|
|
//#region ドライブのファイル
|
|
|
|
const driveFile = e.dataTransfer.getData('mk_drive_file');
|
|
|
|
if (driveFile != null && driveFile != '') {
|
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
this.browser.removeFile(file.id);
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.api('drive/files/update', {
|
2018-03-29 05:48:47 +00:00
|
|
|
fileId: file.id,
|
|
|
|
folderId: this.folder.id
|
2018-02-14 10:03:48 +00:00
|
|
|
});
|
2018-02-26 21:25:17 +00:00
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region ドライブのフォルダ
|
|
|
|
const driveFolder = e.dataTransfer.getData('mk_drive_folder');
|
|
|
|
if (driveFolder != null && driveFolder != '') {
|
|
|
|
const folder = JSON.parse(driveFolder);
|
|
|
|
|
2018-02-14 10:03:48 +00:00
|
|
|
// 移動先が自分自身ならreject
|
2018-02-26 21:25:17 +00:00
|
|
|
if (folder.id == this.folder.id) return;
|
|
|
|
|
|
|
|
this.browser.removeFolder(folder.id);
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.api('drive/folders/update', {
|
2018-03-29 05:48:47 +00:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: this.folder.id
|
2018-02-14 10:03:48 +00:00
|
|
|
}).then(() => {
|
2018-02-26 21:25:17 +00:00
|
|
|
// noop
|
2018-02-14 10:03:48 +00:00
|
|
|
}).catch(err => {
|
|
|
|
switch (err) {
|
|
|
|
case 'detected-circular-definition':
|
2018-12-02 06:28:52 +00:00
|
|
|
this.$root.dialog({
|
2020-03-22 01:51:40 +00:00
|
|
|
title: this.$t('unableToProcess'),
|
|
|
|
text: this.$t('circularReferenceFolder')
|
2018-02-18 03:35:18 +00:00
|
|
|
});
|
2018-02-14 10:03:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-04-16 04:05:10 +00:00
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
2020-03-22 01:51:40 +00:00
|
|
|
text: this.$t('error')
|
2019-04-16 04:05:10 +00:00
|
|
|
});
|
2018-02-14 10:03:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-02-26 21:25:17 +00:00
|
|
|
//#endregion
|
2018-02-14 10:03:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onDragstart(e) {
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
2018-02-26 21:25:17 +00:00
|
|
|
e.dataTransfer.setData('mk_drive_folder', JSON.stringify(this.folder));
|
2018-02-14 10:03:48 +00:00
|
|
|
this.isDragging = true;
|
|
|
|
|
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
|
|
|
this.browser.isDragSource = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragend() {
|
|
|
|
this.isDragging = false;
|
|
|
|
this.browser.isDragSource = false;
|
|
|
|
},
|
|
|
|
|
2018-02-18 03:35:18 +00:00
|
|
|
go() {
|
|
|
|
this.browser.move(this.folder.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
newWindow() {
|
2018-02-21 15:18:19 +00:00
|
|
|
this.browser.newWindow(this.folder);
|
2018-02-18 03:35:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
rename() {
|
2018-12-02 11:10:53 +00:00
|
|
|
this.$root.dialog({
|
2020-03-22 01:51:40 +00:00
|
|
|
title: this.$t('renameFolder'),
|
2018-12-02 11:10:53 +00:00
|
|
|
input: {
|
2020-03-22 01:51:40 +00:00
|
|
|
placeholder: this.$t('inputNewFolderName'),
|
2018-12-02 11:10:53 +00:00
|
|
|
default: this.folder.name
|
|
|
|
}
|
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.api('drive/folders/update', {
|
2018-03-29 05:48:47 +00:00
|
|
|
folderId: this.folder.id,
|
2018-02-18 03:35:18 +00:00
|
|
|
name: name
|
|
|
|
});
|
2018-02-14 10:03:48 +00:00
|
|
|
});
|
2018-02-18 03:35:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteFolder() {
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.api('drive/folders/delete', {
|
2018-10-26 06:06:55 +00:00
|
|
|
folderId: this.folder.id
|
2019-07-07 19:17:53 +00:00
|
|
|
}).then(() => {
|
|
|
|
if (this.$store.state.settings.uploadFolder === this.folder.id) {
|
|
|
|
this.$store.dispatch('settings/set', {
|
|
|
|
key: 'uploadFolder',
|
|
|
|
value: null
|
|
|
|
});
|
|
|
|
}
|
2019-07-07 05:56:51 +00:00
|
|
|
}).catch(err => {
|
|
|
|
switch(err.id) {
|
|
|
|
case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
2020-03-22 01:51:40 +00:00
|
|
|
title: this.$t('unableToDelete'),
|
|
|
|
text: this.$t('hasChildFilesOrFolders')
|
2019-07-07 05:56:51 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
2020-03-22 01:51:40 +00:00
|
|
|
text: this.$t('unableToDelete')
|
2019-07-07 05:56:51 +00:00
|
|
|
});
|
|
|
|
}
|
2018-10-26 06:06:55 +00:00
|
|
|
});
|
2019-07-07 19:17:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setAsUploadFolder() {
|
|
|
|
this.$store.dispatch('settings/set', {
|
|
|
|
key: 'uploadFolder',
|
|
|
|
value: this.folder.id
|
|
|
|
});
|
|
|
|
},
|
2018-02-14 10:03:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.rghtznwe {
|
|
|
|
position: relative;
|
|
|
|
padding: 8px;
|
|
|
|
height: 64px;
|
|
|
|
background: var(--driveFolderBg);
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
&, * {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2019-07-07 19:17:53 +00:00
|
|
|
|
2020-04-21 15:34:56 +00:00
|
|
|
*:not(.checkbox) {
|
2020-01-29 19:37:25 +00:00
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:34:56 +00:00
|
|
|
> .checkbox {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 8px;
|
|
|
|
right: 8px;
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
background: #fff;
|
|
|
|
border: solid 1px #000;
|
|
|
|
|
|
|
|
&.checked {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&[data-draghover] {
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
pointer-events: none;
|
|
|
|
position: absolute;
|
|
|
|
top: -4px;
|
|
|
|
right: -4px;
|
|
|
|
bottom: -4px;
|
|
|
|
left: -4px;
|
|
|
|
border: 2px dashed var(--focus);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
margin: 0;
|
|
|
|
font-size: 0.9em;
|
|
|
|
color: var(--desktopDriveFolderFg);
|
|
|
|
|
|
|
|
> [data-icon] {
|
|
|
|
margin-right: 4px;
|
|
|
|
margin-left: 2px;
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .upload {
|
|
|
|
margin: 4px 4px;
|
|
|
|
font-size: 0.8em;
|
|
|
|
text-align: right;
|
|
|
|
color: var(--desktopDriveFolderFg);
|
|
|
|
}
|
|
|
|
}
|
2018-02-14 10:03:48 +00:00
|
|
|
</style>
|