Skip to content

Commit

Permalink
Merge pull request #119 from camunda-community-hub/primary-action-for…
Browse files Browse the repository at this point in the history
…-completed-jobs

feat: Show previous response before completing the job
  • Loading branch information
saig0 authored Feb 14, 2023
2 parents 78d604e + dc9e9e2 commit b9eae51
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 31 deletions.
48 changes: 29 additions & 19 deletions src/main/resources/public/js/view-bpmn.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,36 +225,44 @@ function makeTaskPlayable(elementId, jobKey, { isUserTask, taskForm } = {}) {
const cachedResponse = localStorage.getItem(
"jobCompletion " + getBpmnProcessId() + " " + elementId
);
if (
!taskForm &&
cachedResponse &&
Object.keys(JSON.parse(cachedResponse)).length > 0
) {
const hasCachedResponse =
cachedResponse && Object.keys(JSON.parse(cachedResponse)).length > 0;

if (!taskForm && hasCachedResponse) {
actions.push({
icon: '<svg class="bi" width="18" height="18"><use xlink:href="/img/bootstrap-icons.svg#robot"/></svg>',
icon: '<svg class="bi" width="18" height="18"><use xlink:href="/img/bootstrap-icons.svg#filetype-json"/></svg>',
text: "Use previous response",
action: `completeJob(${jobKey}, ${JSON.stringify(cachedResponse)});`,
action: `showJobCompleteModal(${jobKey}, "complete", ${JSON.stringify(
cachedResponse
)})`,
});
}

actions.push({
icon: '<svg class="bi" width="18" height="18"><use xlink:href="/img/bootstrap-icons.svg#check"/></svg>',
text: "Complete Job",
action: `completeJob(${jobKey}, "{}");`,
});
if (isUserTask || !hasCachedResponse) {
actions.push({
icon: '<svg class="bi" width="18" height="18"><use xlink:href="/img/bootstrap-icons.svg#check"/></svg>',
text: "Complete Job",
action: `completeJob(${jobKey}, "{}");`,
});
}

if (!taskForm) {
if (!taskForm && !hasCachedResponse) {
actions.push({
icon: '<svg class="bi" width="18" height="18"><use xlink:href="/img/bootstrap-icons.svg#filetype-json"/></svg>',
text: "Complete with variables",
modalTarget: "#complete-job-modal",
action: fillModalAction("complete"),
});

if (!isUserTask) {
actions.push(
{} // DIVIDER
);
}
}

if (!isUserTask) {
actions.push(
{}, // DIVIDER
{
icon: '<svg class="bi" width="18" height="18"><use xlink:href="/img/bootstrap-icons.svg#x"/></svg>',
text: "Fail",
Expand All @@ -270,11 +278,13 @@ function makeTaskPlayable(elementId, jobKey, { isUserTask, taskForm } = {}) {
);
}

let content =
'<div class="btn-group">' +
`<button type="button" class="btn btn-sm btn-primary overlay-button completeButton-${jobKey}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="${actions[0].text}" onclick='${actions[0].action}'>` +
actions[0].icon +
"</button>";
let content = `
<div class="btn-group">
<button type="button" class="btn btn-sm btn-primary overlay-button completeButton-${jobKey}"
data-bs-toggle="tooltip" data-bs-placement="bottom"
title="${actions[0].text}" onclick='${actions[0].action}'>
${actions[0].icon}
</button>`;

if (actions.length > 1) {
// add a dropdown
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/public/js/view-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,18 @@ function executeConnectorJob(jobType, jobKey) {
}

function fillJobModal(jobKey, type) {
resetJobModal();

$("#jobKey-" + type).val(jobKey);
}

function showJobCompleteModal(jobKey, type, variables) {
resetJobModal();

$("#jobKey-" + type).val(jobKey);
$("#jobVariables").val(variables);

$("#complete-job-modal").modal("show");
}

function completeJobModal() {
Expand All @@ -688,6 +699,14 @@ function throwErrorJobModal() {
throwErrorJob(jobKey, errorCode, errorMessage);
}

function resetJobModal() {
$("#jobVariables").val("{}");
$("#jobRetries").val("0");
$("#jobErrorMessage").val("");
$("#jobErrorCode").val("");
$("#job-throw-error-errorMessage").val("");
}

function resolveIncident(incidentKey, jobKey) {
const toastId = "job-update-retries-" + jobKey;

Expand Down
33 changes: 21 additions & 12 deletions src/main/resources/templates/views/modals/complete-job-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,31 @@ <h5 class="modal-title" id="completeJobModal">Complete Job</h5>
</div>
</form>
</div>
<div class="modal-footer">
<div class="modal-footer justify-content-between">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
Close
</button>
<button
type="button"
class="btn btn-primary"
data-bs-dismiss="modal"
onclick="completeJobModal();"
class="btn btn-light"
onclick="resetJobModal();"
>
Complete
Reset
</button>
<div>
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
Close
</button>
<button
type="button"
class="btn btn-primary"
data-bs-dismiss="modal"
onclick="completeJobModal();"
>
Complete
</button>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit b9eae51

Please sign in to comment.