Skip to content

Commit

Permalink
Merge pull request #5399 from ProcessMaker/epic/FOUR-9674
Browse files Browse the repository at this point in the history
Epic/FOUR-9674: AI in modeler
  • Loading branch information
ryancooley authored Oct 4, 2023
2 parents 68ad511 + 43e58fd commit 9d96125
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
44 changes: 44 additions & 0 deletions ProcessMaker/Http/Controllers/Api/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,50 @@ public function update(Request $request, Process $process)
return new Resource($process->refresh());
}

public function updateBpmn(Request $request, Process $process)
{
$request->validate(Process::rules($process));

// bpmn validation
if ($schemaErrors = $this->validateBpmn($request)) {
$warnings = [];
foreach ($schemaErrors as $error) {
if (is_string($error)) {
$text = str_replace('DOMDocument::schemaValidate(): ', '', $error);
$warnings[] = ['title' => __('Schema Validation'), 'text' => $text];
} else {
$warnings[] = $error;
}
}
$process->warnings = $warnings;
} else {
$process->warnings = null;
}

$process->bpmn = $request->input('bpmn');
$process->name = $request->input('name');
$process->description = $request->input('description');
$process->saveOrFail();

// If is a subprocess, we need to update the name in the BPMN too
if ($request->input('parentProcessId') && $request->input('nodeId')) {
$parentProcess = Process::findOrFail($request->input('parentProcessId'));
$definitions = $parentProcess->getDefinitions();
$elements = $definitions->getElementsByTagName('callActivity');
foreach ($elements as $element) {
if ($element->getAttributeNode('id')->value === $request->input('nodeId')) {
$element->setAttribute('name', $request->input('name'));
}
}
$parentProcess->bpmn = $definitions->saveXML();
$parentProcess->saveOrFail();
}

return response()->json([
'success' => true,
], 200);
}

