From d456952d6c6b7739e7b93dc8793c3bde5c97193b Mon Sep 17 00:00:00 2001 From: Denis Voinovich Date: Mon, 2 Jun 2025 08:56:17 +0300 Subject: [PATCH 1/8] =?UTF-8?q?fix=20[P-227]:=20=D1=80=D0=B5=D0=B7=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D0=B0=D1=82=D1=8B=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/testing/TestResults.vue | 189 +++++++++++++++--- src/front/src/views/TestHomePage.vue | 37 +++- 2 files changed, 194 insertions(+), 32 deletions(-) diff --git a/src/front/src/components/testing/TestResults.vue b/src/front/src/components/testing/TestResults.vue index 78c664df5..292419d11 100644 --- a/src/front/src/components/testing/TestResults.vue +++ b/src/front/src/components/testing/TestResults.vue @@ -19,17 +19,18 @@ mdi-checkbox-marked-circle

{{ correctAnswers }}/{{ totalQuestions }}

- Правильных ответов - mdi-information + {{ isPracticeMode ? 'Правильных ответов (нажмите чтобы увидеть детали)' : 'Правильных ответов' }}
@@ -51,7 +52,7 @@
- + @@ -68,10 +69,10 @@
- {{ isQuestionCorrect(index) ? 'mdi-check-circle' : 'mdi-close-circle' }} + {{ getQuestionStatusIcon(index) }} Вопрос {{ index + 1 }}
@@ -79,18 +80,32 @@

{{ question.name }}

