Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Complete connector job #151

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions src/main/resources/public/js/view-bpmn.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,31 +354,64 @@ function makeTaskPlayable(elementId, jobKey, { isUserTask, taskForm } = {}) {
}

function makeConnectorTaskPlayable(elementId, jobKey, jobType) {
let buttonId = `connector-execute-${jobKey}`;
let connectorButtonId = `connector-execute-${jobKey}`;
let completeButtonId = `connector-complete-${jobKey}`;

let content = `
<button id="${buttonId}" type="button" class="btn btn-sm btn-primary" title="Invoke connector">
<svg class="bi" width="18" height="18" fill="white"><use xlink:href="/img/bootstrap-icons.svg#plugin"/></svg>
</button>`;
<div class="btn-group">
<button id="${connectorButtonId}" type="button"
class="btn btn-sm btn-primary overlay-button" title="Invoke connector">
<svg class="bi" width="18" height="18" fill="white">
<use xlink:href="/img/bootstrap-icons.svg#plugin"/>
</svg>
</button>
<button type="button"
class="btn btn-sm btn-primary dropdown-toggle dropdown-toggle-split"
data-bs-toggle="dropdown" aria-expanded="false"><span
class="visually-hidden">Toggle Dropdown</span></button>
<ul class="dropdown-menu">
<li>
<a id="${completeButtonId}" class="dropdown-item" href="#">
<svg class="bi" width="18" height="18" fill="black">
<use xlink:href="/img/bootstrap-icons.svg#check"/>
</svg>
Complete
</a>
</li>
</ul>
</div>`;

overlays.add(elementId, "connector-action", {
position: {
top: -20,
left: -20,
left: -40,
},
html: content,
});

const buttonElement = $("#" + buttonId);
buttonElement.click(function () {
const connectorButtonElement = $("#" + connectorButtonId);
connectorButtonElement.click(function () {
executeConnectorJob(jobType, jobKey);
});

buttonElement.tooltip();
connectorButtonElement.tooltip();

// We have to remove the tooltip manually when removing the element that triggers it
// see https://github.com/twbs/bootstrap/issues/3084#issuecomment-5207780
buttonElement.on("click", () => {
connectorButtonElement.on("click", () => {
$(`[data-bs-toggle="tooltip"]`).tooltip("hide");
});

$("#" + completeButtonId).click(function () {
const cachedResponse = localStorage.getItem(
"jobCompletion " + getBpmnProcessId() + " " + elementId
);
let jobVariables = cachedResponse;
if (!cachedResponse) {
jobVariables = "";
}
showJobCompleteModal(jobKey, "complete", jobVariables);

$(`[data-bs-toggle="tooltip"]`).tooltip("hide");
});
}
Expand Down
47 changes: 29 additions & 18 deletions src/main/resources/public/js/view-process-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,23 @@ function loadJobsOfProcessInstance() {

if (isActiveJob) {
if (isConnectorJob(job)) {
// a job for a connector can only be invoked
// a job for a connector can be invoked, or completed with variables
actionButton = `
<button id="${connectorButtonId}" type="button" class="btn btn-sm btn-primary">
<svg class="bi" width="18" height="18" fill="white"><use xlink:href="/img/bootstrap-icons.svg#plugin"/></svg>
Invoke
</button>`;
<div class="btn-group">
<button id="${connectorButtonId}" type="button" class="btn btn-sm btn-primary overlay-button">
<svg class="bi" width="18" height="18" fill="white"><use xlink:href="/img/bootstrap-icons.svg#plugin"/></svg>
Invoke
</button>
<button type="button" class="btn btn-sm btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false"><span class="visually-hidden">Toggle Dropdown</span></button>
<ul class="dropdown-menu">
<li>
<a id="${jobCompleteButtonId}" class="dropdown-item" href="#">
<svg class="bi" width="18" height="18" fill="black"><use xlink:href="/img/bootstrap-icons.svg#check"/></svg>
Complete
</a>
</li>
</ul>
</div>`;
} else {
// show all actions for a regular job
actionButton = `
Expand Down Expand Up @@ -1055,26 +1066,25 @@ function loadJobsOfProcessInstance() {
</tr>`);

if (isActiveJob) {
// bind actions for job/connector buttons
$("#" + jobCompleteButtonId).click(function () {
const cachedResponse = localStorage.getItem(
"jobCompletion " + getBpmnProcessId() + " " + elementId
);
let jobVariables = cachedResponse;
if (!cachedResponse) {
jobVariables = "";
}
showJobCompleteModal(job.key, "complete", jobVariables);
});

if (isConnectorJob(job)) {
// bind action for connector button
$("#" + connectorButtonId).click(function () {
executeConnectorJob(job.jobType, job.key);
});

makeConnectorTaskPlayable(elementId, job.key, job.jobType);
} else {
// bind actions for job buttons
$("#" + jobCompleteButtonId).click(function () {
const cachedResponse = localStorage.getItem(
"jobCompletion " + getBpmnProcessId() + " " + elementId
);
let jobVariables = cachedResponse;
if (!cachedResponse) {
jobVariables = "";
}
showJobCompleteModal(job.key, "complete", jobVariables);
});

$("#" + jobFailButtonId).click(function () {
fillJobModal(job.key, "fail");
});
Expand Down Expand Up @@ -1203,6 +1213,7 @@ function loadUserTasksOfProcessInstance() {
}

let previousNumberOfIncidents;

function loadIncidentsOfProcessInstance() {
const processInstanceKey = getProcessInstanceKey();

Expand Down