Queue

Framework Core
Tag Helper <queue>

A queue of operations from the client side to be API called to the backend with progress.

Properties

string id

The id for this queue control.

List<QueueFunctions> queueFunctions

The list of QueueFunctions to execute.

List<FinalFunction> string

Am optional Javascript funtion to call when complete.

QueueFunctions
string Id

The Javascript Id for this queue function.

string Display

The display name for this queue function to show on the page.

ShareItLibrary.Queue.Start
string id

The Javascript id for the queue.

string oHide

A string containing JQuery selectors for objects to hide when the queue starts and show again when the queue finishes.

string baseUrl

The URL for the backend C# controller to call each function against.

Array

An array of functions information.

string serverFn

The backend server function name to call.

string stepId

The function step id for this step. It must match that used in the asp functions tag.

function process

Optional. Javascript function to call to process this step. This function can return an optional json object to pass through.

function end

Optional. Javascript function to call to after processing this step. The function being called will be passed the original json object if passed through to this step. It also returns any "data" object returned from the function, and a third parameter with the full QueueResult object.

function hasTotal
Default: true

Optional. Show the ongoing total figure when syncing data. Allows this to be turned off when the total is not known before hand.

string fnFinal

A javascript function to call when the whole queue is complete. Use null if parameters are required after this one.

string pageSize
Default: 100

The number of objects processed in each page.

string start
Default: 1

The inital starting number for the queue.

string to
Default: pageSize

The total in this batch. Is set to pageSize if not provided.

string total
Default: -1

The total number of items.

QueueResult
bool success

Status of this queue call.

int totalPercent

The total percentage completed for this queue function only ie: 10% through all records.

int current

The current item number being processed. ie: 10 to 20 of 50

int to

The last item being processed in this batch. ie: 10 to 20 of 50.

int total

The last item being processed in this batch. ie: 10 to 20 of 50.

bool itemComplete

Are there any more records to process in this function? Does this function need to be called again?

string error

Any error message to be returned back to the client display.

object data

Any optional data to return.

Javascript Events
stepstart

Triggered when each step starts. Sends the index of the starting step. $('#MyQueue').on('stepstart', (i) => { });

stepend

Triggered when each step ends. Sends the index of the ending step. $('#MyQueue').on('stepend', (i) => { });

Simple Queue.

Queue Demo
Razor
<queue id="QueueName">
<queue-step id="Step1" text="Step 1"></queue-step>
<queue-step id="Step2" text="Step 2"></queue-step>
</queue>
Javascript
ShareItLibrary.Queue.Start('QueueName', '/MyArea/MyController/', [{
serverFn: 'Sync1',
stepId: 'Sync1',
}, {
serverFn: 'Sync2',
stepId: 'Sync2',
}]);
Javascript with Page Size
ShareItLibrary.Queue.Start('QueueName', '/MyArea/MyController/', [{
serverFn: 'Sync1',
stepId: 'Sync1',
}, {
serverFn: 'Sync2',
stepId: 'Sync2',
}]), null, 400);
C#
[HttpPost]
[ValidateJsonAntiForgeryToken]
public ActionResult SyncToSystem(int page)
{
QueueResult qr = null;
... Do some work ...
var errors = new List<QueueError>();
if (ok)
{
int current = (page - 1) * 400 + pageTotal;
int to = current + 400 > total ? total : current + 400;
qr = new QueueResult(true, current, to, total, errors);
}
else
{
errors.Add(new()
{
Category = "Step 2 Errors",
Error = "Something went wrong"
});
qr = new QueueResult(false, current, to, total, errors);
}
return Json(qr);
}

Advanced queue with Javascript functions to send a list of selected Checkboxes.

Razor
<queue id="QueueName">
<queue-step id="Step1" text="Step 1"></queue-step>
<queue-step id="Step2" text="Step 2"></queue-step>
</queue>
Javascript
MyApp.JsController.Batch = 10;
MyApp.JsController.Total = 0;

MyApp.JsController.MyFunction = () => {
var temp = $('[name^="Ids["]:checked');
var length;
var o = new Array();

if (temp.length > MyApp.JsController.Batch)
length = MyApp.JsController.Batch;
else
length = length = temp.length;

for (var i = 0; i < length; i++)
o[i] = temp[i].value;

var current = MyApp.JsController.Total - temp.length + 1;
var to = MyApp.JsController.Total - temp.length + length;

var json = {
ids: o,
current: current,
to: to,
total: MyApp.JsController.Total,
myCustomProperty1: $('#Element').prop('checked'),
myCustomProperty2: $('#filterElement').val() === 'ABC'
};

return json;
};


MyApp.JsController.MyFunctionEnd = (json, data, fullData) => {
if (json.Ids.length > 0) {
for (var i = 0; i < json.Ids.length; i++)
$('[value="' + json.Ids[i] + '"]').prop('checked', false).hide();
}
};