From fcc9105633e081d734357bbfc03f0e5b7a77ee37 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Tue, 11 Feb 2025 16:08:45 +0800 Subject: [PATCH] Admin Workflow - Fix Tested Issues - upload 3 documents at one step --- .../UpdateNextQuestionV1AdminWFLogic.php | 4 +- .../SaveAnswerV1AdminWFProcessor.php | 40 +++++++++++++---- .../forms/AdminWorkFlowFormComponent.vue | 43 ++++++++++++++++--- 3 files changed, 70 insertions(+), 17 deletions(-) diff --git a/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php b/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php index b59d7ff8..b78f84e0 100644 --- a/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php +++ b/app/Classes/Modules/Questionnaires/ControllersLogic/UpdateNextQuestionV1AdminWFLogic.php @@ -115,7 +115,7 @@ class UpdateNextQuestionV1AdminWFLogic extends AbstractControllerLogic } //Save answer given by user (both next and previous) - $filesUpload = $request->input('files'); + $filesUpload = $request->only(['files', 'filesA', 'filesB', 'filesC']); $answerOptionId = 0; if ($request->has('answerObj')) { $answerOptionId = intval($request->answerObj['id']); @@ -187,4 +187,4 @@ class UpdateNextQuestionV1AdminWFLogic extends AbstractControllerLogic return $this->resourceResponse(new QuestionResource($returnQuestion, $userId, $request->has('isPrevious'), $isNoGoingBack, $previousAnswer)); } -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php b/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php index 64ff9be7..e33018e1 100644 --- a/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php +++ b/app/Classes/Modules/Questionnaires/Processors/SaveAnswerV1AdminWFProcessor.php @@ -6,6 +6,7 @@ namespace App\Classes\Modules\Questionnaires\Processors; use App\Models\QAUserAnswerSelected; use App\Classes\Modules\Documents\Processors\UploadDocumentProcessor; use App\Classes\ValueObjects\Constants\QAType; +use Illuminate\Support\Facades\Log; class SaveAnswerV1AdminWFProcessor { @@ -27,7 +28,7 @@ class SaveAnswerV1AdminWFProcessor public function execute($userId, $sourceId, $questionId, $questionType, $questionMetadata, $answerInText, $answerOptionId, $filesUpload, $timeUsedSeconds, $isPrevious, $reference = null){ $answer = null; - $attachments = null; + $attachments = []; if(is_null($answer)) { @@ -46,16 +47,25 @@ class SaveAnswerV1AdminWFProcessor $answer->save(); //cief todo: why 2 save() in this file, this is wrong if($filesUpload){ - $result = $this->uploadDocumentForProcessor->execute($filesUpload, $answer, 'questionnaires'); - $attachments = array_map(function ($item) { - return [ - 'document_id' => $item->document_id, - 'file_id' => $item->id, - ]; - }, $result); + if (isset($filesUpload['filesA'])) + { + foreach ($filesUpload as $key => $files) { + $attachments[$key] = $this->saveFile($answer, $files); + } + } + else if (isset($filesUpload['files']) && $filesUpload['files']) + { + $attachments = $this->saveFile($answer, $filesUpload['files']); + } } - if($questionType === QAType::REMARKS_WITH_DOCUMENT_UPLOAD){ + if($questionType === QAType::SUBMIT_1688_3_TYPES_DOCUMENTS){ + $structuredAnswer = [ + 'files' => $attachments, + ]; + $answer->answer = json_encode($structuredAnswer); + } + else if($questionType === QAType::REMARKS_WITH_DOCUMENT_UPLOAD){ $structuredAnswer = [ 'text' => $answerInText, 'files' => $attachments, @@ -75,4 +85,16 @@ class SaveAnswerV1AdminWFProcessor return $answer; } + + private function saveFile($answer, $files){ + $result = $this->uploadDocumentForProcessor->execute($files, $answer, 'questionnaires'); + $attachment = array_map(function ($item) { + return [ + 'name' => $item->document_id, + 'file_id' => $item->id, + ]; + }, $result); + + return $attachment; + } } diff --git a/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue b/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue index 0d9e9bef..b4ae783d 100644 --- a/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue +++ b/resources/assets/vue/components/general/forms/AdminWorkFlowFormComponent.vue @@ -219,7 +219,7 @@ Upload the English PO - + @@ -229,7 +229,7 @@

Upload the China PO

- + @@ -239,7 +239,7 @@

Upload Bank Slip

- + @@ -400,6 +400,9 @@ section: 'adminWorkFlowForm', showAnswerInput: false, showUploadInput: false, + showUploadInputA: false, + showUploadInputB: false, + showUploadInputC: false, formTouched: false, question: null, answer: '', @@ -407,6 +410,9 @@ direction: 'next', documentType: 1, files: [], + filesA: [], //English PO + filesB: [], //China PO + filesC: [], //Bank Slip error: null, // From AdminWorkFlowSectionComponent @@ -430,6 +436,15 @@ }, files: { required: this.formTouched && this.showUploadInput ? required : false, + }, + filesA: { + required: this.formTouched && this.showUploadInputA ? required : false, //English PO + }, + filesB: { + required: this.formTouched && this.showUploadInputB ? required : false, //China PO + }, + filesC: { + required: this.formTouched && this.showUploadInputC ? required : false, //Bank Slip } }; }, @@ -577,7 +592,6 @@ this.parameters.answer = this.answer; this.parameters.answerId = this.answerId; this.parameters.answerObj = this.question.question_answers.find(item => item.id === Number(this.answerId)); - this.parameters.files = this.files; this.parameters.extra = {}; this.error = null; @@ -585,6 +599,7 @@ if(this.question.question_type === 3){ this.showAnswerInput = false; this.showUploadInput = true; + this.parameters.files = this.files; } else if(this.question.question_type === 1 || (this.question.question_type === 2)){ this.showAnswerInput = true; @@ -593,6 +608,17 @@ else if(this.question.question_type === 7){ this.showAnswerInput = true; this.showUploadInput = false; + this.parameters.files = this.files; + } + else if(this.question.question_type === 8){ + this.showAnswerInput = false; + this.showUploadInput = false; + this.showUploadInputA = true; + this.showUploadInputB = true; + this.showUploadInputC = true; + this.parameters.filesA = this.filesA; + this.parameters.filesB = this.filesB; + this.parameters.filesC = this.filesC; } this.parameters.extra.timeUsedSeconds = this.stepTime; @@ -621,13 +647,12 @@ this.parameters.extra.session_id = this.sessionId; if(direction === 'next'){ - if (this.parameters.answer === 'start_work') this.startWork(); if (this.parameters.answer === 'stop_working') this.stopTimer(); - this.submit(this.route('api.questionnaires.next.question'), 'post', this.section, false, false); } else if(direction === 'previous'){ + console.log('previous'); this.formTouched = false; this.parameters.isPrevious = true; this.submit(this.route('api.questionnaires.next.question'), 'post', this.section, false, false); @@ -638,9 +663,15 @@ this.answer = ''; this.answerId = 0; this.files = []; + this.filesA = []; + this.filesB = []; + this.filesC = []; this.formTouched = false; this.showAnswerInput = false; this.showUploadInput = false; + this.showUploadInputA = false; + this.showUploadInputB = false; + this.showUploadInputC = false; this.error = null; this.stepTime = 0; this.externalApiUrl = "";