mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-12 04:01:00 +01:00
wip
This commit is contained in:
parent
0ecd0dc1a1
commit
c5a26efda4
11 changed files with 118 additions and 117 deletions
|
@ -142,54 +142,57 @@
|
|||
<script>
|
||||
this.mixin('i');
|
||||
|
||||
this.uploads = []
|
||||
this.uploads = [];
|
||||
|
||||
|
||||
this.upload = (file, folder) => {
|
||||
id = Math.random!
|
||||
const id = Math.random();
|
||||
|
||||
ctx =
|
||||
id: id
|
||||
name: file.name || 'untitled'
|
||||
const ctx = {
|
||||
id: id,
|
||||
name: file.name || 'untitled',
|
||||
progress: undefined
|
||||
};
|
||||
|
||||
@uploads.push ctx
|
||||
this.trigger 'change-uploads' @uploads
|
||||
this.uploads.push(ctx);
|
||||
this.trigger('change-uploads', this.uploads);
|
||||
this.update();
|
||||
|
||||
reader = new FileReader!
|
||||
reader.onload = (e) =>
|
||||
ctx.img = e.target.result
|
||||
const reader = new FileReader();
|
||||
reader.onload = e => {
|
||||
ctx.img = e.target.result;
|
||||
this.update();
|
||||
reader.read-as-data-URL file
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
data = new FormData!
|
||||
data.append 'i' this.I.token
|
||||
data.append 'file' file
|
||||
const data = new FormData();
|
||||
data.append('i', this.I.token);
|
||||
data.append('file', file);
|
||||
|
||||
if folder?
|
||||
data.append 'folder_id' folder
|
||||
if (folder) data.append('folder_id', folder);
|
||||
|
||||
xhr = new XMLHttpRequest!
|
||||
xhr.open 'POST' CONFIG.apiUrl + '/drive/files/create' true
|
||||
xhr.onload = (e) =>
|
||||
drive-file = JSON.parse e.target.response
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', CONFIG.apiUrl + '/drive/files/create', true);
|
||||
xhr.onload = e => {
|
||||
const driveFile = JSON.parse(e.target.response);
|
||||
|
||||
this.trigger 'uploaded' drive-file
|
||||
this.trigger('uploaded', driveFile);
|
||||
|
||||
this.uploads = @uploads.filter (x) -> x.id != id
|
||||
this.trigger 'change-uploads' @uploads
|
||||
this.uploads = this.uploads.filter(x => x.id != id);
|
||||
this.trigger('change-uploads', this.uploads);
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
xhr.upload.onprogress = (e) =>
|
||||
if e.length-computable
|
||||
if ctx.progress == undefined
|
||||
ctx.progress = {}
|
||||
ctx.progress.max = e.total
|
||||
ctx.progress.value = e.loaded
|
||||
xhr.upload.onprogress = e => {
|
||||
if (e.lengthComputable) {
|
||||
if (ctx.progress == undefined) ctx.progress = {};
|
||||
ctx.progress.max = e.total;
|
||||
ctx.progress.value = e.loaded;
|
||||
this.update();
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send data
|
||||
xhr.send(data);
|
||||
};
|
||||
</script>
|
||||
</mk-uploader>
|
||||
|
|
|
@ -238,6 +238,8 @@
|
|||
|
||||
</style>
|
||||
<script>
|
||||
const contains = require('../../../common/scripts/contains');
|
||||
|
||||
this.mixin('api');
|
||||
this.mixin('dialog');
|
||||
this.mixin('input-dialog');
|
||||
|
@ -253,67 +255,70 @@
|
|||
// * null でルートを表す
|
||||
this.folder = null;
|
||||
|
||||
this.multiple = if this.opts.multiple? then this.opts.multiple else false
|
||||
this.multiple = this.opts.multiple != null ? this.opts.multiple : false;
|
||||
|
||||
// ドロップされようとしているか
|
||||
this.draghover = false;
|
||||
|
||||
// 自信の所有するアイテムがドラッグをスタートさせたか
|
||||
// (自分自身の階層にドロップできないようにするためのフラグ)
|
||||
this.is-drag-source = false;
|
||||
this.isDragSource = false;
|
||||
|
||||
this.on('mount', () => {
|
||||
this.refs.uploader.on('uploaded', (file) => {
|
||||
@add-file file, true
|
||||
this.refs.uploader.on('uploaded', file => {
|
||||
this.addFile(file, true);
|
||||
});
|
||||
|
||||
this.refs.uploader.on('change-uploads', (uploads) => {
|
||||
this.uploads = uploads
|
||||
this.update();
|
||||
this.refs.uploader.on('change-uploads', uploads => {
|
||||
this.update({
|
||||
uploads: uploads
|
||||
});
|
||||
});
|
||||
|
||||
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
|
||||
this.stream.on 'drive_file_created' this.onStreamDriveFileCreated
|
||||
this.stream.on 'drive_file_updated' this.onStreamDriveFileUpdated
|
||||
this.stream.on 'drive_folder_created' this.onStreamDriveFolderCreated
|
||||
this.stream.on 'drive_folder_updated' this.onStreamDriveFolderUpdated
|
||||
|
||||
// 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
|
||||
this.move this.opts.folder
|
||||
else
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.on('unmount', () => {
|
||||
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
|
||||
this.stream.off 'drive_file_created' this.onStreamDriveFileCreated
|
||||
this.stream.off 'drive_file_updated' this.onStreamDriveFileUpdated
|
||||
this.stream.off 'drive_folder_created' this.onStreamDriveFolderCreated
|
||||
this.stream.off 'drive_folder_updated' this.onStreamDriveFolderUpdated
|
||||
|
||||
this.on-stream-drive-file-created = (file) => {
|
||||
@add-file file, true
|
||||
this.onStreamDriveFileCreated = (file) => {
|
||||
this.addFile file, true
|
||||
|
||||
this.on-stream-drive-file-updated = (file) => {
|
||||
this.onStreamDriveFileUpdated = (file) => {
|
||||
current = if this.folder? then this.folder.id else null
|
||||
if current != file.folder_id
|
||||
@remove-file file
|
||||
else
|
||||
@add-file file, true
|
||||
this.addFile file, true
|
||||
|
||||
this.on-stream-drive-folder-created = (folder) => {
|
||||
@add-folder folder, true
|
||||
this.onStreamDriveFolderCreated = (folder) => {
|
||||
this.addFolder folder, true
|
||||
|
||||
this.on-stream-drive-folder-updated = (folder) => {
|
||||
this.onStreamDriveFolderUpdated = (folder) => {
|
||||
current = if this.folder? then this.folder.id else null
|
||||
if current != folder.parent_id
|
||||
@remove-folder folder
|
||||
this.removeFolder folder
|
||||
else
|
||||
@add-folder folder, true
|
||||
this.addFolder folder, true
|
||||
|
||||
this.onmousedown = (e) => {
|
||||
if (contains this.refs.folders-container, e.target) or (contains this.refs.files-container, e.target)
|
||||
return true
|
||||
|
||||
rect = this.refs.main.get-bounding-client-rect!
|
||||
rect = this.refs.main.getBoundingClientRect();
|
||||
|
||||
left = e.pageX + this.refs.main.scroll-left - rect.left - window.pageXOffset
|
||||
top = e.pageY + this.refs.main.scroll-top - rect.top - window.pageYOffset
|
||||
|
@ -341,13 +346,13 @@
|
|||
this.refs.selection.style.top = cursorY + 'px'
|
||||
|
||||
up = (e) =>
|
||||
document.document-element.removeEventListener 'mousemove' move
|
||||
document.document-element.removeEventListener 'mouseup' up
|
||||
document.documentElement.removeEventListener 'mousemove' move
|
||||
document.documentElement.removeEventListener 'mouseup' up
|
||||
|
||||
this.refs.selection.style.display = 'none'
|
||||
|
||||
document.document-element.addEventListener 'mousemove' move
|
||||
document.document-element.addEventListener 'mouseup' up
|
||||
document.documentElement.addEventListener 'mousemove' move
|
||||
document.documentElement.addEventListener 'mouseup' up
|
||||
|
||||
this.path-oncontextmenu = (e) => {
|
||||
e.preventDefault();
|
||||
|
@ -359,7 +364,7 @@
|
|||
e.stopPropagation();
|
||||
|
||||
// ドラッグ元が自分自身の所有するアイテムかどうか
|
||||
if !@is-drag-source
|
||||
if !@isDragSource
|
||||
// ドラッグされてきたものがファイルだったら
|
||||
if e.dataTransfer.effectAllowed == 'all'
|
||||
e.dataTransfer.dropEffect = 'copy'
|
||||
|
@ -373,7 +378,7 @@
|
|||
|
||||
this.ondragenter = (e) => {
|
||||
e.preventDefault();
|
||||
if !@is-drag-source
|
||||
if !@isDragSource
|
||||
this.draghover = true
|
||||
|
||||
this.ondragleave = (e) => {
|
||||
|
@ -421,7 +426,7 @@
|
|||
return false
|
||||
if (this.folders.some (f) => f.id == folder)
|
||||
return false
|
||||
@remove-folder folder
|
||||
this.removeFolder folder
|
||||
this.api('drive/folders/update', {
|
||||
folder_id: folder
|
||||
parent_id: if this.folder? then this.folder.id else null
|
||||
|
@ -483,7 +488,7 @@
|
|||
name: name
|
||||
folder_id: if this.folder? then this.folder.id else undefined
|
||||
}).then((folder) => {
|
||||
@add-folder folder, true
|
||||
this.addFolder folder, true
|
||||
this.update();
|
||||
.catch (err) =>
|
||||
console.error err
|
||||
|
@ -533,7 +538,7 @@
|
|||
x folder.parent
|
||||
|
||||
this.update();
|
||||
@load!
|
||||
this.load();
|
||||
.catch (err, text-status) ->
|
||||
console.error err
|
||||
|
||||
|
@ -590,7 +595,7 @@
|
|||
this.folder = null
|
||||
this.hierarchyFolders = []
|
||||
this.update();
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.load = () => {
|
||||
this.folders = []
|
||||
|
@ -636,20 +641,13 @@
|
|||
complete = =>
|
||||
if flag
|
||||
load-folders.forEach (folder) =>
|
||||
@add-folder folder
|
||||
this.addFolder folder
|
||||
load-files.forEach (file) =>
|
||||
@add-file file
|
||||
this.addFile file
|
||||
this.loading = false
|
||||
this.update();
|
||||
else
|
||||
flag := true
|
||||
|
||||
function contains(parent, child)
|
||||
node = child.parentNode
|
||||
while node?
|
||||
if node == parent
|
||||
return true
|
||||
node = node.parentNode
|
||||
return false
|
||||
</script>
|
||||
</mk-drive-browser>
|
||||
|
|
|
@ -200,10 +200,10 @@
|
|||
|
||||
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
||||
// (=あなたの子供が、ドラッグを開始しましたよ)
|
||||
this.browser.is-drag-source = true
|
||||
this.browser.isDragSource = true
|
||||
|
||||
this.ondragend = (e) => {
|
||||
this.is-dragging = false
|
||||
this.browser.is-drag-source = false
|
||||
this.browser.isDragSource = false
|
||||
</script>
|
||||
</mk-drive-browser-file>
|
||||
|
|
|
@ -155,11 +155,11 @@
|
|||
|
||||
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
||||
// (=あなたの子供が、ドラッグを開始しましたよ)
|
||||
this.browser.is-drag-source = true
|
||||
this.browser.isDragSource = true
|
||||
|
||||
this.ondragend = (e) => {
|
||||
this.is-dragging = false
|
||||
this.browser.is-drag-source = false
|
||||
this.browser.isDragSource = false
|
||||
|
||||
this.oncontextmenu = (e) => {
|
||||
e.preventDefault();
|
||||
|
|
|
@ -133,7 +133,7 @@
|
|||
this.page = 0
|
||||
|
||||
this.on('mount', () => {
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.load = () => {
|
||||
this.loading = true
|
||||
|
@ -155,7 +155,7 @@
|
|||
this.page = 0
|
||||
else
|
||||
this.page++
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.close = () => {
|
||||
this.unmount();
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
this.initializing = true
|
||||
|
||||
this.on('mount', () => {
|
||||
this.stream.on 'drive_file_created' this.on-stream-drive-file-created
|
||||
this.stream.on 'drive_file_created' this.onStreamDriveFileCreated
|
||||
|
||||
this.api('drive/stream', {
|
||||
type: 'image/*'
|
||||
|
@ -75,9 +75,9 @@
|
|||
this.update();
|
||||
|
||||
this.on('unmount', () => {
|
||||
this.stream.off 'drive_file_created' this.on-stream-drive-file-created
|
||||
this.stream.off 'drive_file_created' this.onStreamDriveFileCreated
|
||||
|
||||
this.on-stream-drive-file-created = (file) => {
|
||||
this.onStreamDriveFileCreated = (file) => {
|
||||
if /^image\/.+$/.test file.type
|
||||
@images.unshift file
|
||||
if @images.length > 9
|
||||
|
|
|
@ -98,10 +98,10 @@
|
|||
this.refs.timeline.add-post post
|
||||
|
||||
this.on-stream-follow = () => {
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.on-stream-unfollow = () => {
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.on-scroll = () => {
|
||||
current = window.scrollY + window.inner-height
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
this.image = @images.0
|
||||
|
||||
this.mousemove = (e) => {
|
||||
rect = this.refs.view.get-bounding-client-rect!
|
||||
rect = this.refs.view.getBoundingClientRect();
|
||||
mouse-x = e.client-x - rect.left
|
||||
mouse-y = e.client-y - rect.top
|
||||
xp = mouse-x / this.refs.view.offset-width * 100
|
||||
|
|
|
@ -324,7 +324,7 @@
|
|||
|
||||
this.on('mount', () => {
|
||||
this.refs.uploader.on('uploaded', (file) => {
|
||||
@add-file file
|
||||
this.addFile file
|
||||
|
||||
this.refs.uploader.on('change-uploads', (uploads) => {
|
||||
this.trigger 'change-uploading-files' uploads
|
||||
|
@ -382,7 +382,7 @@
|
|||
|
||||
// (ドライブの)ファイルだったら
|
||||
if obj.type == 'file'
|
||||
@add-file obj.file
|
||||
this.addFile obj.file
|
||||
catch
|
||||
// ignore
|
||||
|
||||
|
@ -409,7 +409,7 @@
|
|||
i = riot.mount browser, do
|
||||
multiple: true
|
||||
i[0].one 'selected' (files) =>
|
||||
files.forEach @add-file
|
||||
files.forEach this.addFile
|
||||
|
||||
this.change-file = () => {
|
||||
files = this.refs.file.files
|
||||
|
|
|
@ -146,10 +146,10 @@
|
|||
this.multiple = if this.opts.multiple? then this.opts.multiple else false
|
||||
|
||||
this.on('mount', () => {
|
||||
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
|
||||
this.stream.on 'drive_file_created' this.onStreamDriveFileCreated
|
||||
this.stream.on 'drive_file_updated' this.onStreamDriveFileUpdated
|
||||
this.stream.on 'drive_folder_created' this.onStreamDriveFolderCreated
|
||||
this.stream.on 'drive_folder_updated' this.onStreamDriveFolderUpdated
|
||||
|
||||
// Riotのバグでnullを渡しても""になる
|
||||
// https://github.com/riot/riot/issues/2080
|
||||
|
@ -159,36 +159,36 @@
|
|||
else if this.opts.file? and this.opts.file != ''
|
||||
@cf this.opts.file, true
|
||||
else
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.on('unmount', () => {
|
||||
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
|
||||
this.stream.off 'drive_file_created' this.onStreamDriveFileCreated
|
||||
this.stream.off 'drive_file_updated' this.onStreamDriveFileUpdated
|
||||
this.stream.off 'drive_folder_created' this.onStreamDriveFolderCreated
|
||||
this.stream.off 'drive_folder_updated' this.onStreamDriveFolderUpdated
|
||||
|
||||
this.on-stream-drive-file-created = (file) => {
|
||||
@add-file file, true
|
||||
this.onStreamDriveFileCreated = (file) => {
|
||||
this.addFile file, true
|
||||
|
||||
this.on-stream-drive-file-updated = (file) => {
|
||||
this.onStreamDriveFileUpdated = (file) => {
|
||||
current = if this.folder? then this.folder.id else null
|
||||
if current != file.folder_id
|
||||
@remove-file file
|
||||
else
|
||||
@add-file file, true
|
||||
this.addFile file, true
|
||||
|
||||
this.on-stream-drive-folder-created = (folder) => {
|
||||
@add-folder folder, true
|
||||
this.onStreamDriveFolderCreated = (folder) => {
|
||||
this.addFolder folder, true
|
||||
|
||||
this.on-stream-drive-folder-updated = (folder) => {
|
||||
this.onStreamDriveFolderUpdated = (folder) => {
|
||||
current = if this.folder? then this.folder.id else null
|
||||
if current != folder.parent_id
|
||||
@remove-folder folder
|
||||
this.removeFolder folder
|
||||
else
|
||||
@add-folder folder, true
|
||||
this.addFolder folder, true
|
||||
|
||||
@_move = (ev) =>
|
||||
@move ev.item.folder
|
||||
this.move ev.item.folder
|
||||
|
||||
this.move = (target-folder) => {
|
||||
@cd target-folder
|
||||
|
@ -222,7 +222,7 @@
|
|||
|
||||
this.update();
|
||||
this.trigger 'open-folder' this.folder, silent
|
||||
@load!
|
||||
this.load();
|
||||
.catch (err, text-status) ->
|
||||
console.error err
|
||||
|
||||
|
@ -278,7 +278,7 @@
|
|||
this.hierarchyFolders = []
|
||||
this.update();
|
||||
this.trigger('move-root');
|
||||
@load!
|
||||
this.load();
|
||||
|
||||
this.load = () => {
|
||||
this.folders = []
|
||||
|
@ -326,9 +326,9 @@
|
|||
complete = =>
|
||||
if flag
|
||||
load-folders.forEach (folder) =>
|
||||
@add-folder folder
|
||||
this.addFolder folder
|
||||
load-files.forEach (file) =>
|
||||
@add-file file
|
||||
this.addFile file
|
||||
this.loading = false
|
||||
this.update();
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@
|
|||
|
||||
this.on('mount', () => {
|
||||
this.refs.uploader.on('uploaded', (file) => {
|
||||
@add-file file
|
||||
this.addFile file
|
||||
|
||||
this.refs.uploader.on('change-uploads', (uploads) => {
|
||||
this.trigger 'change-uploading-files' uploads
|
||||
|
@ -225,7 +225,7 @@
|
|||
multiple: true
|
||||
.0
|
||||
browser.on('selected', (files) => {
|
||||
files.forEach @add-file
|
||||
files.forEach this.addFile
|
||||
|
||||
this.change-file = () => {
|
||||
files = this.refs.file.files
|
||||
|
|
Loading…
Reference in a new issue