From 8e0ec48e49ab7a97d29bec048cdb601675c736e4 Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Thu, 29 Aug 2024 11:37:55 -0400 Subject: [PATCH 1/6] Ready for PR --- resources/js/processes/screen-builder/typeDisplay.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/js/processes/screen-builder/typeDisplay.js b/resources/js/processes/screen-builder/typeDisplay.js index 61c1d21ffa..1aadb7893a 100644 --- a/resources/js/processes/screen-builder/typeDisplay.js +++ b/resources/js/processes/screen-builder/typeDisplay.js @@ -15,6 +15,7 @@ const FormNestedScreen = FormBuilderControls.find((control) => control.rendererB const FileDownloadControl = FormBuilderControls.find((control) => control.builderBinding === "FileDownload"); const FormListTable = FormBuilderControls.find((control) => control.rendererBinding === "FormListTable"); const FormAnalyticsChart = FormBuilderControls.find((control) => control.rendererBinding === "FormAnalyticsChart"); +const FormCollectionRecordControl = FormBuilderControls.find((control) => control.rendererBinding === "FormCollectionRecordControl"); // Remove editable inspector props FormRecordList.control.inspector = FormRecordList.control.inspector.filter((prop) => prop.field !== "editable" && prop.field !== "form"); @@ -32,6 +33,7 @@ const controlsDisplay = [ FileDownloadControl, FormListTable, FormAnalyticsChart, + FormCollectionRecordControl, ]; ProcessMaker.EventBus.$on("screen-builder-init", (manager) => { From 91bc23dd9346baf88634c6928365e22442c23f74 Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Tue, 3 Sep 2024 08:19:03 -0400 Subject: [PATCH 2/6] saving progress Save collection data Finished ready to PR --- resources/js/tasks/show.js | 2 ++ resources/views/tasks/edit.blade.php | 53 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/resources/js/tasks/show.js b/resources/js/tasks/show.js index 160d511131..d6528a1e8f 100644 --- a/resources/js/tasks/show.js +++ b/resources/js/tasks/show.js @@ -13,6 +13,7 @@ import TasksList from "./components/TasksList.vue"; import TaskSavePanel from "./components/TaskSavePanel.vue"; import autosaveMixins from "../modules/autosave/autosaveMixin"; import draftFileUploadMixin from "../modules/autosave/draftFileUploadMixin"; +import Mustache from "mustache"; Vue.use(Vuex); Vue.use("task", Task); @@ -31,3 +32,4 @@ Vue.mixin(draftFileUploadMixin); window.debounce = debounce; window.Vuex = Vuex; +window.Mustache = Mustache; \ No newline at end of file diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index bb40359a0f..ac3aef75c1 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -643,6 +643,46 @@ class="multiselect__tag-icon"> updateTask(val) { this.$set(this, 'task', val); }, + processTaskData(task) { + // Verify if object "screen" exists + if (task.screen) { + // Verify if "config" array exists and it has at least one element + if (Array.isArray(task.screen.config) && task.screen.config.length > 0) { + // Iteration on "config" array + for (let configItem of task.screen.config) { + // Verify if "items" array exists + if (Array.isArray(configItem.items)) { + // Iteration over each "items" element + for (let item of configItem.items) { + // Verify if component "FormCollectionRecordControl" is inside the screen + if (item.component === "FormCollectionRecordControl") { + // Access to FormCollectionRecordControl "config" object + const config = item.config; + + // Saving values into variables + const submitCollectionChecked = config.submitCollectionCheck; + let recordId = ""; + const record = config.record; + + if (this.isMustache(record)) { + recordId = Mustache.render(record, this.formData); + } else { + recordId = parseInt(record, 10); + } + const collectionId = config.collection.collectionId; + // Return values + return { submitCollectionChecked, recordId, collectionId }; + } + } + } + } + } + } + return null; + }, + isMustache(record) { + return /\{\{.*\}\}/.test(record); + }, submit(task) { if (this.isSelfService) { ProcessMaker.alert(this.$t('Claim the Task to continue.'), 'warning'); @@ -651,6 +691,19 @@ class="multiselect__tag-icon"> return; } + // If screen has CollectionControl component saves collection data if submit check is true + const resultCollectionComponent = this.processTaskData(this.task); + let messageCollection = this.$t('Collection data was updated'); + if(resultCollectionComponent && resultCollectionComponent.submitCollectionChecked){ + ProcessMaker.apiClient + .put("collections/" + resultCollectionComponent.collectionId+ "/records/" + resultCollectionComponent.recordId, + {data: this.formData, uploads: []}) + .then(() => { + window.ProcessMaker.alert(messageCollection, 'success', 5, true); + }); + + } + let message = this.$t('Task Completed Successfully'); const taskId = task.id; this.submitting = true; From 96a8a907277fe067f55635dad679df5574a164a3 Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Tue, 3 Sep 2024 09:12:01 -0400 Subject: [PATCH 3/6] Applying changes to manage more than one collection ready for PR --- resources/views/tasks/edit.blade.php | 29 +++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index ac3aef75c1..0384ff4de1 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -644,6 +644,7 @@ class="multiselect__tag-icon"> this.$set(this, 'task', val); }, processTaskData(task) { + const results = []; // Verify if object "screen" exists if (task.screen) { // Verify if "config" array exists and it has at least one element @@ -670,15 +671,15 @@ class="multiselect__tag-icon"> recordId = parseInt(record, 10); } const collectionId = config.collection.collectionId; - // Return values - return { submitCollectionChecked, recordId, collectionId }; + // Save the values into the results array + results.push({ submitCollectionChecked, recordId, collectionId }); } } } } } } - return null; + return results.length > 0 ? results : null; }, isMustache(record) { return /\{\{.*\}\}/.test(record); @@ -691,17 +692,23 @@ class="multiselect__tag-icon"> return; } - // If screen has CollectionControl component saves collection data if submit check is true + // If screen has CollectionControl components saves collection data (if submit check is true) const resultCollectionComponent = this.processTaskData(this.task); let messageCollection = this.$t('Collection data was updated'); - if(resultCollectionComponent && resultCollectionComponent.submitCollectionChecked){ - ProcessMaker.apiClient - .put("collections/" + resultCollectionComponent.collectionId+ "/records/" + resultCollectionComponent.recordId, - {data: this.formData, uploads: []}) - .then(() => { - window.ProcessMaker.alert(messageCollection, 'success', 5, true); - }); + if (resultCollectionComponent && resultCollectionComponent.length > 0) { + resultCollectionComponent.forEach(result => { + if (result.submitCollectionChecked) { + ProcessMaker.apiClient + .put("collections/" + result.collectionId + "/records/" + result.recordId, { + data: this.formData, + uploads: [] + }) + .then(() => { + window.ProcessMaker.alert(messageCollection, 'success', 5, true); + }); + } + }); } let message = this.$t('Task Completed Successfully'); From 721338789454f63cc4135571bd54be8c24cd5232 Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Wed, 4 Sep 2024 17:43:43 -0400 Subject: [PATCH 4/6] Removing unused code --- resources/js/processes/screen-builder/typeDisplay.js | 2 -- resources/views/tasks/edit.blade.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/resources/js/processes/screen-builder/typeDisplay.js b/resources/js/processes/screen-builder/typeDisplay.js index 1aadb7893a..61c1d21ffa 100644 --- a/resources/js/processes/screen-builder/typeDisplay.js +++ b/resources/js/processes/screen-builder/typeDisplay.js @@ -15,7 +15,6 @@ const FormNestedScreen = FormBuilderControls.find((control) => control.rendererB const FileDownloadControl = FormBuilderControls.find((control) => control.builderBinding === "FileDownload"); const FormListTable = FormBuilderControls.find((control) => control.rendererBinding === "FormListTable"); const FormAnalyticsChart = FormBuilderControls.find((control) => control.rendererBinding === "FormAnalyticsChart"); -const FormCollectionRecordControl = FormBuilderControls.find((control) => control.rendererBinding === "FormCollectionRecordControl"); // Remove editable inspector props FormRecordList.control.inspector = FormRecordList.control.inspector.filter((prop) => prop.field !== "editable" && prop.field !== "form"); @@ -33,7 +32,6 @@ const controlsDisplay = [ FileDownloadControl, FormListTable, FormAnalyticsChart, - FormCollectionRecordControl, ]; ProcessMaker.EventBus.$on("screen-builder-init", (manager) => { diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index 0384ff4de1..ed263d340e 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -661,7 +661,7 @@ class="multiselect__tag-icon"> const config = item.config; // Saving values into variables - const submitCollectionChecked = config.submitCollectionCheck; + const submitCollectionChecked = config.collectionmode.submitCollectionCheck; let recordId = ""; const record = config.record; From 4badb7bd078049e69e80bf9162acf5ccd86e26a6 Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Thu, 5 Sep 2024 08:03:31 -0400 Subject: [PATCH 5/6] Changing name to method to be more specific --- resources/js/tasks/show.js | 2 +- resources/views/tasks/edit.blade.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/js/tasks/show.js b/resources/js/tasks/show.js index d6528a1e8f..1dca057b42 100644 --- a/resources/js/tasks/show.js +++ b/resources/js/tasks/show.js @@ -32,4 +32,4 @@ Vue.mixin(draftFileUploadMixin); window.debounce = debounce; window.Vuex = Vuex; -window.Mustache = Mustache; \ No newline at end of file +window.Mustache = Mustache; diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index ed263d340e..7795fe8c4f 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -643,7 +643,7 @@ class="multiselect__tag-icon"> updateTask(val) { this.$set(this, 'task', val); }, - processTaskData(task) { + processCollectionData(task) { const results = []; // Verify if object "screen" exists if (task.screen) { @@ -693,7 +693,7 @@ class="multiselect__tag-icon"> } // If screen has CollectionControl components saves collection data (if submit check is true) - const resultCollectionComponent = this.processTaskData(this.task); + const resultCollectionComponent = this.processCollectionData(this.task); let messageCollection = this.$t('Collection data was updated'); if (resultCollectionComponent && resultCollectionComponent.length > 0) { From ff057ec46706a3935bad4993ecd03a575b8c445b Mon Sep 17 00:00:00 2001 From: CarliPinell Date: Thu, 5 Sep 2024 15:54:18 -0400 Subject: [PATCH 6/6] Improving save collection logic --- resources/views/tasks/edit.blade.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/resources/views/tasks/edit.blade.php b/resources/views/tasks/edit.blade.php index 7795fe8c4f..d497e62bfe 100644 --- a/resources/views/tasks/edit.blade.php +++ b/resources/views/tasks/edit.blade.php @@ -661,6 +661,7 @@ class="multiselect__tag-icon"> const config = item.config; // Saving values into variables + const collectionFields = config.collection.data[0]; const submitCollectionChecked = config.collectionmode.submitCollectionCheck; let recordId = ""; const record = config.record; @@ -672,7 +673,7 @@ class="multiselect__tag-icon"> } const collectionId = config.collection.collectionId; // Save the values into the results array - results.push({ submitCollectionChecked, recordId, collectionId }); + results.push({ submitCollectionChecked, recordId, collectionId, collectionFields }); } } } @@ -699,9 +700,13 @@ class="multiselect__tag-icon"> if (resultCollectionComponent && resultCollectionComponent.length > 0) { resultCollectionComponent.forEach(result => { if (result.submitCollectionChecked) { + let collectionKeys = Object.keys(result.collectionFields); + let matchingKeys = _.intersection(Object.keys(this.formData), collectionKeys); + let collectionsData = _.pick(this.formData, matchingKeys); + ProcessMaker.apiClient .put("collections/" + result.collectionId + "/records/" + result.recordId, { - data: this.formData, + data: collectionsData, uploads: [] }) .then(() => {