From e5a216d744abb1c7cbc915fe5d31ebce5f1af065 Mon Sep 17 00:00:00 2001 From: cherif Date: Tue, 9 Apr 2024 15:28:31 +0200 Subject: [PATCH] 09/04/2024 - 15h19 --- src/components/Partner_Config_Formulaires.js | 165 +++++++++++++++--- src/components/SurveyDocument.js | 141 ++++++++++++++- .../components/_displaypartnersession.scss | 5 + 3 files changed, 285 insertions(+), 26 deletions(-) diff --git a/src/components/Partner_Config_Formulaires.js b/src/components/Partner_Config_Formulaires.js index 6ffffbe..8bed781 100644 --- a/src/components/Partner_Config_Formulaires.js +++ b/src/components/Partner_Config_Formulaires.js @@ -44,10 +44,9 @@ import Autocomplete from '@mui/material/Autocomplete'; import { gridClasses } from '@mui/x-data-grid'; import { PiDotsThree } from "react-icons/pi"; import Link from '@mui/material/Link'; -import { CiCircleMinus } from "react-icons/ci"; import { LiaSave } from "react-icons/lia"; -import { IoMdAddCircleOutline } from "react-icons/io"; +import { IoMdAddCircleOutline, IoMdRemoveCircleOutline } from "react-icons/io"; const Partner_Config_Formulaires = (props) => { @@ -181,9 +180,10 @@ const Partner_Config_Formulaires = (props) => { const columns_question = [ - { field: '_id', headerName: '_id', hide: true }, + { field: '_id', headerName: '_id', hide: true }, { field: 'id', headerName: 'id', hide: true }, { field: 'list_choix', headerName: 'list_choix', hide: true }, + { field: 'list_case_cocher', headerName: 'list_case_cocher', hide: true }, { field: 'question', headerName: 'question', flex: 1, hide: false, editable: false, renderCell: (params) => , }, { field: 'type', headerName: 'type', flex: 1, hide: false, editable: false, renderCell: (params) => , }, { field: 'max_note', headerName: 'max_note', flex: 1, hide: true, editable: false, renderCell: (params) => , }, @@ -478,6 +478,9 @@ const Partner_Config_Formulaires = (props) => { const [p_detail_from_commentaire, setp_detail_from_commentaire] = useState(""); const [p_detail_from_list_question, setp_detail_from_list_question] = useState([]); + const [p_detail_from_list_check_box, setp_detail_from_list_check_box] = useState([]); + + const [p_detail_from_message_intro, setp_detail_from_message_intro] = useState(""); const [p_detail_from_type, setp_detail_from_type] = useState(""); @@ -551,10 +554,14 @@ const Partner_Config_Formulaires = (props) => { setp_detail_from_message_intro(mylocal_form_data.message_introduction); + setp_detail_from_list_check_box([]); + if (mylocal_form_data.list_case_cocher) { + setp_detail_from_list_check_box(mylocal_form_data.list_case_cocher); + } + setp_detail_from_list_question([]); if (mylocal_form_data.list_questions) { setp_detail_from_list_question(mylocal_form_data.list_questions); - } @@ -731,6 +738,7 @@ const Partner_Config_Formulaires = (props) => { { "id": "bool", "label": "Oui/Non", "value": "bool" }, { "id": "entier", "label": "Entier", "value": "entier" }, { "id": "qcm", "label": "Qcm", "value": "qcm" }, + { "id": "checkbox", "label": "Case à cocher", "value": "checkbox" }, { "id": "", "label": "", "value": "" }, ] @@ -957,6 +965,7 @@ const Partner_Config_Formulaires = (props) => { setDialog_Question_open(true); settab_qcm_choix([]); + settab_checkbox_choix([]); } @@ -982,9 +991,9 @@ const Partner_Config_Formulaires = (props) => { form.append("question", question_question); form.append("type", question_type); form.append("max_note", question_max_note); - + var local_list_choix = [] - for(let i = 0; i < tab_qcm_choix.length; i++){ + for (let i = 0; i < tab_qcm_choix.length; i++) { var choix = "reponse"; var val = String(tab_qcm_choix[i]) var node = {}; @@ -993,6 +1002,19 @@ const Partner_Config_Formulaires = (props) => { } form.append("list_choix", JSON.stringify(local_list_choix)); + + var local_list_checkbox = [] + for (let i = 0; i < tab_checkbox_choix.length; i++) { + var choix = "reponse"; + var val = String(tab_checkbox_choix[i]) + var node = {}; + node[choix] = val; + local_list_checkbox.push(node); + } + form.append("list_case_cocher", JSON.stringify(local_list_checkbox)); + + + if (String(selected_question_id).length > 2) { form.append("question_id", selected_question_id); } @@ -1156,6 +1178,31 @@ const Partner_Config_Formulaires = (props) => { } + const [tab_checkbox_choix, settab_checkbox_choix] = useState([]); + const [add_new_checkbox_choix, setadd_new_checkbox_choix] = useState(""); + const [new_checkbox_choix_value, setnew_checkbox_choix_value] = useState(""); + + function add_new_list_to_checkbox() { + var current_tab_checkbox_choix = tab_checkbox_choix; + current_tab_checkbox_choix.push(new_checkbox_choix_value); + settab_checkbox_choix(current_tab_checkbox_choix); + setnew_checkbox_choix_value(""); + } + + + function remove_last_list_to_checkbox() { + var current_tab_checkbox_choix = tab_checkbox_choix; + + var new_current_tab_checkbox_choix = []; + for (let i = 0; i < current_tab_checkbox_choix.length - 1; i++) + new_current_tab_checkbox_choix.push(current_tab_checkbox_choix[i]); + + current_tab_checkbox_choix.pop(); + setnew_checkbox_choix_value(""); + settab_checkbox_choix(new_current_tab_checkbox_choix); + } + + return (
@@ -1174,7 +1221,7 @@ const Partner_Config_Formulaires = (props) => { > MySy Information - + {Dialog_Question_message} @@ -1255,7 +1302,7 @@ const Partner_Config_Formulaires = (props) => { {tab_qcm_choix && tab_qcm_choix.map((choix) => (
- + { />
))} - - {add_new_qcm_choix && String(add_new_qcm_choix) === "1" && -
+
{ name="field_question_qcm_new" fullWidth - + value={new_qcm_choix_value} onChange={(e) => { setnew_qcm_choix_value(e.target.value); @@ -1301,16 +1348,79 @@ const Partner_Config_Formulaires = (props) => { } } /> - { +
}
} + + {String(question_type) === "checkbox" &&
checkbox + + {tab_checkbox_choix && + tab_checkbox_choix.map((choix) => ( +
+ + { + // setquestion_max_note(e.target.value); + + } + } + /> +
+ ))} + + + + + {add_new_checkbox_choix && String(add_new_checkbox_choix) === "1" && + +
+ { + setnew_checkbox_choix_value(e.target.value); + + } + } + /> + +
+ } + +
} +
@@ -1940,7 +2050,8 @@ const Partner_Config_Formulaires = (props) => { type: (item).type, max_note: (item).max_note, list_choix: (item).list_choix, - + list_case_cocher: (item).list_case_cocher, + } ))} @@ -1956,12 +2067,24 @@ const Partner_Config_Formulaires = (props) => { setquestion_type(newSelectionModel.row.type); setquestion_max_note(newSelectionModel.row.max_note); - var tmp_tab = [] - for(let i = 0; i < newSelectionModel.row.list_choix.length; i++){ - tmp_tab.push(newSelectionModel.row.list_choix[i]['reponse_qcm'] ); + if (newSelectionModel.row.list_choix) { + var tmp_tab = [] + for (let i = 0; i < newSelectionModel.row.list_choix.length; i++) { + tmp_tab.push(newSelectionModel.row.list_choix[i]['reponse_qcm']); + } + settab_qcm_choix(tmp_tab); } - settab_qcm_choix(tmp_tab); + console.log(" ") + if (newSelectionModel.row.list_case_cocher) { + var tmp_tab_checkbox = [] + for (let i = 0; i < newSelectionModel.row.list_case_cocher.length; i++) { + tmp_tab_checkbox.push(newSelectionModel.row.list_case_cocher[i]['reponse_checkbox']); + + } + + settab_checkbox_choix(tmp_tab_checkbox); + } setDialog_Question_open(true); diff --git a/src/components/SurveyDocument.js b/src/components/SurveyDocument.js index 07094ce..a12ec10 100644 --- a/src/components/SurveyDocument.js +++ b/src/components/SurveyDocument.js @@ -53,6 +53,7 @@ import FormControl from '@mui/material/FormControl'; import FormLabel from '@mui/material/FormLabel'; import Radio from '@mui/material/Radio'; import { daDK } from "@mui/material/locale"; +import Checkbox from '@mui/material/Checkbox'; function SurveyDocument() { @@ -151,6 +152,10 @@ function SurveyDocument() { var is_empty_field = 0; + console.log(" tab_variable = ", tab_variable); + + + for (let i = 0; i < Object.keys(tab_variable).length; i++) { var key = Object.keys(tab_variable)[i]; @@ -211,6 +216,92 @@ function SurveyDocument() { } + const [value, setValue] = React.useState('female'); + + const handleChange = (event) => { + setValue(event.target.value); + }; + + + + const [selected_qcm_value, setselected_qcm_value] = React.useState(''); + const handleChange_qcm = (event) => { + + console.log(" event.target.name ", event.target.name); + + document.getElementsByName(event.target.name)[0].value = event.target.value; + + // setselected_qcm_value(event.target.value); + change_survey_data(event.target); + }; + + const [selected_checkbox_value, setselected_checkbox_value] = React.useState(''); + const handleChange_checkbox = (event) => { + var tmp_variable = tab_variable; + var tab = String(event.target.name).split(":"); + + var al = String(tab[0]); + + if (event.currentTarget.checked) { + console.log('checked'); + if (!tmp_variable[al] || String(tmp_variable[al]) === "") { + console.log(" première action "); + var t = []; + t.push(String(tab[1])); + } else { + console.log(" PASSS première action "); + var t = tmp_variable[al]; + t.push(String(tab[1])); + } + + + tmp_variable[al] = t; + + console.log(" sortirrr tmp_variable = ", tmp_variable); + settab_variable(tmp_variable); + + console.log(" ### sortir settab_variable = ", tab_variable); + + + } + else { + console.log('not checked'); + + if (!tmp_variable[al] || String(tmp_variable[al]) === "") { + console.log(" première action "); + + } else { + + + + console.log(" PASSS première action "); + + console.log(" Suppression de ", String(tab[1])); + + var new_variable = [] + for (let i = 0; i < tmp_variable[al].length; i++) { + if (String(tmp_variable[al][i]) !== String(tab[1])) { + new_variable.push(String(tmp_variable[al][i])) + + } + } + + tmp_variable[al] = new_variable; + + console.log(" tmp_variable ", tmp_variable); + + settab_variable(tmp_variable); + console.log(" ### sortir settab_variable = ", tab_variable); + + + } + } + + console.log(" ### FINNNNNN settab_variable = ", tab_variable); + }; + + + return (
@@ -232,7 +323,7 @@ function SurveyDocument() {

- {JSON.parse(get_Given_Survey_Data_result).message_introduction} + {JSON.parse(get_Given_Survey_Data_result).message_introduction}

@@ -249,11 +340,9 @@ function SurveyDocument() { {JSON.parse(get_Given_Survey_Data_result).list_questions && JSON.parse(get_Given_Survey_Data_result).list_questions.length > 0 && JSON.parse(get_Given_Survey_Data_result).list_questions.map((question, index) => (
-

- {question.type && String(question.type) === "text" && - -
} + {question.type && String(question.type) === "qcm" && +
+ + + + {question.list_choix && + question.list_choix.map((list_choix, index) => ( + + } label={index + ". " + list_choix.reponse_qcm} /> + ))} + + + + +
} + + + {question.type && String(question.type) === "checkbox" && +
+ + + + {question.list_case_cocher && + question.list_case_cocher.map((case_cocher, index) => ( + } id={question._id + ":" + case_cocher.reponse_checkbox} name={question._id + ":" + case_cocher.reponse_checkbox} onChange={handleChange_checkbox} label={index + ". " + case_cocher.reponse_checkbox} /> + + ))} + + + + +
} + +
{/* diff --git a/src/styles/components/_displaypartnersession.scss b/src/styles/components/_displaypartnersession.scss index ffd34e4..670c65d 100644 --- a/src/styles/components/_displaypartnersession.scss +++ b/src/styles/components/_displaypartnersession.scss @@ -2693,6 +2693,11 @@ background-color: #FFFFFF; } + .session_caract_Dialog_icone_bton_add_reduce { + font-size: large; + cursor: pointer; + } + .css-1v4ccyo {