From 11313e57d6721128c0d932c2e51ba989c2063fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Busso?= <90727999+agustinbusso@users.noreply.github.com> Date: Wed, 27 Sep 2023 13:35:53 -0300 Subject: [PATCH 1/5] Update BPMN with the new generated --- .../Controllers/Api/ProcessController.php | 30 +++++++++++++++++++ .../components/CreateProcessModal.vue | 3 +- routes/api.php | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ProcessMaker/Http/Controllers/Api/ProcessController.php b/ProcessMaker/Http/Controllers/Api/ProcessController.php index 939bf115b3..b0fd60a8dd 100644 --- a/ProcessMaker/Http/Controllers/Api/ProcessController.php +++ b/ProcessMaker/Http/Controllers/Api/ProcessController.php @@ -399,6 +399,36 @@ 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(); + + return response()->json([ + 'success' => true, + ], 200); + } + /** * Update draft process. * diff --git a/resources/js/processes/components/CreateProcessModal.vue b/resources/js/processes/components/CreateProcessModal.vue index be3ff7b715..a74936bb98 100644 --- a/resources/js/processes/components/CreateProcessModal.vue +++ b/resources/js/processes/components/CreateProcessModal.vue @@ -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}`; diff --git a/routes/api.php b/routes/api.php index 097603d4ee..eed6037f43 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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'); From 49aba635d1379b6dbf75966b955c5e6618c7f3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Busso?= <90727999+agustinbusso@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:40:13 -0300 Subject: [PATCH 2/5] Update parent process with name --- .../Http/Controllers/Api/ProcessController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ProcessMaker/Http/Controllers/Api/ProcessController.php b/ProcessMaker/Http/Controllers/Api/ProcessController.php index b0fd60a8dd..5be7304145 100644 --- a/ProcessMaker/Http/Controllers/Api/ProcessController.php +++ b/ProcessMaker/Http/Controllers/Api/ProcessController.php @@ -424,6 +424,20 @@ public function updateBpmn(Request $request, Process $process) $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); From 2c5bcb720069ccb4bacef6a408d5a28c357942fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Busso?= <90727999+agustinbusso@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:41:00 -0300 Subject: [PATCH 3/5] Passing node id for save --- .../js/processes/modeler/components/ModelerApp.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/js/processes/modeler/components/ModelerApp.vue b/resources/js/processes/modeler/components/ModelerApp.vue index 6e95c0d301..d26bb13296 100644 --- a/resources/js/processes/modeler/components/ModelerApp.vue +++ b/resources/js/processes/modeler/components/ModelerApp.vue @@ -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"); @@ -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")) { @@ -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, @@ -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"); From 5563ee0566565204801ff7ba2092e4f1998aa8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Busso?= <90727999+agustinbusso@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:28:44 -0300 Subject: [PATCH 4/5] Add warning messages if code is empty --- .../js/processes/scripts/components/CorneaTab.vue | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/js/processes/scripts/components/CorneaTab.vue b/resources/js/processes/scripts/components/CorneaTab.vue index 0517a0309b..61accfab0d 100644 --- a/resources/js/processes/scripts/components/CorneaTab.vue +++ b/resources/js/processes/scripts/components/CorneaTab.vue @@ -313,6 +313,10 @@ export default { }, async cleanScript() { + if (!this.sourceCode || this.sourceCode === "") { + window.ProcessMaker.alert(this.$t("The text editor does not have any code to clean."), "danger"); + return; + } this.getSelection(); this.getNonce(); this.$emit("set-diff", true); @@ -348,6 +352,10 @@ export default { }, async documentScript() { + if (!this.sourceCode || this.sourceCode === "") { + window.ProcessMaker.alert(this.$t("The text editor does not have any code to document."), "danger"); + return; + } this.getSelection(); this.getNonce(); this.$emit("set-diff", true); @@ -386,6 +394,10 @@ export default { }); }, async explainScript() { + if (!this.sourceCode || this.sourceCode === "") { + window.ProcessMaker.alert(this.$t("The text editor does not have any code to explain."), "danger"); + return; + } this.getSelection(); this.getNonce(); this.$emit("set-diff", false); From 43e58fdb1d2425a219efe76e3b638d2a4342791b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Busso?= <90727999+agustinbusso@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:08:13 -0300 Subject: [PATCH 5/5] UI Fixes in copilot for scripting --- .../scripts/components/CorneaTab.vue | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/resources/js/processes/scripts/components/CorneaTab.vue b/resources/js/processes/scripts/components/CorneaTab.vue index 61accfab0d..4c6dffde1a 100644 --- a/resources/js/processes/scripts/components/CorneaTab.vue +++ b/resources/js/processes/scripts/components/CorneaTab.vue @@ -38,7 +38,7 @@ >
-
+
-
+
+ +
+
{{ error }}
+
@@ -157,6 +161,7 @@ export default { loading: false, promptSessionId: "", prompt: "", + error: "", progress: { progress: 0, }, @@ -314,7 +319,7 @@ export default { async cleanScript() { if (!this.sourceCode || this.sourceCode === "") { - window.ProcessMaker.alert(this.$t("The text editor does not have any code to clean."), "danger"); + this.error = this.$t("Please add and select some code to clean."); return; } this.getSelection(); @@ -353,7 +358,7 @@ export default { async documentScript() { if (!this.sourceCode || this.sourceCode === "") { - window.ProcessMaker.alert(this.$t("The text editor does not have any code to document."), "danger"); + this.error = this.$t("Please add and select some code to document."); return; } this.getSelection(); @@ -395,7 +400,7 @@ export default { }, async explainScript() { if (!this.sourceCode || this.sourceCode === "") { - window.ProcessMaker.alert(this.$t("The text editor does not have any code to explain."), "danger"); + this.error = this.$t("Please add and select some code to explain."); return; } this.getSelection(); @@ -426,7 +431,7 @@ export default { this.$emit( "request-started", this.progress, - this.$t("Generating explanation") + this.$t("Generating explanation"), ); } }) @@ -493,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; +}