998 lines
40 KiB
TypeScript
998 lines
40 KiB
TypeScript
import React, { useEffect, useState } from "react"
|
|
import { SetterOrUpdater, useRecoilState, useRecoilValue } from "recoil"
|
|
import { Button, Form, Modal } from "react-bootstrap"
|
|
import type { autoRecodeArray, labelInfoType, questionInfoType } from "@modules/TypeModule"
|
|
import { regexPureNum, regexNumRange, regexSetNumRange, regexDateRange, regexSetDateRange, regexAuto } from "@modules/Function";
|
|
import { loginToken, memberInfo, modalProcessStatus, projectInfo } from "@token/Token"
|
|
import { Switch } from "@mui/material"
|
|
import axios from "axios";
|
|
import { URL_SEED } from "@modules/AxiosModule";
|
|
|
|
export const ScalarNumericModal = (props:{
|
|
show:boolean,
|
|
onHide: () => void,
|
|
questionUpdate:questionInfoType,
|
|
setQuestionUpdate:SetterOrUpdater<questionInfoType>
|
|
}) => {
|
|
|
|
const [modalProcess, setModalProcess] = useRecoilState(modalProcessStatus);
|
|
const [numericOpenType, setNumericOpenType] = useState<number | undefined>(1);
|
|
const [numericDecimalPoint, setNumericDecimalPoint] = useState<number | undefined>(0);
|
|
const [numericOpenPrefix, setNumericOpenPrefix] = useState<string | undefined>("");
|
|
const [numericOpenRange, setNumericOpenRange] = useState<string | undefined>("");
|
|
const [numericOpenPostfix, setNumericOpenPostfix] = useState<string | undefined>("");
|
|
|
|
// useEffect(() => {
|
|
// setNumericDecimalPoint(0);
|
|
// if(props.questionUpdate.scalar_label?.label_info[0].open_type !== numericOpenType){
|
|
// setNumericOpenRange("");
|
|
// }
|
|
// else{
|
|
// setNumericOpenRange(props.questionUpdate.scalar_label?.label_info[0]?.range);
|
|
// }
|
|
// },[numericOpenType])
|
|
|
|
useEffect(() => {
|
|
if(props.questionUpdate.scalar_label){
|
|
setNumericOpenType(props.questionUpdate.scalar_label?.label_info[0]?.open_type);
|
|
setNumericDecimalPoint(props.questionUpdate.scalar_label?.label_info[0]?.decimal_point);
|
|
setNumericOpenPrefix(props.questionUpdate.scalar_label?.label_info[0]?.prefix);
|
|
setNumericOpenRange(props.questionUpdate.scalar_label?.label_info[0]?.range);
|
|
setNumericOpenPostfix(props.questionUpdate.scalar_label?.label_info[0]?.suffix);
|
|
}
|
|
},[props.questionUpdate.scalar_label])
|
|
|
|
const rangeChange = (e:React.ChangeEvent<HTMLInputElement>) => {
|
|
if(numericOpenType === 3){
|
|
setNumericOpenRange(regexDateRange(e.currentTarget.value))
|
|
}else{
|
|
setNumericOpenRange(regexNumRange(e.currentTarget.value))
|
|
}
|
|
}
|
|
|
|
const setRangeText = (e:React.ChangeEvent<HTMLInputElement>) => {
|
|
if(numericOpenType === 3){
|
|
setNumericOpenRange(regexSetDateRange(e.currentTarget.value))
|
|
}else{
|
|
setNumericOpenRange(regexSetNumRange(e.currentTarget.value))
|
|
}
|
|
}
|
|
|
|
const mackContent = () => {
|
|
let infoArray:labelInfoType[] = [];
|
|
infoArray.push(
|
|
{
|
|
order: 1,
|
|
value: 1,
|
|
label: '',
|
|
open_type: numericOpenType,
|
|
decimal_point: numericDecimalPoint,
|
|
not_duplicate: 0,
|
|
prefix: numericOpenPrefix,
|
|
range: numericOpenRange,
|
|
placeholder:"",
|
|
suffix: numericOpenPostfix,
|
|
is_etc: 0,
|
|
is_not: 0
|
|
}
|
|
)
|
|
|
|
setModalProcess({
|
|
modalProcessStatus: true
|
|
});
|
|
props.onHide();
|
|
|
|
let tempQuestionUpdate = {...props.questionUpdate}
|
|
tempQuestionUpdate.scalar_label!.label_info = infoArray;
|
|
props.setQuestionUpdate(tempQuestionUpdate);
|
|
alert('등록되었습니다');
|
|
}
|
|
//s단축키
|
|
useEffect(() => {
|
|
const handleKeySave = (e: { key: string; ctrlKey: boolean; preventDefault: () => void; }) => {
|
|
if(props.show && e.ctrlKey && e.key?.toLowerCase() === "s"){
|
|
e.preventDefault();
|
|
mackContent();
|
|
}
|
|
}
|
|
window.addEventListener('keydown', handleKeySave);
|
|
return () => {
|
|
window.removeEventListener('keydown', handleKeySave);
|
|
};
|
|
},[props.show, mackContent])
|
|
|
|
return(
|
|
<Modal show={props.show} onHide={props.onHide} size="xl" backdrop='static'>
|
|
<Modal.Header>
|
|
<Modal.Title>
|
|
{ "Numeric Open 설정" }
|
|
</Modal.Title>
|
|
</Modal.Header>
|
|
<Modal.Body>
|
|
{
|
|
props.show ?
|
|
<div className="input-group input-group-sm mt-1 mb-3">
|
|
<div className='custom-sel mr-2' style={{"width":"15%"}}>
|
|
<Form.Control as='select' className='sel-box' value={ numericOpenType } onChange={ (e) => setNumericOpenType(Number(e.currentTarget.value)) }>
|
|
<option value={1}>일반</option>
|
|
<option value={2}>소수점</option>
|
|
<option value={3}>날짜</option>
|
|
</Form.Control>
|
|
</div>
|
|
{ numericOpenType === 2 ?
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='소수점 자리'
|
|
value={ numericDecimalPoint }
|
|
onChange={(e) => setNumericDecimalPoint(Number(regexPureNum(e.currentTarget.value)))}
|
|
//onKeyUp={(e) => setNumericDecimalPoint(Number(regexPureNum(e.currentTarget.value)))}
|
|
/>
|
|
:
|
|
null}
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"20%"}}
|
|
placeholder='Pre Text'
|
|
value={ numericOpenPrefix }
|
|
onChange={(e) => setNumericOpenPrefix(e.currentTarget.value)}
|
|
//onKeyUp={(e) => setNumericOpenPrefix(e.currentTarget.value)}
|
|
/>
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={numericOpenType !== 2 ? {"width":"40%"} : {"width":"20%"}}
|
|
placeholder={ numericOpenType === 3 ? '범위 지정 ex) 2024/01/31~2024/12/31' : "범위 지정 ex) 1~99" }
|
|
value={ numericOpenRange }
|
|
onChange={ rangeChange }
|
|
onBlur={ setRangeText }
|
|
/>
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"20%"}}
|
|
placeholder='Post Text'
|
|
value={ numericOpenPostfix }
|
|
onChange={(e) => setNumericOpenPostfix(e.currentTarget.value)}
|
|
//onKeyUp={(e) => setNumericOpenPostfix(e.currentTarget.value)}
|
|
/>
|
|
</div>
|
|
: null
|
|
}
|
|
</Modal.Body>
|
|
<Modal.Footer>
|
|
<Button className='project-save-btn' variant="primary" onClick={ mackContent }>등록</Button>
|
|
<Button variant="secondary" onClick={props.onHide}>닫기</Button>
|
|
</Modal.Footer>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export const ScalarStringModal = (props:{
|
|
show:boolean,
|
|
onHide: () => void,
|
|
questionUpdate:questionInfoType,
|
|
setQuestionUpdate:SetterOrUpdater<questionInfoType>
|
|
}) => {
|
|
|
|
const [modalProcess, setModalProcess] = useRecoilState(modalProcessStatus);
|
|
const [stringOpenType, setStringOpenType] = useState<number | undefined>(1);
|
|
const [stringOpenPrefix, setStringOpenPrefix] = useState<string | undefined>("");
|
|
// 복수제출 버튼 Toggle
|
|
const [stringScalarToggle, setStringScalarToggle] = useState<boolean | undefined>(false);
|
|
const [stringOpenPlaceHolder, setStringOpenPlaceHolder] = useState<string | undefined>("");
|
|
const [stringOpenPostfix, setStringOpenPostfix] = useState<string | undefined>("");
|
|
|
|
useEffect(() => {
|
|
if(stringOpenType !== 4 && stringOpenType !== 5){
|
|
setStringScalarToggle(false);
|
|
}
|
|
},[stringOpenType])
|
|
|
|
useEffect(() => {
|
|
if(props.questionUpdate.scalar_label){
|
|
setStringOpenType(props.questionUpdate.scalar_label?.label_info[0]?.open_type);
|
|
setStringOpenPrefix(props.questionUpdate.scalar_label?.label_info[0]?.prefix);
|
|
setStringScalarToggle(props.questionUpdate.scalar_label?.label_info[0]?.not_duplicate === 0 ? false : true);
|
|
setStringOpenPlaceHolder(props.questionUpdate.scalar_label?.label_info[0]?.placeholder);
|
|
setStringOpenPostfix(props.questionUpdate.scalar_label?.label_info[0]?.suffix);
|
|
}
|
|
},[props.questionUpdate.scalar_label])
|
|
|
|
const mackContent = () => {
|
|
let infoArray:labelInfoType[] = [];
|
|
infoArray.push(
|
|
{
|
|
order: 1,
|
|
value: 1,
|
|
label: '',
|
|
open_type: stringOpenType,
|
|
decimal_point: 0,
|
|
not_duplicate: stringScalarToggle === false ? 0 : 1,
|
|
prefix: stringOpenPrefix,
|
|
range: "",
|
|
placeholder: stringOpenPlaceHolder,
|
|
suffix: stringOpenPostfix,
|
|
is_etc: 0,
|
|
is_not: 0
|
|
}
|
|
)
|
|
|
|
setModalProcess({
|
|
modalProcessStatus: true
|
|
});
|
|
props.onHide();
|
|
|
|
let tempQuestionUpdate = {...props.questionUpdate}
|
|
tempQuestionUpdate.scalar_label!.label_info = infoArray;
|
|
props.setQuestionUpdate(tempQuestionUpdate);
|
|
alert('등록되었습니다');
|
|
}
|
|
//s단축키
|
|
useEffect(() => {
|
|
const handleKeySave = (e: { key: string; ctrlKey: boolean; preventDefault: () => void; }) => {
|
|
if(props.show && e.ctrlKey && e.key?.toLowerCase() === "s"){
|
|
e.preventDefault();
|
|
mackContent();
|
|
}
|
|
}
|
|
window.addEventListener('keydown', handleKeySave);
|
|
return () => {
|
|
window.removeEventListener('keydown', handleKeySave);
|
|
};
|
|
},[props.show, mackContent])
|
|
|
|
return(
|
|
<Modal show={props.show} onHide={props.onHide} size="xl" backdrop='static'>
|
|
<Modal.Header>
|
|
<Modal.Title>
|
|
{ "String Open 설정" }
|
|
</Modal.Title>
|
|
</Modal.Header>
|
|
<Modal.Body>
|
|
{
|
|
props.show ?
|
|
<div className="input-group input-group-sm mt-1 mb-3">
|
|
<div className='custom-sel mr-2' style={{"width":"15%"}}>
|
|
<Form.Control as='select' className='sel-box'
|
|
value={ stringOpenType }
|
|
onChange={(e) => setStringOpenType(Number(e.currentTarget.value))}
|
|
>
|
|
<option value={1}>일반</option>
|
|
<option value={2}>한글</option>
|
|
<option value={3}>영어</option>
|
|
<option value={4}>이메일</option>
|
|
<option value={5}>전화번호</option>
|
|
<option value={6}>장문</option>
|
|
</Form.Control>
|
|
</div>
|
|
{
|
|
stringOpenType === 4 || stringOpenType === 5 ?
|
|
<Form>
|
|
<div>
|
|
<span style={{cursor:"pointer"}} onClick={ () => {setStringScalarToggle(!stringScalarToggle)}}>
|
|
<Switch
|
|
name="stringMulti"
|
|
checked={ stringScalarToggle }
|
|
onChange={() => { setStringScalarToggle(!stringScalarToggle)}}
|
|
/>
|
|
<span className='mb-1 mr-3' style={{"fontSize":"15px"}}>중복 막기</span>
|
|
</span>
|
|
</div>
|
|
</Form>
|
|
:
|
|
<Form style={{"width":"12%"}} />
|
|
}
|
|
{ stringOpenType !== 6 ?
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"20%"}}
|
|
placeholder='Pre Text'
|
|
value={ stringOpenPrefix }
|
|
onChange={(e) => setStringOpenPrefix(e.currentTarget.value)}
|
|
onKeyUp={(e) => setStringOpenPrefix(e.currentTarget.value)}
|
|
/> :null
|
|
}
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={stringOpenType !== 6 ? {"width":"25%"} : {"width":"65%"}}
|
|
placeholder='Placeholder 지정'
|
|
value={ stringOpenPlaceHolder }
|
|
onChange={(e) => setStringOpenPlaceHolder(e.currentTarget.value)}
|
|
onKeyUp={(e) => setStringOpenPlaceHolder(e.currentTarget.value)}
|
|
|
|
/>
|
|
{ stringOpenType !== 6 ?
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"20%"}}
|
|
placeholder='Post Text'
|
|
value={ stringOpenPostfix }
|
|
onChange={(e) => setStringOpenPostfix(e.currentTarget.value)}
|
|
onKeyUp={(e) => setStringOpenPostfix(e.currentTarget.value)}
|
|
/>
|
|
:null
|
|
}
|
|
</div>
|
|
: null
|
|
}
|
|
</Modal.Body>
|
|
<Modal.Footer>
|
|
<Button className='project-save-btn' variant="primary" onClick={ mackContent }>등록</Button>
|
|
<Button variant="secondary" onClick={props.onHide}>닫기</Button>
|
|
</Modal.Footer>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export const MatrixNumericModal = (props:{
|
|
show:boolean,
|
|
onHide: () => void,
|
|
questionUpdate:questionInfoType,
|
|
setQuestionUpdate:SetterOrUpdater<questionInfoType>
|
|
}) => {
|
|
const [modalProcess, setModalProcess] = useRecoilState(modalProcessStatus);
|
|
const [selectedOption, setSelectedOption] = useState(1);
|
|
const [matrixOpenArray, setMatrixOpenArray] = useState<labelInfoType[]>([]);
|
|
|
|
const addMatrixOpen = () => {
|
|
setMatrixOpenArray([...matrixOpenArray, {
|
|
order: 1,
|
|
value: 1,
|
|
label: '',
|
|
open_type: 1,
|
|
decimal_point: 0,
|
|
not_duplicate: 0,
|
|
prefix: "",
|
|
range: "",
|
|
placeholder:"",
|
|
suffix: "",
|
|
is_etc: 0,
|
|
is_not: 0
|
|
}])
|
|
}
|
|
|
|
useEffect(() => {
|
|
setMatrixOpenArray(props.questionUpdate.matrix_label!.label_info);
|
|
},[props.questionUpdate.matrix_label?.label_info])
|
|
|
|
const changeOption = (e:any, index:number) => {
|
|
changeOpenType(e, index);
|
|
setSelectedOption(e.currentTarget.value);
|
|
}
|
|
|
|
const changeAttrText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].label = e.target.value;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changeOpenType = (e:any, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
let logicData = Number(e.target.value);
|
|
newArray[index].open_type = logicData
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changePrefixText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].prefix = e.target.value;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changeRangeText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
if(matrixOpenArray[index]?.open_type === 3){
|
|
newArray[index].range = regexDateRange(e.target.value);
|
|
}else{
|
|
newArray[index].range = regexNumRange(e.target.value);
|
|
}
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
const changeDecimalPointText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].decimal_point = Number(regexPureNum(e.target.value));
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const setRangeText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
if(matrixOpenArray[index]?.open_type === 2){
|
|
newArray[index].range = regexSetDateRange(e.target.value);
|
|
}else{
|
|
newArray[index].range = regexSetNumRange(e.target.value);
|
|
}
|
|
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changePostfixText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].suffix = e.target.value;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const mackContent = () => {
|
|
let emptyFlag = false;
|
|
let infoArray:labelInfoType[] = [];
|
|
matrixOpenArray.map((matrixEle, matrixIdx) => {
|
|
let setValue = matrixIdx+1;
|
|
let setLabel = matrixEle;
|
|
let valuePattern = /(\d+\|)/gi;
|
|
const regexValue = matrixEle.label?.match(valuePattern);
|
|
|
|
if(regexValue){
|
|
setLabel.label = setLabel.label?.split("|")[1];
|
|
setValue = Number(regexValue[0].replace("|",""));
|
|
}
|
|
|
|
if(matrixEle.label?.trim()===""){
|
|
emptyFlag=true;
|
|
}
|
|
|
|
infoArray.push(
|
|
{
|
|
order: matrixIdx + 1,
|
|
value: setValue,
|
|
label: matrixEle.label,
|
|
open_type: matrixEle.open_type,
|
|
decimal_point: matrixEle.decimal_point,
|
|
prefix: matrixEle.prefix,
|
|
range: matrixEle.range,
|
|
placeholder: matrixEle.placeholder,
|
|
suffix: matrixEle.suffix,
|
|
is_etc: 0,
|
|
is_not: 0
|
|
}
|
|
)
|
|
})
|
|
|
|
if(emptyFlag){
|
|
alert('속성은 공백으로 설정할 수 없습니다.');
|
|
}
|
|
else{
|
|
setModalProcess({
|
|
modalProcessStatus: true
|
|
});
|
|
props.onHide();
|
|
|
|
let tempQuestionUpdate = {...props.questionUpdate}
|
|
tempQuestionUpdate.matrix_label!.label_info = infoArray;
|
|
props.setQuestionUpdate(tempQuestionUpdate);
|
|
alert('등록되었습니다');
|
|
}
|
|
}
|
|
|
|
const removeMatrixOpen = (e:React.MouseEvent<HTMLImageElement>, index:number) =>{
|
|
let newArray = [...matrixOpenArray].filter((ele, arrIdx) => index !== arrIdx );
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const matrixOpenChild = (index:number) => {
|
|
return (
|
|
<div key={index} className="input-group input-group-sm mt-3">
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='속성'
|
|
value={ matrixOpenArray[index]?.label }
|
|
onChange={(e) => changeAttrText(e, index)}
|
|
/>
|
|
<div className='custom-sel mr-2' style={{"width":"15%"}}>
|
|
<Form.Control as='select' className='sel-box'
|
|
value={ matrixOpenArray[index]?.open_type }
|
|
onChange={ (e) => changeOption(e, index) }
|
|
>
|
|
<option value={1}>일반</option>
|
|
<option value={2}>소수점</option>
|
|
<option value={3}>날짜</option>
|
|
</Form.Control>
|
|
</div>
|
|
{matrixOpenArray[index]?.open_type === 2 ?
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"10%"}}
|
|
placeholder='소수점 자리'
|
|
value={ matrixOpenArray[index]?.decimal_point }
|
|
onChange={(e) => changeDecimalPointText(e, index)}
|
|
/>
|
|
:null}
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='Pre Text'
|
|
value={ matrixOpenArray[index]?.prefix }
|
|
onChange={(e) => changePrefixText(e, index)}
|
|
/>
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"20%"}}
|
|
placeholder={matrixOpenArray[index]?.open_type === 3 ? '범위 지정 ex) 2024/01/31~2024/12/31' : '범위 지정 ex) 1~99'}
|
|
value={ matrixOpenArray[index]?.range }
|
|
onChange={(e) => changeRangeText(e, index)}
|
|
onBlur={(e) => setRangeText(e, index)}
|
|
|
|
/>
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='Post Text'
|
|
value={ matrixOpenArray[index]?.suffix }
|
|
onChange={(e) => changePostfixText(e, index)}
|
|
/>
|
|
<img className="mr-2" src={'/public_img/Intersect.svg'} onClick={ (e) => removeMatrixOpen(e, index) }/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
//s단축키
|
|
useEffect(() => {
|
|
const handleKeySave = (e: { key: string; ctrlKey: boolean; preventDefault: () => void; }) => {
|
|
if(props.show && e.ctrlKey && e.key.toLowerCase() === "s"){
|
|
e.preventDefault();
|
|
mackContent();
|
|
}
|
|
}
|
|
window.addEventListener('keydown', handleKeySave);
|
|
return () => {
|
|
window.removeEventListener('keydown', handleKeySave);
|
|
};
|
|
},[props.show, mackContent])
|
|
|
|
return(
|
|
<Modal show={props.show} onHide={props.onHide} size="xl" backdrop='static'>
|
|
<Modal.Header>
|
|
<Modal.Title>
|
|
{ "Matrix Numeric 설정" }
|
|
</Modal.Title>
|
|
</Modal.Header>
|
|
<Modal.Body style={{"overflowY":"scroll"}}>
|
|
{
|
|
props.show ?
|
|
<React.Fragment>
|
|
<div>
|
|
<Button onClick={ addMatrixOpen } >Open 문항 추가</Button>
|
|
</div>
|
|
{
|
|
matrixOpenArray?.map((ele, index) => matrixOpenChild(index))
|
|
}
|
|
</React.Fragment>
|
|
: null
|
|
}
|
|
</Modal.Body>
|
|
<Modal.Footer>
|
|
<Button className='project-save-btn' variant="primary" onClick={ mackContent }>등록</Button>
|
|
<Button variant="secondary" onClick={props.onHide}>닫기</Button>
|
|
</Modal.Footer>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export const MatrixStringModal = (props:{
|
|
show:boolean,
|
|
onHide: () => void,
|
|
questionUpdate:questionInfoType,
|
|
setQuestionUpdate:SetterOrUpdater<questionInfoType>
|
|
}) => {
|
|
const [modalProcess, setModalProcess] = useRecoilState(modalProcessStatus);
|
|
const [matrixOpenArray, setMatrixOpenArray] = useState<labelInfoType[]>([]);
|
|
// 복수제출 버튼 Toggle
|
|
const [stringMulti, setStringMulti] = useState(false);
|
|
|
|
const addMatrixOpen = () => {
|
|
setMatrixOpenArray([...matrixOpenArray, {
|
|
order: 1,
|
|
value: 1,
|
|
label: '',
|
|
open_type: 1,
|
|
decimal_point: 0,
|
|
not_duplicate: 0,
|
|
prefix: "",
|
|
range: "",
|
|
placeholder:"",
|
|
suffix: "",
|
|
is_etc: 0,
|
|
is_not: 0
|
|
}])
|
|
}
|
|
|
|
useEffect(() => {
|
|
setMatrixOpenArray(props.questionUpdate.matrix_label!.label_info);
|
|
},[props.questionUpdate.matrix_label?.label_info])
|
|
|
|
const changeAttrText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].label = e.target.value;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changeDupulicate = (e:React.MouseEvent<HTMLElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].not_duplicate = stringMulti === false ? 0 : 1;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changeOpenType = (e:any, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
let logicData = Number(e.target.value);
|
|
newArray[index].open_type = logicData
|
|
if(logicData !== 4 && logicData !== 5){
|
|
newArray[index].not_duplicate = 0;
|
|
}
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changePrefixText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].prefix = e.target.value;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changePalaceHolderText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].placeholder = e.target.value;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const changePostfixText = (e:React.ChangeEvent<HTMLInputElement>, index:number) => {
|
|
e.preventDefault();
|
|
let newArray = [...matrixOpenArray];
|
|
newArray[index].suffix = e.target.value;
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const mackContent = () => {
|
|
let emptyFlag = false;
|
|
let infoArray:labelInfoType[] = [];
|
|
matrixOpenArray.map((matrixEle, matrixIdx) => {
|
|
let setValue = matrixIdx+1;
|
|
let setLabel = matrixEle;
|
|
let valuePattern = /(\d+\|)/gi;
|
|
const regexValue = matrixEle.label?.match(valuePattern);
|
|
|
|
if(regexValue){
|
|
setLabel.label = setLabel.label?.split("|")[1];
|
|
setValue = Number(regexValue[0].replace("|",""));
|
|
}
|
|
|
|
if(matrixEle.label?.trim() === ""){
|
|
emptyFlag = true;
|
|
}
|
|
infoArray.push(
|
|
{
|
|
order: matrixIdx + 1,
|
|
value: setValue,
|
|
label: matrixEle.label,
|
|
open_type: matrixEle.open_type,
|
|
decimal_point: 0,
|
|
not_duplicate: matrixEle.not_duplicate,
|
|
prefix: matrixEle.prefix,
|
|
range: "",
|
|
placeholder:matrixEle.placeholder,
|
|
suffix: matrixEle.suffix,
|
|
is_etc: 0,
|
|
is_not: 0
|
|
}
|
|
)
|
|
})
|
|
|
|
if(emptyFlag){
|
|
alert('속성은 공백으로 설정할 수 없습니다.');
|
|
}
|
|
else{
|
|
setModalProcess({
|
|
modalProcessStatus: true
|
|
});
|
|
props.onHide();
|
|
|
|
let tempQuestionUpdate = {...props.questionUpdate}
|
|
tempQuestionUpdate.matrix_label!.label_info = infoArray;
|
|
props.setQuestionUpdate(tempQuestionUpdate);
|
|
alert('등록되었습니다');
|
|
}
|
|
}
|
|
|
|
const removeMatrixOpen = (e:React.MouseEvent<HTMLImageElement>, index:number) =>{
|
|
let newArray = [...matrixOpenArray].filter((ele, arrIdx) => index !== arrIdx );
|
|
setMatrixOpenArray(newArray);
|
|
}
|
|
|
|
const matrixOpenChild = (index:number) => {
|
|
return (
|
|
<div key={index} className="input-group input-group-sm mt-1 mb-3">
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='속성'
|
|
value={ matrixOpenArray[index]?.label }
|
|
onChange={(e) => changeAttrText(e, index)}
|
|
/>
|
|
<div className='custom-sel mr-2' style={{"width":"10%"}}>
|
|
<Form.Control as='select' className='sel-box'
|
|
value={ matrixOpenArray[index]?.open_type }
|
|
onChange={(e) => changeOpenType(e, index)}
|
|
>
|
|
<option value={1}>일반</option>
|
|
<option value={2}>한글</option>
|
|
<option value={3}>영어</option>
|
|
<option value={4}>이메일</option>
|
|
<option value={5}>전화번호</option>
|
|
{
|
|
props.questionUpdate.question_dimension === 3? null//tensor일 경우 장문 지우기
|
|
:
|
|
<option value={6}>장문</option>
|
|
}
|
|
</Form.Control>
|
|
</div>
|
|
{
|
|
matrixOpenArray[index]?.open_type === 4 || matrixOpenArray[index]?.open_type === 5 ?
|
|
<Form>
|
|
<div>
|
|
<span style={{cursor:"pointer"}} onClick={ (e) => { changeDupulicate (e, index); setStringMulti(!stringMulti) } }>
|
|
<Switch name="stringMulti" checked={ matrixOpenArray[index].not_duplicate === 0 ? false : true } onChange={ () => setStringMulti(!stringMulti) } />
|
|
<span className='mb-1 mr-3' style={{"fontSize":"15px"}}>중복 막기</span>
|
|
</span>
|
|
</div>
|
|
</Form>
|
|
:
|
|
<Form style={{"width":"12%"}} />
|
|
}
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='Pre Text'
|
|
value={ matrixOpenArray[index]?.prefix }
|
|
onChange={(e) => changePrefixText(e, index)}
|
|
/>
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='Placeholder 지정'
|
|
value={ matrixOpenArray[index]?.placeholder }
|
|
onChange={(e) => changePalaceHolderText(e, index)}
|
|
/>
|
|
<input
|
|
type="text"
|
|
className="mr-2"
|
|
style={{"width":"15%"}}
|
|
placeholder='Post Text'
|
|
value={ matrixOpenArray[index]?.suffix }
|
|
onChange={(e) => changePostfixText(e, index)}
|
|
/>
|
|
<img className="mr-2" src={'/public_img/Intersect.svg'} onClick={ (e) => removeMatrixOpen(e, index) }/>
|
|
</div>
|
|
)
|
|
}
|
|
//s단축키
|
|
useEffect(() => {
|
|
const handleKeySave = (e: { key: string; ctrlKey: boolean; preventDefault: () => void; }) => {
|
|
if(props.show && e.ctrlKey && e.key.toLowerCase() === "s"){
|
|
e.preventDefault();
|
|
mackContent();
|
|
}
|
|
}
|
|
window.addEventListener('keydown', handleKeySave);
|
|
return () => {
|
|
window.removeEventListener('keydown', handleKeySave);
|
|
};
|
|
},[props.show, mackContent])
|
|
|
|
return(
|
|
<Modal show={props.show} onHide={props.onHide} size="xl" backdrop='static'>
|
|
<Modal.Header>
|
|
<Modal.Title>
|
|
{ "Matrix String Open 설정" }
|
|
</Modal.Title>
|
|
</Modal.Header>
|
|
<Modal.Body style={{"overflowY":"scroll"}}>
|
|
{
|
|
props.show ?
|
|
<React.Fragment>
|
|
<div>
|
|
<Button onClick={ addMatrixOpen }>Open 문항 추가</Button>
|
|
</div>
|
|
{
|
|
matrixOpenArray?.map((ele, index) => matrixOpenChild(index))
|
|
}
|
|
</React.Fragment>
|
|
: null
|
|
}
|
|
</Modal.Body>
|
|
<Modal.Footer>
|
|
<Button className='project-save-btn' variant="primary" onClick={ mackContent }>등록</Button>
|
|
<Button variant="secondary" onClick={props.onHide}>닫기</Button>
|
|
</Modal.Footer>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
export const AutoRecodeModal = (props:{
|
|
show:boolean,
|
|
onHide: () => void,
|
|
questionUpdate:questionInfoType,
|
|
setQuestionUpdate:SetterOrUpdater<questionInfoType>,
|
|
setAutoRecodeArray:SetterOrUpdater<autoRecodeArray[]>
|
|
}) => {
|
|
const [autoArray, setAutoArray] = useState<autoRecodeArray[]>([]);
|
|
const info = useRecoilValue(memberInfo);
|
|
const project = useRecoilValue(projectInfo);
|
|
const token = useRecoilValue(loginToken);
|
|
|
|
let defaultAuto = {
|
|
idx: 0,
|
|
projectCode: project.prjcode,
|
|
questionUniqueKey: props.questionUpdate.question_unique_key,
|
|
recodeValue: 0,
|
|
recodeCondition: "",
|
|
regMember: info.member_code
|
|
}
|
|
|
|
useEffect(() => {
|
|
let autoEmptyArray:autoRecodeArray[] = [...autoArray];
|
|
if(autoEmptyArray.length > 0){
|
|
props.questionUpdate.scalar_label?.label_info.map((ele, idx) => {
|
|
if(ele.value !== autoEmptyArray[idx]?.recodeValue){
|
|
autoEmptyArray.push({...defaultAuto, recodeValue: Number(ele.value)});
|
|
}
|
|
})
|
|
}else{
|
|
props.questionUpdate.scalar_label?.label_info.map((ele:labelInfoType, idx:number) => {
|
|
autoEmptyArray.push({...defaultAuto, recodeValue: Number(ele.value)});
|
|
})
|
|
}
|
|
if(props.questionUpdate.question_dimension !== 9){
|
|
autoEmptyArray = [];
|
|
}
|
|
|
|
setAutoArray(autoEmptyArray);
|
|
},[props.questionUpdate.question_dimension, props.questionUpdate.scalar_label?.label_info])
|
|
|
|
useEffect(() => {
|
|
let autoData = {
|
|
projectCode: project.prjcode,
|
|
questionUniqueKey:props.questionUpdate.question_unique_key
|
|
}
|
|
|
|
axios.post(URL_SEED+'/question/getAutoRecode', autoData, {
|
|
headers: {
|
|
'Authorization': `Bearer ${token.access}`,
|
|
}
|
|
}).then((response) => {
|
|
if(response.status === 200){
|
|
setAutoArray(response.data);
|
|
}
|
|
}).catch((error) => {
|
|
console.log("getAutoRecode :", error);
|
|
})
|
|
},[props.questionUpdate.question_unique_key])
|
|
|
|
//s단축키
|
|
useEffect(() => {
|
|
const handleKeySave = (e: { key: string; ctrlKey: boolean; preventDefault: () => void; }) => {
|
|
if(props.show && e.ctrlKey && e.key.toLowerCase() === "s"){
|
|
e.preventDefault();
|
|
autoSave();
|
|
}
|
|
}
|
|
window.addEventListener('keydown', handleKeySave);
|
|
return () => {
|
|
window.removeEventListener('keydown', handleKeySave);
|
|
};
|
|
},[props.show])
|
|
|
|
const autoValueChange = (e:React.ChangeEvent<HTMLInputElement>, value:number) => {
|
|
let copyArray:autoRecodeArray[] = [...autoArray];
|
|
|
|
if(copyArray.length > 0){
|
|
props.questionUpdate.scalar_label?.label_info.map((ele, idx) => {
|
|
if(ele.value !== copyArray[idx]?.recodeValue){
|
|
copyArray.push({...defaultAuto, recodeValue: Number(ele.value)});
|
|
}
|
|
})
|
|
}else{
|
|
props.questionUpdate.scalar_label?.label_info.map((ele, idx) => {
|
|
copyArray.push({...defaultAuto, recodeValue: Number(ele.value)});
|
|
})
|
|
}
|
|
|
|
copyArray.filter((ele) => {
|
|
if (ele.recodeValue === value) {
|
|
ele.recodeCondition = regexAuto(e.currentTarget.value);
|
|
}
|
|
});
|
|
|
|
if (props.questionUpdate.question_type === 41 && copyArray.length > 0) {
|
|
copyArray[0].recodeCondition = regexAuto(e.currentTarget.value);
|
|
}
|
|
|
|
setAutoArray(copyArray);
|
|
}
|
|
|
|
const autoSave = () => {
|
|
props.setAutoRecodeArray(autoArray);
|
|
alert("저장되었습니다.");
|
|
props.onHide();
|
|
}
|
|
|
|
return(
|
|
<div>
|
|
{ props.questionUpdate.question_dimension === 9 ?
|
|
<Modal show={props.show} size="lg" backdrop='static'>
|
|
<Modal.Header>
|
|
<Modal.Title className="text-center">
|
|
{
|
|
props.questionUpdate.auto_type === 1 ? "Auto Recode" : "Brand Recode"
|
|
}
|
|
</Modal.Title>
|
|
</Modal.Header>
|
|
<Modal.Body className="AutoRecodeForm" style={{maxHeight:"600px!important", height:"600px", overflowY:"auto",textAlign:"center"}} >
|
|
{
|
|
props.questionUpdate.scalar_label?.label_info.length === 0 && props.questionUpdate.question_type !== 41?
|
|
"보기를 입력해주세요."
|
|
:
|
|
props.questionUpdate.question_type === 41 ?
|
|
<div className="txt-list lbl-wrap">
|
|
<span className="tbe-pre">{"1"}</span>
|
|
<div className="txt-list txt-list-post">
|
|
<input
|
|
type="text"
|
|
style={{width:"100%"}}
|
|
value={autoArray[0]?.recodeCondition}
|
|
onChange={(e) => autoValueChange(e, Number(1))}
|
|
/>
|
|
</div>
|
|
</div>
|
|
:
|
|
props.questionUpdate.scalar_label?.label_info.map((ele, index) => (
|
|
<div key={index} className="txt-list lbl-wrap">
|
|
<span className="tbe-pre" style={{width: "20%"}}>{ele.label?.replace(/(<([^>]+)>)/ig, "")}</span>
|
|
<div className="txt-list txt-list-post">
|
|
<input
|
|
type="text"
|
|
style={{width:"100%"}}
|
|
value={autoArray[index]?.recodeCondition}
|
|
onChange={(e) => autoValueChange(e, Number(ele.value))}
|
|
/>
|
|
</div>
|
|
</div>
|
|
))
|
|
}
|
|
</Modal.Body>
|
|
<Modal.Footer>
|
|
<div className='mt-2 mr-1 float-right'>
|
|
<Button className='project-save-btn mr-2' variant="primary" onClick={autoSave}>저장</Button>
|
|
<Button variant="secondary" onClick={()=>{props.onHide()}}>닫기</Button>
|
|
</div>
|
|
</Modal.Footer>
|
|
</Modal>
|
|
:
|
|
null
|
|
}
|
|
</div>
|
|
)
|
|
} |