Skip to content

Commit

Permalink
Create addition functions for upload queue
Browse files Browse the repository at this point in the history
  • Loading branch information
itstructure committed Aug 5, 2019
1 parent ccfb904 commit ebc494b
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions src/assets/source/js/uploadmanager.js
Expand Up @@ -4,6 +4,7 @@ $(document).ready(function() {
window.workspace = $('#workspace');
window.uploadManagerContainer = $('[role="uploadmanager"]');
window.fileManagerModalContainer = $(window.frameElement).parents('[role="filemanager-modal"]');
window.upload_tasks = [];

/**
* Add file to upload.
Expand Down Expand Up @@ -54,7 +55,7 @@ $(document).ready(function() {
e.preventDefault();

var fileNumber = $(this).attr('data-file-number'),
fileBlock = $(this).parents('[role="file-block-'+fileNumber+'"]'),
fileBlock = $(this).parents('[role="file-block"]'),
progressBlock = fileBlock.find('[role="progress-block"]'),
url = window.uploadManagerContainer.attr('data-delete-url'),
params = {
Expand Down Expand Up @@ -85,7 +86,7 @@ $(document).ready(function() {
e.preventDefault();

var fileNumber = $(this).attr('data-file-number'),
fileBlock = $(this).parents('[role="file-block-'+fileNumber+'"]');
fileBlock = $(this).parents('[role="file-block"]');

delete window.preparedFiles[fileNumber];

Expand Down Expand Up @@ -168,7 +169,10 @@ $(document).ready(function() {
}

/**
* Single upload file.
*
* @param fileNumber
*
* @returns {boolean}
*/
function upload_file(fileNumber) {
var fileBlock = $('[role="file-block-'+fileNumber+'"]'),
Expand Down Expand Up @@ -245,5 +249,60 @@ $(document).ready(function() {
}, function(data, xhr) {
showPopup(progressBlock, data.message, true, 0);
});

return true;
}

/**
* @param file_number
*/
function push_upload_task(file_number)
{
var status = check_uploading_tasks() ? 'wait' : 'running';

window.upload_tasks.push({
status: status,
file_number: file_number
});

if (status == 'running') {
upload_file(file_number);
}
}

/**
* @returns {boolean}
*/
function check_uploading_tasks()
{
return _.findIndex(window.upload_tasks, function(o) {return o.status == 'running';}) !== -1;
}

/**
* @param file_number
*
* @returns {*}
*/
function find_upload_task_index(file_number)
{
return _.findIndex(window.upload_tasks, function(o) {return o.file_number == file_number;});
}

function close_upload_task_status(file_number)
{
var task_index = find_upload_task_index(file_number);

if (task_index !== -1) {
window.upload_tasks[task_index].status = 'done';
}
}

function retrive_next_upload_task()
{
var next_index = _.findIndex(window.upload_tasks, function(o) {return o.status == 'wait';});

window.upload_tasks[next_index].status = 'wait';

upload_file(window.upload_tasks[next_index].file_number);
}
});

0 comments on commit ebc494b

Please sign in to comment.