From d92199f6b04f625b8500b51ebe2885ffff45cf80 Mon Sep 17 00:00:00 2001 From: Alireza khaji Date: Wed, 6 Jul 2022 15:31:20 +0430 Subject: [PATCH] add note , add lesson , add category , add subexam | 350 --- src/components/selectedCourse/index.js | 97 ++++-- src/redux/actions/exam.js | 16 + src/redux/actions/index.js | 1 + src/redux/actions/note.js | 23 ++ src/redux/reducers/exam.js | 2 +- src/redux/reducers/exam2.js | 2 + src/redux/reducers/file.js | 1 + src/redux/reducers/index.js | 1 + src/redux/reducers/note.js | 37 ++ .../components/addQuestionnaireCourse.js | 5 +- .../addExam/views/addQuestionnaireExam.js | 322 ++++++++++++++---- 11 files changed, 405 insertions(+), 102 deletions(-) create mode 100644 src/redux/actions/note.js create mode 100644 src/redux/reducers/note.js diff --git a/src/components/selectedCourse/index.js b/src/components/selectedCourse/index.js index 9bbf9e5..bdfca66 100644 --- a/src/components/selectedCourse/index.js +++ b/src/components/selectedCourse/index.js @@ -1,42 +1,65 @@ import React from "react"; -const SelectedCourse = ({ onClick, title, questionQuantity, coefficient, optionsQuantity }) => { - return ( -
-
- -

- {title} -

-
-

-

تعداد سوالات

- -

-

-

ضریب

- -

-

-

تعداد گزینه

- -

-

-

نمره منفی

- -

- - -
- -
-

- پاسخ برگ -

+const SelectedCourse = ({ + onClick, + title, + questionQuantity, + coefficient, + optionsQuantity, + optionsNumber, +}) => { + return ( +
+
+

+ {title} +

+
+

+

تعداد سوالات

+ +

+

+

ضریب

+ +

+

+

تعداد گزینه

+ +

+

+

نمره منفی

+ +

- ) -} + +
+

+ پاسخ برگ +

+
+ ); +}; export default SelectedCourse; \ No newline at end of file diff --git a/src/redux/actions/exam.js b/src/redux/actions/exam.js index 7ddc268..770a61f 100644 --- a/src/redux/actions/exam.js +++ b/src/redux/actions/exam.js @@ -117,6 +117,22 @@ const exam = { }); }; }, + addExamQuestionaires: (data = {}) => { + return (dispatch) => { + dispatch({ + type: "ADD_EXAM_QUESTIONAIRES", + payload: data, + }); + }; + }, + addQuestionnaireCourse: (data = {}) => { + return (dispatch) => { + dispatch({ + type: "ADD_QUESTIONNAIRE_COURSES", + payload: data, + }); + }; + }, }; export default exam; diff --git a/src/redux/actions/index.js b/src/redux/actions/index.js index 61923fb..8e5fe85 100644 --- a/src/redux/actions/index.js +++ b/src/redux/actions/index.js @@ -19,6 +19,7 @@ export { default as lesson } from "./lesson"; export { default as question } from "./question"; export { default as category } from "./category"; export { default as examQuestion } from "./examQuestion"; +export { default as note } from "./note"; diff --git a/src/redux/actions/note.js b/src/redux/actions/note.js new file mode 100644 index 0000000..4db0241 --- /dev/null +++ b/src/redux/actions/note.js @@ -0,0 +1,23 @@ + + +import proxy from "../proxy"; +const note = { + info: + (data = {}) => + async (dispatch) => + await proxy.get("note/info", data, { dispatch }), + list: + (data = {}) => + async (dispatch) => + await proxy.get("note/list", data, { dispatch }), + add: + (data = {}) => + async (dispatch) => + await proxy.post("note/add", data, { dispatch }), + delete: + (data = {}) => + async (dispatch) => + await proxy.delete("note/delete", data, { dispatch }), +}; + +export default note; \ No newline at end of file diff --git a/src/redux/reducers/exam.js b/src/redux/reducers/exam.js index 86207a9..77ee3a5 100644 --- a/src/redux/reducers/exam.js +++ b/src/redux/reducers/exam.js @@ -225,7 +225,7 @@ export default function addExamReduser( ); thisQ = { ...thisQ, - courses: [...thisQ.courses, payload], + courses: thisQ?.courses?.length ? [...thisQ?.courses, payload] :[payload], }; console.log(thisQ); return { diff --git a/src/redux/reducers/exam2.js b/src/redux/reducers/exam2.js index 428ca11..0dd2e81 100644 --- a/src/redux/reducers/exam2.js +++ b/src/redux/reducers/exam2.js @@ -9,6 +9,7 @@ const initialState = { lastExamAdd: null, preview: null, subExamList: [], + lastSubExamAdd:null, confirm:null }; export default function exam2(state = initialState, action) { @@ -30,6 +31,7 @@ export default function exam2(state = initialState, action) { ...state, loading: false, error: null, + lastSubExamAdd:data.id, subExamList: [...state.subExamList, data.id], }; case "empty_subexam_list": diff --git a/src/redux/reducers/file.js b/src/redux/reducers/file.js index 9f0ea4d..8731e4a 100644 --- a/src/redux/reducers/file.js +++ b/src/redux/reducers/file.js @@ -11,6 +11,7 @@ export default function file(state = initialState, action) { let { type, data, params } = action; switch (type) { case "file/upload": + toast.success("آپلود با موفقیت انجام شد") return { ...state, loading: false, diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js index 9222d3c..ff3163f 100644 --- a/src/redux/reducers/index.js +++ b/src/redux/reducers/index.js @@ -19,5 +19,6 @@ export { default as lesson } from "./lesson"; export { default as question } from "./question"; export { default as category } from "./category"; export { default as examQuestion } from "./examQuestion"; +export { default as note } from "./note"; diff --git a/src/redux/reducers/note.js b/src/redux/reducers/note.js new file mode 100644 index 0000000..5f5139d --- /dev/null +++ b/src/redux/reducers/note.js @@ -0,0 +1,37 @@ + + +import { toast } from "react-toastify"; + +const initialState = { + loading: false, + error: null, + info: null, + list: null, + lastAdd: null, + myNotes:[] +}; +export default function note(state = initialState, action) { + let { type, data } = action; + switch (type) { + case "note/info": + return { ...state, loading: false, info: data, error: null }; + case "note/add": + toast.success("درخواست با موفقیت انجام شد"); + return { + ...state, + loading: false, + error: null, + lastAdd: data.id, + myNotes:[...state.myNotes,data.id] + }; + case "note/list": + return { ...state, loading: false, error: null, list: data }; + case "note/loading": + return { ...state, loading: true }; + case "note/error": + toast.error(data.message); + return { ...state, loading: false, error: data.message }; + default: + return state; + } +} \ No newline at end of file diff --git a/src/view/addExam/components/addQuestionnaireCourse.js b/src/view/addExam/components/addQuestionnaireCourse.js index 0711217..5bfcdbc 100644 --- a/src/view/addExam/components/addQuestionnaireCourse.js +++ b/src/view/addExam/components/addQuestionnaireCourse.js @@ -7,6 +7,7 @@ const AddQuestionnaireCourse = ({ questionEnd, coefficientOnChange, closeOnClick, + optionsNumber, }) => { return (
@@ -77,13 +78,13 @@ const AddQuestionnaireCourse = ({ type="number" placeholder="ضریب ..." className="w-4/5 p-4 ml-2 rounded border border-red52 h-12 text-red26 outline-none" - onChange={coefficientOnChange} + onChange={(e) => coefficientOnChange(e)} /> optionsNumber(e)} />
diff --git a/src/view/addExam/views/addQuestionnaireExam.js b/src/view/addExam/views/addQuestionnaireExam.js index a3aeb34..b73362c 100644 --- a/src/view/addExam/views/addQuestionnaireExam.js +++ b/src/view/addExam/views/addQuestionnaireExam.js @@ -11,13 +11,34 @@ import { DragDropContext } from "react-beautiful-dnd"; import { Droppable } from "react-beautiful-dnd"; import { Draggable } from "react-beautiful-dnd"; import { toMap } from "draft-js/lib/DefaultDraftBlockRenderMap"; +import { category, exam, file, lesson, note } from "../../../redux/actions"; +import loadingGiff from "../../../assets/img/Rolling-2s-223px.gif"; + + +let lastCourseIndex; const AddQuestionnaireExam = ({ grades, addExamState, dispatch, stepClick, backStep, + uploadNote, + lastUpload, + uploadLoading, + addExamQuestionaires, + addNoteLoading, + myNoteList, + addNote, + examId, + addLesson, + lastlessonAdd, + addCategory, + lastCategoryAdd, + addQuestionnaireCourse, + subexamList, + subexamAdd, + lastSubExamAdd, }) => { const [questionarePopUp, setQuestionairePopUp] = useState(false); const [addCoursePopup, setAddCoursePopup] = useState(false); @@ -33,28 +54,31 @@ const AddQuestionnaireExam = ({ courses: [], }); const [answers, setAnswers] = useState(null); - const [newCourse, setNewCourse] = useState({ - id: selectedQuestionare.courses.length + selectedQuestionare.id + 1, - questionnaireId: selectedQuestionare.id, - questionsQuantity: 20, - name: "", - coefficient: 4, - }); - const [selectedCourse, setSelectedCourse] = useState({ - sortId: 1, - title: "ادبیات فارسی", - coefficient: 3, - questionStart: 1, - questionEnd: 0, - }); + const [newCourse, setNewCourse] = useState(null); + // id: selectedQuestionare?.courses?.length + selectedQuestionare?.id + 1, + // questionnaireId: selectedQuestionare?.id, + // questionsQuantity: 20, + // name: "", + // coefficient: 4, + const [selectedCourse, setSelectedCourse] = useState(null); + const [subexamArray,setSubexamArray]=useState([]); + // { + // sortId: 1, + // title: "ادبیات فارسی", + // coefficient: 3, + // questionStart: 1, + // questionEnd: 0, + // } // console.log(choosedQuestionaries) // console.log(newQuestionaire) // console.log(addExamState.questionnaires) - console.log(newCourse); - console.log(selectedQuestionare); - console.log(selectedCourse.id); - console.log(answers); - + // console.log(newCourse); + // console.log(selectedQuestionare); + // console.log(selectedCourse?.id); + // console.log(answers); + const [noteSelectedId, setNoteSelectedId] = useState(null); + const [NoteList, setNoteList] = useState([]); + // const [noteAndCategory] const [fakeState, setFakeState] = useState(2); useEffect(() => { setSelectedCourse(selectedCourse); @@ -68,13 +92,148 @@ const AddQuestionnaireExam = ({ } }, [answers]); - const [noteFile,setNoteFile]=useState(null); - const noteChooseFile=()=>{ + //add note process ================================================================= + console.log("=======myNoteList==================="); + console.log(myNoteList); + + const [noteFile, setNoteFile] = useState(null); + const noteChooseFile = () => { let input = document.querySelector("#add-note-input-file"); input.click(); - setNoteFile(input); - setFakeState(fakeState + 15); - } + // setNoteFile(input); + // setFakeState(Math.random()*1000); + }; + + const noteChangeFile = (e) => { + console.log("{{{}}}"); + console.log(e.target.value); + setNoteFile(e.target.value); + }; + + const uploadNoteHandler = () => { + let input = document.querySelector("#add-note-input-file"); + uploadNote({ + file: input.files[0], + }); + }; + + const submitNoteHandler = () => { + // dispatch({ + // type: "", + // payload: newQuestionaire, + // }); + addExamQuestionaires(newQuestionaire); + setQuestionairePopUp(false); + addNote({ + name: newQuestionaire.name, + fileId: lastUpload, + examId: examId, + }); + }; + // useEffect(() => { + // setNewQuestionaire({ + // ...newQuestionaire, + // id: lastNoteadd, + // }); + + // }, [lastNoteadd]); + + //add lesson and category process ================================================================= + // console.log("========selectedQuestionare========="); + // console.log(addExamState.questionnaires); + // console.log("========selectedQuestionare========="); + // console.log(addExamState.questionnaires); + console.log("========NoteList========="); + console.log(NoteList); + console.log("========subexamArray========="); + console.log(subexamArray); + const submitLessonhandler = () => { + addQuestionnaireCourse(newCourse); + setAddCoursePopup(false); + setFakeState(fakeState + 356); + addLesson({ + name: newCourse.name, + }); + }; + + useEffect(() => { + if (lastlessonAdd) { + addCategory({ + title: newCourse.name, + lessonId: lastlessonAdd, + gradeId: addExamState.grade, + }); + } + }, [lastlessonAdd]); + + useEffect(() => { + if (lastCategoryAdd) { + setNoteList([ + ...NoteList, + { + noteId: noteSelectedId, + categoryId: lastCategoryAdd, + name: newCourse.name, + }, + ]); + } + }, [lastCategoryAdd]); + + //=========================================================== + const submitSubexam = (item, index) => { + lastCourseIndex = index; + setSelectedCourse(item); + console.log("a...............................a"); + console.log(selectedCourse); + let negetiveInput = document.querySelectorAll( + ".note-course-negetive-point-input" + ); + let categoryId; + for (let i = 0; i < NoteList.length; i++) { + if ( + noteSelectedId === NoteList[i].noteId && + item?.name === NoteList[i].name + ) { + categoryId = NoteList[i].categoryId; + break; + } + } + console.log({ + noteId: noteSelectedId, + name: item?.name, + description: " ", + categoryId, + coefficient: item?.coefficient, + negativePoint: negetiveInput[index].checked, + questionType: item.optionsNumber || 2, + questionCount: Number(item.questionEnd) - Number(item.questionStart) + 1, + }); + subexamAdd({ + pid: examId, + ord:index+1, + noteId: noteSelectedId, + name: item?.name, + description: " ", + categoryId, + coefficient: item?.coefficient, + negativePoint: negetiveInput[index].checked, + questionType: item.optionsNumber || 2, + questionCount: Number(item.questionEnd) - Number(item.questionStart) + 1, + }); + }; + + useEffect(() => { + if (lastSubExamAdd){ + setSubexamArray([ + ...subexamArray, + { + index: lastCourseIndex, + subexamId: lastSubExamAdd, + noteId: noteSelectedId, + }, + ]); + } + }, [lastSubExamAdd]); return ( <> @@ -143,31 +302,43 @@ const AddQuestionnaireExam = ({ انتخاب فایل
- {noteFile!==null ? noteFile?.value : "فایلی اضافه نشده"} -
-
- آپلود + {noteFile !== null ? noteFile : "فایلی اضافه نشده"}
+ {!uploadLoading && ( +
+ آپلود +
+ )} + {uploadLoading && ( +
+ loadingGiff +
+ )} noteChangeFile(e)} />
- + {!addNoteLoading && ( + + )} + {addNoteLoading && ( +
+ loadingGiff +
+ )}
{/* { @@ -235,9 +406,12 @@ const AddQuestionnaireExam = ({ nameOnChange={(e) => setNewCourse({ ...newCourse, name: e.target.value }) } - coefficientOnChange={(e) => - setNewCourse({ ...newCourse, coefficient: e.target.vlaue }) - } + coefficientOnChange={(e) => { + setNewCourse({ ...newCourse, coefficient: e.target.value }); + }} + optionsNumber={(e) => { + setNewCourse({ ...newCourse, optionsNumber: e.target.value }); + }} questionEnd={(e) => setNewCourse({ ...newCourse, @@ -250,14 +424,10 @@ const AddQuestionnaireExam = ({ ...newCourse, questionStart: e.target.value, questionnaireId: selectedQuestionare.id, - id: selectedQuestionare.id + selectedCourse.id + 1, + id: selectedQuestionare?.id + (selectedCourse?.id || 0) + 1, }) } - submitOnClick={() => { - dispatch({ type: "ADD_QUESTIONNAIRE_COURSES", payload: newCourse }); - setAddCoursePopup(false); - setFakeState(fakeState + 356); - }} + submitOnClick={submitLessonhandler} /> )} {/* ==============================top-part============================= */} @@ -314,13 +484,16 @@ const AddQuestionnaireExam = ({ ? "bg-pinkF5 border border-red52 text-red52" : "bg-white border border-gray-300 text-blue3A" } items-center justify-center w-36 h-32 mx-2 font-bold rounded-xl cursor-pointer`} - onClick={() => + onClick={() => { + console.log("note click"); + console.log(item); + setNoteSelectedId(myNoteList[index]); setSelectedQuestionare({ id: item.id, name: item.name, courses: item.courses, - }) - } + }); + }} >

دفترچه {item.name}

@@ -353,8 +526,9 @@ const AddQuestionnaireExam = ({ - {/* ====================================================================== */} + {/* ================================bottom-part====================================== */}
+ {/* ==============================b-right-part============================= */}
{selectedQuestionare.id !== null && ( <> @@ -368,17 +542,17 @@ const AddQuestionnaireExam = ({
{addExamState.questionnaires .find((itm) => itm.id == selectedQuestionare.id) - ?.courses.map((item, index) => ( + ?.courses?.map((item, index) => ( { - setSelectedCourse(item); - console.log(selectedCourse); + submitSubexam(item, index); }} /> @@ -398,13 +572,14 @@ const AddQuestionnaireExam = ({
)}
+ {/* ==============================b-left-part============================= */}
dispatch({ type: "ADD_ANSWERS", payload: data }) } @@ -436,6 +611,29 @@ const AddQuestionnaireExam = ({ const mapStateToProps = (state) => ({ grades: state.publicApi.grades, addExamState: state.addExamReduser, + lastUpload: state.file.lastUpload, + uploadLoading: state.file.loading, + addNoteLoading: state.note.loading, + myNoteList: state.note.myNotes, + lastNoteadd: state.note.lastAdd, + examId: state.exam2.lastExamAdd, + lastlessonAdd: state.lesson.lastAdd, + lastCategoryAdd: state.category.lastAdd, + subexamList: state.exam2.subExamList, + lastSubExamAdd: state.exam2.lastSubExamAdd, }); -export default connect(mapStateToProps)(AddQuestionnaireExam); +const mapDispatchToProps = { + uploadNote: file.upload, + addNote: note.add, + addExamQuestionaires: exam.addExamQuestionaires, + addLesson: lesson.add, + addCategory: category.add, + addQuestionnaireCourse: exam.addQuestionnaireCourse, + subexamAdd: exam.subexamAdd, +}; + +export default connect( + mapStateToProps, + mapDispatchToProps +)(AddQuestionnaireExam);