-
+
- {{ answer.right_wrong ? 'mdi-check' : 'mdi-minus' }} + {{ getAnswerIcon(index, answer) }} - + {{ answer.name }} - (правильный ответ) + + Ваш ответ + +
+
+ +
+ {{ isQuestionCorrect(index) ? 'Правильно ✓' : 'Неправильно ✗' }} +
@@ -98,6 +113,19 @@ + + +
+ + mdi-refresh + Попробовать ещё раз + +
@@ -125,6 +153,10 @@ export default { userAnswers: { type: Array, required: true + }, + fromCompletedTab: { + type: Boolean, + default: false } }, setup(props) { @@ -133,25 +165,132 @@ export default { const isPracticeMode = computed(() => !route.query.mode || route.query.mode === 'practice'); - const isQuestionCorrect = (questionIndex) => { - const question = props.questions[questionIndex]; - const userAnswer = props.userAnswers[questionIndex]; - - if (!userAnswer) return false; - - if (Array.isArray(userAnswer)) { - const correctAnswers = question.answers.filter(a => a.right_wrong).map(a => a.name); - return userAnswer.length === correctAnswers.length && - userAnswer.every(answer => correctAnswers.includes(answer)); + const getQuestionStatusColor = (questionIndex) => { + if (!props.questions[questionIndex]?.answers) return 'grey'; + + if (props.fromCompletedTab) { + return 'grey'; } - - return question.answers.find(a => a.name === userAnswer)?.right_wrong || false; + + const hasCorrectAnswers = props.questions[questionIndex].answers.some(a => a.right_wrong === true); + return hasCorrectAnswers ? 'success' : 'grey'; }; + const getQuestionStatusIcon = (questionIndex) => { + if (!props.questions[questionIndex]?.answers) return 'mdi-circle-outline'; + + if (props.fromCompletedTab) { + return ''; + } + + const hasCorrectAnswers = props.questions[questionIndex].answers.some(a => a.right_wrong === true); + return hasCorrectAnswers ? 'mdi-check-circle' : 'mdi-circle-outline'; + }; + + const hasUserAnswer = (index) => { + const answer = props.userAnswers?.[index]; + return answer !== null && answer !== undefined; + }; + + const showUserAnswer = (index, answerName) => { + const userAnswer = props.userAnswers?.[index]; + if (!userAnswer) return false; + + if (Array.isArray(userAnswer)) { + return userAnswer.includes(answerName); + } + return userAnswer === answerName; + }; const isQuestionCorrect = (questionIndex) => { + const question = props.questions?.[questionIndex]; + if (!question?.answers || !Array.isArray(question.answers)) return false; + + const userAnswer = props.userAnswers?.[questionIndex]; + if (!userAnswer) return false; + + const correctAnswers = question.answers.filter(a => a.right_wrong === true); + if (correctAnswers.length === 0) return false; + + if (Array.isArray(userAnswer)) { + return correctAnswers.length === userAnswer.length && + correctAnswers.every(a => userAnswer.includes(a.name)) && + userAnswer.every(ua => correctAnswers.some(ca => ca.name === ua)); + } + + return correctAnswers.some(a => a.name === userAnswer); + }; + + const isAnswerCorrect = (questionIndex, answer) => { + if (!answer || !answer.name || questionIndex === undefined || questionIndex === null) { + return false; + } + + if (!props.fromCompletedTab) { + return answer.right_wrong === true; + } + + const userAnswer = props.userAnswers?.[questionIndex]; + if (!userAnswer) return false; + + const isSelected = Array.isArray(userAnswer) + ? userAnswer.includes(answer.name) + : userAnswer === answer.name; + + return isSelected && answer.right_wrong === true; + }; + + const getAnswerColor = (questionIndex, answer) => { + if (!answer?.name) return 'grey'; + + if (answer.right_wrong === true) { + return 'success'; + } + + const userAnswer = props.userAnswers?.[questionIndex]; + if (userAnswer) { + const isSelected = Array.isArray(userAnswer) + ? userAnswer.includes(answer.name) + : userAnswer === answer.name; + + if (isSelected) { + return 'error'; + } + } + + return 'grey'; + }; + + const getAnswerIcon = (questionIndex, answer) => { + if (!answer?.name) return 'mdi-circle-outline'; + + if (answer.right_wrong === true) { + return 'mdi-check-circle'; + } + + const userAnswer = props.userAnswers?.[questionIndex]; + if (userAnswer) { + const isSelected = Array.isArray(userAnswer) + ? userAnswer.includes(answer.name) + : userAnswer === answer.name; + + if (isSelected) { + return 'mdi-close-circle'; + } + } + + return 'mdi-circle-outline'; + }; + return { showAnswersDialog, isPracticeMode, - isQuestionCorrect + isQuestionCorrect, + hasUserAnswer, + showUserAnswer, + isAnswerCorrect, + getAnswerColor, + getAnswerIcon, + getQuestionStatusColor, + getQuestionStatusIcon }; } }; diff --git a/src/front/src/views/TestHomePage.vue b/src/front/src/views/TestHomePage.vue index 3c96f67ee..9dbf50343 100644 --- a/src/front/src/views/TestHomePage.vue +++ b/src/front/src/views/TestHomePage.vue @@ -175,6 +175,7 @@ :formattedTime="testResults.time_spent" :questions="testResults.questions" :userAnswers="testResults.user_answers" + :fromCompletedTab="testResults.fromCompletedTab" /> @@ -387,14 +388,36 @@ export default { axiosApiInstance.get(`/api/tests/testresultview/?id=${id}`) ]); + const questions = (testDetailResponse.data.questions || []).map(q => ({ + ...q, + answers: (q.answers || []).map(a => ({ + ...a, + isUserAnswer: false + })) + })); + + const userAnswers = questions.map(question => { + const userAnswer = resultResponse.data.user_answers?.[question.id]; + if (!userAnswer) return null; + + question.answers.forEach(answer => { + answer.isUserAnswer = Array.isArray(userAnswer) + ? userAnswer.includes(answer.name) + : userAnswer === answer.name; + }); + + return userAnswer; + }); + testResults.value = { - passed: resultResponse.data.is_passed, - total_questions: testDetailResponse.data.question_count, - total_answers: resultResponse.data.answered_questions_total, - correct_answers: resultResponse.data.score, - time_spent: `${testDetailResponse.data.time} мин`, - questions: [], - userAnswers: [] + passed: resultResponse.data.is_passed || false, + total_questions: testDetailResponse.data.question_count || 0, + total_answers: resultResponse.data.answered_questions_total || 0, + correct_answers: resultResponse.data.score || 0, + time_spent: `${testDetailResponse.data.time || 0} мин`, + questions: questions, + userAnswers: userAnswers, + fromCompletedTab: activeTab.value === 1 }; showResultsDialog.value = true; From b3a8d81e4e64d96a6510884fa809ea5784676329 Mon Sep 17 00:00:00 2001 From: Denis Voinovich Date: Mon, 2 Jun 2025 09:06:19 +0300 Subject: [PATCH 2/8] =?UTF-8?q?fix=20[P-229]:=20=D0=A1=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=20-=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20is=5Fstaff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/src/views/TestHomePage.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/front/src/views/TestHomePage.vue b/src/front/src/views/TestHomePage.vue index 9dbf50343..074e7eb4b 100644 --- a/src/front/src/views/TestHomePage.vue +++ b/src/front/src/views/TestHomePage.vue @@ -105,7 +105,7 @@ - + @@ -265,7 +265,7 @@ export default { { value: 0, title: `Назначенные (${currentTest.value})` }, { value: 1, title: 'Завершенные' }, { value: 2, title: 'Каталог' }, - { value: 3, title: 'Создать новый тест' }, + ...(accountStore.user.is_staff ? [{ value: 3, title: 'Создать новый тест' }] : []), ]); const goToTest = (id) => router.push(`/test/testdetail/${id}`); From 5672bebde56401ab804ee54109a71eeeeb109ca0 Mon Sep 17 00:00:00 2001 From: Denis Voinovich Date: Mon, 2 Jun 2025 09:13:23 +0300 Subject: [PATCH 3/8] =?UTF-8?q?fix=20[P-230]:=20=D1=84=D0=B8=D0=BA=D1=81?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=B0=20=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/src/components/vote/VoteConstructor.vue | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/front/src/components/vote/VoteConstructor.vue b/src/front/src/components/vote/VoteConstructor.vue index 0719e40ae..5878acb0f 100644 --- a/src/front/src/components/vote/VoteConstructor.vue +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -44,11 +44,8 @@ > From 5d38480fdfef177cc13260d84cdf4a0926c55b97 Mon Sep 17 00:00:00 2001 From: Denis Voinovich Date: Mon, 2 Jun 2025 09:28:28 +0300 Subject: [PATCH 4/8] =?UTF-8?q?fix=20[P-231]:=20=D0=92=D0=B5=D1=80=D1=81?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/src/components/vote/ConstructorVote/AnswerList.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/front/src/components/vote/ConstructorVote/AnswerList.vue b/src/front/src/components/vote/ConstructorVote/AnswerList.vue index 10ca74b52..b61b72142 100644 --- a/src/front/src/components/vote/ConstructorVote/AnswerList.vue +++ b/src/front/src/components/vote/ConstructorVote/AnswerList.vue @@ -4,7 +4,7 @@
Date: Mon, 2 Jun 2025 09:33:43 +0300 Subject: [PATCH 5/8] =?UTF-8?q?fix=20[P-234]:=20=20=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=BF=D1=80=D0=BE=D1=81=D0=BC=D0=BE=D1=82=D1=80=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BA=D0=B8=20=D0=BE=D1=82=D0=B2?= =?UTF-8?q?=D0=B5=D1=82=D0=B0=20=D0=B2=D1=8B=D1=80=D0=BE=D0=B2=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/src/components/vote/ConstructorVote/AnswerList.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/front/src/components/vote/ConstructorVote/AnswerList.vue b/src/front/src/components/vote/ConstructorVote/AnswerList.vue index b61b72142..5e7c5d35d 100644 --- a/src/front/src/components/vote/ConstructorVote/AnswerList.vue +++ b/src/front/src/components/vote/ConstructorVote/AnswerList.vue @@ -40,7 +40,7 @@
- +
From a6aee5cbccc628314479a75450687ed10104ddff Mon Sep 17 00:00:00 2001 From: Denis Voinovich Date: Mon, 2 Jun 2025 09:47:20 +0300 Subject: [PATCH 6/8] =?UTF-8?q?fix=20[P-235]:=20=D0=A1=D0=BA=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=20=D0=BF=D1=80=D0=B8=20=D1=82=D0=B0=D0=B1=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/front/src/components/vote/VoteConstructor.vue | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/front/src/components/vote/VoteConstructor.vue b/src/front/src/components/vote/VoteConstructor.vue index 5878acb0f..9742b7e35 100644 --- a/src/front/src/components/vote/VoteConstructor.vue +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -313,6 +313,21 @@ export default { setup(props, { emit }) { const step = ref(0); const isVoteCreated = ref(false); + + // Добавляем наблюдение за изменением шага + watch(step, () => { + // Прокручиваем основной скролл страницы + window.scrollTo({ top: 0, behavior: 'smooth' }); + + // Находим все контейнеры с overflow-y: auto и прокручиваем их наверх + setTimeout(() => { + const scrollContainers = document.querySelectorAll('.v-card-text[style*="overflow-y: auto"]'); + scrollContainers.forEach(container => { + container.scrollTo({ top: 0, behavior: 'smooth' }); + }); + }, 100); + }); + const form = ref({ title: '', description: '', From 985543e2965d4cd9cfee299ac5f2e69fea18644d Mon Sep 17 00:00:00 2001 From: Denis Voinovich Date: Mon, 2 Jun 2025 10:04:24 +0300 Subject: [PATCH 7/8] =?UTF-8?q?fix=20[P-236]:=20=D0=A4=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D1=8B=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BE=D0=BA?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=B0=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vote/ConstructorVote/AnswerList.vue | 45 +++++++++++++++++- .../vote/ConstructorVote/QuestionItem.vue | 46 ++++++++++++++++++- .../src/components/vote/VoteConstructor.vue | 46 +++++++++++++++++-- 3 files changed, 130 insertions(+), 7 deletions(-) diff --git a/src/front/src/components/vote/ConstructorVote/AnswerList.vue b/src/front/src/components/vote/ConstructorVote/AnswerList.vue index 5e7c5d35d..7b80a8506 100644 --- a/src/front/src/components/vote/ConstructorVote/AnswerList.vue +++ b/src/front/src/components/vote/ConstructorVote/AnswerList.vue @@ -35,7 +35,8 @@ hide-details label="Картинка" variant="outlined" - @update:model-value="() => previewAnswerImage(answer, aIndex)" + :error-messages="answer.imageError" + @update:model-value="(file) => handleImageUpload(file, answer, aIndex)" > @@ -93,11 +94,50 @@ export default { setup(props) { const route = useRoute(); - // Поддерживаем оба способа определения: через роут или через явный проп const isTestRoute = computed(() => { return route.path && String(route.path).includes('test'); }); + const validateImage = (file) => { + if (!file) return null; + + // Проверяем тип файла + const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']; + if (!validTypes.includes(file.type)) { + return 'Разрешены только изображения (JPEG, PNG, GIF, WEBP)'; + } + + // Проверяем размер файла (максимум 5MB) + const maxSize = 5 * 1024 * 1024; // 5MB в байтах + if (file.size > maxSize) { + return 'Размер изображения не должен превышать 5MB'; + } + + return null; + }; + + const handleImageUpload = (file, answer, index) => { + // Сбрасываем предыдущие ошибки + answer.imageError = ''; + + if (!file) { + answer.image = null; + answer.imagePreview = null; + return; + } + + const error = validateImage(file); + if (error) { + answer.imageError = error; + answer.image = null; + answer.imagePreview = null; + return; + } + + // Если валидация прошла успешно, показываем превью + previewAnswerImage(answer, index); + }; + const toggleCorrect = (answer) => { // Используем right_wrong для тестов (совместимо с бэкендом) answer.right_wrong = !answer.right_wrong; @@ -128,6 +168,7 @@ export default { isTestRoute, toggleCorrect, previewAnswerImage, + handleImageUpload, isTest: props.isTest }; } diff --git a/src/front/src/components/vote/ConstructorVote/QuestionItem.vue b/src/front/src/components/vote/ConstructorVote/QuestionItem.vue index 2c110c596..aa91e35ba 100644 --- a/src/front/src/components/vote/ConstructorVote/QuestionItem.vue +++ b/src/front/src/components/vote/ConstructorVote/QuestionItem.vue @@ -12,7 +12,9 @@ label="Картинка для вопроса" variant="outlined" class="flex-grow-1" - @update:model-value="previewQuestionImage" + :error-messages="question.imageError" + hint="Допустимые форматы: JPEG, PNG, GIF, WEBP. Макс. размер: 5MB" + @update:model-value="handleQuestionImageUpload" > @@ -225,6 +227,45 @@ export default { const route = useRoute(); const questionImagePreview = ref(null); + const validateImage = (file) => { + if (!file) return null; + + // Проверяем тип файла + const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']; + if (!validTypes.includes(file.type)) { + return 'Разрешены только изображения (JPEG, PNG, GIF, WEBP)'; + } + + // Проверяем размер файла (максимум 5MB) + const maxSize = 5 * 1024 * 1024; // 5MB в байтах + if (file.size > maxSize) { + return 'Размер изображения не должен превышать 5MB'; + } + + return null; + }; + + const handleQuestionImageUpload = (file) => { + // Сбрасываем предыдущие ошибки + props.question.imageError = ''; + questionImagePreview.value = null; + + if (!file) { + props.question.image = null; + return; + } + + const error = validateImage(file); + if (error) { + props.question.imageError = error; + props.question.image = null; + return; + } + + // Если валидация прошла успешно, показываем превью + previewQuestionImage(); + }; + const resetAnswers = () => { props.question.answers = []; emit('update:question', props.question); @@ -290,7 +331,8 @@ export default { onEmployeesChange, isTestRoute, questionImagePreview, - previewQuestionImage + previewQuestionImage, + handleQuestionImageUpload }; }, }; diff --git a/src/front/src/components/vote/VoteConstructor.vue b/src/front/src/components/vote/VoteConstructor.vue index 9742b7e35..437c5f2d9 100644 --- a/src/front/src/components/vote/VoteConstructor.vue +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -69,9 +69,10 @@ variant="outlined" prepend-icon="mdi-image" placeholder="Выберите изображение для теста" - hint="Логотип или изображение для теста" + hint="Логотип или изображение для теста (макс. 5MB, форматы: JPEG, PNG, GIF, WEBP)" + :error-messages="imageError" :show-size="true" - @update:model-value="previewImage" + @update:model-value="handleTestImageUpload" > @@ -451,6 +452,45 @@ export default { }); }; + const validateImage = (file) => { + if (!file) return null; + + // Проверяем тип файла + const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']; + if (!validTypes.includes(file.type)) { + return 'Разрешены только изображения (JPEG, PNG, GIF, WEBP)'; + } + + // Проверяем размер файла (максимум 5MB) + const maxSize = 5 * 1024 * 1024; // 5MB в байтах + if (file.size > maxSize) { + return 'Размер изображения не должен превышать 5MB'; + } + + return null; + }; + + const handleTestImageUpload = (file) => { + // Сбрасываем предыдущие ошибки + imageError.value = ''; + imagePreview.value = null; + + if (!file) { + testImage.value = null; + return; + } + + const error = validateImage(file); + if (error) { + imageError.value = error; + testImage.value = null; + return; + } + + // Если валидация прошла успешно, показываем превью + previewImage(); + }; + const saveVoting = async () => { try { if (props.isTest) { @@ -615,7 +655,7 @@ export default { } watch(testImage, () => { - previewImage(); + handleTestImageUpload(testImage.value); }); return { From afd60880a4bf453fdf74c989c14a5f89d270c66f Mon Sep 17 00:00:00 2001 From: Denis Voinovich Date: Mon, 2 Jun 2025 10:29:41 +0300 Subject: [PATCH 8/8] =?UTF-8?q?fix=20[P-244]:=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ing_datestart_testing_news.cpython-310.pyc | Bin 0 -> 958 bytes .../components/testing/AssignTestDialog.vue | 75 +++++++++++++++--- src/front/src/utils/axios-api.js | 14 +++- src/front/src/views/TestHomePage.vue | 9 ++- 4 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 src/back/tests/migrations/__pycache__/0005_testing_datestart_testing_news.cpython-310.pyc diff --git a/src/back/tests/migrations/__pycache__/0005_testing_datestart_testing_news.cpython-310.pyc b/src/back/tests/migrations/__pycache__/0005_testing_datestart_testing_news.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..49da51ae8bb9788fb992932481ae7ed770764382 GIT binary patch literal 958 zcmYjPOHUL*5bk+D*aa?<7!yOHm%Z$AP)}eWARY`{;53&`FIB8F%wwIIU4kcHi5CeM zul@jUgoK1dA;w=Yd+n#F*?y0T`|XSBYpEj<5jF!nJ3nwy(@z;jHpA@US= z3qH(Bq)S$bMOnz18do|G3oeEtj72v_=_ps2_M`_wsUj~2^Yn`9V|6%sQytD$C$rVj z=v8%GeH|UlR;T2CUmaFo2qOG=^qS-e;b+wmxlc(ypsEhwwiv{vYz#5)W(9E)3APMs zr)ptsNmKcxwH;y%WDx1ims8hoYAerRQjz&or$1B0Mju+1w7RiKcPM5M$I{DEPC2ne zsh3&apn&z(v~+o0g>&h1PE`jnlHTC_#X!WWva$gCm;$C-Ar`q#k8MuZR5NbNJQYTzOP)+Woy;4ZBObXxEBv=$iT0 zv~`V6&DG3*=DF#NEhT;0g#0nj-CuQV%gOIhq`W<5--d2`Jml@mC**e(?p@(^o9gD& d39g?q*6yp@?) literal 0 HcmV?d00001 diff --git a/src/front/src/components/testing/AssignTestDialog.vue b/src/front/src/components/testing/AssignTestDialog.vue index ace525521..86543268f 100644 --- a/src/front/src/components/testing/AssignTestDialog.vue +++ b/src/front/src/components/testing/AssignTestDialog.vue @@ -29,6 +29,17 @@ +
+
+ + Дата начала теста +
+ +
+
@@ -36,7 +47,7 @@
@@ -59,6 +70,9 @@
{{ employee.fio }} +
+ Дата начала: {{ new Date(employee.datestart).toLocaleDateString('ru-RU') }} +
Дата окончания: {{ new Date(employee.completion_date).toLocaleDateString('ru-RU') }}
@@ -150,9 +164,12 @@ export default { emits: ['update:modelValue', 'assign', 'unassign'], setup(props, { emit }) { const selectedEmployees = ref([]); - const defaultDate = new Date(); - defaultDate.setHours(18, 0, 0, 0); - const completionDate = ref(defaultDate); + const defaultEndDate = new Date(); + defaultEndDate.setHours(18, 0, 0, 0); + const defaultStartDate = new Date(); + defaultStartDate.setHours(9, 0, 0, 0); + const completionDate = ref(defaultEndDate); + const startDate = ref(defaultStartDate); const snackbar = ref({ show: false, text: '', @@ -171,18 +188,43 @@ export default { selectedEmployees.value = value; }; - const handleDateChange = (date) => { + const handleDateChange = (date, type = 'end') => { if (date) { - date.setHours(18, 0, 0, 0); + const newDate = new Date(date); + if (type === 'end') { + newDate.setHours(18, 0, 0, 0); + } else { + newDate.setHours(9, 0, 0, 0); + } + const today = new Date(); today.setHours(0, 0, 0, 0); - if (date < today) { + if (newDate < today) { showSnackbar('Нельзя назначить прошедшую дату'); - completionDate.value = null; + if (type === 'end') { + completionDate.value = null; + } else { + startDate.value = null; + } return; } + + if (type === 'end') { + if (startDate.value && newDate < startDate.value) { + showSnackbar('Дата окончания не может быть раньше даты начала'); + completionDate.value = null; + return; + } + completionDate.value = newDate; + } else { + if (completionDate.value && newDate > completionDate.value) { + showSnackbar('Дата начала не может быть позже даты окончания'); + startDate.value = null; + return; + } + startDate.value = newDate; + } } - completionDate.value = date; }; const handleAssign = () => { @@ -191,21 +233,27 @@ export default { return; } - if (!completionDate.value) { - showSnackbar('Укажите дату окончания теста'); + if (!completionDate.value || !startDate.value) { + showSnackbar('Укажите дату начала и окончания теста'); return; } const today = new Date(); today.setHours(0, 0, 0, 0); - if (completionDate.value < today) { + if (completionDate.value < today || startDate.value < today) { showSnackbar('Нельзя назначить прошедшую дату'); return; } + if (startDate.value > completionDate.value) { + showSnackbar('Дата начала не может быть позже даты окончания'); + return; + } + emit('assign', { selectedEmployees: selectedEmployees.value, - completionDate: completionDate.value + completionDate: completionDate.value, + startDate: startDate.value }); selectedEmployees.value = []; @@ -216,6 +264,7 @@ export default { return { selectedEmployees, completionDate, + startDate, handleEmployeeSelection, handleAssign, handleDateChange, diff --git a/src/front/src/utils/axios-api.js b/src/front/src/utils/axios-api.js index b597b7e58..18280f15b 100644 --- a/src/front/src/utils/axios-api.js +++ b/src/front/src/utils/axios-api.js @@ -243,16 +243,21 @@ async function createTest(testData) { } } -async function assignTest(testId, employeeIds, completionDate) { +async function assignTest(testId, employeeIds, completionDate, startDate) { try { if (!completionDate) { const testDetails = await getTestDetail(testId); completionDate = testDetails.dateend; } + if (!startDate) { + const testDetails = await getTestDetail(testId); + startDate = testDetails.datestart; + } + const userIds = Array.from(employeeIds).map(id => Number(id)); const promises = userIds.map(userId => - assignTestToUser(userId, testId, completionDate) + assignTestToUser(userId, testId, completionDate, startDate) ); await Promise.all(promises); @@ -291,13 +296,14 @@ async function deleteTest(id) { } } -async function assignTestToUser(userId, testId, completionDate) { +async function assignTestToUser(userId, testId, completionDate, startDate) { try { const response = await axiosApiInstance.post('/api/tests/testingview/', { user_id: Number(userId), test_id: Number(testId), - completion_date: completionDate + completion_date: completionDate, + datestart: startDate }); return response.data; } catch (error) { diff --git a/src/front/src/views/TestHomePage.vue b/src/front/src/views/TestHomePage.vue index 074e7eb4b..c7a9af2a0 100644 --- a/src/front/src/views/TestHomePage.vue +++ b/src/front/src/views/TestHomePage.vue @@ -293,18 +293,21 @@ export default { try { const response = await getTestToUser(id); + console.log('API Response:', response); const assignmentsByUser = response.reduce((acc, testing) => { if (testing.user_details && testing.is_active) { const existingUser = acc.find(u => u.id === testing.user_details.id); if (!existingUser) { acc.push({ ...testing.user_details, - completion_date: testing.completion_date + completion_date: testing.completion_date, + datestart: testing.datestart }); } } return acc; }, []); + console.log('Transformed Data:', assignmentsByUser); assignedEmployees.value = assignmentsByUser.map(user => user.id); @@ -351,7 +354,7 @@ export default { } }; - const handleAssign = async ({ selectedEmployees: employees, completionDate }) => { + const handleAssign = async ({ selectedEmployees: employees, completionDate, startDate }) => { try { let employeesToAssign = [...employees]; @@ -362,7 +365,7 @@ export default { } } - await assignTest(selectedTestId.value, employeesToAssign, completionDate); + await assignTest(selectedTestId.value, employeesToAssign, completionDate, startDate); addDialog.value = false; getTestById();