barkey/src/client/app/desktop/views/components/drive.folder.vue

270 lines
6 KiB
Vue
Raw Normal View History

2018-02-14 10:03:48 +00:00
<template>
2018-07-24 19:36:02 +00:00
<div class="ynntpczxvnusfwdyxsfuhvcmuypqopdd"
2018-02-14 10:03:48 +00: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 03:35:18 +00:00
@contextmenu.prevent.stop="onContextmenu"
2018-02-14 10:03:48 +00: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 03:35:18 +00:00
import contextmenu from '../../api/contextmenu';
2018-02-14 10:03:48 +00:00
export default Vue.extend({
2018-02-18 03:35:18 +00:00
props: ['folder'],
2018-02-14 10:03:48 +00:00
data() {
return {
hover: false,
draghover: false,
isDragging: false,
isContextmenuShowing: false
};
},
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;
}
},
methods: {
onClick() {
this.browser.move(this.folder);
},
2018-02-18 03:35:18 +00:00
onContextmenu(e) {
this.isContextmenuShowing = true;
2018-05-29 15:15:32 +00:00
contextmenu((this as any).os)(e, [{
2018-02-18 03:35:18 +00:00
type: 'item',
2018-05-20 11:26:38 +00:00
text: '%i18n:@contextmenu.move-to-this-folder%',
2018-02-18 03:35:18 +00:00
icon: '%fa:arrow-right%',
2018-06-08 02:46:45 +00:00
action: this.go
2018-02-18 03:35:18 +00:00
}, {
type: 'item',
2018-05-20 11:26:38 +00:00
text: '%i18n:@contextmenu.show-in-new-window%',
2018-02-18 03:35:18 +00:00
icon: '%fa:R window-restore%',
2018-06-08 02:46:45 +00:00
action: this.newWindow
}, null, {
2018-02-18 03:35:18 +00:00
type: 'item',
2018-05-20 11:26:38 +00:00
text: '%i18n:@contextmenu.rename%',
2018-02-18 03:35:18 +00:00
icon: '%fa:i-cursor%',
2018-06-08 02:46:45 +00:00
action: this.rename
2018-08-13 13:08:59 +00:00
}/*, null, {
2018-02-18 03:35:18 +00:00
type: 'item',
2018-05-20 11:26:38 +00:00
text: '%i18n:common.delete%',
2018-02-18 03:35:18 +00:00
icon: '%fa:R trash-alt%',
2018-06-08 02:46:45 +00:00
action: this.deleteFolder
2018-08-13 13:08:59 +00:00
}*/], {
closed: () => {
this.isContextmenuShowing = false;
}
});
2018-02-18 03:35:18 +00:00
},
2018-02-14 10:03:48 +00:00
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) {
Array.from(e.dataTransfer.files).forEach(file => {
this.browser.upload(file, this.folder);
});
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-02-18 03:35:18 +00:00
(this as any).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-02-18 03:35:18 +00:00
(this as any).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-02-18 03:35:18 +00:00
(this as any).apis.dialog({
2018-05-20 11:26:38 +00:00
title: '%fa:exclamation-triangle%%i18n:@unable-to-process%',
text: '%i18n:@circular-reference-detected%',
2018-02-18 03:35:18 +00:00
actions: [{
2018-05-20 11:26:38 +00:00
text: '%i18n:common.ok%'
2018-02-18 03:35:18 +00:00
}]
});
2018-02-14 10:03:48 +00:00
break;
default:
2018-09-01 14:12:51 +00:00
alert(`%i18n:@unhandled-error% ${err}`);
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() {
(this as any).apis.input({
2018-05-20 11:26:38 +00:00
title: '%i18n:@contextmenu.rename-folder%',
placeholder: '%i18n:@contextmenu.input-new-folder-name%',
2018-02-18 03:35:18 +00:00
default: this.folder.name
}).then(name => {
(this as any).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() {
alert('not implemented yet');
2018-02-14 10:03:48 +00:00
}
}
});
</script>
<style lang="stylus" scoped>
2018-09-26 11:19:35 +00:00
2018-03-03 04:47:55 +00:00
2018-07-24 19:36:02 +00:00
root(isDark)
2018-02-14 10:03:48 +00:00
padding 8px
height 64px
2018-09-26 11:19:35 +00:00
background isDark ? var(--primaryAlpha02) : var(--primaryLighten95)
2018-02-14 10:03:48 +00:00
border-radius 4px
&, *
cursor pointer
*
pointer-events none
&:hover
2018-09-26 11:19:35 +00:00
//background isDark ? rgba(var(--primaryLighten10), 0.2) : var(--primaryLighten90)
2018-02-14 10:03:48 +00:00
&:active
2018-09-26 11:19:35 +00:00
//background isDark ? rgba(var(--primaryDarken10), 0.2) : var(--primaryLighten85)
2018-02-14 10:03:48 +00:00
&[data-is-contextmenu-showing]
&[data-draghover]
&:after
content ""
pointer-events none
position absolute
top -4px
right -4px
bottom -4px
left -4px
2018-09-26 11:19:35 +00:00
border 2px dashed var(--primaryAlpha03)
2018-02-14 10:03:48 +00:00
border-radius 4px
&[data-draghover]
2018-09-26 11:19:35 +00:00
//background isDark ? rgba(var(--primaryDarken10), 0.2) : var(--primaryLighten90)
2018-02-14 10:03:48 +00:00
> .name
margin 0
font-size 0.9em
2018-09-26 11:19:35 +00:00
color isDark ? #fff : var(--primaryDarken30)
2018-02-14 10:03:48 +00:00
> [data-fa]
margin-right 4px
margin-left 2px
text-align left
2018-07-24 19:36:02 +00:00
.ynntpczxvnusfwdyxsfuhvcmuypqopdd[data-darkmode]
root(true)
.ynntpczxvnusfwdyxsfuhvcmuypqopdd:not([data-darkmode])
root(false)
2018-02-14 10:03:48 +00:00
</style>