diff --git a/ProcessMaker/Http/Controllers/Api/ProcessController.php b/ProcessMaker/Http/Controllers/Api/ProcessController.php index 939bf115b3..5be7304145 100644 --- a/ProcessMaker/Http/Controllers/Api/ProcessController.php +++ b/ProcessMaker/Http/Controllers/Api/ProcessController.php @@ -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. * 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/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"); diff --git a/resources/js/processes/scripts/components/CorneaTab.vue b/resources/js/processes/scripts/components/CorneaTab.vue index 0517a0309b..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, }, @@ -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); @@ -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); @@ -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); @@ -414,7 +431,7 @@ export default { this.$emit( "request-started", this.progress, - this.$t("Generating explanation") + this.$t("Generating explanation"), ); } }) @@ -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; +} 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');