misskey/src/client/components/drive.vue

747 lines
17 KiB
Vue
Raw Normal View History

2018-02-14 07:54:18 +01:00
<template>
<div class="yfudmmck">
2017-01-11 21:55:38 +01:00
<nav>
2018-02-14 07:54:18 +01:00
<div class="path" @contextmenu.prevent.stop="() => {}">
2018-02-22 23:56:35 +01:00
<x-nav-folder :class="{ current: folder == null }"/>
<template v-for="f in hierarchyFolders">
<span class="separator" :key="f.id + ':separator'"><fa :icon="faAngleRight"/></span>
<x-nav-folder :folder="f" :key="f.id"/>
2018-02-08 06:50:18 +01:00
</template>
<span class="separator" v-if="folder != null"><fa :icon="faAngleRight"/></span>
2018-02-18 04:35:18 +01:00
<span class="folder current" v-if="folder != null">{{ folder.name }}</span>
2017-01-11 21:55:38 +01:00
</div>
</nav>
2018-02-18 04:35:18 +01:00
<div class="main" :class="{ uploading: uploadings.length > 0, fetching }"
2018-02-14 07:54:18 +01:00
ref="main"
@dragover.prevent.stop="onDragover"
2018-02-26 22:35:16 +01:00
@dragenter="onDragenter"
2018-02-14 07:54:18 +01:00
@dragleave="onDragleave"
@drop.prevent.stop="onDrop"
>
2017-01-11 21:55:38 +01:00
<div class="contents" ref="contents">
<div class="folders" ref="foldersContainer" v-show="folders.length > 0">
<x-folder v-for="f in folders" :key="f.id" class="folder" :folder="f" :select-mode="select === 'folder'" :is-selected="selectedFolders.some(x => x.id === f.id)" @chosen="chooseFolder"/>
2017-12-19 05:18:17 +01:00
<!-- SEE: https://stackoverflow.com/questions/18744164/flex-box-align-last-row-to-grid -->
<div class="padding" v-for="(n, i) in 16" :key="i"></div>
<mk-button ref="moreFolders" v-if="moreFolders">{{ $t('loadMore') }}</mk-button>
2017-01-11 21:55:38 +01:00
</div>
<div class="files" ref="filesContainer" v-show="files.length > 0">
<x-file v-for="file in files" :key="file.id" class="file" :file="file" :select-mode="select === 'file'" :is-selected="selectedFiles.some(x => x.id === file.id)" @chosen="chooseFile"/>
2017-12-19 05:18:17 +01:00
<!-- SEE: https://stackoverflow.com/questions/18744164/flex-box-align-last-row-to-grid -->
<div class="padding" v-for="(n, i) in 16" :key="i"></div>
<mk-button ref="loadMoreFiles" @click="fetchMoreFiles" v-show="moreFiles">{{ $t('loadMore') }}</mk-button>
2017-01-11 21:55:38 +01:00
</div>
<div class="empty" v-if="files.length == 0 && folders.length == 0 && !fetching">
<p v-if="draghover">{{ $t('empty-draghover') }}</p>
<p v-if="!draghover && folder == null"><strong>{{ $t('emptyDrive') }}</strong><br/>{{ $t('empty-drive-description') }}</p>
<p v-if="!draghover && folder != null">{{ $t('emptyFolder') }}</p>
2016-12-28 23:49:51 +01:00
</div>
2017-01-11 21:55:38 +01:00
</div>
<mk-loading v-if="fetching"/>
2017-01-11 21:55:38 +01:00
</div>
2018-02-07 10:34:43 +01:00
<div class="dropzone" v-if="draghover"></div>
<x-uploader ref="uploader" @change="onChangeUploaderUploads" @uploaded="onUploaderUploaded"/>
2018-02-14 07:54:18 +01:00
<input ref="fileInput" type="file" accept="*/*" multiple="multiple" tabindex="-1" @change="onChangeFileInput"/>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import { faAngleRight } from '@fortawesome/free-solid-svg-icons';
2018-02-22 23:56:35 +01:00
import XNavFolder from './drive.nav-folder.vue';
import XFolder from './drive.folder.vue';
import XFile from './drive.file.vue';
import XUploader from './uploader.vue';
import MkButton from './ui/button.vue';
2018-02-14 07:54:18 +01:00
export default Vue.extend({
2018-02-22 23:56:35 +01:00
components: {
XNavFolder,
XFolder,
XFile,
XUploader,
MkButton,
2018-02-22 23:56:35 +01:00
},
2018-02-14 07:54:18 +01:00
props: {
initFolder: {
2018-02-18 04:35:18 +01:00
type: Object,
2018-02-14 07:54:18 +01:00
required: false
},
type: {
type: String,
required: false,
default: undefined
},
2018-02-14 07:54:18 +01:00
multiple: {
2018-02-18 04:35:18 +01:00
type: Boolean,
required: false,
default: false
},
select: {
type: String,
required: false,
default: null
2018-02-14 07:54:18 +01:00
}
},
2018-02-14 07:54:18 +01:00
data() {
return {
/**
* 現在の階層(フォルダ)
* * null でルートを表す
*/
folder: null,
files: [],
folders: [],
moreFiles: false,
moreFolders: false,
hierarchyFolders: [],
selectedFiles: [],
selectedFolders: [],
2018-02-14 07:54:18 +01:00
uploadings: [],
2018-10-26 08:06:55 +02:00
connection: null,
2018-02-14 07:54:18 +01:00
/**
* ドロップされようとしているか
*/
draghover: false,
/**
* 自信の所有するアイテムがドラッグをスタートさせたか
* (自分自身の階層にドロップできないようにするためのフラグ)
*/
isDragSource: false,
fetching: true,
ilFilesObserver: new IntersectionObserver(
(entries) => entries.some((entry) => entry.isIntersecting)
&& !this.fetching && this.moreFiles &&
this.fetchMoreFiles()
),
moreFilesElement: null as Element,
faAngleRight
2017-02-21 01:49:35 +01:00
};
2018-02-14 07:54:18 +01:00
},
watch: {
folder() {
this.$emit('cd', this.folder);
}
},
2018-02-14 07:54:18 +01:00
mounted() {
if (this.$store.state.device.enableInfiniteScroll && this.$refs.loadMoreFiles) {
this.$nextTick(() => {
this.ilFilesObserver.observe((this.$refs.loadMoreFiles as Vue).$el)
});
}
2018-11-09 00:13:34 +01:00
this.connection = this.$root.stream.useSharedConnection('drive');
2018-02-14 07:54:18 +01:00
2018-10-23 00:01:43 +02:00
this.connection.on('fileCreated', this.onStreamDriveFileCreated);
this.connection.on('fileUpdated', this.onStreamDriveFileUpdated);
this.connection.on('fileDeleted', this.onStreamDriveFileDeleted);
this.connection.on('folderCreated', this.onStreamDriveFolderCreated);
this.connection.on('folderUpdated', this.onStreamDriveFolderUpdated);
2018-10-26 08:06:55 +02:00
this.connection.on('folderDeleted', this.onStreamDriveFolderDeleted);
2018-02-14 07:54:18 +01:00
if (this.initFolder) {
this.move(this.initFolder);
} else {
this.fetch();
}
},
activated() {
if (this.$store.state.device.enableInfiniteScroll) {
this.$nextTick(() => {
this.ilFilesObserver.observe((this.$refs.loadMoreFiles as Vue).$el)
});
}
},
2018-02-14 07:54:18 +01:00
beforeDestroy() {
this.connection.dispose();
this.ilFilesObserver.disconnect();
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
methods: {
2018-02-14 07:54:18 +01:00
onStreamDriveFileCreated(file) {
this.addFile(file, true);
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
onStreamDriveFileUpdated(file) {
2017-02-21 01:49:35 +01:00
const current = this.folder ? this.folder.id : null;
2018-03-29 07:48:47 +02:00
if (current != file.folderId) {
2017-02-21 01:49:35 +01:00
this.removeFile(file);
} else {
this.addFile(file, true);
}
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
onStreamDriveFileDeleted(fileId) {
this.removeFile(fileId);
},
2018-02-14 07:54:18 +01:00
onStreamDriveFolderCreated(folder) {
2017-02-21 01:49:35 +01:00
this.addFolder(folder, true);
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
onStreamDriveFolderUpdated(folder) {
2017-02-21 01:49:35 +01:00
const current = this.folder ? this.folder.id : null;
2018-03-29 07:48:47 +02:00
if (current != folder.parentId) {
2017-02-21 01:49:35 +01:00
this.removeFolder(folder);
} else {
this.addFolder(folder, true);
}
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-10-26 08:06:55 +02:00
onStreamDriveFolderDeleted(folderId) {
this.removeFolder(folderId);
},
2018-02-14 07:54:18 +01:00
onChangeUploaderUploads(uploads) {
this.uploadings = uploads;
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
onUploaderUploaded(file) {
this.addFile(file, true);
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
onDragover(e): any {
2018-02-26 22:25:17 +01: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 01:49:35 +01:00
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
} else {
e.dataTransfer.dropEffect = 'none';
}
2018-02-26 22:35:16 +01:00
return false;
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
onDragenter(e) {
2017-02-21 01:49:35 +01:00
if (!this.isDragSource) this.draghover = true;
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
onDragleave(e) {
2017-02-21 01:49:35 +01:00
this.draghover = false;
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
onDrop(e): any {
2017-02-21 01:49:35 +01:00
this.draghover = false;
2017-01-11 21:55:38 +01:00
2017-02-20 01:53:57 +01:00
// ドロップされてきたものがファイルだったら
2017-02-21 01:49:35 +01:00
if (e.dataTransfer.files.length > 0) {
for (const file of Array.from(e.dataTransfer.files)) {
2017-02-21 01:49:35 +01:00
this.upload(file, this.folder);
}
2018-02-26 22:25:17 +01:00
return;
2017-02-21 01:49:35 +01:00
}
2017-01-11 21:55:38 +01:00
2018-02-26 22:25:17 +01: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-11-09 00:13:34 +01:00
this.$root.api('drive/files/update', {
2018-03-29 07:48:47 +02:00
fileId: file.id,
folderId: this.folder ? this.folder.id : null
2017-02-21 01:49:35 +01:00
});
2018-02-26 22:25:17 +01:00
}
//#endregion
//#region ドライブのフォルダ
const driveFolder = e.dataTransfer.getData('mk_drive_folder');
if (driveFolder != null && driveFolder != '') {
const folder = JSON.parse(driveFolder);
2017-02-20 01:53:57 +01:00
// 移動先が自分自身ならreject
2018-02-26 22:25:17 +01: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-11-09 00:13:34 +01:00
this.$root.api('drive/folders/update', {
2018-03-29 07:48:47 +02:00
folderId: folder.id,
parentId: this.folder ? this.folder.id : null
2017-02-20 12:13:42 +01:00
}).then(() => {
2018-02-26 22:25:17 +01:00
// noop
2017-02-21 01:49:35 +01:00
}).catch(err => {
switch (err) {
case 'detected-circular-definition':
2018-12-02 07:28:52 +01:00
this.$root.dialog({
title: this.$t('unableToProcess'),
text: this.$t('circularReferenceFolder')
2018-02-18 04:35:18 +01:00
});
2017-02-21 01:49:35 +01:00
break;
default:
this.$root.dialog({
type: 'error',
text: this.$t('error')
});
2017-02-21 01:49:35 +01:00
}
});
}
2018-02-26 22:25:17 +01:00
//#endregion
2018-02-14 07:54:18 +01:00
},
2017-01-11 21:55:38 +01:00
2018-02-14 07:54:18 +01:00
selectLocalFile() {
(this.$refs.fileInput as any).click();
},
2017-04-26 09:36:29 +02:00
2018-02-18 04:35:18 +01:00
urlUpload() {
2018-12-02 12:10:53 +01:00
this.$root.dialog({
title: this.$t('uploadFromUrl'),
2018-12-02 12:10:53 +01:00
input: {
placeholder: this.$t('uploadFromUrlDescription')
2018-12-02 12:10:53 +01:00
}
}).then(({ canceled, result: url }) => {
if (canceled) return;
2018-11-09 00:13:34 +01:00
this.$root.api('drive/files/upload_from_url', {
2017-02-21 01:49:35 +01:00
url: url,
2018-03-29 07:48:47 +02:00
folderId: this.folder ? this.folder.id : undefined
2017-02-21 01:49:35 +01:00
});
2017-02-16 21:46:14 +01:00
2018-12-02 07:28:52 +01:00
this.$root.dialog({
title: this.$t('uploadFromUrlRequested'),
text: this.$t('uploadFromUrlMayTakeTime')
2018-02-18 04:35:18 +01:00
});
2017-02-21 01:49:35 +01:00
});
2018-02-14 07:54:18 +01:00
},
2017-04-26 09:36:29 +02:00
2018-02-18 04:35:18 +01:00
createFolder() {
2018-12-02 12:10:53 +01:00
this.$root.dialog({
title: this.$t('createFolder'),
2018-12-02 12:10:53 +01:00
input: {
placeholder: this.$t('folderName')
2018-12-02 12:10:53 +01:00
}
}).then(({ canceled, result: name }) => {
if (canceled) return;
2018-11-09 00:13:34 +01:00
this.$root.api('drive/folders/create', {
2017-02-21 01:49:35 +01:00
name: name,
2018-11-07 04:15:28 +01:00
parentId: this.folder ? this.folder.id : undefined
2017-02-21 01:49:35 +01:00
}).then(folder => {
this.addFolder(folder, true);
});
});
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
renameFolder(folder) {
this.$root.dialog({
title: this.$t('renameFolder'),
input: {
placeholder: this.$t('inputNewFolderName'),
default: folder.name
}
}).then(({ canceled, result: name }) => {
if (canceled) return;
this.$root.api('drive/folders/update', {
folderId: folder.id,
name: name
}).then(folder => {
// FIXME: 画面を更新するために自分自身に移動
this.move(folder);
});
});
},
deleteFolder(folder) {
this.$root.api('drive/folders/delete', {
folderId: folder.id
}).then(() => {
// 削除時に親フォルダに移動
this.move(folder.parentId);
}).catch(err => {
switch(err.id) {
case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
this.$root.dialog({
type: 'error',
title: this.$t('unableToDelete'),
text: this.$t('hasChildFilesOrFolders')
});
break;
default:
this.$root.dialog({
type: 'error',
text: this.$t('unableToDelete')
});
}
});
},
2018-02-14 07:54:18 +01:00
onChangeFileInput() {
for (const file of Array.from((this.$refs.fileInput as any).files)) {
2017-02-21 01:49:35 +01:00
this.upload(file, this.folder);
}
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
upload(file, folder) {
2017-02-21 01:49:35 +01:00
if (folder && typeof folder == 'object') folder = folder.id;
2018-02-14 07:54:18 +01:00
(this.$refs.uploader as any).upload(file, folder);
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
chooseFile(file) {
2017-02-25 05:23:54 +01: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 05:11:30 +01:00
this.$emit('change-selection', this.selectedFiles);
2017-02-23 09:12:09 +01:00
} else {
2017-02-25 05:23:54 +01:00
if (isAlreadySelected) {
2018-02-09 05:11:30 +01:00
this.$emit('selected', file);
2017-02-25 05:23:54 +01:00
} else {
this.selectedFiles = [file];
2018-02-09 05:11:30 +01:00
this.$emit('change-selection', [file]);
2017-02-25 05:23:54 +01:00
}
2017-02-23 09:12:09 +01:00
}
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
chooseFolder(folder) {
const isAlreadySelected = this.selectedFolders.some(f => f.id == folder.id);
if (this.multiple) {
if (isAlreadySelected) {
this.selectedFolders = this.selectedFolders.filter(f => f.id != folder.id);
} else {
this.selectedFolders.push(folder);
}
this.$emit('change-selection', this.selectedFolders);
} else {
if (isAlreadySelected) {
this.$emit('selected', folder);
} else {
this.selectedFolders = [folder];
this.$emit('change-selection', [folder]);
}
}
},
2018-02-14 07:54:18 +01:00
move(target) {
2017-02-21 01:49:35 +01:00
if (target == null) {
this.goRoot();
return;
} else if (typeof target == 'object') {
target = target.id;
}
2018-02-14 07:54:18 +01:00
this.fetching = true;
2016-12-28 23:49:51 +01:00
2018-11-09 00:13:34 +01:00
this.$root.api('drive/folders/show', {
2018-03-29 07:48:47 +02:00
folderId: target
2017-02-21 01:49:35 +01:00
}).then(folder => {
this.folder = folder;
this.hierarchyFolders = [];
2016-12-28 23:49:51 +01:00
2017-02-21 01:49:35 +01:00
const dive = folder => {
this.hierarchyFolders.unshift(folder);
if (folder.parent) dive(folder.parent);
};
2016-12-28 23:49:51 +01:00
2017-02-21 01:49:35 +01:00
if (folder.parent) dive(folder.parent);
2017-01-11 21:55:38 +01:00
2018-02-09 05:11:30 +01:00
this.$emit('open-folder', folder);
this.fetch();
2017-02-21 01:49:35 +01:00
});
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
addFolder(folder, unshift = false) {
2017-02-21 01:49:35 +01:00
const current = this.folder ? this.folder.id : null;
2018-03-29 07:48:47 +02:00
if (current != folder.parentId) return;
2017-01-11 21:55:38 +01:00
2017-02-21 01:49:35 +01:00
if (this.folders.some(f => f.id == folder.id)) {
const exist = this.folders.map(f => f.id).indexOf(folder.id);
2018-02-20 17:23:25 +01:00
Vue.set(this.folders, exist, folder);
2017-02-21 01:49:35 +01:00
return;
}
2017-01-11 21:55:38 +01:00
2017-02-21 01:49:35 +01:00
if (unshift) {
this.folders.unshift(folder);
} else {
this.folders.push(folder);
}
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
addFile(file, unshift = false) {
2017-02-21 01:49:35 +01:00
const current = this.folder ? this.folder.id : null;
2018-03-29 07:48:47 +02:00
if (current != file.folderId) return;
2017-01-11 21:55:38 +01:00
2017-02-21 01:49:35 +01:00
if (this.files.some(f => f.id == file.id)) {
const exist = this.files.map(f => f.id).indexOf(file.id);
2018-02-20 17:23:25 +01:00
Vue.set(this.files, exist, file);
2017-02-21 01:49:35 +01:00
return;
}
2016-12-28 23:49:51 +01:00
2017-02-21 01:49:35 +01:00
if (unshift) {
this.files.unshift(file);
} else {
this.files.push(file);
}
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
removeFolder(folder) {
2017-02-21 01:49:35 +01:00
if (typeof folder == 'object') folder = folder.id;
this.folders = this.folders.filter(f => f.id != folder);
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
removeFile(file) {
2017-02-21 01:49:35 +01:00
if (typeof file == 'object') file = file.id;
this.files = this.files.filter(f => f.id != file);
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
appendFile(file) {
this.addFile(file);
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
appendFolder(folder) {
this.addFolder(folder);
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
prependFile(file) {
this.addFile(file, true);
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
prependFolder(folder) {
this.addFolder(folder, true);
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
goRoot() {
2017-02-21 01:49:35 +01:00
// 既にrootにいるなら何もしない
if (this.folder == null) return;
2018-02-14 07:54:18 +01:00
this.folder = null;
this.hierarchyFolders = [];
2018-02-09 05:11:30 +01:00
this.$emit('move-root');
this.fetch();
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
fetch() {
this.folders = [];
this.files = [];
this.moreFolders = false;
this.moreFiles = false;
this.fetching = true;
2016-12-28 23:49:51 +01:00
2017-02-21 01:49:35 +01:00
let fetchedFolders = null;
let fetchedFiles = null;
2017-01-11 21:55:38 +01:00
2017-02-21 01:49:35 +01:00
const foldersMax = 30;
const filesMax = 30;
2017-01-11 21:55:38 +01:00
2017-02-20 01:53:57 +01:00
// フォルダ一覧取得
2018-11-09 00:13:34 +01:00
this.$root.api('drive/folders', {
2018-03-29 07:48:47 +02:00
folderId: this.folder ? this.folder.id : null,
2017-02-21 01:49:35 +01:00
limit: foldersMax + 1
}).then(folders => {
if (folders.length == foldersMax + 1) {
this.moreFolders = true;
folders.pop();
}
fetchedFolders = folders;
complete();
});
2017-01-11 21:55:38 +01:00
2017-02-20 01:53:57 +01:00
// ファイル一覧取得
2018-11-09 00:13:34 +01:00
this.$root.api('drive/files', {
2018-03-29 07:48:47 +02:00
folderId: this.folder ? this.folder.id : null,
type: this.type,
2017-02-21 01:49:35 +01: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 18:05:44 +01:00
const complete = () => {
2017-02-21 01:49:35 +01:00
if (flag) {
for (const x of fetchedFolders) this.appendFolder(x);
for (const x of fetchedFiles) this.appendFile(x);
2018-02-14 07:54:18 +01:00
this.fetching = false;
2017-02-21 01:49:35 +01:00
} else {
flag = true;
}
};
2018-02-14 07:54:18 +01:00
},
2018-02-18 04:35:18 +01:00
2018-02-14 07:54:18 +01:00
fetchMoreFiles() {
this.fetching = true;
const max = 30;
// ファイル一覧取得
2018-11-09 00:13:34 +01:00
this.$root.api('drive/files', {
2018-03-29 07:48:47 +02:00
folderId: this.folder ? this.folder.id : null,
type: this.type,
2018-08-12 17:59:36 +02:00
untilId: this.files[this.files.length - 1].id,
limit: max + 1
}).then(files => {
if (files.length == max + 1) {
this.moreFiles = true;
files.pop();
} else {
this.moreFiles = false;
}
for (const x of files) this.appendFile(x);
2018-02-14 07:54:18 +01:00
this.fetching = false;
});
2018-02-14 07:54:18 +01:00
}
}
});
</script>
<style lang="scss" scoped>
.yfudmmck {
> nav {
display: block;
z-index: 2;
width: 100%;
overflow: auto;
font-size: 0.9em;
box-shadow: 0 1px 0 var(--divider);
&, * {
user-select: none;
}
> .path {
display: inline-block;
vertical-align: bottom;
line-height: 38px;
white-space: nowrap;
> * {
display: inline-block;
margin: 0;
padding: 0 8px;
line-height: 38px;
cursor: pointer;
* {
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-icon] {
margin: 0;
}
}
}
}
}
> .main {
padding: 8px 0;
overflow: auto;
&, * {
user-select: none;
}
2018-02-14 07:54:18 +01:00
&.fetching {
cursor: wait !important;
* {
pointer-events: none;
}
> .contents {
opacity: 0.5;
}
}
&.uploading {
height: calc(100% - 38px - 100px);
}
> .contents {
> .folders,
> .files {
display: flex;
flex-wrap: wrap;
> .folder,
> .file {
flex-grow: 1;
width: 144px;
margin: 4px;
box-sizing: border-box;
}
> .padding {
flex-grow: 1;
pointer-events: none;
width: 144px + 8px;
2018-02-14 07:54:18 +01:00
}
}
> .empty {
padding: 16px;
text-align: center;
pointer-events: none;
opacity: 0.5;
2018-02-14 07:54:18 +01:00
> p {
margin: 0;
}
}
}
}
2018-02-14 07:54:18 +01:00
> .dropzone {
position: absolute;
left: 0;
top: 38px;
width: 100%;
height: calc(100% - 38px);
border: dashed 2px var(--focus);
pointer-events: none;
}
> .mk-uploader {
height: 100px;
padding: 16px;
}
> input {
display: none;
}
}
2018-02-14 07:54:18 +01:00
</style>