861918334d69ce08f9c66ab3fe98e109.json
23.1 KB
{"ast":null,"code":"import { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nvar _jsxFileName = \"C:\\\\Users\\\\kkwan_000\\\\Desktop\\\\git\\\\2017110269\\\\minsung\\\\src\\\\Container\\\\Tikz.js\",\n _s = $RefreshSig$();\n\nimport React, { useState, useEffect, useCallback } from 'react';\nimport { Drawer, message } from 'antd';\nimport { UploadOutlined, RetweetOutlined } from '@ant-design/icons';\nimport 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';\nimport { getTexToSvg, checkQno, saveFileAndQno } from '../lib/api/tikz'; // Request api\n\nconst fetchTexToSvg = async data => {\n // getTexToSvg api를 이용하기 위한 const\n try {\n const result = await getTexToSvg({\n tex: data\n });\n\n if (result.status === 200) {\n console.log(result.status);\n console.log(result.data);\n return result.data;\n }\n } catch (e) {\n console.log(e); //Notification. 추가해서 변환상태 알려주기\n\n return null;\n }\n};\n\nconst fetchSaveData = async data => {\n try {\n const result = await saveFileAndQno(data);\n console.log(result);\n\n if (result.status === 200) {\n return result.data;\n }\n } catch (e) {\n console.log(e);\n message.warning(e.message);\n }\n};\n/* 문항번호 체크 */\n\n\nconst fetchCheckQno = async qno => {\n try {\n const result = await checkQno(qno);\n\n if (result.status === 200) {\n console.log(result);\n message.info(\"사용 가능한 문항 번호 입니다.\");\n return true;\n } else {\n message.info(\"존재 하지 않는 문항 번호 입니다.\");\n return false;\n }\n } catch (e) {\n console.log(e);\n message.info(\"존재 하지 않는 문항 번호 입니다.\");\n return false;\n }\n};\n\nconst _tikzcode = \"% 예시 (x축, y축, 반지름이 1cm인 원의 그림) %\\n\\\r\n% 오른쪽의 변환 버튼을 눌러보세요! %\\n\\n\\\r\n \\\\documentclass{article}\\n\\\r\n \\\\usepackage{tikz}\\n\\\r\n \\\\begin{document}\\n\\n\\n\\\r\n \\\\begin{tikzpicture}\\n\\\r\n \\\\draw (-1.5,0) -- (1.5,0);\\n\\\r\n \\\\draw (0,-1.5) -- (0,1.5);\\n\\\r\n \\\\draw (0,0) circle (1cm);\\n\\\r\n \\\\end{tikzpicture}\\n\\n\\n\\\r\n \\\\end{document}\";\n\nconst Tikz = ({\n onLeave,\n visible,\n callback,\n selectItem,\n mode\n}) => {\n _s();\n\n const [fields, setFields] = useState([]);\n const [qno, setQno] = useState(null);\n const [number, setNumber] = useState(null); //문항번호를 저장하는 state\n\n const [inputText, setinputText] = useState(_tikzcode); //tikz code를 저장하는 state\n\n const [svg, setSvg] = useState(null); //변환된 svg 데이터를 저장하는 state\n\n const [qnoCheck, setQnoCheck] = useState(false);\n const [tikzcode, setTikzCode] = useState(_tikzcode); //svg\n //onclickevent : Tikz 변환하기 Button의 onClick Event\n //onChangeTikz : TextArea 컴포넌트의 onChange event\n //onFinish : Form data를 제출하기 위한 event\n\n useEffect(() => {\n if (mode === 'preview' && selectItem) {\n console.log(selectItem);\n let initFields = [{\n name: ['qno'],\n value: selectItem.qno\n }, {\n name: ['typeSol'],\n value: selectItem.typeSol\n }, {\n name: ['typeQue'],\n value: selectItem.typeQue\n }, {\n name: ['creator'],\n value: selectItem.creator\n }];\n setQno(selectItem.qno);\n setTikzCode(selectItem.tex);\n setFields(initFields);\n setSvg(null);\n }\n }, [mode, selectItem]);\n useEffect(() => {\n if (mode === 'new') {\n let initFields = [{\n name: ['qno'],\n value: null\n }, {\n name: ['typeSol'],\n value: null\n }, {\n name: ['typeQue'],\n value: null\n }, {\n name: ['creator'],\n value: null\n }];\n setQno(null);\n setTikzCode(_tikzcode);\n setFields(initFields);\n setSvg(null);\n }\n }, [mode]);\n\n const onClickEvent = e => {\n if (inputText) {\n callbackSVG(inputText);\n }\n\n if (inputText === null) {\n console.log(inputText);\n alert( //data에 null이 입력된 경우\n 'Code 값을 입력해주세요!');\n } else {\n console.log(inputText);\n callbackSVG(inputText);\n }\n };\n\n const onChangeQno = value => {\n console.log(value);\n setQno(value);\n setFields([...fields, {\n name: ['qno'],\n value: value\n }]);\n };\n /*\r\n \tuseEffect(()=>{\r\n \t\tif(!visible ){\r\n \t\t let initFields = [\r\n \t\t\t{name:['qno'],value:null},\r\n \t\t\t{name:['typeSol'],value:null},\r\n \t\t\t{name:['typeQue'],value:null},\r\n \t\t\t{name:['creator'],value:null},\r\n \t\t ];\r\n \t\t setQno(null);\r\n \t\t setTikzCode(tikzcode);\r\n \t\t setFields(initFields);\r\n \t\t}\r\n \t },[visible,mode]);\r\n */\n\n\n const callbackSVG = useCallback(async () => {\n const result = await fetchTexToSvg(inputText);\n setSvg(result); //api로 받아온 result를 svg state에 저장\n }, [inputText]);\n\n const onChangeTikz = e => {\n if (e) {\n setinputText(e.target.value);\n } else setinputText(null);\n };\n\n const onSaveEvent = () => {\n try {\n //서버에 저장이 확인 됐을때 200, 500(오류) http status\n const result = alert('전송이 성공적으로 완료됐습니다.');\n } catch (e) {\n //서버에 저장 오류가 났을때\n console.log(e);\n alert(e);\n }\n };\n\n const onClickQno = async e => {\n e.preventDefault(); //번호가 호출 성공시 setQnoCheck(true);\n\n if (qno) {\n const _checkQno = await fetchCheckQno(qno);\n\n setQnoCheck(_checkQno);\n }\n };\n\n const onFinish = async values => {\n console.log(values);\n console.log(qnoCheck);\n\n if (!qnoCheck) {\n message.warning(\"문제 번호를 확인해 주세요.\");\n return;\n } else {\n const creator = sessionStorage.getItem('id');\n console.log('Received values of form: ', values);\n const result = await fetchSaveData({ ...values,\n creator\n });\n console.log(result);\n\n if (result) {\n message.info(result.message);\n let initFields = [{\n name: ['qno'],\n value: null\n }, {\n name: ['typeSol'],\n value: null\n }, {\n name: ['typeQue'],\n value: null\n }, {\n name: ['creator'],\n value: null\n }];\n setFields(initFields);\n onLeave();\n callback({\n status: 'SAVE_OK'\n });\n setQno(null);\n } else {\n callback({\n status: 'SAVE_FAIL'\n });\n }\n }\n };\n\n const onChangeTypeSol = value => {\n console.log(value);\n setFields([...fields, {\n name: ['typeSol'],\n value: value\n }]);\n };\n\n const onChangeTypeQue = value => {\n console.log(value);\n setFields([...fields, {\n name: ['typeQue'],\n value: value\n }]);\n };\n\n return /*#__PURE__*/_jsxDEV(Drawer, {\n title: 'Tikz Editor',\n placement: 'bottom',\n closable: true,\n height: '90vh',\n onClose: onLeave,\n visible: visible,\n children: /*#__PURE__*/_jsxDEV(TikzForm, {\n svg: svg,\n onClickEvent: onClickEvent,\n onChangeTikz: onChangeTikz,\n onSaveEvent: onSaveEvent,\n onFinish: onFinish,\n tikzcode: tikzcode,\n fields: fields,\n onClickQno: onClickQno,\n onChangeQno: onChangeQno,\n onChangeTypeSol: onChangeTypeSol,\n onChangeTypeQue: onChangeTypeQue,\n qno: qno\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 233,\n columnNumber: 4\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 226,\n columnNumber: 3\n }, this);\n};\n\n_s(Tikz, \"4ADPAqkfb/0Pvs9O3Ja+bAEkqnk=\");\n\n_c = Tikz;\nexport default Tikz; //<Transform value={tikzHtml}></Transform>\n\nvar _c;\n\n$RefreshReg$(_c, \"Tikz\");","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/Container/Tikz.js"],"names":["React","useState","useEffect","useCallback","Drawer","message","UploadOutlined","RetweetOutlined","getTexToSvg","checkQno","saveFileAndQno","fetchTexToSvg","data","result","tex","status","console","log","e","fetchSaveData","warning","fetchCheckQno","qno","info","_tikzcode","Tikz","onLeave","visible","callback","selectItem","mode","fields","setFields","setQno","number","setNumber","inputText","setinputText","svg","setSvg","qnoCheck","setQnoCheck","tikzcode","setTikzCode","initFields","name","value","typeSol","typeQue","creator","onClickEvent","callbackSVG","alert","onChangeQno","onChangeTikz","target","onSaveEvent","onClickQno","preventDefault","_checkQno","onFinish","values","sessionStorage","getItem","onChangeTypeSol","onChangeTypeQue"],"mappings":";;;;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,EAAqCC,WAArC,QAAwD,OAAxD;AACA,SAASC,M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EAAE,aADR;AAEC,IAAA,SAAS,EAAE,QAFZ;AAGC,IAAA,QAAQ,EAAE,IAHX;AAIC,IAAA,MAAM,EAAE,MAJT;AAKC,IAAA,OAAO,EAAEpB,OALV;AAMC,IAAA,OAAO,EAAEC,OANV;AAAA,2BAOC,QAAC,QAAD;AACC,MAAA,GAAG,EAAEW,GADN;AAEC,MAAA,YAAY,EAAEY,YAFf;AAGC,MAAA,YAAY,EAAEI,YAHf;AAIC,MAAA,WAAW,EAAEE,WAJd;AAKC,MAAA,QAAQ,EAAEI,QALX;AAMC,MAAA,QAAQ,EAAElB,QANX;AAOC,MAAA,MAAM,EAAEX,MAPT;AAQC,MAAA,UAAU,EAAE0B,UARb;AASC,MAAA,WAAW,EAAEJ,WATd;AAUC,MAAA,eAAe,EAAEW,eAVlB;AAWC,MAAA,eAAe,EAAEC,eAXlB;AAYC,MAAA,GAAG,EAAE3C;AAZN;AAAA;AAAA;AAAA;AAAA;AAPD;AAAA;AAAA;AAAA;AAAA,UADD;AAwBA,CAjLC;;GAAMG,I;;KAAAA,I;AAmLR,eAAeA,IAAf,C,CAEA","sourcesContent":["import React, { useState, useEffect, useCallback } from 'react';\r\nimport { Drawer, message } from 'antd';\r\nimport { UploadOutlined, RetweetOutlined } from '@ant-design/icons';\r\nimport 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';\r\nimport { getTexToSvg, checkQno, saveFileAndQno } from '../lib/api/tikz'; // Request api\r\n\r\n\r\n\r\nconst fetchTexToSvg = async (data) => {\r\n\t// getTexToSvg api를 이용하기 위한 const\r\n\ttry {\r\n\t\tconst result = await getTexToSvg({ tex: data });\r\n\t\tif (result.status === 200) {\r\n\t\t\tconsole.log(result.status);\r\n\t\t\tconsole.log(result.data);\r\n\t\t\treturn result.data;\r\n\t\t}\r\n\t} catch (e) {\r\n\t\tconsole.log(e);\r\n\t\t//Notification. 추가해서 변환상태 알려주기\r\n\t\treturn null;\r\n\t}\r\n};\r\n\r\n\r\nconst fetchSaveData = async (data) => {\r\n\ttry{\r\n\t const result = await saveFileAndQno(data);\r\n\t console.log(result);\r\n\t if(result.status===200){\r\n\t\treturn result.data;\r\n\t } \r\n\t}catch(e){\r\n\t console.log(e);\r\n\t message.warning(e.message);\r\n\t}\r\n }\r\n\r\n/* 문항번호 체크 */\r\nconst fetchCheckQno = async(qno) => {\r\n\ttry{\r\n\t const result = await checkQno(qno);\r\n\t if(result.status===200){\r\n\t\tconsole.log(result);\r\n\t\tmessage.info(\"사용 가능한 문항 번호 입니다.\");\r\n\t\treturn true;\r\n\t }else{ \r\n\t\tmessage.info(\"존재 하지 않는 문항 번호 입니다.\");\r\n\t\treturn false;\r\n\t }\r\n\t}catch(e){\r\n\t console.log(e);\r\n\t message.info(\"존재 하지 않는 문항 번호 입니다.\");\r\n\t return false;\r\n\t}\r\n }\r\n\r\n\r\n const _tikzcode= \"% 예시 (x축, y축, 반지름이 1cm인 원의 그림) %\\n\\\r\n% 오른쪽의 변환 버튼을 눌러보세요! %\\n\\n\\\r\n \\\\documentclass{article}\\n\\\r\n \\\\usepackage{tikz}\\n\\\r\n \\\\begin{document}\\n\\n\\n\\\r\n \\\\begin{tikzpicture}\\n\\\r\n \\\\draw (-1.5,0) -- (1.5,0);\\n\\\r\n \\\\draw (0,-1.5) -- (0,1.5);\\n\\\r\n \\\\draw (0,0) circle (1cm);\\n\\\r\n \\\\end{tikzpicture}\\n\\n\\n\\\r\n \\\\end{document}\";\r\n \r\n \r\n const Tikz = ({ onLeave, visible, callback, selectItem, mode }) => {\r\n\tconst [fields,setFields] =useState([]);\r\n\tconst [qno, setQno] = useState(null);\r\n\tconst [number, setNumber] = useState(null); //문항번호를 저장하는 state\r\n\tconst [inputText, setinputText] = useState(_tikzcode); //tikz code를 저장하는 state\r\n\tconst [svg, setSvg] = useState(null); //변환된 svg 데이터를 저장하는 state\r\n\tconst [qnoCheck,setQnoCheck] = useState(false);\r\n\tconst [tikzcode,setTikzCode] = useState(_tikzcode);\r\n\t//svg\r\n\t//onclickevent : Tikz 변환하기 Button의 onClick Event\r\n\t//onChangeTikz : TextArea 컴포넌트의 onChange event\r\n\t//onFinish : Form data를 제출하기 위한 event\r\n\t\r\n\tuseEffect(()=> {\r\n\t\t\tif(mode==='preview'&&selectItem){\r\n\t\t\t\tconsole.log(selectItem);\r\n\r\n\t\t\t\tlet initFields = [\r\n\t\t\t\t\t{name:['qno'],value:selectItem.qno},\r\n\t\t\t\t\t{name:['typeSol'],value:selectItem.typeSol},\r\n\t\t\t\t\t{name:['typeQue'],value:selectItem.typeQue},\r\n\t\t\t\t\t{name:['creator'],value:selectItem.creator},\r\n\t\t\t\t\r\n\t\t\t\t ];\r\n\t\t\t\t setQno(selectItem.qno);\r\n\t\t\t\t setTikzCode(selectItem.tex);\r\n\t\t\t\t setFields(initFields);\r\n\t\t\t\t setSvg(null);\r\n\t\t\t}\r\n\t},[mode, selectItem]);\r\n\r\n\tuseEffect(()=>{\r\n\t\tif(mode === 'new'){\r\n\t\t\tlet initFields = [\r\n\t\t\t\t{name:['qno'],value:null},\r\n\t\t\t\t{name:['typeSol'],value:null},\r\n\t\t\t\t{name:['typeQue'],value:null},\r\n\t\t\t\t{name:['creator'],value:null},\r\n\t\t\t ];\r\n\t\t\t setQno(null);\r\n\t\t\t setTikzCode(_tikzcode);\r\n\t\t\t setFields(initFields);\r\n\t\t\t setSvg(null);\r\n\t\t}\r\n\t},[mode]);\r\n\r\n\tconst onClickEvent = (e) => {\r\n\t\tif(inputText){\r\n\t\t\tcallbackSVG(inputText);\r\n\t\t}\r\n\t\t\r\n\t\tif (inputText === null) {\r\n\t\t\tconsole.log(inputText);\r\n\t\t\talert(\r\n\t\t\t\t//data에 null이 입력된 경우\r\n\t\t\t\t'Code 값을 입력해주세요!'\r\n\t\t\t);\r\n\t\t} else {\r\n\t\t\tconsole.log(inputText);\r\n\t\t\tcallbackSVG(inputText);\r\n\t\t}\r\n\t};\r\n\tconst onChangeQno = (value) => {\r\n\t\tconsole.log(value);\r\n\t\tsetQno(value);\r\n\t\tsetFields([...fields, {name:['qno'],value:value}]);\r\n\t};\r\n/*\r\n\tuseEffect(()=>{\r\n\t\tif(!visible ){\r\n\t\t let initFields = [\r\n\t\t\t{name:['qno'],value:null},\r\n\t\t\t{name:['typeSol'],value:null},\r\n\t\t\t{name:['typeQue'],value:null},\r\n\t\t\t{name:['creator'],value:null},\r\n\t\t ];\r\n\t\t setQno(null);\r\n\t\t setTikzCode(tikzcode);\r\n\t\t setFields(initFields);\r\n\t\t}\r\n\t },[visible,mode]);\r\n*/\r\n\tconst callbackSVG = useCallback(async () => {\r\n\t\tconst result = await fetchTexToSvg(inputText);\r\n\t\tsetSvg(result); //api로 받아온 result를 svg state에 저장\r\n\t}, [inputText]);\r\n\r\n\tconst onChangeTikz = (e) => {\r\n\t\tif (e) {\r\n\t\t\tsetinputText(e.target.value);\r\n\t\t} else setinputText(null);\r\n\t};\r\n\r\n\tconst onSaveEvent = () => {\r\n\t\ttry {\r\n\t\t\t//서버에 저장이 확인 됐을때 200, 500(오류) http status\r\n\t\t\tconst result = alert('전송이 성공적으로 완료됐습니다.');\r\n\t\t} catch (e) {\r\n\t\t\t//서버에 저장 오류가 났을때\r\n\t\t\tconsole.log(e);\r\n\t\t\talert(e);\r\n\t\t}\r\n\t};\r\n\tconst onClickQno = async(e)=>{\r\n\t\te.preventDefault();\r\n\t\t//번호가 호출 성공시 setQnoCheck(true);\r\n\t\tif(qno){\r\n\t\t const _checkQno= await fetchCheckQno(qno);\r\n\t\t setQnoCheck(_checkQno);\r\n\t\t}\r\n\t };\r\n\t\r\n\r\n\tconst onFinish = async(values) => {\r\n\t\tconsole.log(values);\r\n\t\tconsole.log(qnoCheck);\r\n\t\tif(!qnoCheck){\r\n\t\t message.warning(\"문제 번호를 확인해 주세요.\")\r\n\t\t return;\r\n\t\t}else{\r\n\t\t\tconst creator = sessionStorage.getItem('id');\r\n\t\t\tconsole.log('Received values of form: ', values); \r\n\t\t\tconst result = await fetchSaveData({...values, creator});\r\n\t\t\tconsole.log(result);\r\n\t\t\tif(result){\r\n\t\t\t message.info(result.message);\r\n\t\t\t let initFields = [\r\n\t\t\t\t{name:['qno'],value:null},\r\n\t\t\t\t{name:['typeSol'],value:null},\r\n\t\t\t\t{name:['typeQue'],value:null},\r\n\t\t\t\t{name:['creator'],value:null},\r\n\t\t\t ];\r\n\t\t\t setFields(initFields);\r\n\t\t\t onLeave();\r\n\t\t\t callback({status:'SAVE_OK'});\r\n\t\t\t setQno(null);\r\n\t\t\t}else{\r\n\t\t\t\tcallback({status:'SAVE_FAIL'})\r\n\t\t\t} \r\n\t\t}\r\n\t};\r\n\r\n\t\r\n\tconst onChangeTypeSol = (value) => {\r\n\t\tconsole.log(value);\r\n\t\tsetFields([...fields, {name:['typeSol'],value:value}]);\r\n\t}\r\n\t\r\n\tconst onChangeTypeQue = (value) => {\r\n\t\tconsole.log(value);\r\n\t\tsetFields([...fields, {name:['typeQue'],value:value}])\r\n\t}\r\n\r\n\treturn (\r\n\t\t<Drawer\r\n\t\t\ttitle={'Tikz Editor'}\r\n\t\t\tplacement={'bottom'}\r\n\t\t\tclosable={true}\r\n\t\t\theight={'90vh'}\r\n\t\t\tonClose={onLeave}\r\n\t\t\tvisible={visible}>\r\n\t\t\t<TikzForm\r\n\t\t\t\tsvg={svg}\r\n\t\t\t\tonClickEvent={onClickEvent}\r\n\t\t\t\tonChangeTikz={onChangeTikz}\r\n\t\t\t\tonSaveEvent={onSaveEvent}\r\n\t\t\t\tonFinish={onFinish}\r\n\t\t\t\ttikzcode={tikzcode}\r\n\t\t\t\tfields={fields}\r\n\t\t\t\tonClickQno={onClickQno}\r\n\t\t\t\tonChangeQno={onChangeQno}\r\n\t\t\t\tonChangeTypeSol={onChangeTypeSol}\r\n\t\t\t\tonChangeTypeQue={onChangeTypeQue}\r\n\t\t\t\tqno={qno}>\r\n\t\t\t</TikzForm>\r\n\t\t</Drawer>\r\n\t);\r\n};\r\n\r\nexport default Tikz;\r\n\r\n//<Transform value={tikzHtml}></Transform>\r\n"]},"metadata":{},"sourceType":"module"}