2017-01-11 20:55:38 +00:00
|
|
|
<mk-drive-browser>
|
|
|
|
<nav>
|
2017-01-11 21:00:12 +00:00
|
|
|
<div class="path" oncontextmenu={ pathOncontextmenu }>
|
|
|
|
<mk-drive-browser-nav-folder class={ current: folder == null } folder={ null }></mk-drive-browser-nav-folder>
|
|
|
|
<virtual each={ folder in hierarchyFolders }><span class="separator"><i class="fa fa-angle-right"></i></span>
|
|
|
|
<mk-drive-browser-nav-folder folder={ folder }></mk-drive-browser-nav-folder>
|
|
|
|
</virtual><span class="separator" if={ folder != null }><i class="fa fa-angle-right"></i></span><span class="folder current" if={ folder != null }>{ folder.name }</span>
|
2017-01-11 20:55:38 +00:00
|
|
|
</div>
|
|
|
|
<input class="search" type="search" placeholder=" 検索"/>
|
|
|
|
</nav>
|
2017-01-14 03:16:20 +00:00
|
|
|
<div class="main { uploading: uploads.length > 0, loading: loading }" ref="main" onmousedown={ onmousedown } ondragover={ ondragover } ondragenter={ ondragenter } ondragleave={ ondragleave } ondrop={ ondrop } oncontextmenu={ oncontextmenu }>
|
2017-01-11 20:55:38 +00:00
|
|
|
<div class="selection" ref="selection"></div>
|
|
|
|
<div class="contents" ref="contents">
|
2017-01-14 03:16:20 +00:00
|
|
|
<div class="folders" ref="foldersContainer" if={ folders.length > 0 }>
|
2017-01-11 21:00:12 +00:00
|
|
|
<virtual each={ folder in folders }>
|
|
|
|
<mk-drive-browser-folder class="folder" folder={ folder }></mk-drive-browser-folder>
|
2017-01-11 20:55:38 +00:00
|
|
|
</virtual>
|
2017-01-11 21:00:12 +00:00
|
|
|
<button if={ moreFolders }>もっと読み込む</button>
|
2017-01-11 20:55:38 +00:00
|
|
|
</div>
|
2017-01-14 03:16:20 +00:00
|
|
|
<div class="files" ref="filesContainer" if={ files.length > 0 }>
|
2017-01-11 21:00:12 +00:00
|
|
|
<virtual each={ file in files }>
|
|
|
|
<mk-drive-browser-file class="file" file={ file }></mk-drive-browser-file>
|
2017-01-11 20:55:38 +00:00
|
|
|
</virtual>
|
2017-01-11 21:00:12 +00:00
|
|
|
<button if={ moreFiles }>もっと読み込む</button>
|
2017-01-11 20:55:38 +00:00
|
|
|
</div>
|
2017-01-11 21:03:49 +00:00
|
|
|
<div class="empty" if={ files.length == 0 && folders.length == 0 && !loading }>
|
2017-01-11 21:00:12 +00:00
|
|
|
<p if={ draghover }>ドロップですか?いいですよ、ボクはカワイイですからね</p>
|
2017-01-11 21:03:49 +00:00
|
|
|
<p if={ !draghover && folder == null }><strong>ドライブには何もありません。</strong><br/>右クリックして「ファイルをアップロード」を選んだり、ファイルをドラッグ&ドロップすることでもアップロードできます。</p>
|
|
|
|
<p if={ !draghover && folder != null }>このフォルダーは空です</p>
|
2017-01-11 20:55:38 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-01-11 21:00:12 +00:00
|
|
|
<div class="loading" if={ loading }>
|
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>
|
2017-01-11 21:00:12 +00:00
|
|
|
<div class="dropzone" if={ draghover }></div>
|
2017-01-11 20:55:38 +00:00
|
|
|
<mk-uploader ref="uploader"></mk-uploader>
|
2017-01-11 21:00:12 +00:00
|
|
|
<input ref="fileInput" type="file" accept="*/*" multiple="multiple" tabindex="-1" onchange={ changeFileInput }/>
|
2017-02-19 03:31:53 +00:00
|
|
|
<style>
|
2017-01-11 20:55:38 +00:00
|
|
|
:scope
|
|
|
|
display block
|
|
|
|
|
|
|
|
> nav
|
|
|
|
display block
|
|
|
|
z-index 2
|
|
|
|
width 100%
|
|
|
|
overflow auto
|
|
|
|
font-size 0.9em
|
|
|
|
color #555
|
|
|
|
background #fff
|
|
|
|
//border-bottom 1px solid #dfdfdf
|
|
|
|
box-shadow 0 1px 0 rgba(0, 0, 0, 0.05)
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
&, *
|
|
|
|
user-select none
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
> .path
|
|
|
|
display inline-block
|
|
|
|
vertical-align bottom
|
2016-12-28 22:49:51 +00:00
|
|
|
margin 0
|
2017-01-11 20:55:38 +00:00
|
|
|
padding 0 8px
|
|
|
|
width calc(100% - 200px)
|
|
|
|
line-height 38px
|
|
|
|
white-space nowrap
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
> *
|
|
|
|
display inline-block
|
2016-12-28 22:49:51 +00:00
|
|
|
margin 0
|
2017-01-11 20:55:38 +00:00
|
|
|
padding 0 8px
|
|
|
|
line-height 38px
|
|
|
|
cursor pointer
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
i
|
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
*
|
|
|
|
pointer-events none
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
&:hover
|
|
|
|
text-decoration underline
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
&.current
|
|
|
|
font-weight bold
|
|
|
|
cursor default
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
&:hover
|
|
|
|
text-decoration none
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
&.separator
|
|
|
|
margin 0
|
|
|
|
padding 0
|
|
|
|
opacity 0.5
|
|
|
|
cursor default
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
> i
|
|
|
|
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-controll-foreground-color
|
|
|
|
|
|
|
|
> .main
|
|
|
|
padding 8px
|
|
|
|
height calc(100% - 38px)
|
|
|
|
overflow auto
|
|
|
|
|
|
|
|
&, *
|
|
|
|
user-select none
|
|
|
|
|
|
|
|
&.loading
|
|
|
|
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
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
display block
|
|
|
|
clear both
|
|
|
|
|
|
|
|
> .folder
|
|
|
|
float left
|
|
|
|
|
|
|
|
> .files
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
display block
|
|
|
|
clear both
|
|
|
|
|
|
|
|
> .file
|
|
|
|
float left
|
|
|
|
|
|
|
|
> .empty
|
|
|
|
padding 16px
|
|
|
|
text-align center
|
|
|
|
color #999
|
|
|
|
pointer-events none
|
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0
|
|
|
|
|
|
|
|
> .loading
|
|
|
|
.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
|
|
|
|
background-color rgba(0, 0, 0, 0.3)
|
|
|
|
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)
|
2016-12-28 22:49:51 +00:00
|
|
|
pointer-events none
|
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
> mk-uploader
|
|
|
|
height 100px
|
|
|
|
padding 16px
|
|
|
|
background #fff
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
> input
|
|
|
|
display none
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
</style>
|
|
|
|
<script>
|
2017-02-20 00:53:57 +00:00
|
|
|
this.mixin('api');
|
|
|
|
this.mixin('dialog');
|
|
|
|
this.mixin('input-dialog');
|
|
|
|
this.mixin('stream');
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 02:02:43 +00:00
|
|
|
this.files = [];
|
|
|
|
this.folders = [];
|
|
|
|
this.hierarchyFolders = [];
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 02:02:43 +00:00
|
|
|
this.uploads = [];
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// 現在の階層(フォルダ)
|
|
|
|
// * null でルートを表す
|
2017-02-20 02:02:43 +00:00
|
|
|
this.folder = null;
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.multiple = if this.opts.multiple? then this.opts.multiple else false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// ドロップされようとしているか
|
2017-02-20 02:02:43 +00:00
|
|
|
this.draghover = false;
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// 自信の所有するアイテムがドラッグをスタートさせたか
|
|
|
|
// (自分自身の階層にドロップできないようにするためのフラグ)
|
2017-02-20 02:02:43 +00:00
|
|
|
this.is-drag-source = false;
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.on('mount', () => {
|
|
|
|
this.refs.uploader.on('uploaded', (file) => {
|
2017-01-11 20:55:38 +00:00
|
|
|
@add-file file, true
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.refs.uploader.on('change-uploads', (uploads) => {
|
|
|
|
this.uploads = uploads
|
|
|
|
this.update();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 02:02:43 +00:00
|
|
|
this.stream.on 'drive_file_created' this.on-stream-drive-file-created
|
|
|
|
this.stream.on 'drive_file_updated' this.on-stream-drive-file-updated
|
|
|
|
this.stream.on 'drive_folder_created' this.on-stream-drive-folder-created
|
|
|
|
this.stream.on 'drive_folder_updated' this.on-stream-drive-folder-updated
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// Riotのバグでnullを渡しても""になる
|
|
|
|
// https://github.com/riot/riot/issues/2080
|
|
|
|
#if this.opts.folder?
|
|
|
|
if this.opts.folder? and this.opts.folder != ''
|
|
|
|
@move this.opts.folder
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
|
|
|
@load!
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.on('unmount', () => {
|
2017-02-20 02:02:43 +00:00
|
|
|
this.stream.off 'drive_file_created' this.on-stream-drive-file-created
|
|
|
|
this.stream.off 'drive_file_updated' this.on-stream-drive-file-updated
|
|
|
|
this.stream.off 'drive_folder_created' this.on-stream-drive-folder-created
|
|
|
|
this.stream.off 'drive_folder_updated' this.on-stream-drive-folder-updated
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.on-stream-drive-file-created = (file) => {
|
2016-12-28 22:49:51 +00:00
|
|
|
@add-file file, true
|
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.on-stream-drive-file-updated = (file) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
current = if this.folder? then this.folder.id else null
|
2017-01-11 20:55:38 +00:00
|
|
|
if current != file.folder_id
|
|
|
|
@remove-file file
|
|
|
|
else
|
|
|
|
@add-file file, true
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.on-stream-drive-folder-created = (folder) => {
|
2016-12-28 22:49:51 +00:00
|
|
|
@add-folder folder, true
|
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.on-stream-drive-folder-updated = (folder) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
current = if this.folder? then this.folder.id else null
|
2017-01-11 20:55:38 +00:00
|
|
|
if current != folder.parent_id
|
|
|
|
@remove-folder folder
|
|
|
|
else
|
|
|
|
@add-folder folder, true
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.onmousedown = (e) => {
|
2017-02-20 00:53:57 +00:00
|
|
|
if (contains this.refs.folders-container, e.target) or (contains this.refs.files-container, e.target)
|
2017-01-11 20:55:38 +00:00
|
|
|
return true
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
rect = this.refs.main.get-bounding-client-rect!
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 02:02:43 +00:00
|
|
|
left = e.pageX + this.refs.main.scroll-left - rect.left - window.pageXOffset
|
|
|
|
top = e.pageY + this.refs.main.scroll-top - rect.top - window.pageYOffset
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
move = (e) =>
|
|
|
|
this.refs.selection.style.display = 'block'
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 02:02:43 +00:00
|
|
|
cursorX = e.pageX + this.refs.main.scroll-left - rect.left - window.pageXOffset
|
|
|
|
cursorY = e.pageY + this.refs.main.scroll-top - rect.top - window.pageYOffset
|
|
|
|
w = cursorX - left
|
|
|
|
h = cursorY - top
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
if w > 0
|
2017-02-20 00:53:57 +00:00
|
|
|
this.refs.selection.style.width = w + 'px'
|
|
|
|
this.refs.selection.style.left = left + 'px'
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
2017-02-20 00:53:57 +00:00
|
|
|
this.refs.selection.style.width = -w + 'px'
|
2017-02-20 02:02:43 +00:00
|
|
|
this.refs.selection.style.left = cursorX + 'px'
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
if h > 0
|
2017-02-20 00:53:57 +00:00
|
|
|
this.refs.selection.style.height = h + 'px'
|
|
|
|
this.refs.selection.style.top = top + 'px'
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
2017-02-20 00:53:57 +00:00
|
|
|
this.refs.selection.style.height = -h + 'px'
|
2017-02-20 02:02:43 +00:00
|
|
|
this.refs.selection.style.top = cursorY + 'px'
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
up = (e) =>
|
2017-02-20 01:34:57 +00:00
|
|
|
document.document-element.removeEventListener 'mousemove' move
|
|
|
|
document.document-element.removeEventListener 'mouseup' up
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.refs.selection.style.display = 'none'
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
document.document-element.addEventListener 'mousemove' move
|
|
|
|
document.document-element.addEventListener 'mouseup' up
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.path-oncontextmenu = (e) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
e.preventDefault();
|
2017-02-20 02:02:43 +00:00
|
|
|
e.stopImmediatePropagation();
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondragover = (e) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// ドラッグ元が自分自身の所有するアイテムかどうか
|
2017-01-11 20:55:38 +00:00
|
|
|
if !@is-drag-source
|
2017-02-20 00:53:57 +00:00
|
|
|
// ドラッグされてきたものがファイルだったら
|
2017-02-20 02:02:43 +00:00
|
|
|
if e.dataTransfer.effectAllowed == 'all'
|
2017-02-20 01:27:44 +00:00
|
|
|
e.dataTransfer.dropEffect = 'copy'
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
2017-02-20 01:27:44 +00:00
|
|
|
e.dataTransfer.dropEffect = 'move'
|
2017-02-20 00:53:57 +00:00
|
|
|
this.draghover = true
|
2016-12-28 22:49:51 +00:00
|
|
|
else
|
2017-02-20 00:53:57 +00:00
|
|
|
// 自分自身にはドロップさせない
|
2017-02-20 01:27:44 +00:00
|
|
|
e.dataTransfer.dropEffect = 'none'
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondragenter = (e) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
e.preventDefault();
|
2017-01-11 20:55:38 +00:00
|
|
|
if !@is-drag-source
|
2017-02-20 00:53:57 +00:00
|
|
|
this.draghover = true
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondragleave = (e) => {
|
2017-02-20 00:53:57 +00:00
|
|
|
this.draghover = false
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.ondrop = (e) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.draghover = false
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// ドロップされてきたものがファイルだったら
|
2017-02-20 01:27:44 +00:00
|
|
|
if e.dataTransfer.files.length > 0
|
2017-02-20 02:02:43 +00:00
|
|
|
Array.prototype.forEach.call e.dataTransfer.files, (file) =>
|
2017-02-20 01:27:44 +00:00
|
|
|
@upload file, this.folder
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// データ取得
|
2017-02-20 01:27:44 +00:00
|
|
|
data = e.dataTransfer.get-data 'text'
|
2017-01-11 20:55:38 +00:00
|
|
|
if !data?
|
|
|
|
return false
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// パース
|
2017-01-11 20:55:38 +00:00
|
|
|
obj = JSON.parse data
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// (ドライブの)ファイルだったら
|
|
|
|
if obj.type == 'file'
|
2017-01-11 20:55:38 +00:00
|
|
|
file = obj.id
|
2017-02-20 01:27:44 +00:00
|
|
|
if (this.files.some (f) => f.id == file)
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
|
|
|
@remove-file file
|
2017-02-20 07:09:46 +00:00
|
|
|
this.api('drive/files/update', {
|
2017-01-11 20:55:38 +00:00
|
|
|
file_id: file
|
2017-02-20 01:27:44 +00:00
|
|
|
folder_id: if this.folder? then this.folder.id else null
|
2017-02-20 00:53:57 +00:00
|
|
|
.then =>
|
|
|
|
// something
|
|
|
|
.catch (err, text-status) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
console.error err
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// (ドライブの)フォルダーだったら
|
|
|
|
else if obj.type == 'folder'
|
2017-01-11 20:55:38 +00:00
|
|
|
folder = obj.id
|
2017-02-20 00:53:57 +00:00
|
|
|
// 移動先が自分自身ならreject
|
2017-02-20 01:27:44 +00:00
|
|
|
if this.folder? and folder == this.folder.id
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
2017-02-20 01:27:44 +00:00
|
|
|
if (this.folders.some (f) => f.id == folder)
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
|
|
|
@remove-folder folder
|
2017-02-20 07:09:46 +00:00
|
|
|
this.api('drive/folders/update', {
|
2017-01-11 20:55:38 +00:00
|
|
|
folder_id: folder
|
2017-02-20 01:27:44 +00:00
|
|
|
parent_id: if this.folder? then this.folder.id else null
|
2017-02-20 00:53:57 +00:00
|
|
|
.then =>
|
|
|
|
// something
|
|
|
|
.catch (err) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
if err == 'detected-circular-definition'
|
|
|
|
@dialog do
|
|
|
|
'<i class="fa fa-exclamation-triangle"></i>操作を完了できません'
|
|
|
|
'移動先のフォルダーは、移動するフォルダーのサブフォルダーです。'
|
|
|
|
[
|
2017-02-20 00:53:57 +00:00
|
|
|
text: 'OK'
|
2017-01-11 20:55:38 +00:00
|
|
|
]
|
2016-12-28 22:49:51 +00:00
|
|
|
|
|
|
|
return false
|
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.oncontextmenu = (e) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
e.preventDefault();
|
2017-02-20 02:02:43 +00:00
|
|
|
e.stopImmediatePropagation();
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 07:09:46 +00:00
|
|
|
ctx = document.body.appendChild(document.createElement('mk-drive-browser-base-contextmenu'));
|
|
|
|
ctx = riot.mount ctx, do
|
2017-02-20 02:02:43 +00:00
|
|
|
browser: this
|
2017-01-11 20:55:38 +00:00
|
|
|
ctx = ctx.0
|
|
|
|
ctx.open do
|
2017-02-20 02:02:43 +00:00
|
|
|
x: e.pageX - window.pageXOffset
|
|
|
|
y: e.pageY - window.pageYOffset
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2016-12-28 22:49:51 +00:00
|
|
|
return false
|
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.select-local-file = () => {
|
2017-02-20 02:02:43 +00:00
|
|
|
this.refs.file-input.click();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.url-upload = () => {
|
2017-02-16 20:46:14 +00:00
|
|
|
url <~ @input-dialog do
|
|
|
|
'URLアップロード'
|
|
|
|
'アップロードしたいファイルのURL'
|
|
|
|
null
|
|
|
|
|
|
|
|
if url? and url != ''
|
2017-02-20 07:09:46 +00:00
|
|
|
this.api('drive/files/upload_from_url', {
|
2017-02-16 20:46:14 +00:00
|
|
|
url: url
|
2017-02-20 01:27:44 +00:00
|
|
|
folder_id: if this.folder? then this.folder.id else undefined
|
2017-02-16 20:46:14 +00:00
|
|
|
|
|
|
|
@dialog do
|
|
|
|
'<i class="fa fa-check"></i>アップロードをリクエストしました'
|
|
|
|
'アップロードが完了するまで時間がかかる場合があります。'
|
|
|
|
[
|
2017-02-20 00:53:57 +00:00
|
|
|
text: 'OK'
|
2017-02-16 20:46:14 +00:00
|
|
|
]
|
|
|
|
|
2017-02-20 07:09:46 +00:00
|
|
|
this.createFolder = () => {
|
2017-01-11 20:55:38 +00:00
|
|
|
name <~ @input-dialog do
|
|
|
|
'フォルダー作成'
|
|
|
|
'フォルダー名'
|
|
|
|
null
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 07:09:46 +00:00
|
|
|
this.api('drive/folders/create', {
|
2017-01-11 20:55:38 +00:00
|
|
|
name: name
|
2017-02-20 01:27:44 +00:00
|
|
|
folder_id: if this.folder? then this.folder.id else undefined
|
2017-02-20 07:09:46 +00:00
|
|
|
}).then((folder) => {
|
2017-01-11 20:55:38 +00:00
|
|
|
@add-folder folder, true
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
|
|
|
.catch (err) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
console.error err
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.change-file-input = () => {
|
2017-02-20 00:53:57 +00:00
|
|
|
files = this.refs.file-input.files
|
2017-01-11 20:55:38 +00:00
|
|
|
for i from 0 to files.length - 1
|
|
|
|
file = files.item i
|
2017-02-20 01:27:44 +00:00
|
|
|
@upload file, this.folder
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.upload = (file, folder) => {
|
2017-02-20 00:53:57 +00:00
|
|
|
if folder? and typeof folder == 'object'
|
2017-01-11 20:55:38 +00:00
|
|
|
folder = folder.id
|
2017-02-20 00:53:57 +00:00
|
|
|
this.refs.uploader.upload file, folder
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.get-selection = () => {
|
2017-02-20 01:27:44 +00:00
|
|
|
this.files.filter (file) -> file._selected
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 07:09:46 +00:00
|
|
|
this.newWindow = (folder-id) => {
|
|
|
|
browser = document.body.appendChild(document.createElement('mk-drive-browser-window'));
|
|
|
|
riot.mount browser, do
|
2017-01-11 20:55:38 +00:00
|
|
|
folder: folder-id
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.move = (target-folder) => {
|
2017-02-20 00:53:57 +00:00
|
|
|
if target-folder? and typeof target-folder == 'object'
|
2017-01-11 20:55:38 +00:00
|
|
|
target-folder = target-folder.id
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
if target-folder == null
|
|
|
|
@go-root!
|
|
|
|
return
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.loading = true
|
|
|
|
this.update();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 07:09:46 +00:00
|
|
|
this.api('drive/folders/show', {
|
2017-01-11 20:55:38 +00:00
|
|
|
folder_id: target-folder
|
2017-02-20 07:09:46 +00:00
|
|
|
}).then((folder) => {
|
2017-02-20 00:53:57 +00:00
|
|
|
this.folder = folder
|
2017-02-20 02:02:43 +00:00
|
|
|
this.hierarchyFolders = []
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
x = (f) =>
|
2017-02-20 02:02:43 +00:00
|
|
|
@hierarchyFolders.unshift f
|
2017-01-11 20:55:38 +00:00
|
|
|
if f.parent?
|
|
|
|
x f.parent
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
if folder.parent?
|
|
|
|
x folder.parent
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2017-01-11 20:55:38 +00:00
|
|
|
@load!
|
|
|
|
.catch (err, text-status) ->
|
|
|
|
console.error err
|
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.add-folder = (folder, unshift = false) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
current = if this.folder? then this.folder.id else null
|
2017-01-11 20:55:38 +00:00
|
|
|
if current != folder.parent_id
|
|
|
|
return
|
|
|
|
|
2017-02-20 01:27:44 +00:00
|
|
|
if (this.folders.some (f) => f.id == folder.id)
|
|
|
|
exist = (this.folders.map (f) -> f.id).index-of folder.id
|
|
|
|
this.folders[exist] = folder
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2017-01-11 20:55:38 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if unshift
|
2017-02-20 01:27:44 +00:00
|
|
|
this.folders.unshift folder
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
2017-02-20 01:27:44 +00:00
|
|
|
this.folders.push folder
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.add-file = (file, unshift = false) => {
|
2017-02-20 01:27:44 +00:00
|
|
|
current = if this.folder? then this.folder.id else null
|
2017-01-11 20:55:38 +00:00
|
|
|
if current != file.folder_id
|
|
|
|
return
|
|
|
|
|
2017-02-20 01:27:44 +00:00
|
|
|
if (this.files.some (f) => f.id == file.id)
|
|
|
|
exist = (this.files.map (f) -> f.id).index-of file.id
|
|
|
|
this.files[exist] = file
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2017-01-11 20:55:38 +00:00
|
|
|
return
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
if unshift
|
2017-02-20 01:27:44 +00:00
|
|
|
this.files.unshift file
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
2017-02-20 01:27:44 +00:00
|
|
|
this.files.push file
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.remove-folder = (folder) => {
|
2017-02-20 00:53:57 +00:00
|
|
|
if typeof folder == 'object'
|
2017-01-11 20:55:38 +00:00
|
|
|
folder = folder.id
|
2017-02-20 01:27:44 +00:00
|
|
|
this.folders = this.folders.filter (f) -> f.id != folder
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2017-01-11 20:55:38 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.remove-file = (file) => {
|
2017-02-20 00:53:57 +00:00
|
|
|
if typeof file == 'object'
|
2017-01-11 20:55:38 +00:00
|
|
|
file = file.id
|
2017-02-20 01:27:44 +00:00
|
|
|
this.files = this.files.filter (f) -> f.id != file
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.go-root = () => {
|
2017-02-20 01:27:44 +00:00
|
|
|
if this.folder != null
|
2017-02-20 00:53:57 +00:00
|
|
|
this.folder = null
|
2017-02-20 02:02:43 +00:00
|
|
|
this.hierarchyFolders = []
|
2017-02-20 00:53:57 +00:00
|
|
|
this.update();
|
2017-01-11 20:55:38 +00:00
|
|
|
@load!
|
|
|
|
|
2017-02-20 01:34:57 +00:00
|
|
|
this.load = () => {
|
2017-02-20 00:53:57 +00:00
|
|
|
this.folders = []
|
|
|
|
this.files = []
|
|
|
|
this.more-folders = false
|
|
|
|
this.more-files = false
|
|
|
|
this.loading = true
|
|
|
|
this.update();
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2017-01-11 20:55:38 +00:00
|
|
|
load-folders = null
|
|
|
|
load-files = null
|
|
|
|
|
|
|
|
folders-max = 30
|
|
|
|
files-max = 30
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// フォルダ一覧取得
|
2017-02-20 07:09:46 +00:00
|
|
|
this.api('drive/folders', {
|
2017-02-20 01:27:44 +00:00
|
|
|
folder_id: if this.folder? then this.folder.id else null
|
2017-01-11 20:55:38 +00:00
|
|
|
limit: folders-max + 1
|
2017-02-20 07:09:46 +00:00
|
|
|
}).then((folders) => {
|
2017-01-11 20:55:38 +00:00
|
|
|
if folders.length == folders-max + 1
|
2017-02-20 00:53:57 +00:00
|
|
|
this.more-folders = true
|
2017-01-11 20:55:38 +00:00
|
|
|
folders.pop!
|
|
|
|
load-folders := folders
|
|
|
|
complete!
|
2017-02-20 00:53:57 +00:00
|
|
|
.catch (err, text-status) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
console.error err
|
|
|
|
|
2017-02-20 00:53:57 +00:00
|
|
|
// ファイル一覧取得
|
2017-02-20 07:09:46 +00:00
|
|
|
this.api('drive/files', {
|
2017-02-20 01:27:44 +00:00
|
|
|
folder_id: if this.folder? then this.folder.id else null
|
2017-01-11 20:55:38 +00:00
|
|
|
limit: files-max + 1
|
2017-02-20 07:09:46 +00:00
|
|
|
}).then((files) => {
|
2017-01-11 20:55:38 +00:00
|
|
|
if files.length == files-max + 1
|
2017-02-20 00:53:57 +00:00
|
|
|
this.more-files = true
|
2017-01-11 20:55:38 +00:00
|
|
|
files.pop!
|
|
|
|
load-files := files
|
|
|
|
complete!
|
2017-02-20 00:53:57 +00:00
|
|
|
.catch (err, text-status) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
console.error err
|
|
|
|
|
|
|
|
flag = false
|
2017-02-20 00:53:57 +00:00
|
|
|
complete = =>
|
2017-01-11 20:55:38 +00:00
|
|
|
if flag
|
2017-02-20 02:02:43 +00:00
|
|
|
load-folders.forEach (folder) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
@add-folder folder
|
2017-02-20 02:02:43 +00:00
|
|
|
load-files.forEach (file) =>
|
2017-01-11 20:55:38 +00:00
|
|
|
@add-file file
|
2017-02-20 00:53:57 +00:00
|
|
|
this.loading = false
|
|
|
|
this.update();
|
2017-01-11 20:55:38 +00:00
|
|
|
else
|
|
|
|
flag := true
|
|
|
|
|
|
|
|
function contains(parent, child)
|
2017-02-20 01:27:44 +00:00
|
|
|
node = child.parentNode
|
2017-01-11 20:55:38 +00:00
|
|
|
while node?
|
|
|
|
if node == parent
|
|
|
|
return true
|
2017-02-20 01:27:44 +00:00
|
|
|
node = node.parentNode
|
2017-01-11 20:55:38 +00:00
|
|
|
return false
|
|
|
|
</script>
|
|
|
|
</mk-drive-browser>
|