Skip to content

Commit

Permalink
Merge pull request #20 from codeacme17/feat-dev
Browse files Browse the repository at this point in the history
feat: completed the development of signle-choice feature
  • Loading branch information
codeacme17 authored Aug 31, 2023
2 parents 89a49e3 + 754eaee commit 83e0559
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 90 deletions.
46 changes: 44 additions & 2 deletions app/src/components/blocks/ExamineBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

<!-- Answer tab connent -->
<section v-show="currentTab === 'answer'">
<!-- Answer block -->
<!-- Short answer input -->
<v-textarea
v-if="props.questionType === 'short' || props.questionType === ''"
v-model="currentData.answer"
variant="solo"
auto-grow
Expand All @@ -37,6 +38,22 @@
@keyup="handleKeyup"
/>

<!-- Single choice -->
<v-card
class="pt-5 pb-0 px-4 mb-5"
:elevation="0"
:color="defaultBgColor"
>
<v-radio-group v-model="currentData.answer" :disabled="isShowExamine">
<v-radio
v-for="item in options"
:key="item"
:label="item"
:value="item"
/>
</v-radio-group>
</v-card>

<!-- Examine block -->
<Transition name="scroll-x-reverse-transition">
<v-card
Expand Down Expand Up @@ -115,7 +132,11 @@ import { ErrorResponse } from '@/constant'
const { locale, t } = useI18n()
const PROFILE_STORE = useProfileStore()
const props = defineProps(['id'])
const props = defineProps<{
id: string
questionContent: string
questionType: 'short' | 'choice' | 'blank' | ''
}>()
const currentTab = ref<'answer' | 'lastAnswer' | 'document'>('answer')
// Get data cache
Expand Down Expand Up @@ -214,13 +235,34 @@ const handleGetDocument = async () => {
document_content.value = data
}
const options = ref<string[]>([])
const splitQuestionToOptions = () => {
if (props.questionType !== 'choice') return
const questionLines = props.questionContent.trim().split('\n')
for (let i = 1; i < questionLines.length; i++) {
const optionLine = questionLines[i].trim()
if (
optionLine.startsWith('A.') ||
optionLine.startsWith('B.') ||
optionLine.startsWith('C.') ||
optionLine.startsWith('D.')
) {
options.value.push(optionLine)
}
}
console.log(options.value)
}
// Watching if current question id is changed
watch(
() => props.id,
async () => {
await handleGetLastAnswer()
await handleGetDocument()
if (props.questionType === 'choice') splitQuestionToOptions()
if (currentData.value.examine) {
isShowExamine.value = true
isFinishExaming.value = true
Expand Down
5 changes: 4 additions & 1 deletion app/src/components/blocks/QuestionBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
</h3>
<div class="ml-2">{{ switchRoleEmoji }}</div>
</div>
<p class="mb-6 text-body-1" v-html="toMarkdown(props.content)" />
<p
class="mb-6 text-body-1"
v-html="toMarkdown(props.content.split('\n')[0])"
/>

<!-- Memory progress -->
<v-tooltip
Expand Down
39 changes: 29 additions & 10 deletions app/src/components/forms/UploadForm.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
<template>
<form>
<!-- Choose question type radio -->
<t-radio-group
v-model="formData.questionType"
variant="default-filled"
class="mb-5"
>
<t-radio-button value="short">📝 {{ $t('button.short') }}</t-radio-button>
<t-radio-button value="choice">
🔠 {{ $t('button.choice') }}
</t-radio-button>
<!-- TODO -->
<t-radio-button value="blank" disabled="true">
⬜ {{ $t('button.blank') }}
</t-radio-button>
</t-radio-group>

<!-- TODO -->
<!-- <v-select
v-model="formData.noteType"
class="mt-4"
variant="outlined"
density="compact"
item-title="label"
item-value="value"
:label="$t('label.selectNoteType')"
:items="noteTypeOptions"
@update:model-value="handleSelectChange"
/> -->
v-model="formData.noteType"
class="mt-4"
variant="outlined"
density="compact"
item-title="label"
item-value="value"
:label="$t('label.selectNoteType')"
:items="noteTypeOptions"
/> -->

<!-- File upload component -->
<t-config-provider :global-config="locale === 'en' ? enConfig : cnConfig">
Expand Down Expand Up @@ -67,6 +83,7 @@ import cnConfig from 'tdesign-vue-next/es/locale/zh_CN'
type FormData = {
noteType: 'files' | 'notion' | null
questionType: 'short' | 'choice' | 'blank'
files: any[]
notion: string
}
Expand All @@ -79,6 +96,7 @@ const emits = defineEmits(['success'])
const formData = reactive<FormData>({
noteType: 'files',
questionType: 'short',
files: [],
notion: '',
})
Expand Down Expand Up @@ -116,6 +134,7 @@ const handleConfirm = async () => {
const _formData = new FormData()
_formData.append('language', locale.value)
_formData.append('questionType', formData.questionType)
_formData.append('noteName', props.noteName)
_formData.append('notionId', formData.notion)
formData.files.forEach((item) => {
Expand Down
10 changes: 9 additions & 1 deletion app/src/components/tables/QuestionTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
/>
</td>

<!-- Quesiton type emoji -->
<td style="width: 20px">
<div v-if="item.question_type === 'short'">📝</div>
<div v-if="item.question_type === 'choice'">🔠</div>
<div v-if="item.question_type === 'blank'">⬜</div>
</td>

<!-- Question content td -->
<td style="overflow: hidden" v-html="toMarkdown(item.content)" />
<td v-html="toMarkdown(item.content.split('\n')[0])" />

<!-- Action buttons td -->
<td style="width: 145px">
Expand Down Expand Up @@ -74,6 +81,7 @@ export type TableItem = {
id: number
content: string
designated_role: string
question_type: 'short' | 'choice' | 'blank' | ''
document_id?: number
is_pushed?: string
is_answered_today?: string
Expand Down
3 changes: 3 additions & 0 deletions app/src/plugins/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const en = {
examiner: 'Examiner',
export: 'Export configuration and notes',
import: 'Import file',
short: 'Short Answer',
choice: 'Single Choice',
blank: 'Fill in the blank'
},

// the title & subtitle on each page
Expand Down
3 changes: 3 additions & 0 deletions app/src/plugins/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const zhCN = {
examiner: '考官',
export: '导出配置及笔记',
import: '文件导入',
short: '简答题',
choice: '单选题',
blank: '填空题',
},

title: {
Expand Down
8 changes: 7 additions & 1 deletion app/src/views/Note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
/>

<!-- Examine block -->
<examine-block :id="pickedQuestion.id" />
<examine-block
:id="pickedQuestion.id"
:questionContent="pickedQuestion.content"
:questionType="pickedQuestion.question_type"
/>
</section>
</Transition>
</v-container>
Expand Down Expand Up @@ -103,6 +107,7 @@ const pickedQuestion = reactive<TableItem>({
content: '',
designated_role: '',
progress: 0,
question_type: '',
})
const isShowAnswer = ref(false)
const handlePickQuestion = (item: TableItem) => {
Expand All @@ -111,5 +116,6 @@ const handlePickQuestion = (item: TableItem) => {
pickedQuestion.content = item.content
pickedQuestion.designated_role = item.designated_role
pickedQuestion.progress = item.progress
pickedQuestion.question_type = item.question_type
}
</script>
8 changes: 7 additions & 1 deletion app/src/views/Random.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
/>

<!-- Enswer block -->
<examine-block :id="questionInfo.id" v-if="trigger" />
<examine-block
v-if="trigger"
:id="questionInfo.id"
:questionType="questionInfo.question_type"
:questionContent="questionInfo.content"
/>
</section>
</v-container>
</template>
Expand All @@ -41,6 +46,7 @@ const [_getRandomQuestion, getRQLoading] = useFetch(
const getRandomQuestion = async () => {
const { data } = await _getRandomQuestion()
questionInfo.value = data
console.log(questionInfo.value)
trigger.value = false
nextTick(() => {
trigger.value = true
Expand Down
3 changes: 2 additions & 1 deletion database/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ COLLATE=utf8_general_ci;

CREATE TABLE t_question (
id int(12) auto_increment NOT NULL COMMENT 'question id',
content varchar(500) NOT NULL COMMENT 'question content',
content varchar(1000) NOT NULL COMMENT 'question content',
document_id int(12) NOT NULL COMMENT 'document id',
question_type char(20) COMMENT 'the type of the question',
designated_role char(20) NOT NULL COMMENT 'role when generating this question',
push_date DATE DEFAULT NULL COMMENT 'date the question needs to be asked',
is_pushed_today char(1) DEFAULT '0' NOT NULL COMMENT 'has pushed this quesiton at today to user 0-No 1-Yes',
Expand Down
4 changes: 4 additions & 0 deletions server/apis/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import db_services as _dbs_

from fastapi import File, Form, UploadFile

from utils import api_result, types, upload_file


Expand Down Expand Up @@ -50,6 +51,7 @@ def get_questions_by_note_id(note_id: int):
# Add new note
async def add_note(
language: str,
questionType: str,
noteName: str = Form(),
files: list[UploadFile] = File(default=None),
notionId: str = Form(default=None),
Expand All @@ -64,13 +66,15 @@ async def add_note(
try:
await upload_file(
language=language,
questionType=questionType,
noteId=_dbs_.note.get_inserted_note_id(noteName),
noteName=noteName,
files=files
)
except Exception as e:
return api_result.error(str(e))

# TODO notion databse
if (notionId is not None):
pass

Expand Down
2 changes: 2 additions & 0 deletions server/apis/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def examine_question(data: types.AnswerQuestion):
context=document_info["document"],
question=question_info["content"],
role=question_info["designated_role"],
question_type=question_info["question_type"],
answer=data.answer
)

Expand Down Expand Up @@ -50,6 +51,7 @@ def get_random_question():
"id": question_info["id"],
"content": question_info["content"],
"designated_role": question_info["designated_role"],
"question_type": question_info["question_type"],
"progress": question_info["progress"],
"note_name": note_info["name"]
})
12 changes: 9 additions & 3 deletions server/db_services/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ def get_question_by_id(id: int):
def save_question_to_db(
question_content: str,
document_id: int,
question_type: str
):
question_content = remove_prefix_numbers(question_content)
query = """
INSERT INTO t_question (content, document_id, designated_role)
VALUES (%s, %s, %s)
INSERT INTO t_question (content, document_id, designated_role, question_type)
VALUES (%s, %s, %s, %s)
"""
data = (question_content, document_id, os.environ.get("CURRENT_ROLE"), )
data = (
question_content,
document_id,
os.environ.get("CURRENT_ROLE"),
question_type,
)
MySQLHandler().insert_table_data(query, data)


Expand Down
Loading

0 comments on commit 83e0559

Please sign in to comment.