Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
survey
Commits
80ab8493
Commit
80ab8493
authored
Jul 13, 2022
by
Jiwon Yoon
Browse files
객관식 choice추가 삭제
parent
e19694ac
Changes
7
Hide whitespace changes
Inline
Side-by-side
frontend/src/questions/CheckboxForm.tsx
View file @
80ab8493
...
@@ -4,9 +4,10 @@ import { CheckboxType } from "../types";
...
@@ -4,9 +4,10 @@ import { CheckboxType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
CheckboxType
;
element
:
CheckboxType
;
handleQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
id
:
string
)
=>
void
;
currentId
:
string
;
};
};
export
const
CheckboxForm
=
({
element
,
handleQuestion
}:
Props
)
=>
{
export
const
CheckboxForm
=
({
element
,
handleQuestion
,
currentId
}:
Props
)
=>
{
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
...
@@ -16,21 +17,55 @@ export const CheckboxForm = ({ element, handleQuestion }: Props) => {
...
@@ -16,21 +17,55 @@ export const CheckboxForm = ({ element, handleQuestion }: Props) => {
handleQuestion
(
element
.
_id
);
handleQuestion
(
element
.
_id
);
console
.
log
(
choices
);
console
.
log
(
choices
);
}
}
function
deleteValue
()
{
//제일 마지막 index 제거
choices
.
splice
(
-
1
,
1
);
element
.
content
.
choices
=
choices
;
handleQuestion
(
element
.
_id
);
}
function
addValue
()
{
choices
.
push
({
text
:
""
,
value
:
choices
.
length
});
element
.
content
.
choices
=
choices
;
handleQuestion
(
element
.
_id
);
}
return
(
return
(
<
div
id
=
"content"
className
=
"flex mt-4"
>
<>
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
<
div
id
=
"content"
className
=
"mt-4 p-5"
>
<
div
>
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
<
input
type
=
"checkbox"
disabled
></
input
>
<
div
className
=
"m-5"
>
<
input
<
input
type
=
"checkbox"
disabled
></
input
>
id
=
{
`
${
index
}
`
}
<
input
type
=
"text"
id
=
{
`
${
index
}
`
}
className
=
"mx-2 border-b-2"
type
=
"text"
placeholder
=
{
choice
.
text
}
className
=
"mx-2 border-b-2"
onChange
=
{
handleContent
}
placeholder
=
"선택지"
></
input
>
value
=
{
choice
.
text
}
</
div
>
onChange
=
{
handleContent
}
))
}
disabled
=
{
currentId
!==
element
.
_id
}
</
div
>
></
input
>
</
div
>
))
}
</
div
>
<
div
>
<
button
type
=
"button"
name
=
"rateValues"
className
=
"border border-red-500 rounded mx-2 px-2"
onClick
=
{
deleteValue
}
disabled
=
{
currentId
!==
element
.
_id
}
>
삭제
</
button
>
<
button
type
=
"button"
name
=
"rateValues"
className
=
"border border-blue-500 rounded mx-2 px-2"
onClick
=
{
addValue
}
disabled
=
{
currentId
!==
element
.
_id
}
>
추가
</
button
>
</
div
>
</>
);
);
};
};
frontend/src/questions/DropdownForm.tsx
View file @
80ab8493
...
@@ -4,9 +4,10 @@ import { DropdownType } from "../types";
...
@@ -4,9 +4,10 @@ import { DropdownType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
DropdownType
;
element
:
DropdownType
;
handleQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
id
:
string
)
=>
void
;
currentId
:
string
;
};
};
export
const
DropdownForm
=
({
element
,
handleQuestion
}:
Props
)
=>
{
export
const
DropdownForm
=
({
element
,
handleQuestion
,
currentId
}:
Props
)
=>
{
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
...
@@ -16,22 +17,59 @@ export const DropdownForm = ({ element, handleQuestion }: Props) => {
...
@@ -16,22 +17,59 @@ export const DropdownForm = ({ element, handleQuestion }: Props) => {
handleQuestion
(
element
.
_id
);
handleQuestion
(
element
.
_id
);
console
.
log
(
choices
);
console
.
log
(
choices
);
}
}
function
deleteValue
()
{
//제일 마지막 index 제거
choices
.
splice
(
-
1
,
1
);
element
.
content
.
choices
=
choices
;
handleQuestion
(
element
.
_id
);
}
function
addValue
()
{
choices
.
push
({
text
:
""
,
value
:
choices
.
length
});
element
.
content
.
choices
=
choices
;
handleQuestion
(
element
.
_id
);
}
return
(
return
(
<
div
id
=
"content"
className
=
"flex mt-4"
>
<>
<
select
className
=
"mr-3"
>
<
div
id
=
"content"
className
=
"flex-row mt-4 p-5"
>
<
select
className
=
"mr-3"
>
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
<
option
>
{
choice
.
text
}
</
option
>
))
}
</
select
>
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
<
option
>
{
choice
.
text
}
</
option
>
<
div
className
=
"my-5"
>
<
input
id
=
{
`
${
index
}
`
}
type
=
"text"
className
=
"mx-2 border-b-2"
placeholder
=
"선택지"
value
=
{
choice
.
text
}
onChange
=
{
handleContent
}
disabled
=
{
currentId
!==
element
.
_id
}
></
input
>
</
div
>
))
}
))
}
</
select
>
</
div
>
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
<
div
>
<
input
<
button
id
=
{
`
${
index
}
`
}
type
=
"button"
type
=
"text"
name
=
"rateValues"
className
=
"mx-2 border-b-2"
className
=
"border border-red-500 rounded mx-2 px-2"
placeholder
=
{
choice
.
text
}
onClick
=
{
deleteValue
}
onChange
=
{
handleContent
}
disabled
=
{
currentId
!==
element
.
_id
}
></
input
>
>
))
}
삭제
</
div
>
</
button
>
<
button
type
=
"button"
name
=
"rateValues"
className
=
"border border-blue-500 rounded mx-2 px-2"
onClick
=
{
addValue
}
disabled
=
{
currentId
!==
element
.
_id
}
>
추가
</
button
>
</
div
>
</>
);
);
};
};
frontend/src/questions/EssayForm.tsx
View file @
80ab8493
...
@@ -3,9 +3,10 @@ import { EssayType } from "../types";
...
@@ -3,9 +3,10 @@ import { EssayType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
EssayType
;
element
:
EssayType
;
currentId
:
string
;
};
};
export
const
EssayForm
=
({
element
}:
Props
)
=>
{
export
const
EssayForm
=
({
element
,
currentId
}:
Props
)
=>
{
return
(
return
(
<
div
id
=
"commentarea"
className
=
"flex mt-4 w-full justify-center"
>
<
div
id
=
"commentarea"
className
=
"flex mt-4 w-full justify-center"
>
<
input
className
=
"border w-11/12 h-16"
disabled
></
input
>
<
input
className
=
"border w-11/12 h-16"
disabled
></
input
>
...
...
frontend/src/questions/FileForm.tsx
View file @
80ab8493
...
@@ -3,9 +3,10 @@ import { FileType } from "../types";
...
@@ -3,9 +3,10 @@ import { FileType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
FileType
;
element
:
FileType
;
currentId
:
string
;
};
};
export
const
FileForm
=
({
element
}:
Props
)
=>
{
export
const
FileForm
=
({
element
,
currentId
}:
Props
)
=>
{
return
(
return
(
<
div
id
=
"content"
className
=
"flex mt-4 w-full justify-center"
>
<
div
id
=
"content"
className
=
"flex mt-4 w-full justify-center"
>
<
input
type
=
"file"
className
=
" w-11/12 h-16"
disabled
></
input
>
<
input
type
=
"file"
className
=
" w-11/12 h-16"
disabled
></
input
>
...
...
frontend/src/questions/Question.tsx
View file @
80ab8493
...
@@ -34,12 +34,10 @@ export const Question = ({
...
@@ -34,12 +34,10 @@ export const Question = ({
changeCurrentId
,
changeCurrentId
,
currentId
,
currentId
,
}:
Props
)
=>
{
}:
Props
)
=>
{
const
handleEdit
=
()
=>
{
const
handleEditClick
=
()
=>
{
//setCurrentId해주고 currentId===element._id가 같은 input들만 disabled=false
changeCurrentId
(
element
.
_id
);
changeCurrentId
(
element
.
_id
);
};
};
async
function
handleComplete
()
{
async
function
handleEditComplete
()
{
//db에서 element._id인 애를 findOneAndUpdate() 해준다.
try
{
try
{
const
newQuestion
:
BasicQuestionType
=
await
questionApi
.
updateQuestion
(
const
newQuestion
:
BasicQuestionType
=
await
questionApi
.
updateQuestion
(
element
element
...
@@ -65,21 +63,21 @@ export const Question = ({
...
@@ -65,21 +63,21 @@ export const Question = ({
)
{
)
{
element
.
content
=
{
element
.
content
=
{
choices
:
[
choices
:
[
{
text
:
"
선택지1
"
,
value
:
"
1
"
},
{
text
:
""
,
value
:
0
},
{
text
:
"
선택지2
"
,
value
:
"
2
"
},
{
text
:
""
,
value
:
1
},
{
text
:
"
선택지3
"
,
value
:
"
3
"
},
{
text
:
""
,
value
:
2
},
],
],
};
};
}
else
if
(
selectedType
===
"
essay
"
)
{
}
else
if
(
selectedType
===
"
essay
"
)
{
element
.
content
=
{
choices
:
[]
};
element
.
content
=
{
choices
:
[]
};
}
else
if
(
selectedType
===
"
rating
"
)
{
}
else
if
(
selectedType
===
"
rating
"
)
{
element
.
content
=
{
element
.
content
=
{
minRateDescription
:
"
가장 낮음
"
,
minRateDescription
:
""
,
maxRateDescription
:
"
가장 높음
"
,
maxRateDescription
:
""
,
choices
:
[
choices
:
[
{
text
:
"
1
"
,
value
:
"
1
"
},
{
text
:
""
,
value
:
0
},
{
text
:
"
2
"
,
value
:
"
2
"
},
{
text
:
""
,
value
:
1
},
{
text
:
"
3
"
,
value
:
"
3
"
},
{
text
:
""
,
value
:
2
},
],
],
};
};
}
}
...
@@ -100,21 +98,41 @@ export const Question = ({
...
@@ -100,21 +98,41 @@ export const Question = ({
function
getContent
(
element
:
BasicQuestionType
)
{
function
getContent
(
element
:
BasicQuestionType
)
{
switch
(
element
.
type
)
{
switch
(
element
.
type
)
{
case
"
essay
"
:
case
"
essay
"
:
return
<
EssayForm
element
=
{
element
}
/>;
return
<
EssayForm
element
=
{
element
}
currentId
=
{
currentId
}
/>;
case
"
radio
"
:
case
"
radio
"
:
return
<
RadioForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
/>;
return
(
<
RadioForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
currentId
=
{
currentId
}
/>
);
case
"
checkbox
"
:
case
"
checkbox
"
:
return
(
return
(
<
CheckboxForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
/>
<
CheckboxForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
currentId
=
{
currentId
}
/>
);
);
case
"
dropdown
"
:
case
"
dropdown
"
:
return
(
return
(
<
DropdownForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
/>
<
DropdownForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
currentId
=
{
currentId
}
/>
);
);
case
"
file
"
:
case
"
file
"
:
return
<
FileForm
element
=
{
element
}
/>;
return
<
FileForm
element
=
{
element
}
currentId
=
{
currentId
}
/>;
case
"
rating
"
:
case
"
rating
"
:
return
<
RatingForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
/>;
return
(
<
RatingForm
handleQuestion
=
{
handleQuestion
}
element
=
{
element
}
currentId
=
{
currentId
}
/>
);
default
:
default
:
return
<></>;
return
<></>;
}
}
...
@@ -131,6 +149,7 @@ export const Question = ({
...
@@ -131,6 +149,7 @@ export const Question = ({
placeholder
=
{
"
Question Title
"
}
placeholder
=
{
"
Question Title
"
}
value
=
{
element
.
title
}
value
=
{
element
.
title
}
onChange
=
{
handleQuestionInfo
}
onChange
=
{
handleQuestionInfo
}
disabled
=
{
currentId
!==
element
.
_id
}
></
input
>
></
input
>
<
select
<
select
id
=
{
element
.
_id
}
id
=
{
element
.
_id
}
...
@@ -158,6 +177,7 @@ export const Question = ({
...
@@ -158,6 +177,7 @@ export const Question = ({
placeholder
=
"질문에 대한 설명을 입력해주세요"
placeholder
=
"질문에 대한 설명을 입력해주세요"
value
=
{
element
.
comment
}
value
=
{
element
.
comment
}
onChange
=
{
handleQuestionInfo
}
onChange
=
{
handleQuestionInfo
}
disabled
=
{
currentId
!==
element
.
_id
}
></
input
>
></
input
>
</
div
>
</
div
>
{
getContent
(
element
)
}
{
getContent
(
element
)
}
...
@@ -173,11 +193,11 @@ export const Question = ({
...
@@ -173,11 +193,11 @@ export const Question = ({
삭제
삭제
</
button
>
</
button
>
{
currentId
===
element
.
_id
?
(
{
currentId
===
element
.
_id
?
(
<
button
type
=
"button"
className
=
"px-1"
onClick
=
{
handleComplete
}
>
<
button
type
=
"button"
className
=
"px-1"
onClick
=
{
handle
Edit
Complete
}
>
수정완료
수정완료
</
button
>
</
button
>
)
:
(
)
:
(
<
button
type
=
"button"
className
=
"px-1"
onClick
=
{
handleEdit
}
>
<
button
type
=
"button"
className
=
"px-1"
onClick
=
{
handleEdit
Click
}
>
수정하기
수정하기
</
button
>
</
button
>
)
}
)
}
...
...
frontend/src/questions/RadioForm.tsx
View file @
80ab8493
...
@@ -4,9 +4,10 @@ import { RadioType } from "../types";
...
@@ -4,9 +4,10 @@ import { RadioType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
RadioType
;
element
:
RadioType
;
handleQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
id
:
string
)
=>
void
;
currentId
:
string
;
};
};
export
const
RadioForm
=
({
element
,
handleQuestion
}:
Props
)
=>
{
export
const
RadioForm
=
({
element
,
handleQuestion
,
currentId
}:
Props
)
=>
{
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
...
@@ -16,20 +17,56 @@ export const RadioForm = ({ element, handleQuestion }: Props) => {
...
@@ -16,20 +17,56 @@ export const RadioForm = ({ element, handleQuestion }: Props) => {
handleQuestion
(
element
.
_id
);
handleQuestion
(
element
.
_id
);
console
.
log
(
choices
);
console
.
log
(
choices
);
}
}
function
deleteValue
()
{
//제일 마지막 index 제거
choices
.
splice
(
-
1
,
1
);
element
.
content
.
choices
=
choices
;
handleQuestion
(
element
.
_id
);
}
function
addValue
()
{
choices
.
push
({
text
:
""
,
value
:
choices
.
length
});
element
.
content
.
choices
=
choices
;
handleQuestion
(
element
.
_id
);
}
return
(
return
(
<
div
id
=
"content"
className
=
"flex mt-4"
>
<>
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
<
div
id
=
"content"
className
=
"mt-4 p-5"
>
<
div
>
{
choices
.
map
((
choice
:
any
,
index
:
number
)
=>
(
<
input
type
=
"radio"
disabled
></
input
>
<
div
className
=
"m-5"
>
<
input
<
input
type
=
"radio"
disabled
></
input
>
id
=
{
`
${
index
}
`
}
<
input
type
=
"text"
id
=
{
`
${
index
}
`
}
className
=
"mx-2 border-b-2"
type
=
"text"
placeholder
=
{
choice
.
text
}
className
=
"mx-2 border-b-2"
onChange
=
{
handleContent
}
placeholder
=
"선택지"
></
input
>
value
=
{
choice
.
text
}
</
div
>
onChange
=
{
handleContent
}
))
}
disabled
=
{
currentId
!==
element
.
_id
}
</
div
>
></
input
>
</
div
>
))
}
</
div
>
<
div
>
<
button
type
=
"button"
name
=
"rateValues"
className
=
"border border-red-500 rounded mx-2 px-2"
onClick
=
{
deleteValue
}
disabled
=
{
currentId
!==
element
.
_id
}
>
삭제
</
button
>
<
button
type
=
"button"
name
=
"rateValues"
className
=
"border border-blue-500 rounded mx-2 px-2"
onClick
=
{
addValue
}
disabled
=
{
currentId
!==
element
.
_id
}
>
추가
</
button
>
</
div
>
</>
);
);
};
};
frontend/src/questions/RatingForm.tsx
View file @
80ab8493
...
@@ -4,9 +4,10 @@ import { RatingType } from "../types";
...
@@ -4,9 +4,10 @@ import { RatingType } from "../types";
type
Props
=
{
type
Props
=
{
element
:
RatingType
;
element
:
RatingType
;
handleQuestion
:
(
id
:
string
)
=>
void
;
handleQuestion
:
(
id
:
string
)
=>
void
;
currentId
:
string
;
};
};
export
const
RatingForm
=
({
element
,
handleQuestion
}:
Props
)
=>
{
export
const
RatingForm
=
({
element
,
handleQuestion
,
currentId
}:
Props
)
=>
{
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
const
[
choices
,
setChoices
]
=
useState
([...
element
.
content
.
choices
]);
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
function
handleContent
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
{
...
@@ -30,7 +31,7 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
...
@@ -30,7 +31,7 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
handleQuestion
(
element
.
_id
);
handleQuestion
(
element
.
_id
);
}
}
function
addValue
()
{
function
addValue
()
{
choices
.
push
({
text
:
"
0
"
,
value
:
0
});
choices
.
push
({
text
:
"
0
"
,
value
:
choices
.
length
});
element
.
content
.
choices
=
choices
;
element
.
content
.
choices
=
choices
;
handleQuestion
(
element
.
_id
);
handleQuestion
(
element
.
_id
);
}
}
...
@@ -42,26 +43,32 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
...
@@ -42,26 +43,32 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
name
=
"minRateDescription"
name
=
"minRateDescription"
className
=
"border-b-2 text-center"
className
=
"border-b-2 text-center"
size
=
{
10
}
size
=
{
10
}
placeholder
=
{
element
.
content
.
minRateDescription
}
placeholder
=
"비동의"
value
=
{
element
.
content
.
minRateDescription
}
onChange
=
{
handleContent
}
onChange
=
{
handleContent
}
disabled
=
{
currentId
!==
element
.
_id
}
></
input
>
></
input
>
{
choices
.
map
((
e
:
any
,
index
:
number
)
=>
(
{
choices
.
map
((
choic
e
:
any
,
index
:
number
)
=>
(
<
input
<
input
name
=
"text"
name
=
"text"
id
=
{
`
${
index
}
`
}
id
=
{
`
${
index
}
`
}
type
=
"text"
type
=
"text"
className
=
"border border-black rounded-full py-1 m-2 text-center"
className
=
"border border-black rounded-full py-1 m-2 text-center"
size
=
{
1
}
size
=
{
1
}
placeholder
=
{
e
.
text
}
placeholder
=
"0"
value
=
{
choice
.
text
}
onChange
=
{
handleContent
}
onChange
=
{
handleContent
}
disabled
=
{
currentId
!==
element
.
_id
}
></
input
>
></
input
>
))
}
))
}
<
input
<
input
name
=
"maxRateDescription"
name
=
"maxRateDescription"
className
=
"border-b-2 text-center"
className
=
"border-b-2 text-center"
size
=
{
10
}
size
=
{
10
}
placeholder
=
{
element
.
content
.
maxRateDescription
}
placeholder
=
"동의"
value
=
{
element
.
content
.
maxRateDescription
}
onChange
=
{
handleContent
}
onChange
=
{
handleContent
}
disabled
=
{
currentId
!==
element
.
_id
}
></
input
>
></
input
>
</
div
>
</
div
>
<
div
>
<
div
>
...
@@ -70,6 +77,7 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
...
@@ -70,6 +77,7 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
name
=
"rateValues"
name
=
"rateValues"
className
=
"border border-red-500 rounded mx-2 px-2"
className
=
"border border-red-500 rounded mx-2 px-2"
onClick
=
{
deleteValue
}
onClick
=
{
deleteValue
}
disabled
=
{
currentId
!==
element
.
_id
}
>
>
삭제
삭제
</
button
>
</
button
>
...
@@ -78,6 +86,7 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
...
@@ -78,6 +86,7 @@ export const RatingForm = ({ element, handleQuestion }: Props) => {
name
=
"rateValues"
name
=
"rateValues"
className
=
"border border-blue-500 rounded mx-2 px-2"
className
=
"border border-blue-500 rounded mx-2 px-2"
onClick
=
{
addValue
}
onClick
=
{
addValue
}
disabled
=
{
currentId
!==
element
.
_id
}
>
>
추가
추가
</
button
>
</
button
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment