Browse Source

asignacion full flow

amenpunk 2 years ago
parent
commit
428e78228c

+ 0 - 1
src/Components/Navigation/listItems.js

85
 };
85
 };
86
 
86
 
87
 export const UserListItems = (_props) =>  {
87
 export const UserListItems = (_props) =>  {
88
-    // const [open, setOpen] = React.useState(false);
89
     return(
88
     return(
90
         <List>
89
         <List>
91
             <ListSubheader inset>MENÚ</ListSubheader>
90
             <ListSubheader inset>MENÚ</ListSubheader>

+ 4 - 1
src/Components/Routes.js

44
         }
44
         }
45
       >
45
       >
46
         <Route path="home" element={<HomeUser />} />
46
         <Route path="home" element={<HomeUser />} />
47
-        <Route path="prueba/:id" element={<Prueba/>} />
47
+        <Route path="prueba">
48
+          <Route path=":id" element={<Prueba/>}/>
49
+          <Route path="" element={<Prueba/>}/>
50
+        </Route>
48
       </Route>
51
       </Route>
49
 
52
 
50
 
53
 

+ 1 - 1
src/Pages/Logincs.jsx

68
         .then(response => {
68
         .then(response => {
69
 
69
 
70
           console.log("Service Response :: ", response)
70
           console.log("Service Response :: ", response)
71
-          let { token, nombre, apelidos, id: pass_id, idSueperContrasenia } = response;
71
+          let { token, nombre, apelidos, idcontrasenia : pass_id, idSueperContrasenia } = response;
72
           toast.success(`Bienvenido ${nombre} ${apelidos}!!`)
72
           toast.success(`Bienvenido ${nombre} ${apelidos}!!`)
73
           token = token.replace("Bearer ", "")
73
           token = token.replace("Bearer ", "")
74
           let { exp } = jwt_decode(token);
74
           let { exp } = jwt_decode(token);

+ 20 - 21
src/Pages/Prueba.jsx

17
   let dispatch = useDispatch();
17
   let dispatch = useDispatch();
18
   let [data, setData] = useState({});
18
   let [data, setData] = useState({});
19
 
19
 
20
-  console.log('PROFILE: ', profile)
21
-
22
   useState(() => {
20
   useState(() => {
23
     let rest = new Service(`/prueba/findid/${id}`)
21
     let rest = new Service(`/prueba/findid/${id}`)
24
     rest.get(auth.token)
22
     rest.get(auth.token)
28
       .catch(_e => setData({}))
26
       .catch(_e => setData({}))
29
   }, [id])
27
   }, [id])
30
 
28
 
31
-  console.log('Prueba info: ', data)
29
+  let now = new Date().toISOString();
30
+  let assig_data = {
31
+    "id": -1,
32
+    "fechaasignacio": now,
33
+    "fechafinexamen": now,
34
+    "estado": "1",
35
+    "score": "0",
36
+    "mensaje": "0",
37
+    "mensaje2": "0",
38
+    "candidatoinpwd_id": profile.profile.idsuperpwd,
39
+    //candidatoinpwd -> idSuperContraseña -> viene al hacer login
40
+    "idcontrasenia": profile.role.pass, // ya no se va enviar
41
+    "nombre": "new " + now,
42
+    //cattest_id // catalogo de examenes -> viene del api del catalogo del admin
43
+    "cattest_id": data.id
44
+  }
32
 
45
 
33
   const CreateAssign = () => {
46
   const CreateAssign = () => {
34
 
47
 
35
-    let now = new Date().toISOString();
36
-    let body = {
37
-      "id": -1,
38
-      "fechaasignacio": now,
39
-      "fechafinexamen": now,
40
-      "estado": "1",
41
-      "score": "0",
42
-      "mensaje": "0",
43
-      "mensaje2": "0",
44
-      "candidatoinpwd_id": profile.profile.idsuperpwd,
45
-      //candidatoinpwd -> idSuperContraseña -> viene al hacer login
46
-      "idcontrasenia": profile.role.pass, // ya no se va enviar
47
-      "nombre": "assing CLEVAERR",
48
-      //cattest_id // catalogo de examenes -> viene del api del catalogo del admin
49
-      "cattest_id": data.id
50
-    }
51
 
48
 
52
     let rest = new Service("/prueba/asignacion");
49
     let rest = new Service("/prueba/asignacion");
53
-    rest.postQuery(body, auth.token)
50
+    rest.postQuery(assig_data, auth.token)
54
       .then(({ data: resp }) => {
51
       .then(({ data: resp }) => {
55
         let { id: assingid } = resp
52
         let { id: assingid } = resp
56
         toast.success("Asignación creada ", assingid)
53
         toast.success("Asignación creada ", assingid)
57
-        dispatch(setRole({ assingid }))
54
+        dispatch(setRole({ assingid, current_test_id: id }))
58
       })
55
       })
59
       .catch(() => {
56
       .catch(() => {
60
         toast.error("Error al crear la asignación")
57
         toast.error("Error al crear la asignación")
62
   }
59
   }
63
 
60
 
64
   if (profile.role.assingid) {
61
   if (profile.role.assingid) {
62
+    //TODO:
63
+    //case current test id to render specific examn template
65
     return <Cleaver />
64
     return <Cleaver />
66
   }
65
   }
67
 
66
 

+ 72 - 72
src/Pages/Pruebas/Cleaver.jsx

1
 import React from 'react'
1
 import React from 'react'
2
 import { Service } from '../../Utils/HTTP'
2
 import { Service } from '../../Utils/HTTP'
3
 import { Question } from '../../Components/Test/Cleaver/Question.jsx'
3
 import { Question } from '../../Components/Test/Cleaver/Question.jsx'
4
-import { Box,Button, LinearProgress, Backdrop, CircularProgress, } from '@mui/material'
4
+import { Box, Button, LinearProgress, Backdrop, CircularProgress, } from '@mui/material'
5
 import { useSelector } from 'react-redux';
5
 import { useSelector } from 'react-redux';
6
 import { useParams, useNavigate } from 'react-router-dom'
6
 import { useParams, useNavigate } from 'react-router-dom'
7
 import toast, { Toaster } from 'react-hot-toast';
7
 import toast, { Toaster } from 'react-hot-toast';
27
       main: '#fd4b4b',
27
       main: '#fd4b4b',
28
       darker: '#053e85',
28
       darker: '#053e85',
29
     },
29
     },
30
-    secondary : {
30
+    secondary: {
31
       main: '#2ec5d3',
31
       main: '#2ec5d3',
32
       darker: '#053e85',
32
       darker: '#053e85',
33
     },
33
     },
52
   const [progress, setProgress] = React.useState(0);
52
   const [progress, setProgress] = React.useState(0);
53
   const [open, setOpen] = React.useState(false);
53
   const [open, setOpen] = React.useState(false);
54
 
54
 
55
-  const BadQuestion = () => toast.error("Escoge una respuesta en cada columna") 
55
+  const BadQuestion = () => toast.error("Escoge una respuesta en cada columna")
56
   //toast("Escoge una respuesta en cada columna",{ icon : '⚠️' });
56
   //toast("Escoge una respuesta en cada columna",{ icon : '⚠️' });
57
   const CalculateProgress = () => {
57
   const CalculateProgress = () => {
58
     let total_preguntas = totalPreguntas.length + totalRespondidas.length
58
     let total_preguntas = totalPreguntas.length + totalRespondidas.length
59
-    let x = totalRespondidas.length *100 / (total_preguntas)
59
+    let x = totalRespondidas.length * 100 / (total_preguntas)
60
     setProgress(x.toFixed(2))
60
     setProgress(x.toFixed(2))
61
   }
61
   }
62
 
62
 
66
       .then(({ data }) => {
66
       .then(({ data }) => {
67
         console.log(data.questions)
67
         console.log(data.questions)
68
         setPreguntas(data.questions)
68
         setPreguntas(data.questions)
69
-        setRespondidas(data.questions.slice(0,1))
69
+        setRespondidas(data.questions.slice(0, 1))
70
         setCurrent(0)
70
         setCurrent(0)
71
       }).catch(console.log)
71
       }).catch(console.log)
72
-  }, [id,auth]);
72
+  }, [id, auth]);
73
 
73
 
74
   const saveRespones = () => {
74
   const saveRespones = () => {
75
 
75
 
76
     setOpen(true)
76
     setOpen(true)
77
 
77
 
78
     let { responses: userResp } = cleaver;
78
     let { responses: userResp } = cleaver;
79
-    let mapResponses = totalRespondidas.map( resp => {
80
-      let { respuestas : posibles, id } = resp;
81
-      console.log(resp.id,posibles)
82
-      let opciones_multiples = posibles.map( quiz => {
79
+    let mapResponses = totalRespondidas.map(resp => {
80
+      let { respuestas: posibles, id } = resp;
81
+      console.log(resp.id, posibles)
82
+      let opciones_multiples = posibles.map(quiz => {
83
         let body = {
83
         let body = {
84
           "respuestaid": resp.id,
84
           "respuestaid": resp.id,
85
-          "asignacionid":role.assingid,
86
-          "anotacion1": parseInt( userResp[id].A ) === parseInt(quiz.id) ? 1: 0, // + = A
87
-          "anotacion2":parseInt( userResp[id].B ) === parseInt(quiz.id) ? 1: 0,  // - = B
88
-          "anotacion3":0
85
+          "asignacionid": role.assingid,
86
+          "anotacion1": parseInt(userResp[id].A) === parseInt(quiz.id) ? 1 : 0, // + = A
87
+          "anotacion2": parseInt(userResp[id].B) === parseInt(quiz.id) ? 1 : 0,  // - = B
88
+          "anotacion3": 0
89
         }
89
         }
90
         return body;
90
         return body;
91
       })
91
       })
93
     })
93
     })
94
 
94
 
95
     let body = []
95
     let body = []
96
-    mapResponses.forEach( arr =>  arr.forEach(r => body.push(r)));
96
+    mapResponses.forEach(arr => arr.forEach(r => body.push(r)));
97
 
97
 
98
     let rest = new Service('/prueba/addrespuestas/opcionmultiple')
98
     let rest = new Service('/prueba/addrespuestas/opcionmultiple')
99
     rest.postQuery(body, auth.token)
99
     rest.postQuery(body, auth.token)
112
   }
112
   }
113
 
113
 
114
   const handleAddQuestion = () => {
114
   const handleAddQuestion = () => {
115
-    let currentAnswer  = totalRespondidas[totalRespondidas.length - 1];
115
+    let currentAnswer = totalRespondidas[totalRespondidas.length - 1];
116
     let current_resp = cleaver.responses[currentAnswer.id];
116
     let current_resp = cleaver.responses[currentAnswer.id];
117
 
117
 
118
-    if(!current_resp){
118
+    if (!current_resp) {
119
       return BadQuestion();
119
       return BadQuestion();
120
     }
120
     }
121
-    if(parseInt( current_resp.A ) ===0 || parseInt( current_resp.B ) === 0){
121
+    if (parseInt(current_resp.A) === 0 || parseInt(current_resp.B) === 0) {
122
       return BadQuestion();
122
       return BadQuestion();
123
     }
123
     }
124
-    const nextHiddenItem = totalPreguntas.filter(({id}) => id !== currentAnswer.id );
124
+    const nextHiddenItem = totalPreguntas.filter(({ id }) => id !== currentAnswer.id);
125
     if (nextHiddenItem) {
125
     if (nextHiddenItem) {
126
       setPreguntas(nextHiddenItem);
126
       setPreguntas(nextHiddenItem);
127
-      setCurrent(current+1);
127
+      setCurrent(current + 1);
128
       let temp = nextHiddenItem.shift()
128
       let temp = nextHiddenItem.shift()
129
-      setRespondidas([...totalRespondidas,temp]);
129
+      setRespondidas([...totalRespondidas, temp]);
130
     }
130
     }
131
     CalculateProgress()
131
     CalculateProgress()
132
   };
132
   };
133
 
133
 
134
   const handleRemoveQuestion = () => {
134
   const handleRemoveQuestion = () => {
135
     let ultimaRespondida = totalRespondidas[totalRespondidas.length - 1];
135
     let ultimaRespondida = totalRespondidas[totalRespondidas.length - 1];
136
-    setPreguntas([ultimaRespondida,...totalPreguntas]);
137
-    let current_without_last = totalRespondidas.filter(({id}) => id !== ultimaRespondida.id);
136
+    setPreguntas([ultimaRespondida, ...totalPreguntas]);
137
+    let current_without_last = totalRespondidas.filter(({ id }) => id !== ultimaRespondida.id);
138
     setRespondidas([...current_without_last]);
138
     setRespondidas([...current_without_last]);
139
-    setCurrent(current - 1 )
139
+    setCurrent(current - 1)
140
     CalculateProgress()
140
     CalculateProgress()
141
   }
141
   }
142
 
142
 
145
   return (
145
   return (
146
     <ThemeProvider theme={theme}>
146
     <ThemeProvider theme={theme}>
147
       <div className="content-section question">
147
       <div className="content-section question">
148
-        <div style={{marginTop : 35}}>
149
-          <LinearProgressWithLabel value={progress ? parseInt(progress) : 0 } />
148
+        <div style={{ marginTop: 35 }}>
149
+          <LinearProgressWithLabel value={progress ? parseInt(progress) : 0} />
150
         </div>
150
         </div>
151
         <Box className="question_body">
151
         <Box className="question_body">
152
-          {totalRespondidas.map((item,i) => (
153
-            <Question 
154
-              key={item.id} 
155
-              id={item.id} 
156
-              quiz={item} 
157
-              index={i} 
158
-              current={current} 
159
-              />)
152
+          {totalRespondidas.map((item, i) => (
153
+            <Question
154
+              key={item.id}
155
+              id={item.id}
156
+              quiz={item}
157
+              index={i}
158
+              current={current}
159
+            />)
160
           )}
160
           )}
161
         </Box>
161
         </Box>
162
 
162
 
163
         {
163
         {
164
-        totalPreguntas.length > 0 ?
165
-          (
166
-            <div className="question_btn">
167
-              <Button
168
-                className="nextquestion_btn"
169
-                sx={{ backgroundColor: 'var(--main)' }}
170
-                variant="contained"
171
-                disabled={totalRespondidas.length <= 1}
172
-                onClick={handleRemoveQuestion}
173
-              >
174
-                Anterior
175
-              </Button>
176
-              <Button
177
-                className="nextquestion_btn"
178
-                sx={{ backgroundColor: 'var(--main)' }}
179
-                variant="contained"
180
-                disabled={totalPreguntas.length <= 0}
181
-                onClick={handleAddQuestion}
182
-              >
183
-                Siguiente
184
-              </Button>
185
-            </div>
186
-          ) : (
187
-
188
-            <div className="question_btn">
189
-              <Button
190
-                className="nextquestion_btn"
191
-                sx={{ backgroundColor: 'var(--main)' }}
192
-                variant="contained"
193
-                onClick={saveRespones}
194
-              >
195
-                Guardar
196
-              </Button>
197
-            </div>
198
-          )
199
-
200
-      }
164
+          totalPreguntas.length > 0 ?
165
+            (
166
+              <div className="question_btn">
167
+                <Button
168
+                  className="nextquestion_btn"
169
+                  sx={{ backgroundColor: 'var(--main)' }}
170
+                  variant="contained"
171
+                  disabled={totalRespondidas.length <= 1}
172
+                  onClick={handleRemoveQuestion}
173
+                >
174
+                  Anterior
175
+                </Button>
176
+                <Button
177
+                  className="nextquestion_btn"
178
+                  sx={{ backgroundColor: 'var(--main)' }}
179
+                  variant="contained"
180
+                  disabled={totalPreguntas.length <= 0}
181
+                  onClick={handleAddQuestion}
182
+                >
183
+                  Siguiente
184
+                </Button>
185
+              </div>
186
+            ) : (
187
+
188
+              <div className="question_btn">
189
+                <Button
190
+                  className="nextquestion_btn"
191
+                  sx={{ backgroundColor: 'var(--main)' }}
192
+                  variant="contained"
193
+                  onClick={saveRespones}
194
+                >
195
+                  Guardar
196
+                </Button>
197
+              </div>
198
+            )
199
+
200
+        }
201
         <Toaster position="bottom-right" />
201
         <Toaster position="bottom-right" />
202
         <Backdrop
202
         <Backdrop
203
           sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
203
           sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
204
           open={open}
204
           open={open}
205
-          // onClick={()}
205
+        // onClick={()}
206
         >
206
         >
207
           <CircularProgress color="inherit" />
207
           <CircularProgress color="inherit" />
208
         </Backdrop>
208
         </Backdrop>

+ 3 - 2
src/Slices/userSlice.js

11
     },
11
     },
12
     setRole : (state, action ) => {
12
     setRole : (state, action ) => {
13
       state.role = Object.assign({}, state.role, action.payload);
13
       state.role = Object.assign({}, state.role, action.payload);
14
-    }
14
+    },
15
+    getTestID : (state) => state.role.current_test_id
15
   }
16
   }
16
 })
17
 })
17
 
18
 
18
-export const { setProfile, setRole } = userSlice.actions;
19
+export const { setProfile, setRole, getTestID } = userSlice.actions;
19
 export default userSlice.reducer;
20
 export default userSlice.reducer;

+ 1 - 2
src/Utils/MenuItems.js

6
     AssignmentTurnedIn
6
     AssignmentTurnedIn
7
 } from '@mui/icons-material'
7
 } from '@mui/icons-material'
8
 
8
 
9
-
10
 export const UserItems = [
9
 export const UserItems = [
11
     {
10
     {
12
         icon : <Home/>,
11
         icon : <Home/>,
20
     },
19
     },
21
     {
20
     {
22
         icon : <Star/>,
21
         icon : <Star/>,
23
-        route : 'prueba/:id',
22
+        route : 'prueba/:id' ,
24
         title : 'Test Actual'
23
         title : 'Test Actual'
25
     },
24
     },
26
 ]
25
 ]