/**
* Update draft process.
*
Expand Down
3 changes: 1 addition & 2 deletions resources/js/processes/components/CreateProcessModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@
ProcessMaker.alert(this.$t("The process was created."), "success");
if (this.callFromAiModeler) {
const url = `http://processmaker.test/package-ai/processes/create/${response.data.id}`;
this.$emit("clear-ai-history");
const url = `/package-ai/processes/create/${response.data.id}`;
this.$emit("process-created-from-modeler", url, response.data.id, response.data.name);
} else {
window.location = `/modeler/${response.data.id}`;
Expand Down
14 changes: 7 additions & 7 deletions resources/js/processes/modeler/components/ModelerApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export default {
ProcessMaker.$modeler = this.$refs.modeler;
window.ProcessMaker.EventBus.$emit("modeler-app-init", this);
window.ProcessMaker.EventBus.$on("modeler-save", (redirectUrl, onSuccess, onError) => {
this.saveProcess(onSuccess, onError, redirectUrl);
window.ProcessMaker.EventBus.$on("modeler-save", (redirectUrl, nodeId, onSuccess, onError) => {
this.saveProcess(onSuccess, onError, redirectUrl, nodeId);
});
window.ProcessMaker.EventBus.$on("modeler-change", () => {
window.ProcessMaker.EventBus.$emit("new-changes");
Expand Down Expand Up @@ -203,15 +203,15 @@ export default {
});
return notifications;
},
emitSaveEvent({ xml, svg, redirectUrl = null }) {
emitSaveEvent({ xml, svg, redirectUrl = null, nodeId = null }) {
this.dataXmlSvg.xml = xml;
this.dataXmlSvg.svg = svg;
if (this.externalEmit.includes("open-modal-versions")) {
window.ProcessMaker.EventBus.$emit("open-modal-versions", redirectUrl);
window.ProcessMaker.EventBus.$emit("open-modal-versions", redirectUrl, nodeId);
return;
}
window.ProcessMaker.EventBus.$emit("modeler-save", redirectUrl);
window.ProcessMaker.EventBus.$emit("modeler-save", redirectUrl, nodeId);
},
emitDiscardEvent() {
if (this.externalEmit.includes("open-versions-discard-modal")) {
Expand All @@ -227,7 +227,7 @@ export default {
window.location.reload();
});
},
saveProcess(onSuccess, onError, redirectUrl = null) {
saveProcess(onSuccess, onError, redirectUrl = null, nodeId = null) {
const data = {
name: this.process.name,
description: this.process.description,
Expand All @@ -246,7 +246,7 @@ export default {
ProcessMaker.alert(this.$t(`The ${type} was saved.`, { type }), "success");
// Set published status.
this.setVersionIndicator(false);
window.ProcessMaker.EventBus.$emit("save-changes", redirectUrl);
window.ProcessMaker.EventBus.$emit("save-changes", redirectUrl, nodeId);
this.$set(this, "warnings", response.data.warnings || []);
if (response.data.warnings && response.data.warnings.length > 0) {
window.ProcessMaker.EventBus.$emit("save-changes-activate-autovalidate");
Expand Down
32 changes: 29 additions & 3 deletions resources/js/processes/scripts/components/CorneaTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
>
<b-collapse id="assistant" :visible="showPromptArea">
<div v-if="!showPromptArea">
<div class="card-header m-0 d-flex border-0 pb-1">
<div class="card-header m-0 d-flex border-0 pb-1 px-2">
<div class="d-flex w-50 p-2 ai-button-container">
<div
role="button"
Expand Down Expand Up @@ -75,7 +75,7 @@
</div>
</div>

<div class="card-header m-0 d-flex border-0 pt-0">
<div class="card-header m-0 d-flex border-0 pt-0 px-2">
<div class="d-flex w-50 p-2 ai-button-container">
<div
role="button"
Expand Down Expand Up @@ -119,6 +119,10 @@
:default-prompt="defaultPrompt"
@generate-script="onGenerateScript"
/>

<div v-if="error" class="pb-3 px-3 bg-assistant-buttons">
<div class="alert alert-error m-0 text-center px-2 ">{{ error }}</div>
</div>
</b-collapse>
</b-list-group-item>
</div>
Expand Down Expand Up @@ -157,6 +161,7 @@ export default {
loading: false,
promptSessionId: "",
prompt: "",
error: "",
progress: {
progress: 0,
},
Expand Down Expand Up @@ -313,6 +318,10 @@ export default {
},
async cleanScript() {
if (!this.sourceCode || this.sourceCode === "") {
this.error = this.$t("Please add and select some code to clean.");
return;
}
this.getSelection();
this.getNonce();
this.$emit("set-diff", true);
Expand Down Expand Up @@ -348,6 +357,10 @@ export default {
},
async documentScript() {
if (!this.sourceCode || this.sourceCode === "") {
this.error = this.$t("Please add and select some code to document.");
return;
}
this.getSelection();
this.getNonce();
this.$emit("set-diff", true);
Expand Down Expand Up @@ -386,6 +399,10 @@ export default {
});
},
async explainScript() {
if (!this.sourceCode || this.sourceCode === "") {
this.error = this.$t("Please add and select some code to explain.");
return;
}
this.getSelection();
this.getNonce();
this.$emit("set-diff", false);
Expand Down Expand Up @@ -414,7 +431,7 @@ export default {
this.$emit(
"request-started",
this.progress,
this.$t("Generating explanation")
this.$t("Generating explanation"),
);
}
})
Expand Down Expand Up @@ -481,4 +498,13 @@ export default {
.ai-icon {
margin-left: -1px;
}
.bg-assistant-buttons {
background: #f8f8f8;
}
.alert-error {
background-color: #D3E1FC;
border: 0;
border-radius: 8px;
color: #1C4193;
}
</style>
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
Route::post('processes/{process}/import/assignments', [ProcessController::class, 'importAssignments'])->name('processes.import.assignments')->middleware('can:import-processes');
Route::post('processes', [ProcessController::class, 'store'])->name('processes.store')->middleware('can:create-processes');
Route::put('processes/{process}', [ProcessController::class, 'update'])->name('processes.update')->middleware('can:edit-processes');
Route::put('processes/{process}/update-bpmn', [ProcessController::class, 'updateBpmn'])->name('processes.update_bpmn')->middleware('can:edit-processes');
Route::put('processes/{process}/draft', [ProcessController::class, 'updateDraft'])->name('processes.update_draft')->middleware('can:edit-screens');
Route::post('processes/{process}/close', [ProcessController::class, 'close'])->name('processes.close')->middleware('can:edit-processes');
Route::delete('processes/{process}', [ProcessController::class, 'destroy'])->name('processes.destroy')->middleware('can:archive-processes');
Expand Down

0 comments on commit 9d96125

Please sign in to comment.