Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

feat(uploader*.api.js): addInitialFiles() accepts non-successful files. #1751

30 changes: 21 additions & 9 deletions client/js/uploader.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,7 @@
self._markFileAsSuccessful(id);
}
else {
qq(fileContainer).addClass(self._classes.fail);
templating.showCancel(id);

if (templating.isRetryPossible() && !self._preventRetries[id]) {
qq(fileContainer).addClass(self._classes.retryable);
templating.showRetry(id);
}
self._controlFailureTextDisplay(id, result);
self._markFileAsFailed(id, result);
}
}

Expand Down Expand Up @@ -410,6 +403,20 @@
this._maybeUpdateThumbnail(id);
},

_markFileAsFailed: function(id, result) {
var templating = this._templating,
fileContainer = templating.getFileContainer(id);

qq(fileContainer).addClass(this._classes.fail);
templating.showCancel(id);

if (templating.isRetryPossible() && !this._preventRetries[id]) {
qq(fileContainer).addClass(this._classes.retryable);
templating.showRetry(id);
}
this._controlFailureTextDisplay(id, result);
},

_onUploadPrep: function(id) {
this._parent.prototype._onUploadPrep.apply(this, arguments);
this._templating.showSpinner(id);
Expand Down Expand Up @@ -706,7 +713,12 @@
this._addToList(id, this.getName(id), true);
this._templating.hideSpinner(id);
this._templating.hideCancel(id);
this._markFileAsSuccessful(id);
if (sessionData.status !== qq.status.UPLOAD_FAILED) {
this._markFileAsSuccessful(id);
} else {
this._preventRetries[id] = true;
this._markFileAsFailed(id, sessionData);
}

return id;
},
Expand Down
8 changes: 5 additions & 3 deletions client/js/uploader.basic.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
uuid: sessionData.uuid,
name: sessionData.name,
size: sessionData.size,
status: qq.status.UPLOAD_SUCCESSFUL
status: sessionData.status || qq.status.UPLOAD_SUCCESSFUL
});

sessionData.deleteFileEndpoint && this.setDeleteFileEndpoint(sessionData.deleteFileEndpoint, id);
Expand All @@ -456,8 +456,10 @@
this._thumbnailUrls[id] = sessionData.thumbnailUrl;
}

this._netUploaded++;
this._netUploadedOrQueued++;
if (sessionData.status !== qq.status.UPLOAD_FAILED) {
this._netUploaded++;
this._netUploadedOrQueued++;
}

return id;
},
Expand Down
1 change: 1 addition & 0 deletions docs/features/session.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Here are the following properties of each `Object` that Fine Uploader recognizes
* *s3Key: `String` - Key of the file in your S3 bucket. Only required if using Fine Uploader S3.
* *s3Bucket: `String` - Name of the bucket where the file is stored in S3. Only required if using Fine Uploader S3 and if the bucket cannot be determined by examining the endpoint URL (such as when routing through a CDN).
* *blobName: `String` - Name of the file in your Azure Blob Storage container. Only required if using Fine Uploader Azure.
* status: `String` - Either `qq.status.UPLOAD_SUCCESSFUL` (default) or `qq.status.UPLOAD_FAILED`

The response will be converted into a JavaScript `Array` and passed to your `sessionRequestComplete` event handler.
So, any non-standard object properties passed with your server response will also be passed to your event handler.
Expand Down
43 changes: 43 additions & 0 deletions test/unit/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,49 @@ describe("file list initialization tests", function() {
assert.equal(uploader.getRemainingAllowedItems(), 3, "wrong number of remaining allowed items");
});

it("adds SUCCESSFUL and FAILED items to the initial file list via API", function() {
var uploader = new qq.FineUploaderBasic({
validation: {
itemLimit: 5
}
});

uploader.addInitialFiles([
{
name: "failed.jpg",
uuid: "123",
size: 456,
status: qq.status.UPLOAD_FAILED
},
{
name: "successful.jpg",
uuid: "abc",
status: qq.status.UPLOAD_SUCCESSFUL
}
]);

assert.equal(uploader.getUploads().length, 2, "wrong number of pre-populated uploads recorded");
assert.equal(uploader.getUploads({status: qq.status.UPLOAD_FAILED}).length, 1, "did not find failed upload");
assert.equal(uploader.getUploads({status: qq.status.UPLOAD_SUCCESSFUL}).length, 1, "did not find successful upload");

assert.equal(uploader.getUuid(0), "123", "123 UUID was not recorded");
assert.equal(uploader.getUuid(1), "abc", "abc UUID was not recorded");

assert.equal(uploader.getSize(0), 456, "wrong size for first file");
assert.equal(uploader.getSize(1), -1, "wrong size for second file");

assert.equal(uploader.getName(0), "failed.jpg", "wrong name for first file");
assert.equal(uploader.getName(1), "successful.jpg", "wrong name for second file");

assert.equal(uploader.getFile(0), null, "unexpected return value for getFile");
assert.equal(uploader.getFile(1), null, "unexpected return value for getFile");

assert.equal(uploader.getInProgress(), 0, "unexpected getInProgress value");
assert.equal(uploader.getNetUploads(), 1, "unexpected getNetUploads value");

assert.equal(uploader.getRemainingAllowedItems(), 4, "wrong number of remaining allowed items");
});

it("adds valid items to the initial file list via GET request", function(done) {
var expectedSessionResponse = [
{
Expand Down