diff --git a/LEAF_Request_Portal/admin/templates/mod_workflow.tpl b/LEAF_Request_Portal/admin/templates/mod_workflow.tpl index d0ddac74e..57914a241 100644 --- a/LEAF_Request_Portal/admin/templates/mod_workflow.tpl +++ b/LEAF_Request_Portal/admin/templates/mod_workflow.tpl @@ -21,6 +21,10 @@ role="button" tabindex="0">Rename Workflow Rename Workflow +
@@ -54,18 +58,11 @@ dialog.setTitle('Create new workflow'); dialog.setContent('
'); dialog.setSaveHandler(function() { - $.ajax({ - type: 'POST', - url: '../api/workflow/new', - data: { - description: $('#description').val(), - CSRFToken: CSRFToken - }, - success: (res) => { - loadWorkflowList(res); - dialog.hide(); - }, - error: (err) => console.log(err), + let workflowID; + + postWorkflow(function(workflow_id) { + loadWorkflowList(workflow_id); + dialog.hide(); }); }); dialog.show(); @@ -276,17 +273,9 @@ function addEmailReminderDialog(stepID) { $('.workflowStepInfo').css('display', 'none'); let workflowStep = null; - $.ajax({ - type: 'GET', - data: { - CSRFToken: CSRFToken, - }, - url: '../api/workflow/step/' + stepID, - async: false, - success: function(res) { - workflowStep = res - }, - error: function() { console.log('Failed to gather workflow step!'); } + + getStep(stepID, function (workflow_step) { + workflowStep = workflow_step; }); dialog.setTitle('Email Reminder'); @@ -333,22 +322,13 @@ } } - $.ajax({ - type: 'POST', - data: { - CSRFToken: CSRFToken, - seriesData: seriesData - }, - url: '../api/workflow/stepdata/' + stepID, - success: function(res) { - if (res == 1) { - loadWorkflow(currentWorkflow); - dialog.hide(); - } else { - alert(res); - } - }, - error: function() { console.log('Failed to save automated email reminder data'); } + updateStepData(seriesData, stepID, function (res) { + if (res == 1) { + loadWorkflow(currentWorkflow); + dialog.hide(); + } else { + alert(res); + } }); }); @@ -534,9 +514,8 @@ }) .trigger("change"); dialog.setSaveHandler(function() { - let ajaxData = {eventID: $('#eventID').val(), - CSRFToken: CSRFToken - }; + let ajaxData = {eventID: $('#eventID').val(), + CSRFToken: CSRFToken}; if ($('#eventID').val() == 'automated_email_reminder') { var formObj = {}; $.each($('#eventData :input').serializeArray(), function() { @@ -545,17 +524,11 @@ $.extend(ajaxData, formObj); } - $.ajax({ - type: 'POST', - url: '../api/workflow/' + workflowID + '/step/' + stepID + '/_' + actionType + - '/events', - data: ajaxData, - cache: false - }).done(function() { + postEvent(stepID, actionType, workflowID, ajaxData, function (res) { loadWorkflow(workflowID); - }).fail(function(error) { - alert(error); - }); dialog.hide(); + }); + + dialog.hide(); }); }).fail(function(error) { alert(error); @@ -771,40 +744,22 @@ $('.workflowStepInfo').css('display', 'none'); let workflowStep = null; - $.ajax({ - type: 'GET', - data: { - CSRFToken: CSRFToken, - }, - url: '../api/workflow/step/' + stepID, - async: false, - success: function(res) { - workflowStep = res - }, - error: function() { console.log('Failed to gather workflow step!'); } - }); + getStep(stepID, function(workflow_step) { + workflowStep = workflow_step; + }) dialog.setTitle('Edit Step'); dialog.setContent(` `); dialog.setSaveHandler(function() { - $.ajax({ - type: 'POST', - data: { - CSRFToken: CSRFToken, - title: $('#title').val() - }, - url: '../api/workflow/step/' + stepID, - success: function(res) { - if (res == 1) { - loadWorkflow(currentWorkflow); - dialog.hide(); - } else { - alert(res); - } - }, - error: (err) => console.log(err), - }); + updateTitle($('#title').val(), stepID, function(step_id) { + if (step_id == 1) { + loadWorkflow(currentWorkflow); + dialog.hide(); + } else { + alert(res); + } + }); }); dialog.show(); } @@ -854,17 +809,9 @@ function linkDependency(stepID, dependencyID) { dialog.indicateBusy(); - $.ajax({ - type: 'POST', - url: '../api/workflow/step/' + stepID + '/dependencies', - data: {dependencyID: dependencyID, - CSRFToken: CSRFToken - }, - success: function() { - dialog.hide(); - showStepInfo(stepID); - }, - error: (err) => console.log(err), + postStepDependency(stepID, dependencyID, function(res) { + dialog.hide(); + showStepInfo(stepID); }); } @@ -1032,63 +979,41 @@ '


Example: "Service Chief"' ); dialog.setSaveHandler(function() { - $.ajax({ - type: 'POST', - url: '../api/workflow/' + currentWorkflow + '/step', - data: { - stepTitle: $('#stepTitle').val(), - CSRFToken: CSRFToken - }, - success: function(res) { + addStep(currentWorkflow, $('#stepTitle').val(), function(stepID) { + if (isNaN(stepID)) { + console.log(stepID); + } else { loadWorkflow(currentWorkflow); - dialog.hide(); - }, - error: (err) => console.log(err), + } + + dialog.hide(); }); }); dialog.show(); } function setInitialStep(stepID) { - $.ajax({ - type: 'POST', - url: '../api/workflow/' + currentWorkflow + '/initialStep', - data: { - stepID: stepID, - CSRFToken: CSRFToken - }, - success: function() { - // ending step - if (stepID == 0) { - $.ajax({ - type: 'POST', - url: '../api/workflow/' + currentWorkflow + '/action', - data: { - stepID: -1, - nextStepID: 0, - action: 'submit', - CSRFToken: CSRFToken - }, - success: function() {}, - error: (err) => console.log(err), - }); - } - - workflows = {}; - $.ajax({ - type: 'GET', - url: '../api/workflow', - success: function(res) { - for (let i in res) { - workflows[res[i].workflowID] = res[i]; - } - loadWorkflow(currentWorkflow); - }, - error: (err) => console.log(err), - cache: false + updateInitialStep(currentWorkflow, stepID, function() { + // ending step + if (stepID == 0) { + postAction(-1, 0, 'submit', currentWorkflow, function (res) { + // nothing happened here to begin with }); - }, - error: (err) => console.log(err), + } + + workflows = {}; + $.ajax({ + type: 'GET', + url: '../api/workflow', + success: function(res) { + for (let i in res) { + workflows[res[i].workflowID] = res[i]; + } + loadWorkflow(currentWorkflow); + }, + error: (err) => console.log(err), + cache: false + }); }); } @@ -1343,19 +1268,8 @@ // automatically select "return to requestor" if the user links a step to the requestor's step if (source > 0) { - $.ajax({ - type: 'POST', - url: '../api/workflow/' + currentWorkflow + '/action', - data: { - stepID: source, - nextStepID: target, - action: 'sendback', - CSRFToken: CSRFToken - }, - success: function() { - loadWorkflow(currentWorkflow); - }, - error: (err) => console.log(err), + postAction(source, target, 'sendback', currentWorkflow, function(res) { + loadWorkflow(currentWorkflow); }); return; } @@ -1398,19 +1312,8 @@ loadWorkflow(currentWorkflow); });*/ dialog.setSaveHandler(function() { - $.ajax({ - type: 'POST', - url: '../api/workflow/' + currentWorkflow + '/action', - data: { - stepID: source, - nextStepID: target, - action: $('#actionType').val(), - CSRFToken: CSRFToken - }, - success: function() { - loadWorkflow(currentWorkflow); - }, - error: (err) => console.log(err), + postAction(source, target, $('#actionType').val(), currentWorkflow, function(res) { + loadWorkflow(currentWorkflow); }); dialog.hide(); }); @@ -1445,58 +1348,53 @@ $('#stepInfo_' + params.stepID).html('Loading...'); let stepID = params.stepID; - $.ajax({ - type: 'GET', - url: '../api/workflow/' + currentWorkflow + '/step/' + stepID + '/_' + params.action + '/events', - success: function(res) { - let find_required = ''; -console.log(params); - if (typeof params.required === 'undefined' || params.required === '') { - find_required = $.parseJSON('{"required":"false"}'); - } else { - find_required = $.parseJSON(params.required); - } - let output = ''; - let required = ''; + getRouteEvents(currentWorkflow, stepID, params.action, function (res) { + let find_required = ''; - if (find_required.required == 'true') { - required = 'checked=checked'; - } + if (typeof params.required === 'undefined' || params.required === '') { + find_required = $.parseJSON('{"required":"false"}'); + } else { + find_required = $.parseJSON(params.required); + } - stepTitle = steps[stepID] != undefined ? steps[stepID].stepTitle : 'Requestor'; - output = '

Action: ' + stepTitle + ' clicks ' + params.action + '

'; + let output = ''; + let required = ''; - if (params.action == 'sendback') { - output += '
Require a comment to sendback.
'; - } + if (find_required.required == 'true') { + required = 'checked=checked'; + } - output += '
Triggers these events:
'; - output += - '
Remove Action
'; - $('#stepInfo_' + stepID).html(output); - $('#event_' + currentWorkflow + '_' + stepID + '_' + params.action).on('click', function() { - addEventDialog(currentWorkflow, stepID, params.action); - }); - }, - error: (err) => console.log(err), - cache: false + stepTitle = steps[stepID] != undefined ? steps[stepID].stepTitle : 'Requestor'; + output = '

Action: ' + stepTitle + ' clicks ' + params.action + '

'; + + if (params.action == 'sendback') { + output += '
Require a comment to sendback.
'; + } + + output += '
Triggers these events:
'; + output += + '
Remove Action
'; + $('#stepInfo_' + stepID).html(output); + $('#event_' + currentWorkflow + '_' + stepID + '_' + params.action).on('click', function() { + addEventDialog(currentWorkflow, stepID, params.action); + }); }); $('#stepInfo_' + stepID).css({ @@ -1511,19 +1409,8 @@ console.log(params); let e = document.getElementById("workflows"); let workflowID = e.value; - $.ajax({ - type: 'POST', - url: '../api/workflowRoute/require', - data: {required: element.checked, - step_id: stepID[2], - workflow_id: workflowID, - CSRFToken: CSRFToken}, - success: function (res) { - console.log(res); - }, - error: function (err) { - console.log(err); - } + updateRequiredCheckbox(workflowID, stepID[2], element.checked, function(res) { + console.log(res); }); } @@ -1554,20 +1441,10 @@ console.log(params); cache: false }); - dialog.setSaveHandler(function() { - $.ajax({ - type: 'POST', - url: '../api/workflow/step/' + stepID + '/indicatorID_for_assigned_empUID', - data: { - indicatorID: $('#indicatorID').val(), - CSRFToken: CSRFToken - }, - success: function(res) { - loadWorkflow(currentWorkflow); - dialog.hide(); - }, - error: (err) => console.log(err), + updateApprover($('#indicatorID').val(), stepID, function(res) { + loadWorkflow(currentWorkflow); + dialog.hide(); }); }); dialog.show(); @@ -1600,20 +1477,10 @@ console.log(params); cache: false }); - dialog.setSaveHandler(function() { - $.ajax({ - type: 'POST', - url: '../api/workflow/step/' + stepID + '/indicatorID_for_assigned_groupID', - data: { - indicatorID: $('#indicatorID').val(), - CSRFToken: CSRFToken - }, - success: function(res) { - loadWorkflow(currentWorkflow); - dialog.hide(); - }, - error: (err) => console.log(err), + updateGroupApprover($('#indicatorID').val(), stepID, function (res) { + loadWorkflow(currentWorkflow); + dialog.hide(); }); }); dialog.show(); @@ -1718,14 +1585,8 @@ console.log(params); steps[stepID].stepModules[i].moduleConfig = JSON.stringify({indicatorID: $('#workflowIndicator_' + stepID).val()}); } } - $.ajax({ - type: 'POST', - url: '../api/workflow/step/' + stepID + '/inlineIndicator', - data: { - indicatorID: $('#workflowIndicator_' + stepID).val(), - CSRFToken: CSRFToken - } - }); + + postModule(stepID, $('#workflowIndicator_' + stepID).val()); }); } @@ -1904,6 +1765,7 @@ console.log(params); type: 'GET', url: '../api/workflow/' + workflowID + '/route', success: function(res) { + routes = res; if (endPoints[-1] == undefined) { endPoints[-1] = jsPlumb.addEndpoint('step_-1', {anchor: 'Continuous'}, endpointOptions); jsPlumb.draggable('step_-1'); @@ -2042,6 +1904,7 @@ console.log(params); $('#btn_listEvents').css('display', 'block'); $('#btn_viewHistory').css('display', 'block'); $('#btn_renameWorkflow').css('display', 'block'); + $('#btn_duplicateWorkflow').css('display', 'block'); //508 $('#btn_createStep').on('keypress', function(event) { @@ -2124,21 +1987,8 @@ console.log(params); stop: function(stepID) { return function() { var position = $('#step_' + stepID).offset(); - $.ajax({ - type: 'POST', - url: '../api/workflow/' + workflowID + - '/editorPosition', - data: { - stepID: stepID, - x: position.left, - y: position.top, - CSRFToken: CSRFToken - }, - success: function() { - - }, - error: (err) => console.log(err), - }); + + updatePosition(workflowID, stepID, position.left, position.top); } }(res[i].stepID) }); @@ -2179,6 +2029,7 @@ console.log(params); function loadWorkflowList(workflowID) { $.ajax({ + async: false, type: 'GET', url: '../api/workflow', success: function(res) { @@ -2272,6 +2123,578 @@ console.log(params); dialog.show(); } + /** + * The script to duplicate the currently selected workflow + * + * Created at: 7/26/2023, 1:08:10 PM (America/New_York) + */ + function duplicateWorkflow() { + $('.workflowStepInfo').css('display', 'none'); + + dialog.setTitle('Duplicate current workflow'); + dialog.setContent('


The following will NOT be copied over:

    Data fields that show up next to the workflow action buttons'); + dialog.setSaveHandler(function() { + let old_steps = {}; + let workflowID; + let title = $('#description').val(); + + postWorkflow(function(workflow_id) { + workflowID = workflow_id; + dialog.hide(); + }); + + workflows[workflowID] = workflows[currentWorkflow]; + workflows[workflowID]['workflowID'] = parseInt(workflowID); + workflows[workflowID]['description'] = title; + + for(let i in steps) { + // add step, if successful update that step + addStep(workflowID, steps[i].stepTitle, function(stepID) { + + if (isNaN(stepID)) { + console.log(stepID); + } else { + old_steps[steps[i].stepID] = stepID; + updatePosition(workflowID, stepID, steps[i].posX, steps[i].posY); + + updateTitle(steps[i].stepTitle, stepID, function(res) { + // Alls well that ends well. + }); + + if (steps[i].stepData != null) { + let auto = JSON.parse(steps[i].stepData); + + let seriesData = { + AutomatedEmailReminders: { + 'Automate Email Group': auto.AutomatedEmailReminders.AutomateEmailGroup, + 'Days Selected': auto.AutomatedEmailReminders.DaysSelected, + 'Additional Days Selected': auto.AutomatedEmailReminders.AdditionalDaysSelected, + } + }; + + updateStepData(seriesData, stepID, function (res) { + // Alls well that ends well. + }); + } + + updateApprover(steps[i].indicatorID_for_assigned_empUID, stepID, function (res) { + // Alls well that ends well. + }); + + updateGroupApprover(steps[i].indicatorID_for_assigned_groupID, stepID, function (res) { + // Alls well that ends well. + }); + + // set requireDigitalSignature + // this endpoint does not exist in this file at this time. + + updateDependencies(steps[i].stepID, old_steps); + } + }); + + + } + + workflows[workflowID]['initialStepID'] = parseInt(old_steps[workflows[currentWorkflow].initialStepID]); + + updateInitialStep(workflowID, workflows[workflowID]['initialStepID'], function () { + // nothing to do here + }); + + updateRoutes(workflowID, old_steps); + updateRouteEvents(currentWorkflow, workflowID, old_steps); + loadWorkflowList(workflowID); + }); + dialog.show(); + } + + /** + * @param int workflowID + * @param int stepID + * @param closure callback + * + * Created at: 7/26/2023, 1:13:07 PM (America/New_York) + */ + function updateInitialStep(workflowID, stepID, callback) { + $.ajax({ + async: false, + type: 'POST', + url: '../api/workflow/' + workflowID + '/initialStep', + data: { + stepID: stepID, + CSRFToken: CSRFToken + }, + success: function() { + callback(); + + }, + error: (err) => console.log(err), + }); + } + + /** + * This gets a list of dependencies to a particular step and + * creates a duplicate for the new workflow + * + * @param int stepID + * @param array old_steps + * + * Created at: 7/26/2023, 1:14:37 PM (America/New_York) + */ + function updateDependencies(stepID, old_steps) { + let dependency; + + getStepDependencies(stepID, function (res) { + if (res.status.code == 2) { + dependency = res.data; + + for (let i in dependency) { + postStepDependency(old_steps[dependency[i].stepID], dependency[i].dependencyID, function (res) { + // nothing to do here + }); + } + } else { + console.log('no dependencies exist'); + } + }); + } + + /** + * This gets a list of route_events to loop through and make + * new records for the new workflow being duplicated + * + * @param int currentWorkflow + * @param int workflow + * @param array old_steps + * + * Created at: 7/26/2023, 1:16:18 PM (America/New_York) + */ + function updateRouteEvents(currentWorkflow, workflow, old_steps) { + let workflow_events; + let listAllEvents; + + getWorkflowEvents(currentWorkflow, function (res ) { + workflow_events = res; + }); + + + if (workflow_events.status.code == 2) { + listAllEvents = workflow_events.data; + + for (let i in listAllEvents) { + let event = {eventID: listAllEvents[i].eventID, + CSRFToken: CSRFToken}; + + postEvent(old_steps[listAllEvents[i].stepID], listAllEvents[i].actionType, workflow, event, function (res) { + // nothing to do here. + }); + } + } + } + + /** + * This is taking the routes array and looping through it to create + * the new routes for the duplicated workflow + * + * @param int workflow + * @param array old_steps + * + * Created at: 7/26/2023, 1:17:21 PM (America/New_York) + */ + function updateRoutes(workflow, old_steps) { + for (let i in routes) { + postAction(old_steps[routes[i].stepID], old_steps[routes[i].nextStepID], routes[i].actionType, workflow, function (res) { + // check to see if this is a sendback and if the requirement is true + if (routes[i].displayConditional) { + let required = JSON.parse(routes[i].displayConditional); + + updateRequiredCheckbox(workflow, old_steps[routes[i].stepID], required.required, function (res) { + // nothing to do here. + }) + } + }); + } + } + + /** + * Create the group approver for a duplicated workflow + * + * @param int indicatorID + * @param int stepID + * @param closure callback + * + * Created at: 7/26/2023, 1:20:42 PM (America/New_York) + */ + function updateGroupApprover(indicatorID, stepID, callback) { + $.ajax({ + type: 'POST', + url: '../api/workflow/step/' + stepID + '/indicatorID_for_assigned_groupID', + data: { + indicatorID: indicatorID, + CSRFToken: CSRFToken + }, + success: function(res) { + callback(res); + }, + error: (err) => console.log(err), + }); + } + + /** + * Create the approver for a duplicated workflow + * + * @param int indicatorID + * @param int stepID + * @param closure callback + * + * Created at: 7/26/2023, 1:23:08 PM (America/New_York) + */ + function updateApprover(indicatorID, stepID, callback) { + $.ajax({ + type: 'POST', + url: '../api/workflow/step/' + stepID + '/indicatorID_for_assigned_empUID', + data: { + indicatorID: indicatorID, + CSRFToken: CSRFToken + }, + success: function(res) { + callback(res); + }, + error: (err) => console.log(err), + }); + } + + /** + * @param array data + * @param int stepID + * @param closure callback + * + * Created at: 7/26/2023, 1:23:50 PM (America/New_York) + */ + function updateStepData(data, stepID, callback) { + $.ajax({ + type: 'POST', + data: { + CSRFToken: CSRFToken, + seriesData: data + }, + url: '../api/workflow/stepdata/' + stepID, + success: function(res) { + callback(res); + }, + error: function() { console.log('Failed to save automated email reminder data'); } + }); + } + + /** + * @param int workflowID + * @param string title + * @param closure callback + * + * @return [type] + * + * Created at: 7/26/2023, 1:25:08 PM (America/New_York) + */ + function addStep(workflowID, title, callback) { + $.ajax({ + async: false, + type: 'POST', + url: '../api/workflow/' + workflowID + '/step', + data: { + stepTitle: title, + CSRFToken: CSRFToken + }, + success: function(res) { + callback(res); + }, + error: (err) => callback(err), + }); + } + + /** + * This save the position of the step on the screen + * + * @param int workflowID + * @param int stepID + * @param int left + * @param int top + * + * Created at: 7/26/2023, 1:25:40 PM (America/New_York) + */ + function updatePosition(workflowID, stepID, left, top) { + $.ajax({ + type: 'POST', + url: '../api/workflow/' + workflowID + + '/editorPosition', + data: { + stepID: stepID, + x: left, + y: top, + CSRFToken: CSRFToken + }, + success: function() { + + }, + error: (err) => console.log(err), + }); + } + + /** + * Updates the requirement label + * + * @param string title + * @param int stepID + * @param closure callback + * + * @return array + * + * Created at: 7/26/2023, 1:27:49 PM (America/New_York) + */ + function updateTitle(title, stepID, callback) { + $.ajax({ + type: 'POST', + data: { + CSRFToken: CSRFToken, + title: title + }, + url: '../api/workflow/step/' + stepID, + success: function(res) { + callback(res); + }, + error: (err) => console.log(err), + }); + } + + function updateRequiredCheckbox(workflow, stepID, checkMark, callback) { + $.ajax({ + type: 'POST', + url: '../api/workflowRoute/require', + data: {required: checkMark, + step_id: stepID, + workflow_id: workflow, + CSRFToken: CSRFToken}, + success: function (res) { + callback(res); + }, + error: function (err) { + console.log(err); + } + }); + } + + /** + * @param int stepID + * @param int dependencyID + * @param closure callback + * + * @return void + * + * Created at: 7/26/2023, 1:28:44 PM (America/New_York) + */ + function postStepDependency(stepID, dependencyID, callback) { + $.ajax({ + type: 'POST', + url: '../api/workflow/step/' + stepID + '/dependencies', + data: {dependencyID: dependencyID, + CSRFToken: CSRFToken + }, + success: function() { + callback(); + }, + error: (err) => console.log(err), + }); + } + + /** + * Create a new workflow + * + * @param closure callback + * + * @return int + * + * Created at: 7/26/2023, 1:29:18 PM (America/New_York) + */ + function postWorkflow(callback) { + $.ajax({ + async: false, + type: 'POST', + url: '../api/workflow/new', + data: { + description: $('#description').val(), + CSRFToken: CSRFToken + }, + success: function (res) { + callback(res); + }, + error: (err) => callback(err), + }); + } + + /** + * @param int stepID + * @param int nextStepID + * @param string action + * @param int workflowID + * @param closure callback + * + * @return array + * + * Created at: 7/26/2023, 1:29:52 PM (America/New_York) + */ + function postAction(stepID, nextStepID, action, workflowID, callback) { + $.ajax({ + type: 'POST', + url: '../api/workflow/' + workflowID + '/action', + data: { + stepID: stepID, + nextStepID: nextStepID, + action: action, + CSRFToken: CSRFToken + }, + success: function(res) { + callback(res) + }, + error: (err) => console.log(err), + }); + } + + /** + * @param int stepID + * @param string action + * @param int workflowID + * @param string event + * @param closure callback + * + * @return array + * + * Created at: 7/26/2023, 1:31:07 PM (America/New_York) + */ + function postEvent(stepID, action, workflowID, event, callback) { + $.ajax({ + type: 'POST', + url: '../api/workflow/' + workflowID + '/step/' + stepID + '/_' + action + + '/events', + data: event, + success: function (res) { + callback(res); + }, + error: function (err) { + alert(err); + }, + cache: false + }) + } + + /** + * @param int stepID + * @param int indicatorID + * + * Created at: 7/26/2023, 1:31:50 PM (America/New_York) + */ + function postModule(stepID, indicatorID) { + $.ajax({ + type: 'POST', + url: '../api/workflow/step/' + stepID + '/inlineIndicator', + data: { + indicatorID: indicatorID, + CSRFToken: CSRFToken + } + }); + } + + /** + * Get a specific step + * + * @param int stepID + * @param closure callback + * + * @return array + * + * Created at: 7/26/2023, 1:32:32 PM (America/New_York) + */ + function getStep(stepID, callback) { + $.ajax({ + type: 'GET', + data: { + CSRFToken: CSRFToken + }, + url: '../api/workflow/step/' + stepID, + async: false, + success: function(res) { + console.log(res); + callback(res); + }, + error: function(err) { + console.log('Failed to gather workflow step!'); + callback(err); + } + }); + } + + /** + * @param int workflowID + * @param int stepID + * @param string action + * @param closure callback + * + * @return array + * + * Created at: 7/26/2023, 1:33:15 PM (America/New_York) + */ + function getRouteEvents(workflowID, stepID, action, callback) { + $.ajax({ + type: 'GET', + url: '../api/workflow/' + workflowID + '/step/' + stepID + '/_' + action + '/events', + success: function(res) { + callback(res); + }, + error: (err) => console.log(err), + cache: false + }); + } + + /** + * @param int workflowID + * @param closure callback + * + * @return array + * + * Created at: 7/26/2023, 1:33:56 PM (America/New_York) + */ + function getWorkflowEvents(workflowID, callback) { + $.ajax({ + async: false, + type: 'GET', + url: '../api/workflow/' + workflowID + '/step/routeEvents', + success: function(res) { + callback(res); + }, + error: (err) => console.log(err), + cache: false + }); + } + + /** + * @param int stepID + * @param closure callback + * + * @return array + * + * Created at: 7/26/2023, 1:34:49 PM (America/New_York) + */ + function getStepDependencies(stepID, callback) { + $.ajax({ + async: false, + type: 'GET', + url: '../api/workflow/' + stepID + '/stepDependencies', + success: function(res) { + callback(res); + }, + error: (err) => console.log(err), + cache: false + }); + } + /* START: EMAIL REMINDER BLOCK */ @@ -2445,6 +2868,7 @@ console.log(params); var dialog, dialog_confirm, dialog_simple; var workflows = {}; var steps = {}; + var routes = {}; var endpointOptions = { isSource: true, isTarget: true, diff --git a/LEAF_Request_Portal/api/controllers/WorkflowController.php b/LEAF_Request_Portal/api/controllers/WorkflowController.php index c3170be00..f36f0b022 100644 --- a/LEAF_Request_Portal/api/controllers/WorkflowController.php +++ b/LEAF_Request_Portal/api/controllers/WorkflowController.php @@ -124,6 +124,16 @@ public function get($act) return $workflow->getEmailReminderData((int)$args[1], \Leaf\XSSHelpers::xscrub($args[2])); }); + $this->index['GET']->register('workflow/[digit]/step/routeEvents', function ($args) use ( $workflow) { + $workflow->setWorkflowID($args[0]); + + return $workflow->getWorkflowEvents((int) $args[0]); + }); + + $this->index['GET']->register('workflow/[digit]/stepDependencies', function ($args) use ( $workflow) { + return $workflow->getStepDependencies((int) $args[0]); + }); + return $this->index['GET']->runControl($act['key'], $act['args']); } diff --git a/LEAF_Request_Portal/sources/Workflow.php b/LEAF_Request_Portal/sources/Workflow.php index 8281bc014..cc5ab0e19 100644 --- a/LEAF_Request_Portal/sources/Workflow.php +++ b/LEAF_Request_Portal/sources/Workflow.php @@ -361,16 +361,14 @@ public function createAction($stepID, $nextStepID, $action) return 'Restricted command.'; } - $required = json_encode(array ('required' => false)); + if ($action == 'sendback') { + $required = json_encode(array ('required' => false)); + } else { + $required = ''; + } - $vars = array(':workflowID' => $this->workflowID, - ':stepID' => $stepID, - ':nextStepID' => $nextStepID, - ':action' => $action, - ':displayConditional' => $required, - ); - $res = $this->db->prepared_query('INSERT INTO workflow_routes (workflowID, stepID, nextStepID, actionType, displayConditional) - VALUES (:workflowID, :stepID, :nextStepID, :action, :displayConditional)', $vars); + + $this->postRoute($this->workflowID, $stepID, $nextStepID, $action, $required); $this->dataActionLogger->logAction(\Leaf\DataActions::ADD, \Leaf\LoggableTypes::WORKFLOW_ROUTE, [ new \Leaf\LogItem("workflow_routes", "workflowID", $this->workflowID), @@ -383,6 +381,36 @@ public function createAction($stepID, $nextStepID, $action) return true; } + /** + * @param int $workflowID + * @param int $stepID + * @param int $nextStepID + * @param string $action + * @param string $conditional + * + * The db method being used is returning a properly formatted json response + * @return array + * + * Created at: 7/26/2023, 7:59:46 AM (America/New_York) + */ + public function postRoute(int $workflowID, int $stepID, int $nextStepID, string $action, string $conditional): array + { + $vars = array(':workflowID' => $workflowID, + ':stepID' => $stepID, + ':nextStepID' => $nextStepID, + ':action' => $action, + ':displayConditional' => $conditional, + ); + $sql = 'INSERT INTO `workflow_routes` (`workflowID`, `stepID`, `nextStepID`, + `actionType`, `displayConditional`) + VALUES (:workflowID, :stepID, :nextStepID, :action, + :displayConditional)'; + + $res = $this->db->pdo_insert_query($sql, $vars); + + return $res; + } + public function getAllEvents() { $vars = array(); @@ -392,6 +420,25 @@ public function getAllEvents() return $res; } + /** + * @param int $workflowID + * + * @return array + * + * Created at: 7/26/2023, 8:00:08 AM (America/New_York) + */ + public function getWorkflowEvents(int $workflowID): array + { + $vars = array(':workflowID' => $workflowID); + $sql = 'SELECT `workflowID`, `stepID`, `actionType`, `eventID` + FROM `route_events` + WHERE `workflowID` = :workflowID'; + + $return_value = $this->db->pdo_select_query($sql, $vars); + + return $return_value; + } + /** * Purpose: Populate list with all Custom Events * @return array Custom Events list @@ -1217,6 +1264,25 @@ public function setDynamicGroupApprover($stepID, $indicatorID) return true; } + /** + * @param int $stepID + * + * @return array + * + * Created at: 7/25/2023, 3:01:12 PM (America/New_York) + */ + public function getStepDependencies(int $stepID): array + { + $vars = array(':stepID' => $stepID); + $sql = 'SELECT `stepID`, `dependencyID` + FROM `step_dependencies` + WHERE `stepID` = :stepID'; + + $return_value = $this->db->pdo_select_query($sql, $vars); + + return $return_value; + } + /** * Retrieve a high level map of the workflow (if valid) to show how steps are routed forwards * (a valid workflow is one that has an end)