architecture too complex

This commit is contained in:
Jörn Friedrich Dreyer 2013-08-21 14:58:28 +02:00
parent f94e603698
commit bf04daff82
7 changed files with 934 additions and 339 deletions

@ -1 +1 @@
Subproject commit 2f3ae9f56a9838b45254393e13c14f8a8c380d6b
Subproject commit 75a05d76ab86ba7454b4312fd0ff2ca5bd5828cf

View File

@ -1,4 +1,7 @@
/**
*
* use put t ocacnel upload before it starts? use chunked uploads?
*
* 1. tracking which file to upload next -> upload queue with data elements added whenever add is called
* 2. tracking progress for each folder individually -> track progress in a progress[dirname] object
* - every new selection increases the total size and number of files for a directory
@ -63,6 +66,7 @@ OC.Upload = {
* @type Array
*/
_selections: {},
_selectionCount: 0,
/*
* queue which progress tracker to use for the next upload
* @type Array
@ -77,7 +81,7 @@ OC.Upload = {
},
getSelection:function(originalFiles) {
if (!originalFiles.selectionKey) {
originalFiles.selectionKey = 'selection-' + $.assocArraySize(this._selections);
originalFiles.selectionKey = 'selection-' + this._selectionCount++;
this._selections[originalFiles.selectionKey] = {
selectionKey:originalFiles.selectionKey,
files:{},
@ -90,22 +94,41 @@ OC.Upload = {
}
return this._selections[originalFiles.selectionKey];
},
deleteSelection:function(selectionKey) {
if (this._selections[selectionKey]) {
jQuery.each(this._selections[selectionKey].uploads, function(i, upload) {
upload.abort();
});
delete this._selections[selectionKey];
} else {
console.log('OC.Upload: selection ' + selectionKey + ' does not exist');
}
},
deleteSelectionUpload:function(selection, filename) {
if(selection.uploads[filename]) {
selection.uploads[filename].abort();
return true;
} else {
console.log('OC.Upload: selection ' + selection.selectionKey + ' does not contain upload for ' + filename);
}
return false;
},
cancelUpload:function(dir, filename) {
var self = this;
var deleted = false;
jQuery.each(this._selections, function(i, selection) {
if (selection.dir === dir && selection.uploads[filename]) {
delete selection.uploads[filename];
deleted = true;
deleted = self.deleteSelectionUpload(selection, filename);
return false; // end searching through selections
}
});
return deleted;
},
cancelUploads:function() {
jQuery.each(this._selections,function(i,selection){
jQuery.each(selection.uploads, function (j, jqXHR) {
delete jqXHR;
});
console.log('canceling uploads');
var self = this;
jQuery.each(this._selections,function(i, selection){
self.deleteSelection(selection.selectionKey);
});
this._queue = [];
this._isProcessing = false;
@ -132,7 +155,7 @@ OC.Upload = {
} else {
//queue is empty, we are done
this._isProcessing = false;
//TODO free data
OC.Upload.cancelUploads();
}
},
progressBytes: function() {
@ -157,13 +180,13 @@ OC.Upload = {
total += selection.totalBytes;
});
return total;
},
handleExists:function(data) {
},
onCancel:function(data){
//TODO cancel all uploads
OC.Upload.cancelUploads();
//TODO cancel all uploads of this selection
var selection = this.getSelection(data.originalFiles);
OC.Upload.deleteSelection(selection.selectionKey);
//FIXME hide progressbar
},
onSkip:function(data){
var selection = this.getSelection(data.originalFiles);
@ -171,20 +194,19 @@ OC.Upload = {
this.nextUpload();
},
onReplace:function(data){
//TODO overwrite file
data.data.append('replace', true);
data.submit();
},
onRename:function(data, newName){
//TODO rename file in filelist, stop spinner
data.data.append('newname', newName);
data.submit();
},
setAction:function(data, action) {
},
setDefaultAction:function(action) {
logStatus:function(caption, e, data) {
console.log(caption+' ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
if (data) {
console.log(data);
}
console.log(e);
}
};
@ -195,6 +217,7 @@ $(document).ready(function() {
//singleFileUploads is on by default, so the data.files array will always have length 1
add: function(e, data) {
OC.Upload.logStatus('add', e, data);
var that = $(this);
// lookup selection for dir
@ -267,14 +290,17 @@ $(document).ready(function() {
* @param e
*/
start: function(e) {
OC.Upload.logStatus('start', e, null);
//IE < 10 does not fire the necessary events for the progress bar.
if($('html.lte9').length > 0) {
return true;
}
$('#uploadprogresswrapper input.stop').show();
$('#uploadprogressbar').progressbar({value:0});
$('#uploadprogressbar').fadeIn();
},
fail: function(e, data) {
OC.Upload.logStatus('fail', e, data);
if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) {
if (data.textStatus === 'abort') {
$('#notification').text(t('files', 'Upload cancelled.'));
@ -289,12 +315,26 @@ $(document).ready(function() {
}, 5000);
}
var selection = OC.Upload.getSelection(data.originalFiles);
delete selection.uploads[data.files[0]];
OC.Upload.deleteSelectionUpload(selection, data.files[0].name);
//if user pressed cancel hide upload progress bar and cancel button
if (data.errorThrown === 'abort') {
$('#uploadprogresswrapper input.stop').fadeOut();
$('#uploadprogressbar').fadeOut();
}
},
progress: function(e, data) {
OC.Upload.logStatus('progress', e, data);
// TODO: show nice progress bar in file row
},
/**
*
* @param {type} e
* @param {type} data (only has loaded, total and lengthComputable)
* @returns {unresolved}
*/
progressall: function(e, data) {
OC.Upload.logStatus('progressall', e, data);
//IE < 10 does not fire the necessary events for the progress bar.
if($('html.lte9').length > 0) {
return;
@ -309,6 +349,7 @@ $(document).ready(function() {
* @param data
*/
done:function(e, data) {
OC.Upload.logStatus('done', e, data);
// handle different responses (json or body from iframe for ie)
var response;
if (typeof data.result === 'string') {
@ -323,7 +364,9 @@ $(document).ready(function() {
if(typeof result[0] !== 'undefined'
&& result[0].status === 'success'
) {
selection.loadedBytes+=data.loaded;
if (selection) {
selection.loadedBytes+=data.loaded;
}
OC.Upload.nextUpload();
} else {
if (result[0].status === 'existserror') {
@ -333,13 +376,19 @@ $(document).ready(function() {
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
OC.dialogs.fileexists(data, original, replacement, OC.Upload, fu);
} else {
delete selection.uploads[data.files[0]];
OC.Upload.deleteSelectionUpload(selection, data.files[0].name);
data.textStatus = 'servererror';
data.errorThrown = t('files', result.data.message);
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
fu._trigger('fail', e, data);
}
}
//if user pressed cancel hide upload chrome
if (! OC.Upload.isProcessing()) {
$('#uploadprogresswrapper input.stop').fadeOut();
$('#uploadprogressbar').fadeOut();
}
},
/**
@ -348,7 +397,10 @@ $(document).ready(function() {
* @param data
*/
stop: function(e, data) {
if(OC.Upload.progressBytes()>=100) {
OC.Upload.logStatus('stop', e, data);
if(OC.Upload.progressBytes()>=100) { //only hide controls when all selections have ended uploading
OC.Upload.cancelUploads(); //cleanup
if(data.dataType !== 'iframe') {
$('#uploadprogresswrapper input.stop').hide();
@ -362,6 +414,11 @@ $(document).ready(function() {
$('#uploadprogressbar').progressbar('value', 100);
$('#uploadprogressbar').fadeOut();
}
//if user pressed cancel hide upload chrome
if (! OC.Upload.isProcessing()) {
$('#uploadprogresswrapper input.stop').fadeOut();
$('#uploadprogressbar').fadeOut();
}
}
};
@ -384,8 +441,8 @@ $(document).ready(function() {
};
// warn user not to leave the page while upload is in progress
$(window).bind('beforeunload', function(e) {
if ($.assocArraySize(uploadingFiles) > 0) {
$(window).on('beforeunload', function(e) {
if (OC.Upload.isProcessing()) {
return t('files', 'File upload is in progress. Leaving the page now will cancel the upload.');
}
});

View File

@ -409,7 +409,7 @@ $(document).ready(function(){
var file_upload_start = $('#file_upload_start');
file_upload_start.on('fileuploaddrop', function(e, data) {
console.log('fileuploaddrop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploaddrop', e, data);
var dropTarget = $(e.originalEvent.target).closest('tr');
if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder
@ -448,7 +448,7 @@ $(document).ready(function(){
});
file_upload_start.on('fileuploadadd', function(e, data) {
console.log('fileuploadadd ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploadadd', e, data);
// lookup selection for dir
var selection = OC.Upload.getSelection(data.originalFiles);
@ -482,8 +482,11 @@ $(document).ready(function(){
}
});
file_upload_start.on('fileuploadstart', function(e, data) {
OC.Upload.logStatus('fileuploadstart', e, data);
});
file_upload_start.on('fileuploaddone', function(e, data) {
console.log('fileuploaddone ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploaddone', e, data);
var response;
if (typeof data.result === 'string') {
@ -545,28 +548,58 @@ $(document).ready(function(){
});
}
}
//if user pressed cancel hide upload chrome
if (! OC.Upload.isProcessing()) {
//cleanup uploading to a dir
var uploadtext = $('tr .uploadtext');
var img = OC.imagePath('core', 'filetypes/folder.png');
uploadtext.parents('td.filename').attr('style','background-image:url('+img+')');
uploadtext.fadeOut();
uploadtext.attr('currentUploads', 0);
}
});
file_upload_start.on('fileuploadalways', function(e, data) {
console.log('fileuploadalways ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploadalways', e, data);
});
file_upload_start.on('fileuploadsend', function(e, data) {
console.log('fileuploadsend ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploadsend', e, data);
// TODOD add vis
//data.context.element =
});
file_upload_start.on('fileuploadprogress', function(e, data) {
console.log('fileuploadprogress ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploadprogress', e, data);
});
file_upload_start.on('fileuploadprogressall', function(e, data) {
console.log('fileuploadprogressall ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploadprogressall', e, data);
});
file_upload_start.on('fileuploadstop', function(e, data) {
console.log('fileuploadstop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploadstop', e, data);
//if user pressed cancel hide upload chrome
if (! OC.Upload.isProcessing()) {
//cleanup uploading to a dir
var uploadtext = $('tr .uploadtext');
var img = OC.imagePath('core', 'filetypes/folder.png');
uploadtext.parents('td.filename').attr('style','background-image:url('+img+')');
uploadtext.fadeOut();
uploadtext.attr('currentUploads', 0);
}
});
file_upload_start.on('fileuploadfail', function(e, data) {
console.log('fileuploadfail ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
OC.Upload.logStatus('fileuploadfail', e, data);
//if user pressed cancel hide upload chrome
if (data.errorThrown === 'abort') {
//cleanup uploading to a dir
var uploadtext = $('tr .uploadtext');
var img = OC.imagePath('core', 'filetypes/folder.png');
uploadtext.parents('td.filename').attr('style','background-image:url('+img+')');
uploadtext.fadeOut();
uploadtext.attr('currentUploads', 0);
}
});
/*
file_upload_start.on('fileuploadfail', function(e, data) {

View File

@ -1,4 +1,3 @@
var uploadingFiles = {};
Files={
updateMaxUploadFilesize:function(response) {
if(response == undefined) {
@ -235,12 +234,6 @@ $(document).ready(function() {
return size;
};
// warn user not to leave the page while upload is in progress
$(window).bind('beforeunload', function(e) {
if ($.assocArraySize(uploadingFiles) > 0)
return t('files','File upload is in progress. Leaving the page now will cancel the upload.');
});
//add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
if(navigator.userAgent.search(/konqueror/i)==-1){
$('#file_upload_start').attr('multiple','multiple')

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* jQuery Iframe Transport Plugin 1.3
* jQuery Iframe Transport Plugin 1.7
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
@ -30,27 +30,45 @@
// The iframe transport accepts three additional options:
// options.fileInput: a jQuery collection of file input fields
// options.paramName: the parameter name for the file form data,
// overrides the name property of the file input field(s)
// overrides the name property of the file input field(s),
// can be a string or an array of strings.
// options.formData: an array of objects with name and value properties,
// equivalent to the return data of .serializeArray(), e.g.:
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
$.ajaxTransport('iframe', function (options) {
if (options.async && (options.type === 'POST' || options.type === 'GET')) {
if (options.async) {
var form,
iframe;
iframe,
addParamChar;
return {
send: function (_, completeCallback) {
form = $('<form style="display:none;"></form>');
form.attr('accept-charset', options.formAcceptCharset);
addParamChar = /\?/.test(options.url) ? '&' : '?';
// XDomainRequest only supports GET and POST:
if (options.type === 'DELETE') {
options.url = options.url + addParamChar + '_method=DELETE';
options.type = 'POST';
} else if (options.type === 'PUT') {
options.url = options.url + addParamChar + '_method=PUT';
options.type = 'POST';
} else if (options.type === 'PATCH') {
options.url = options.url + addParamChar + '_method=PATCH';
options.type = 'POST';
}
// javascript:false as initial iframe src
// prevents warning popups on HTTPS in IE6.
// IE versions below IE8 cannot set the name property of
// elements that have already been added to the DOM,
// so we set the name along with the iframe HTML markup:
counter += 1;
iframe = $(
'<iframe src="javascript:false;" name="iframe-transport-' +
(counter += 1) + '"></iframe>'
counter + '"></iframe>'
).bind('load', function () {
var fileInputClones;
var fileInputClones,
paramNames = $.isArray(options.paramName) ?
options.paramName : [options.paramName];
iframe
.unbind('load')
.bind('load', function () {
@ -79,7 +97,12 @@
// (happens on form submits to iframe targets):
$('<iframe src="javascript:false;"></iframe>')
.appendTo(form);
form.remove();
window.setTimeout(function () {
// Removing the form in a setTimeout call
// allows Chrome's developer tools to display
// the response result
form.remove();
}, 0);
});
form
.prop('target', iframe.prop('name'))
@ -101,8 +124,11 @@
return fileInputClones[index];
});
if (options.paramName) {
options.fileInput.each(function () {
$(this).prop('name', options.paramName);
options.fileInput.each(function (index) {
$(this).prop(
'name',
paramNames[index] || options.paramName
);
});
}
// Appending the file input fields to the hidden form
@ -144,22 +170,36 @@
});
// The iframe transport returns the iframe content document as response.
// The following adds converters from iframe to text, json, html, and script:
// The following adds converters from iframe to text, json, html, xml
// and script.
// Please note that the Content-Type for JSON responses has to be text/plain
// or text/html, if the browser doesn't include application/json in the
// Accept header, else IE will show a download dialog.
// The Content-Type for XML responses on the other hand has to be always
// application/xml or text/xml, so IE properly parses the XML response.
// See also
// https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
$.ajaxSetup({
converters: {
'iframe text': function (iframe) {
return $(iframe[0].body).text();
return iframe && $(iframe[0].body).text();
},
'iframe json': function (iframe) {
return $.parseJSON($(iframe[0].body).text());
return iframe && $.parseJSON($(iframe[0].body).text());
},
'iframe html': function (iframe) {
return $(iframe[0].body).html();
return iframe && $(iframe[0].body).html();
},
'iframe xml': function (iframe) {
var xmlDoc = iframe && iframe[0];
return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
$.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
$(xmlDoc.body).html());
},
'iframe script': function (iframe) {
return $.globalEval($(iframe[0].body).text());
return iframe && $.globalEval($(iframe[0].body).text());
}
}
});
}));
}));

View File

@ -1,7 +1,8 @@
<input type="hidden" id="disableSharing" data-status="<?php p($_['disableSharing']); ?>">
<?php $totalfiles = 0;
$totaldirs = 0;
$totalsize = 0; ?>
$totalsize = 0;
$pc = 0; ?>
<?php foreach($_['files'] as $file):
$totalsize += $file['size'];
if ($file['type'] === 'dir') {
@ -17,7 +18,9 @@ $totalsize = 0; ?>
$relative_date_color = round((time()-$file['mtime'])/60/60/24*14);
if($relative_date_color>160) $relative_date_color = 160;
$name = \OCP\Util::encodePath($file['name']);
$directory = \OCP\Util::encodePath($file['directory']); ?>
$directory = \OCP\Util::encodePath($file['directory']);
?>
<!--<tr style="position:absolute; width:100%"><td colspan="3" style="display:block;"><div style="width: <?php echo $pc++; ?>%; height: 31px;background-color: green;"/></td></tr>-->
<tr data-id="<?php p($file['fileid']); ?>"
data-file="<?php p($name);?>"
data-type="<?php ($file['type'] == 'dir')?p('dir'):p('file')?>"
@ -52,12 +55,14 @@ $totalsize = 0; ?>
</td>
<td class="filesize"
style="color:rgb(<?php p($simple_size_color.','.$simple_size_color.','.$simple_size_color) ?>)">
<span style="position:relative;">
<?php print_unescaped(OCP\human_file_size($file['size'])); ?>
</span>
</td>
<td class="date">
<span class="modified"
title="<?php p($file['date']); ?>"
style="color:rgb(<?php p($relative_date_color.','
style="position:relative; color:rgb(<?php p($relative_date_color.','
.$relative_date_color.','
.$relative_date_color) ?>)">
<?php p($relative_modified_date); ?>