2018-02-14 19:03:48 +09:00
|
|
|
<template>
|
2018-02-23 07:56:35 +09:00
|
|
|
<div class="root folder"
|
2018-02-14 19:03:48 +09:00
|
|
|
:data-is-contextmenu-showing="isContextmenuShowing"
|
|
|
|
: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"
|
2018-02-18 12:35:18 +09:00
|
|
|
@contextmenu.prevent.stop="onContextmenu"
|
2018-02-14 19:03:48 +09:00
|
|
|
:title="title"
|
|
|
|
>
|
|
|
|
<p class="name">
|
|
|
|
<template v-if="hover">%fa:R folder-open .fw%</template>
|
|
|
|
<template v-if="!hover">%fa:R folder .fw%</template>
|
|
|
|
{{ folder.name }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-02-18 12:35:18 +09:00
|
|
|
import contextmenu from '../../api/contextmenu';
|
2018-02-14 19:03:48 +09:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-02-18 12:35:18 +09:00
|
|
|
props: ['folder'],
|
2018-02-14 19:03:48 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
hover: false,
|
|
|
|
draghover: false,
|
|
|
|
isDragging: false,
|
|
|
|
isContextmenuShowing: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2018-02-18 12:35:18 +09:00
|
|
|
browser(): any {
|
|
|
|
return this.$parent;
|
|
|
|
},
|
2018-02-14 19:03:48 +09:00
|
|
|
title(): string {
|
|
|
|
return this.folder.name;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClick() {
|
|
|
|
this.browser.move(this.folder);
|
|
|
|
},
|
|
|
|
|
2018-02-18 12:35:18 +09:00
|
|
|
onContextmenu(e) {
|
|
|
|
this.isContextmenuShowing = true;
|
|
|
|
contextmenu(e, [{
|
|
|
|
type: 'item',
|
|
|
|
text: '%i18n:desktop.tags.mk-drive-browser-folder-contextmenu.move-to-this-folder%',
|
|
|
|
icon: '%fa:arrow-right%',
|
|
|
|
onClick: this.go
|
|
|
|
}, {
|
|
|
|
type: 'item',
|
|
|
|
text: '%i18n:desktop.tags.mk-drive-browser-folder-contextmenu.show-in-new-window%',
|
|
|
|
icon: '%fa:R window-restore%',
|
|
|
|
onClick: this.newWindow
|
|
|
|
}, {
|
|
|
|
type: 'divider',
|
|
|
|
}, {
|
|
|
|
type: 'item',
|
|
|
|
text: '%i18n:desktop.tags.mk-drive-browser-folder-contextmenu.rename%',
|
|
|
|
icon: '%fa:i-cursor%',
|
|
|
|
onClick: this.rename
|
|
|
|
}, {
|
|
|
|
type: 'divider',
|
|
|
|
}, {
|
|
|
|
type: 'item',
|
|
|
|
text: '%i18n:common.delete%',
|
|
|
|
icon: '%fa:R trash-alt%',
|
|
|
|
onClick: this.deleteFolder
|
|
|
|
}], {
|
|
|
|
closed: () => {
|
|
|
|
this.isContextmenuShowing = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-02-14 19:03:48 +09:00
|
|
|
onMouseover() {
|
|
|
|
this.hover = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseout() {
|
|
|
|
this.hover = false
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragover(e) {
|
2018-02-27 06:25:17 +09:00
|
|
|
// 自分自身がドラッグされている場合
|
|
|
|
if (this.isDragging) {
|
2018-02-14 19:03:48 +09:00
|
|
|
// 自分自身にはドロップさせない
|
|
|
|
e.dataTransfer.dropEffect = 'none';
|
2018-02-27 06:25:17 +09: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 19:03:48 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragenter() {
|
|
|
|
if (!this.isDragging) this.draghover = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragleave() {
|
|
|
|
this.draghover = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop(e) {
|
|
|
|
this.draghover = false;
|
|
|
|
|
|
|
|
// ファイルだったら
|
|
|
|
if (e.dataTransfer.files.length > 0) {
|
|
|
|
Array.from(e.dataTransfer.files).forEach(file => {
|
|
|
|
this.browser.upload(file, this.folder);
|
|
|
|
});
|
2018-02-27 06:25:17 +09:00
|
|
|
return;
|
2018-02-23 07:56:35 +09:00
|
|
|
}
|
2018-02-14 19:03:48 +09:00
|
|
|
|
2018-02-27 06:25:17 +09: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-02-18 12:35:18 +09:00
|
|
|
(this as any).api('drive/files/update', {
|
2018-03-29 14:48:47 +09:00
|
|
|
fileId: file.id,
|
|
|
|
folderId: this.folder.id
|
2018-02-14 19:03:48 +09:00
|
|
|
});
|
2018-02-27 06:25:17 +09:00
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region ドライブのフォルダ
|
|
|
|
const driveFolder = e.dataTransfer.getData('mk_drive_folder');
|
|
|
|
if (driveFolder != null && driveFolder != '') {
|
|
|
|
const folder = JSON.parse(driveFolder);
|
|
|
|
|
2018-02-14 19:03:48 +09:00
|
|
|
// 移動先が自分自身ならreject
|
2018-02-27 06:25:17 +09:00
|
|
|
if (folder.id == this.folder.id) return;
|
|
|
|
|
|
|
|
this.browser.removeFolder(folder.id);
|
2018-02-18 12:35:18 +09:00
|
|
|
(this as any).api('drive/folders/update', {
|
2018-03-29 14:48:47 +09:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: this.folder.id
|
2018-02-14 19:03:48 +09:00
|
|
|
}).then(() => {
|
2018-02-27 06:25:17 +09:00
|
|
|
// noop
|
2018-02-14 19:03:48 +09:00
|
|
|
}).catch(err => {
|
|
|
|
switch (err) {
|
|
|
|
case 'detected-circular-definition':
|
2018-02-18 12:35:18 +09:00
|
|
|
(this as any).apis.dialog({
|
|
|
|
title: '%fa:exclamation-triangle%%i18n:desktop.tags.mk-drive-browser-folder.unable-to-process%',
|
|
|
|
text: '%i18n:desktop.tags.mk-drive-browser-folder.circular-reference-detected%',
|
|
|
|
actions: [{
|
|
|
|
text: '%i18n:common.ok%'
|
|
|
|
}]
|
|
|
|
});
|
2018-02-14 19:03:48 +09:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
alert('%i18n:desktop.tags.mk-drive-browser-folder.unhandled-error% ' + err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-02-27 06:25:17 +09:00
|
|
|
//#endregion
|
2018-02-14 19:03:48 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
onDragstart(e) {
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
2018-02-27 06:25:17 +09:00
|
|
|
e.dataTransfer.setData('mk_drive_folder', JSON.stringify(this.folder));
|
2018-02-14 19:03:48 +09:00
|
|
|
this.isDragging = true;
|
|
|
|
|
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
|
|
|
this.browser.isDragSource = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragend() {
|
|
|
|
this.isDragging = false;
|
|
|
|
this.browser.isDragSource = false;
|
|
|
|
},
|
|
|
|
|
2018-02-18 12:35:18 +09:00
|
|
|
go() {
|
|
|
|
this.browser.move(this.folder.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
newWindow() {
|
2018-02-22 00:18:19 +09:00
|
|
|
this.browser.newWindow(this.folder);
|
2018-02-18 12:35:18 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
rename() {
|
|
|
|
(this as any).apis.input({
|
|
|
|
title: '%i18n:desktop.tags.mk-drive-browser-folder-contextmenu.rename-folder%',
|
|
|
|
placeholder: '%i18n:desktop.tags.mk-drive-browser-folder-contextmenu.input-new-folder-name%',
|
|
|
|
default: this.folder.name
|
|
|
|
}).then(name => {
|
|
|
|
(this as any).api('drive/folders/update', {
|
2018-03-29 14:48:47 +09:00
|
|
|
folderId: this.folder.id,
|
2018-02-18 12:35:18 +09:00
|
|
|
name: name
|
|
|
|
});
|
2018-02-14 19:03:48 +09:00
|
|
|
});
|
2018-02-18 12:35:18 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteFolder() {
|
|
|
|
alert('not implemented yet');
|
2018-02-14 19:03:48 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-03-03 13:47:55 +09:00
|
|
|
@import '~const.styl'
|
|
|
|
|
2018-02-23 07:56:35 +09:00
|
|
|
.root.folder
|
2018-02-14 19:03:48 +09:00
|
|
|
padding 8px
|
|
|
|
height 64px
|
|
|
|
background lighten($theme-color, 95%)
|
|
|
|
border-radius 4px
|
|
|
|
|
|
|
|
&, *
|
|
|
|
cursor pointer
|
|
|
|
|
|
|
|
*
|
|
|
|
pointer-events none
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
background lighten($theme-color, 90%)
|
|
|
|
|
|
|
|
&:active
|
|
|
|
background lighten($theme-color, 85%)
|
|
|
|
|
|
|
|
&[data-is-contextmenu-showing]
|
|
|
|
&[data-draghover]
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
pointer-events none
|
|
|
|
position absolute
|
|
|
|
top -4px
|
|
|
|
right -4px
|
|
|
|
bottom -4px
|
|
|
|
left -4px
|
|
|
|
border 2px dashed rgba($theme-color, 0.3)
|
|
|
|
border-radius 4px
|
|
|
|
|
|
|
|
&[data-draghover]
|
|
|
|
background lighten($theme-color, 90%)
|
|
|
|
|
|
|
|
> .name
|
|
|
|
margin 0
|
|
|
|
font-size 0.9em
|
|
|
|
color darken($theme-color, 30%)
|
|
|
|
|
|
|
|
> [data-fa]
|
|
|
|
margin-right 4px
|
|
|
|
margin-left 2px
|
|
|
|
text-align left
|
|
|
|
|
|
|
|
</style>
|