From b58786085d167b663e7cabeadfce0f3619965534 Mon Sep 17 00:00:00 2001 From: Denzel Date: Fri, 24 Jan 2025 13:53:26 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/vote/VoteConstructor.vue | 79 ++++++++++++++----- 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/src/front/src/components/vote/VoteConstructor.vue b/src/front/src/components/vote/VoteConstructor.vue index b7810cf92..78caae4de 100644 --- a/src/front/src/components/vote/VoteConstructor.vue +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -142,13 +142,29 @@
- - - + + + + +
@@ -425,17 +441,37 @@ export default { const errorMessage = ref(""); + const validateAnswers = () => { + return form.value.questions.some((question) => { + if (question.settings.choice === "free") { + return question.answers.some( + (answer) => !answer.text || answer.text.trim() === "" + ); + } + return false; + }); + }; + const saveVoting = async () => { const hasEmptyQuestions = quests.value.includes(false); - if (!form.value.title || !form.value.description || form.value.questions.length < 1 || hasEmptyQuestions) { - errorMessage.value = "Все обязательные поля должны быть заполнены"; + const hasInvalidAnswers = validateAnswers(); + + if ( + !form.value.title || + !form.value.description || + form.value.questions.length < 1 || + hasEmptyQuestions || + hasInvalidAnswers + ) { + errorMessage.value = "Все обязательные поля и ответы должны быть заполнены"; return; } + try { const response = await createVote(form.value); console.log("Голосование успешно создано:", response); isVoteCreated.value = true; - emit('updating', 'active'); + emit("updating", "active"); } catch (error) { console.error("Ошибка при создании голосования:", error); } @@ -469,8 +505,7 @@ export default { ); watch(form.value, () => { - const hasEmptyQuestions = quests.value.includes(false); - if (!form.value.title || !form.value.description || form.value.questions.length < 1 || hasEmptyQuestions) { + if (!form.value.title || !form.value.description || form.value.questions.length < 1) { errorMessage.value = "Все обязательные поля должны быть заполнены"; } else { errorMessage.value = ""; @@ -483,12 +518,20 @@ export default { watch(() => form.value.questions, updateQuests, { deep: true }); - watch(() => form.value.questions, (newQuestions) => { - const hasEmptyQuestions = newQuestions.some((q) => !q.text || q.text.trim() === ""); - errorMessage.value = hasEmptyQuestions - ? "Все вопросы должны быть заполнены" - : ""; - }, { deep: true }); + watch( + () => form.value.questions, + (newQuestions) => { + const hasEmptyQuestions = newQuestions.some((q) => !q.text || q.text.trim() === ""); + const hasInvalidAnswers = validateAnswers(); + + if (hasEmptyQuestions || hasInvalidAnswers) { + errorMessage.value = "Все вопросы и ответы должны быть заполнены"; + } else { + errorMessage.value = ""; + } + }, + { deep: true } + ); watch(selectedTimeStart, () => { From 59eb528db823f45a5f556ee7b41f65c8ee260359 Mon Sep 17 00:00:00 2001 From: Denzel Date: Fri, 24 Jan 2025 14:07:19 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D1=80=D0=B5=D1=84=20=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/src/components/vote/VoteResult.vue | 6 +++++- src/front/src/views/VoteHomePage.vue | 17 +++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/front/src/components/vote/VoteResult.vue b/src/front/src/components/vote/VoteResult.vue index f48e5df08..efe28558e 100644 --- a/src/front/src/components/vote/VoteResult.vue +++ b/src/front/src/components/vote/VoteResult.vue @@ -35,7 +35,10 @@ v-for="(winner, department) in getWinnersByDepartment(question).winnersByDepartment" :key="department" > - + {{ department }} @@ -181,6 +184,7 @@ @click.stop="opendialog(answer)"/> {{ answer.employee ? answer.employee.fio : answer.name }}: {{ answer.count }} + {{ voteCount(answer.count) }}