misskey-awawa/src/client/app/desktop/views/components/drive.vue

789 lines
18 KiB
Vue
Raw Normal View History

2018-02-14 06:54:18 +00:00
<template>
<div class="mk-drive">
2017-01-11 20:55:38 +00:00
<nav>
2018-02-14 06:54:18 +00:00
<div class="path" @contextmenu.prevent.stop="() => {}">
2018-02-22 22:56:35 +00:00
<x-nav-folder :class="{ current: folder == null }"/>
2018-02-18 03:35:18 +00:00
<template v-for="folder in hierarchyFolders">
2018-02-20 16:39:51 +00:00
<span class="separator">%fa:angle-right%</span>
2018-02-22 22:56:35 +00:00
<x-nav-folder :folder="folder" :key="folder.id"/>
2018-02-08 05:50:18 +00:00
</template>
2018-02-07 09:34:43 +00:00
<span class="separator" v-if="folder != null">%fa:angle-right%</span>
2018-02-18 03:35:18 +00:00
<span class="folder current" v-if="folder != null">{{ folder.name }}</span>
2017-01-11 20:55:38 +00:00
</div>
<!--
TODO: #343
<input class="search" type="search" placeholder="&#xf002; %i18n:@search%"/>
-->
2017-01-11 20:55:38 +00:00
</nav>
2018-02-18 03:35:18 +00:00
<div class="main" :class="{ uploading: uploadings.length > 0, fetching }"
2018-02-14 06:54:18 +00:00
ref="main"
@mousedown="onMousedown"
@dragover.prevent.stop="onDragover"
2018-02-26 21:35:16 +00:00
@dragenter="onDragenter"
2018-02-14 06:54:18 +00:00
@dragleave="onDragleave"
@drop.prevent.stop="onDrop"
@contextmenu.prevent.stop="onContextmenu"
>
2017-01-11 20:55:38 +00:00
<div class="selection" ref="selection"></div>
<div class="contents" ref="contents">
2018-02-07 09:34:43 +00:00
<div class="folders" ref="foldersContainer" v-if="folders.length > 0">
2018-02-22 22:56:35 +00:00
<x-folder v-for="folder in folders" :key="folder.id" class="folder" :folder="folder"/>
2017-12-19 04:18:17 +00:00
<!-- SEE: https://stackoverflow.com/questions/18744164/flex-box-align-last-row-to-grid -->
2018-02-20 16:39:51 +00:00
<div class="padding" v-for="n in 16"></div>
2018-04-14 16:04:40 +00:00
<button v-if="moreFolders">%i18n:@load-more%</button>
2017-01-11 20:55:38 +00:00
</div>
2018-02-07 09:34:43 +00:00
<div class="files" ref="filesContainer" v-if="files.length > 0">
2018-02-22 22:56:35 +00:00
<x-file v-for="file in files" :key="file.id" class="file" :file="file"/>
2017-12-19 04:18:17 +00:00
<!-- SEE: https://stackoverflow.com/questions/18744164/flex-box-align-last-row-to-grid -->
2018-02-20 16:39:51 +00:00
<div class="padding" v-for="n in 16"></div>
2018-04-14 16:04:40 +00:00
<button v-if="moreFiles" @click="fetchMoreFiles">%i18n:@load-more%</button>
2017-01-11 20:55:38 +00:00
</div>
2018-02-07 09:34:43 +00:00
<div class="empty" v-if="files.length == 0 && folders.length == 0 && !fetching">
2018-04-14 16:04:40 +00:00
<p v-if="draghover">%i18n:@empty-draghover%</p>
<p v-if="!draghover && folder == null"><strong>%i18n:@empty-drive%</strong><br/>%i18n:@empty-drive-description%</p>
<p v-if="!draghover && folder != null">%i18n:@empty-folder%</p>
2017-01-11 20:55:38 +00:00
</div>
</div>
2018-02-07 09:34:43 +00:00
<div class="fetching" v-if="fetching">
2016-12-28 22:49:51 +00:00
<div class="spinner">
<div class="dot1"></div>
<div class="dot2"></div>
</div>
2017-01-11 20:55:38 +00:00
</div>
</div>
2018-02-07 09:34:43 +00:00
<div class="dropzone" v-if="draghover"></div>
2018-02-20 20:55:19 +00:00
<mk-uploader ref="uploader" @change="onChangeUploaderUploads" @uploaded="onUploaderUploaded"/>
2018-02-14 06:54:18 +00:00
<input ref="fileInput" type="file" accept="*/*" multiple="multiple" tabindex="-1" @change="onChangeFileInput"/>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-02-18 03:35:18 +00:00
import MkDriveWindow from './drive-window.vue';
2018-02-22 22:56:35 +00:00
import XNavFolder from './drive.nav-folder.vue';
import XFolder from './drive.folder.vue';
import XFile from './drive.file.vue';
2018-02-14 06:54:18 +00:00
import contains from '../../../common/scripts/contains';
2018-02-18 03:35:18 +00:00
import contextmenu from '../../api/contextmenu';
2018-03-03 07:39:53 +00:00
import { url } from '../../../config';
2018-02-14 06:54:18 +00:00
export default Vue.extend({
2018-02-22 22:56:35 +00:00
components: {
XNavFolder,
XFolder,
XFile
},
2018-02-14 06:54:18 +00:00
props: {
initFolder: {
2018-02-18 03:35:18 +00:00
type: Object,
2018-02-14 06:54:18 +00:00
required: false
},
multiple: {
2018-02-18 03:35:18 +00:00
type: Boolean,
2018-02-14 06:54:18 +00:00
default: false
}
},
data() {
return {
/**
* 現在の階層(フォルダ)
* * null でルートを表す
*/
folder: null,
files: [],
folders: [],
moreFiles: false,
moreFolders: false,
hierarchyFolders: [],
selectedFiles: [],
uploadings: [],
connection: null,
connectionId: null,
/**
* ドロップされようとしているか
*/
draghover: false,
/**
* 自信の所有するアイテムがドラッグをスタートさせたか
* (自分自身の階層にドロップできないようにするためのフラグ)
*/
isDragSource: false,
fetching: true
2017-02-21 00:49:35 +00:00
};
2018-02-14 06:54:18 +00:00
},
mounted() {
2018-02-18 03:35:18 +00:00
this.connection = (this as any).os.streams.driveStream.getConnection();
this.connectionId = (this as any).os.streams.driveStream.use();
2018-02-14 06:54:18 +00:00
this.connection.on('file_created', this.onStreamDriveFileCreated);
this.connection.on('file_updated', this.onStreamDriveFileUpdated);
this.connection.on('file_deleted', this.onStreamDriveFileDeleted);
2018-02-14 06:54:18 +00:00
this.connection.on('folder_created', this.onStreamDriveFolderCreated);
this.connection.on('folder_updated', this.onStreamDriveFolderUpdated);
if (this.initFolder) {
this.move(this.initFolder);
} else {
this.fetch();
}
},
beforeDestroy() {
this.connection.off('file_created', this.onStreamDriveFileCreated);
this.connection.off('file_updated', this.onStreamDriveFileUpdated);
this.connection.off('file_deleted', this.onStreamDriveFileDeleted);
2018-02-14 06:54:18 +00:00
this.connection.off('folder_created', this.onStreamDriveFolderCreated);
this.connection.off('folder_updated', this.onStreamDriveFolderUpdated);
2018-02-18 03:35:18 +00:00
(this as any).os.streams.driveStream.dispose(this.connectionId);
2018-02-14 06:54:18 +00:00
},
methods: {
2018-02-18 03:35:18 +00:00
onContextmenu(e) {
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.create-folder%',
2018-02-18 03:35:18 +00:00
icon: '%fa:R folder%',
2018-06-08 02:46:45 +00:00
action: this.createFolder
2018-02-18 03:35:18 +00:00
}, {
type: 'item',
2018-05-20 11:26:38 +00:00
text: '%i18n:@contextmenu.upload%',
2018-02-18 03:35:18 +00:00
icon: '%fa:upload%',
2018-06-08 02:46:45 +00:00
action: this.selectLocalFile
2018-02-18 03:35:18 +00:00
}, {
type: 'item',
2018-05-20 11:26:38 +00:00
text: '%i18n:@contextmenu.url-upload%',
2018-02-18 03:35:18 +00:00
icon: '%fa:cloud-upload-alt%',
2018-06-08 02:46:45 +00:00
action: this.urlUpload
2018-02-18 03:35:18 +00:00
}]);
},
2018-02-14 06:54:18 +00:00
onStreamDriveFileCreated(file) {
this.addFile(file, true);
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onStreamDriveFileUpdated(file) {
2017-02-21 00:49:35 +00:00
const current = this.folder ? this.folder.id : null;
2018-03-29 05:48:47 +00:00
if (current != file.folderId) {
2017-02-21 00:49:35 +00:00
this.removeFile(file);
} else {
this.addFile(file, true);
}
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
onStreamDriveFileDeleted(fileId) {
this.removeFile(fileId);
},
2018-02-14 06:54:18 +00:00
onStreamDriveFolderCreated(folder) {
2017-02-21 00:49:35 +00:00
this.addFolder(folder, true);
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onStreamDriveFolderUpdated(folder) {
2017-02-21 00:49:35 +00:00
const current = this.folder ? this.folder.id : null;
2018-03-29 05:48:47 +00:00
if (current != folder.parentId) {
2017-02-21 00:49:35 +00:00
this.removeFolder(folder);
} else {
this.addFolder(folder, true);
}
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onChangeUploaderUploads(uploads) {
this.uploadings = uploads;
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onUploaderUploaded(file) {
this.addFile(file, true);
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onMousedown(e): any {
2018-02-07 09:17:59 +00:00
if (contains(this.$refs.foldersContainer, e.target) || contains(this.$refs.filesContainer, e.target)) return true;
2017-02-21 00:49:35 +00:00
2018-02-14 06:54:18 +00:00
const main = this.$refs.main as any;
const selection = this.$refs.selection as any;
const rect = main.getBoundingClientRect();
2017-02-21 00:49:35 +00:00
2018-02-14 06:54:18 +00:00
const left = e.pageX + main.scrollLeft - rect.left - window.pageXOffset
const top = e.pageY + main.scrollTop - rect.top - window.pageYOffset
2017-02-21 00:49:35 +00:00
const move = e => {
2018-02-14 06:54:18 +00:00
selection.style.display = 'block';
2017-02-21 00:49:35 +00:00
2018-02-14 06:54:18 +00:00
const cursorX = e.pageX + main.scrollLeft - rect.left - window.pageXOffset;
const cursorY = e.pageY + main.scrollTop - rect.top - window.pageYOffset;
2017-02-21 00:49:35 +00:00
const w = cursorX - left;
const h = cursorY - top;
if (w > 0) {
2018-02-14 06:54:18 +00:00
selection.style.width = w + 'px';
selection.style.left = left + 'px';
2017-02-21 00:49:35 +00:00
} else {
2018-02-14 06:54:18 +00:00
selection.style.width = -w + 'px';
selection.style.left = cursorX + 'px';
2017-02-21 00:49:35 +00:00
}
if (h > 0) {
2018-02-14 06:54:18 +00:00
selection.style.height = h + 'px';
selection.style.top = top + 'px';
2017-02-21 00:49:35 +00:00
} else {
2018-02-14 06:54:18 +00:00
selection.style.height = -h + 'px';
selection.style.top = cursorY + 'px';
2017-02-21 00:49:35 +00:00
}
};
2017-02-26 08:27:34 +00:00
const up = e => {
2017-02-21 00:49:35 +00:00
document.documentElement.removeEventListener('mousemove', move);
document.documentElement.removeEventListener('mouseup', up);
2018-02-14 06:54:18 +00:00
selection.style.display = 'none';
2017-02-21 00:49:35 +00:00
};
document.documentElement.addEventListener('mousemove', move);
document.documentElement.addEventListener('mouseup', up);
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onDragover(e): any {
2018-02-26 21:25:17 +00:00
// ドラッグ元が自分自身の所有するアイテムだったら
if (this.isDragSource) {
// 自分自身にはドロップさせない
e.dataTransfer.dropEffect = 'none';
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) {
2017-02-21 00:49:35 +00:00
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
} else {
e.dataTransfer.dropEffect = 'none';
}
2018-02-26 21:35:16 +00:00
return false;
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onDragenter(e) {
2017-02-21 00:49:35 +00:00
if (!this.isDragSource) this.draghover = true;
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onDragleave(e) {
2017-02-21 00:49:35 +00:00
this.draghover = false;
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onDrop(e): any {
2017-02-21 00:49:35 +00:00
this.draghover = false;
2017-01-11 20:55:38 +00:00
2017-02-20 00:53:57 +00:00
// ドロップされてきたものがファイルだったら
2017-02-21 00:49:35 +00:00
if (e.dataTransfer.files.length > 0) {
2017-11-13 09:05:35 +00:00
Array.from(e.dataTransfer.files).forEach(file => {
2017-02-21 00:49:35 +00:00
this.upload(file, this.folder);
});
2018-02-26 21:25:17 +00:00
return;
2017-02-21 00:49:35 +00:00
}
2017-01-11 20:55:38 +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);
if (this.files.some(f => f.id == file.id)) return;
this.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 ? this.folder.id : null
2017-02-21 00:49:35 +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);
2017-02-20 00:53:57 +00:00
// 移動先が自分自身ならreject
2018-02-26 21:25:17 +00:00
if (this.folder && folder.id == this.folder.id) return false;
if (this.folders.some(f => f.id == folder.id)) return false;
this.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 ? this.folder.id : null
2017-02-20 11:13:42 +00:00
}).then(() => {
2018-02-26 21:25:17 +00:00
// noop
2017-02-21 00:49:35 +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
}]
});
2017-02-21 00:49:35 +00:00
break;
default:
2018-05-20 11:26:38 +00:00
alert('%i18n:@unhandled-error% ' + err);
2017-02-21 00:49:35 +00:00
}
});
}
2018-02-26 21:25:17 +00:00
//#endregion
2018-02-14 06:54:18 +00:00
},
2017-01-11 20:55:38 +00:00
2018-02-14 06:54:18 +00:00
selectLocalFile() {
(this.$refs.fileInput as any).click();
},
2017-04-26 07:36:29 +00:00
2018-02-18 03:35:18 +00:00
urlUpload() {
(this as any).apis.input({
2018-05-20 11:26:38 +00:00
title: '%i18n:@url-upload%',
placeholder: '%i18n:@url-of-file%'
2018-02-18 03:35:18 +00:00
}).then(url => {
(this as any).api('drive/files/upload_from_url', {
2017-02-21 00:49:35 +00:00
url: url,
2018-03-29 05:48:47 +00:00
folderId: this.folder ? this.folder.id : undefined
2017-02-21 00:49:35 +00:00
});
2017-02-16 20:46:14 +00:00
2018-02-18 03:35:18 +00:00
(this as any).apis.dialog({
2018-04-14 16:04:40 +00:00
title: '%fa:check%%i18n:@url-upload-requested%',
2018-05-20 11:26:38 +00:00
text: '%i18n:@may-take-time%',
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
}]
});
2017-02-21 00:49:35 +00:00
});
2018-02-14 06:54:18 +00:00
},
2017-04-26 07:36:29 +00:00
2018-02-18 03:35:18 +00:00
createFolder() {
(this as any).apis.input({
2018-05-20 11:26:38 +00:00
title: '%i18n:@create-folder%',
placeholder: '%i18n:@folder-name%'
2018-02-18 03:35:18 +00:00
}).then(name => {
(this as any).api('drive/folders/create', {
2017-02-21 00:49:35 +00:00
name: name,
2018-03-29 05:48:47 +00:00
folderId: this.folder ? this.folder.id : undefined
2017-02-21 00:49:35 +00:00
}).then(folder => {
this.addFolder(folder, true);
});
});
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
onChangeFileInput() {
Array.from((this.$refs.fileInput as any).files).forEach(file => {
2017-02-21 00:49:35 +00:00
this.upload(file, this.folder);
});
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
upload(file, folder) {
2017-02-21 00:49:35 +00:00
if (folder && typeof folder == 'object') folder = folder.id;
2018-02-14 06:54:18 +00:00
(this.$refs.uploader as any).upload(file, folder);
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
chooseFile(file) {
2017-02-25 04:23:54 +00:00
const isAlreadySelected = this.selectedFiles.some(f => f.id == file.id);
if (this.multiple) {
if (isAlreadySelected) {
this.selectedFiles = this.selectedFiles.filter(f => f.id != file.id);
} else {
this.selectedFiles.push(file);
}
2018-02-09 04:11:30 +00:00
this.$emit('change-selection', this.selectedFiles);
2017-02-23 08:12:09 +00:00
} else {
2017-02-25 04:23:54 +00:00
if (isAlreadySelected) {
2018-02-09 04:11:30 +00:00
this.$emit('selected', file);
2017-02-25 04:23:54 +00:00
} else {
this.selectedFiles = [file];
2018-02-09 04:11:30 +00:00
this.$emit('change-selection', [file]);
2017-02-25 04:23:54 +00:00
}
2017-02-23 08:12:09 +00:00
}
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-21 15:18:19 +00:00
newWindow(folder) {
2018-03-03 07:39:53 +00:00
if (document.body.clientWidth > 800) {
(this as any).os.new(MkDriveWindow, {
folder: folder
});
} else {
window.open(url + '/i/drive/folder/' + folder.id,
'drive_window',
'height=500, width=800');
}
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
move(target) {
2017-02-21 00:49:35 +00:00
if (target == null) {
this.goRoot();
return;
} else if (typeof target == 'object') {
target = target.id;
}
2018-02-14 06:54:18 +00:00
this.fetching = true;
2016-12-28 22:49:51 +00:00
2018-02-18 03:35:18 +00:00
(this as any).api('drive/folders/show', {
2018-03-29 05:48:47 +00:00
folderId: target
2017-02-21 00:49:35 +00:00
}).then(folder => {
this.folder = folder;
this.hierarchyFolders = [];
2016-12-28 22:49:51 +00:00
2017-02-21 00:49:35 +00:00
const dive = folder => {
this.hierarchyFolders.unshift(folder);
if (folder.parent) dive(folder.parent);
};
2016-12-28 22:49:51 +00:00
2017-02-21 00:49:35 +00:00
if (folder.parent) dive(folder.parent);
2017-01-11 20:55:38 +00:00
2018-02-09 04:11:30 +00:00
this.$emit('open-folder', folder);
this.fetch();
2017-02-21 00:49:35 +00:00
});
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
addFolder(folder, unshift = false) {
2017-02-21 00:49:35 +00:00
const current = this.folder ? this.folder.id : null;
2018-03-29 05:48:47 +00:00
if (current != folder.parentId) return;
2017-01-11 20:55:38 +00:00
2017-02-21 00:49:35 +00:00
if (this.folders.some(f => f.id == folder.id)) {
const exist = this.folders.map(f => f.id).indexOf(folder.id);
2018-02-20 16:23:25 +00:00
Vue.set(this.folders, exist, folder);
2017-02-21 00:49:35 +00:00
return;
}
2017-01-11 20:55:38 +00:00
2017-02-21 00:49:35 +00:00
if (unshift) {
this.folders.unshift(folder);
} else {
this.folders.push(folder);
}
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
addFile(file, unshift = false) {
2017-02-21 00:49:35 +00:00
const current = this.folder ? this.folder.id : null;
2018-03-29 05:48:47 +00:00
if (current != file.folderId) return;
2017-01-11 20:55:38 +00:00
2017-02-21 00:49:35 +00:00
if (this.files.some(f => f.id == file.id)) {
const exist = this.files.map(f => f.id).indexOf(file.id);
2018-02-20 16:23:25 +00:00
Vue.set(this.files, exist, file);
2017-02-21 00:49:35 +00:00
return;
}
2016-12-28 22:49:51 +00:00
2017-02-21 00:49:35 +00:00
if (unshift) {
this.files.unshift(file);
} else {
this.files.push(file);
}
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
removeFolder(folder) {
2017-02-21 00:49:35 +00:00
if (typeof folder == 'object') folder = folder.id;
this.folders = this.folders.filter(f => f.id != folder);
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
removeFile(file) {
2017-02-21 00:49:35 +00:00
if (typeof file == 'object') file = file.id;
this.files = this.files.filter(f => f.id != file);
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
appendFile(file) {
this.addFile(file);
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
appendFolder(folder) {
this.addFolder(folder);
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
prependFile(file) {
this.addFile(file, true);
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
prependFolder(folder) {
this.addFolder(folder, true);
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
goRoot() {
2017-02-21 00:49:35 +00:00
// 既にrootにいるなら何もしない
if (this.folder == null) return;
2018-02-14 06:54:18 +00:00
this.folder = null;
this.hierarchyFolders = [];
2018-02-09 04:11:30 +00:00
this.$emit('move-root');
this.fetch();
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
fetch() {
this.folders = [];
this.files = [];
this.moreFolders = false;
this.moreFiles = false;
this.fetching = true;
2016-12-28 22:49:51 +00:00
2017-02-21 00:49:35 +00:00
let fetchedFolders = null;
let fetchedFiles = null;
2017-01-11 20:55:38 +00:00
2017-02-21 00:49:35 +00:00
const foldersMax = 30;
const filesMax = 30;
2017-01-11 20:55:38 +00:00
2017-02-20 00:53:57 +00:00
// フォルダ一覧取得
2018-02-18 03:35:18 +00:00
(this as any).api('drive/folders', {
2018-03-29 05:48:47 +00:00
folderId: this.folder ? this.folder.id : null,
2017-02-21 00:49:35 +00:00
limit: foldersMax + 1
}).then(folders => {
if (folders.length == foldersMax + 1) {
this.moreFolders = true;
folders.pop();
}
fetchedFolders = folders;
complete();
});
2017-01-11 20:55:38 +00:00
2017-02-20 00:53:57 +00:00
// ファイル一覧取得
2018-02-18 03:35:18 +00:00
(this as any).api('drive/files', {
2018-03-29 05:48:47 +00:00
folderId: this.folder ? this.folder.id : null,
2017-02-21 00:49:35 +00:00
limit: filesMax + 1
}).then(files => {
if (files.length == filesMax + 1) {
this.moreFiles = true;
files.pop();
}
fetchedFiles = files;
complete();
});
let flag = false;
2017-02-21 17:05:44 +00:00
const complete = () => {
2017-02-21 00:49:35 +00:00
if (flag) {
2017-02-23 15:18:33 +00:00
fetchedFolders.forEach(this.appendFolder);
fetchedFiles.forEach(this.appendFile);
2018-02-14 06:54:18 +00:00
this.fetching = false;
2017-02-21 00:49:35 +00:00
} else {
flag = true;
}
};
2018-02-14 06:54:18 +00:00
},
2018-02-18 03:35:18 +00:00
2018-02-14 06:54:18 +00:00
fetchMoreFiles() {
this.fetching = true;
const max = 30;
// ファイル一覧取得
2018-02-18 03:35:18 +00:00
(this as any).api('drive/files', {
2018-03-29 05:48:47 +00:00
folderId: this.folder ? this.folder.id : null,
limit: max + 1
}).then(files => {
if (files.length == max + 1) {
this.moreFiles = true;
files.pop();
} else {
this.moreFiles = false;
}
files.forEach(this.appendFile);
2018-02-14 06:54:18 +00:00
this.fetching = false;
});
2018-02-14 06:54:18 +00:00
}
}
});
</script>
<style lang="stylus" scoped>
2018-03-03 04:47:55 +00:00
@import '~const.styl'
2018-04-19 22:45:37 +00:00
root(isDark)
2018-02-14 06:54:18 +00:00
> nav
display block
z-index 2
width 100%
overflow auto
font-size 0.9em
2018-04-19 22:45:37 +00:00
color isDark ? #d2d9dc : #555
background isDark ? #282c37 : #fff
2018-04-28 23:51:17 +00:00
box-shadow 0 1px 0 rgba(#000, 0.05)
2018-02-14 06:54:18 +00:00
&, *
user-select none
> .path
display inline-block
vertical-align bottom
margin 0
padding 0 8px
width calc(100% - 200px)
line-height 38px
white-space nowrap
> *
display inline-block
margin 0
padding 0 8px
line-height 38px
cursor pointer
i
margin-right 4px
*
pointer-events none
&:hover
text-decoration underline
&.current
font-weight bold
cursor default
&:hover
text-decoration none
&.separator
margin 0
padding 0
opacity 0.5
cursor default
> [data-fa]
margin 0
> .search
display inline-block
vertical-align bottom
user-select text
cursor auto
margin 0
padding 0 18px
width 200px
font-size 1em
line-height 38px
background transparent
outline none
//border solid 1px #ddd
border none
border-radius 0
box-shadow none
transition color 0.5s ease, border 0.5s ease
font-family FontAwesome, sans-serif
&[data-active='true']
background #fff
&::-webkit-input-placeholder,
&:-ms-input-placeholder,
&:-moz-placeholder
color $ui-control-foreground-color
> .main
padding 8px
height calc(100% - 38px)
overflow auto
2018-04-19 22:45:37 +00:00
background isDark ? #191b22 : #fff
2018-02-14 06:54:18 +00:00
&, *
user-select none
&.fetching
cursor wait !important
*
pointer-events none
> .contents
opacity 0.5
&.uploading
height calc(100% - 38px - 100px)
> .selection
display none
position absolute
z-index 128
top 0
left 0
border solid 1px $theme-color
background rgba($theme-color, 0.5)
pointer-events none
> .contents
> .folders
> .files
display flex
flex-wrap wrap
> .folder
> .file
flex-grow 1
width 144px
margin 4px
> .padding
flex-grow 1
pointer-events none
width 144px + 8px // 8px is margin
> .empty
padding 16px
text-align center
color #999
pointer-events none
> p
margin 0
> .fetching
.spinner
margin 100px auto
width 40px
height 40px
text-align center
animation sk-rotate 2.0s infinite linear
.dot1, .dot2
width 60%
height 60%
display inline-block
position absolute
top 0
2018-04-28 23:51:17 +00:00
background-color rgba(#000, 0.3)
2018-02-14 06:54:18 +00:00
border-radius 100%
animation sk-bounce 2.0s infinite ease-in-out
.dot2
top auto
bottom 0
animation-delay -1.0s
@keyframes sk-rotate { 100% { transform: rotate(360deg); }}
@keyframes sk-bounce {
0%, 100% {
transform: scale(0.0);
} 50% {
transform: scale(1.0);
}
}
> .dropzone
position absolute
left 0
top 38px
width 100%
height calc(100% - 38px)
border dashed 2px rgba($theme-color, 0.5)
pointer-events none
> .mk-uploader
height 100px
padding 16px
background #fff
> input
display none
2018-04-19 22:45:37 +00:00
.mk-drive[data-darkmode]
root(true)
.mk-drive:not([data-darkmode])
root(false)
2018-02-14 06:54:18 +00:00
</style>