2018-02-14 11:03:48 +01:00
|
|
|
<template>
|
2020-01-29 20:37:25 +01:00
|
|
|
<div class="rghtznwe"
|
2020-10-17 13:12:00 +02:00
|
|
|
:class="{ draghover }"
|
2021-11-19 11:36:12 +01:00
|
|
|
draggable="true"
|
|
|
|
:title="title"
|
2018-02-14 11:03:48 +01:00
|
|
|
@click="onClick"
|
2020-11-03 02:27:00 +01:00
|
|
|
@contextmenu.stop="onContextmenu"
|
2018-02-14 11:03:48 +01:00
|
|
|
@mouseover="onMouseover"
|
|
|
|
@mouseout="onMouseout"
|
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@dragenter.prevent="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.prevent.stop="onDrop"
|
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
>
|
|
|
|
<p class="name">
|
2021-04-20 16:22:59 +02:00
|
|
|
<template v-if="hover"><i class="fas fa-folder-open fa-fw"></i></template>
|
|
|
|
<template v-if="!hover"><i class="fas fa-folder fa-fw"></i></template>
|
2018-02-14 11:03:48 +01:00
|
|
|
{{ folder.name }}
|
|
|
|
</p>
|
2021-11-19 11:36:12 +01:00
|
|
|
<p v-if="$store.state.uploadFolder == folder.id" class="upload">
|
2020-12-26 02:47:36 +01:00
|
|
|
{{ $ts.uploadFolder }}
|
2019-07-07 21:17:53 +02:00
|
|
|
</p>
|
2020-04-21 17:34:56 +02:00
|
|
|
<button v-if="selectMode" class="checkbox _button" :class="{ checked: isSelected }" @click.prevent.stop="checkboxClicked"></button>
|
2018-02-14 11:03:48 +01:00
|
|
|
</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 * as os from '@/os';
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-01-29 20:37:25 +01:00
|
|
|
props: {
|
|
|
|
folder: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
2020-04-21 17:34:56 +02:00
|
|
|
},
|
|
|
|
isSelected: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
selectMode: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
emits: ['chosen'],
|
|
|
|
|
2018-02-14 11:03:48 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
hover: false,
|
|
|
|
draghover: false,
|
|
|
|
isDragging: false,
|
|
|
|
};
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2018-02-14 11:03:48 +01:00
|
|
|
computed: {
|
2018-02-18 04:35:18 +01:00
|
|
|
browser(): any {
|
|
|
|
return this.$parent;
|
|
|
|
},
|
2018-02-14 11:03:48 +01:00
|
|
|
title(): string {
|
|
|
|
return this.folder.name;
|
|
|
|
}
|
|
|
|
},
|
2020-04-21 17:34:56 +02:00
|
|
|
|
2018-02-14 11:03:48 +01:00
|
|
|
methods: {
|
2020-04-21 17:34:56 +02:00
|
|
|
checkboxClicked(e) {
|
|
|
|
this.$emit('chosen', this.folder);
|
|
|
|
},
|
|
|
|
|
2018-02-14 11:03:48 +01:00
|
|
|
onClick() {
|
|
|
|
this.browser.move(this.folder);
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseover() {
|
|
|
|
this.hover = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseout() {
|
|
|
|
this.hover = false
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragover(e) {
|
2018-02-26 22:25:17 +01:00
|
|
|
// 自分自身がドラッグされている場合
|
|
|
|
if (this.isDragging) {
|
2018-02-14 11:03:48 +01:00
|
|
|
// 自分自身にはドロップさせない
|
|
|
|
e.dataTransfer.dropEffect = 'none';
|
2018-02-26 22:25:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isFile = e.dataTransfer.items[0].kind == 'file';
|
2020-10-17 13:12:00 +02:00
|
|
|
const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
|
|
|
|
const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_;
|
2018-02-26 22:25:17 +01:00
|
|
|
|
|
|
|
if (isFile || isDriveFile || isDriveFolder) {
|
|
|
|
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
|
|
|
|
} else {
|
|
|
|
e.dataTransfer.dropEffect = 'none';
|
2018-02-14 11:03:48 +01: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 12:36:55 +01:00
|
|
|
for (const file of Array.from(e.dataTransfer.files)) {
|
2018-02-14 11:03:48 +01:00
|
|
|
this.browser.upload(file, this.folder);
|
2018-12-11 12:36:55 +01:00
|
|
|
}
|
2018-02-26 22:25:17 +01:00
|
|
|
return;
|
2018-02-22 23:56:35 +01:00
|
|
|
}
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2018-02-26 22:25:17 +01:00
|
|
|
//#region ドライブのファイル
|
2020-10-17 13:12:00 +02:00
|
|
|
const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
2018-02-26 22:25:17 +01:00
|
|
|
if (driveFile != null && driveFile != '') {
|
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
this.browser.removeFile(file.id);
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('drive/files/update', {
|
2018-03-29 07:48:47 +02:00
|
|
|
fileId: file.id,
|
|
|
|
folderId: this.folder.id
|
2018-02-14 11:03:48 +01:00
|
|
|
});
|
2018-02-26 22:25:17 +01:00
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region ドライブのフォルダ
|
2020-10-17 13:12:00 +02:00
|
|
|
const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
|
2018-02-26 22:25:17 +01:00
|
|
|
if (driveFolder != null && driveFolder != '') {
|
|
|
|
const folder = JSON.parse(driveFolder);
|
|
|
|
|
2018-02-14 11:03:48 +01:00
|
|
|
// 移動先が自分自身ならreject
|
2018-02-26 22:25:17 +01:00
|
|
|
if (folder.id == this.folder.id) return;
|
|
|
|
|
|
|
|
this.browser.removeFolder(folder.id);
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('drive/folders/update', {
|
2018-03-29 07:48:47 +02:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: this.folder.id
|
2018-02-14 11:03:48 +01:00
|
|
|
}).then(() => {
|
2018-02-26 22:25:17 +01:00
|
|
|
// noop
|
2018-02-14 11:03:48 +01:00
|
|
|
}).catch(err => {
|
|
|
|
switch (err) {
|
|
|
|
case 'detected-circular-definition':
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.unableToProcess,
|
|
|
|
text: this.$ts.circularReferenceFolder
|
2018-02-18 04:35:18 +01:00
|
|
|
});
|
2018-02-14 11:03:48 +01:00
|
|
|
break;
|
|
|
|
default:
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-04-16 06:05:10 +02:00
|
|
|
type: 'error',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.somethingHappened
|
2019-04-16 06:05:10 +02:00
|
|
|
});
|
2018-02-14 11:03:48 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-02-26 22:25:17 +01:00
|
|
|
//#endregion
|
2018-02-14 11:03:48 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onDragstart(e) {
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
2020-10-17 13:12:00 +02:00
|
|
|
e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FOLDER_, JSON.stringify(this.folder));
|
2018-02-14 11:03:48 +01:00
|
|
|
this.isDragging = true;
|
|
|
|
|
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
|
|
|
this.browser.isDragSource = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragend() {
|
|
|
|
this.isDragging = false;
|
|
|
|
this.browser.isDragSource = false;
|
|
|
|
},
|
|
|
|
|
2018-02-18 04:35:18 +01:00
|
|
|
go() {
|
|
|
|
this.browser.move(this.folder.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
newWindow() {
|
2018-02-21 16:18:19 +01:00
|
|
|
this.browser.newWindow(this.folder);
|
2018-02-18 04:35:18 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
rename() {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.inputText({
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.renameFolder,
|
2021-11-18 10:45:58 +01:00
|
|
|
placeholder: this.$ts.inputNewFolderName,
|
|
|
|
default: this.folder.name
|
2018-12-02 12:10:53 +01:00
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('drive/folders/update', {
|
2018-03-29 07:48:47 +02:00
|
|
|
folderId: this.folder.id,
|
2018-02-18 04:35:18 +01:00
|
|
|
name: name
|
|
|
|
});
|
2018-02-14 11:03:48 +01:00
|
|
|
});
|
2018-02-18 04:35:18 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteFolder() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('drive/folders/delete', {
|
2018-10-26 08:06:55 +02:00
|
|
|
folderId: this.folder.id
|
2019-07-07 21:17:53 +02:00
|
|
|
}).then(() => {
|
2020-12-19 02:55:52 +01:00
|
|
|
if (this.$store.state.uploadFolder === this.folder.id) {
|
|
|
|
this.$store.set('uploadFolder', null);
|
2019-07-07 21:17:53 +02:00
|
|
|
}
|
2019-07-07 07:56:51 +02:00
|
|
|
}).catch(err => {
|
|
|
|
switch(err.id) {
|
|
|
|
case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-07-07 07:56:51 +02:00
|
|
|
type: 'error',
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.unableToDelete,
|
|
|
|
text: this.$ts.hasChildFilesOrFolders
|
2019-07-07 07:56:51 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-07-07 07:56:51 +02:00
|
|
|
type: 'error',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.unableToDelete
|
2019-07-07 07:56:51 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-26 08:06:55 +02:00
|
|
|
});
|
2019-07-07 21:17:53 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setAsUploadFolder() {
|
2020-12-19 02:55:52 +01:00
|
|
|
this.$store.set('uploadFolder', this.folder.id);
|
2019-07-07 21:17:53 +02:00
|
|
|
},
|
2020-11-03 02:27:00 +01:00
|
|
|
|
|
|
|
onContextmenu(e) {
|
|
|
|
os.contextMenu([{
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.openInWindow,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-window-restore',
|
2020-11-03 07:22:55 +01:00
|
|
|
action: () => {
|
|
|
|
os.popup(import('./drive-window.vue'), {
|
2020-11-03 02:27:00 +01:00
|
|
|
initialFolder: this.folder
|
|
|
|
}, {
|
|
|
|
}, 'closed');
|
|
|
|
}
|
|
|
|
}, null, {
|
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-11-03 02:27:00 +01:00
|
|
|
action: this.rename
|
|
|
|
}, 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-11-03 02:27:00 +01:00
|
|
|
danger: true,
|
|
|
|
action: this.deleteFolder
|
|
|
|
}], e);
|
|
|
|
},
|
2018-02-14 11:03:48 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.rghtznwe {
|
|
|
|
position: relative;
|
|
|
|
padding: 8px;
|
|
|
|
height: 64px;
|
|
|
|
background: var(--driveFolderBg);
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
&, * {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2019-07-07 21:17:53 +02:00
|
|
|
|
2020-04-21 17:34:56 +02:00
|
|
|
*:not(.checkbox) {
|
2020-01-29 20:37:25 +01:00
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2020-04-21 17:34:56 +02:00
|
|
|
> .checkbox {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 8px;
|
|
|
|
right: 8px;
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
background: #fff;
|
|
|
|
border: solid 1px #000;
|
|
|
|
|
|
|
|
&.checked {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
&.draghover {
|
2020-01-29 20:37:25 +01:00
|
|
|
&: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);
|
|
|
|
|
2021-04-20 16:22:59 +02:00
|
|
|
> i {
|
2020-01-29 20:37:25 +01:00
|
|
|
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 11:03:48 +01:00
|
|
|
</style>
|