浏览代码

list asignacines in home

amenpunk 2 年之前
父节点
当前提交
d702cc457c
共有 6 个文件被更改,包括 218 次插入137 次删除
  1. 5 0
      src/App.css
  2. 72 32
      src/Components/Home/Candidato.jsx
  3. 110 100
      src/Components/Home/Candidatos.js
  4. 26 2
      src/Pages/Home.jsx
  5. 1 0
      src/Pages/Login.jsx
  6. 4 3
      src/Pages/Puestos.jsx

+ 5 - 0
src/App.css

@@ -385,3 +385,8 @@
385 385
   justify-content: center;
386 386
   align-items: center;
387 387
 }
388
+
389
+table, th, td {
390
+  border: 1px solid black;
391
+  border-collapse: collapse;
392
+}

+ 72 - 32
src/Components/Home/Candidato.jsx

@@ -1,41 +1,81 @@
1
+import '../../App.css'
1 2
 import { Skeleton, Box } from '@mui/material';
2 3
 import React from 'react'
3 4
 const big_as = 70
4 5
 
5
-export function Candidato (props) {
6
-    let { password,puesto,DPI, aplicacion,pendientes } = props.user
7
-
8
-    return(
9
-        <div className="data_candidato">
10
-            <div className="row">
11
-                <div className="col20">
12
-                    <p>{ password }</p>
13
-                </div>
14
-                <div className="col20">
15
-                    <p>{ puesto }</p>
16
-                </div>
17
-                <div className="col20">
18
-                    <p>{ DPI }</p>
19
-                </div>
20
-                <div className="col20">
21
-                    <p>{ aplicacion }</p>
22
-                </div>
23
-                <div className="col20">
24
-                    <p>{ pendientes }</p>
25
-                </div>
26
-            </div>
6
+function Asignaciones(props) {
7
+  let { asign } = props;
8
+  let { cattest } = asign;
9
+  // console.log(cattest)
10
+  return (
11
+    <tr>
12
+      <td className="tg-0lax">{cattest.decription}</td>
13
+    </tr>
14
+  )
15
+}
16
+
17
+function TableUser(props) {
18
+  let { user } = props;
19
+  let { asignaciones, candi } = user
20
+  console.log(asignaciones)
21
+  return (
22
+    <tr>
23
+      <td className="tg-0lax">{candi.nombre + " " + candi.apellidos}</td>
24
+      <td className="tg-0lax">
25
+        <table className="tg">
26
+          <tbody>
27
+            {
28
+              asignaciones.map(a => <Asignaciones key={a.id} asign={a} />)
29
+            }
30
+          </tbody>
31
+        </table>
32
+
33
+      </td>
34
+    </tr>
35
+  )
36
+}
37
+
38
+export function Candidato(props) {
39
+  // console.log("USER: ", props.user)
40
+  let { password, candidatos } = props.user
41
+
42
+  return (
43
+    <div className="data_candidato">
44
+      <div className="row">
45
+        <div className="col20">
46
+          <p>{password}</p>
47
+        </div>
48
+        <div className="col20">
49
+
50
+          <table className="tg">
51
+            <thead>
52
+              <tr>
53
+                <th className="tg-0lax">Nombre</th>
54
+                <th className="tg-0lax">Asignaciones</th>
55
+              </tr>
56
+            </thead>
57
+            <tbody>
58
+              {
59
+                candidatos.map(u => <TableUser key={u.candi.id} user={u} />)
60
+              }
61
+            </tbody>
62
+          </table>
63
+
64
+
27 65
         </div>
28
-    )
66
+      </div>
67
+    </div>
68
+  )
29 69
 }
30 70
 
31 71
 export function Preview() {
32
-    return(
33
-        <Box sx={{ width: '100%' }}>
34
-            <Skeleton height={big_as} animation="wave" />
35
-            <Skeleton height={big_as} animation="wave" />
36
-            <Skeleton height={big_as} animation="wave" />
37
-            <Skeleton height={big_as} animation="wave" />
38
-            <Skeleton height={big_as} animation="wave" />
39
-        </Box>
40
-    )
72
+  return (
73
+    <Box sx={{ width: '100%' }}>
74
+      <Skeleton height={big_as} animation="wave" />
75
+      <Skeleton height={big_as} animation="wave" />
76
+      <Skeleton height={big_as} animation="wave" />
77
+      <Skeleton height={big_as} animation="wave" />
78
+      <Skeleton height={big_as} animation="wave" />
79
+    </Box>
80
+  )
41 81
 }

+ 110 - 100
src/Components/Home/Candidatos.js

@@ -1,112 +1,122 @@
1 1
 import React, { useState, useEffect } from 'react';
2 2
 import UpdateIcon from '@mui/icons-material/Update';
3
-
4 3
 import { Typography, Pagination, Stack, } from '@mui/material'
5
-
6 4
 import { Row, Col } from 'react-bootstrap';
7
-
8 5
 import { Candidato, Preview } from './Candidato'
9
-// const USER_LENGTH = 14
10
-const USER_LENGTH = 120
11 6
 
7
+function Divide(arregloOriginal) {
12 8
 
13
-function Divide(arregloOriginal){
9
+  const LONGITUD_PEDAZOS = 8;
10
+  let arregloDeArreglos = [];
11
+  for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
12
+    let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);
13
+    arregloDeArreglos.push(pedazo);
14
+  }
15
+  return arregloDeArreglos
16
+}
14 17
 
15
-    const LONGITUD_PEDAZOS = 8;
16
-    let arregloDeArreglos = [];
17
-    for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
18
-        let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);
19
-        arregloDeArreglos.push(pedazo);
20
-    }
21
-    return arregloDeArreglos
18
+function fromBase64(text) {
19
+  try {
20
+    return atob(text)
21
+  } catch (_e) {
22
+    return text
23
+  }
22 24
 }
23 25
 
24
-export default function Candidatos () {
25
-
26
-    const [page, setPage] = useState(1);
27
-    const [users, setUser] = useState([]);
28
-
29
-    const changePage = ( _ , value) => {
30
-        let page_numer = value;
31
-        Divide(users)
32
-        setPage(page_numer);
33
-    };
34
-
35
-    useEffect(() => {
36
-
37
-        setTimeout(() => {
38
-            let list =  [{
39
-                password : 'tester',
40
-                puesto : "Piloto Repartidor",
41
-                DPI : 0,
42
-                // aplicacion : "27/12/2018 12:02 PM",
43
-                aplicacion : new Date().toUTCString(),
44
-                pendientes : "No"
45
-            }]
46
-
47
-            let a = 1;
48
-            for( let _ of new Array(USER_LENGTH)  ){
49
-                if(_) break
50
-
51
-                let temp = {
52
-                    ...list[0],
53
-                    DPI : a * 1000,
54
-                    password : Math.random().toString(36).slice(5), 
55
-                    aplicacion : new Date(10,12,a).toUTCString(),
56
-                }
57
-
58
-                a=a+1;
59
-                list.push(temp)
60
-            }
61
-
62
-            let divided = Divide(list);
63
-
64
-            setUser(divided)
65
-
66
-        },3000)
67
-
68
-    }, [])
69
-
70
-
71
-
72
-    return (
73
-        <div className="body_historial">
74
-            <div className="header_historial">
75
-                <UpdateIcon style={{  color : "white", fontSize : 25, margin : 0, marginRight: 15, marginLeft :15 }}/>
76
-                <p className="titlie_main">HISTORIAL DE ACCESO DE CANDIDATOS</p>
77
-            </div>
78
-            <div className="content_historial">
79
-                <p>Últimos candidatos que han ingresado al sistema:</p>
80
-                <div className="cabeceras">
81
-                    <Row>
82
-                        <div className="col20"><p>Contraseña</p></div>
83
-                        <div className="col20"><p>Puesto</p> </div>
84
-                        <div className="col20"><p>No. Identificación</p></div>
85
-                        <div className="col20"><p>Fecha de aplicación</p></div>
86
-                        <div className="col20"><p>Pruebas Pendientes</p></div>
87
-                    </Row>
88
-                </div>
89
-                {
90
-                    users.length 
91
-                    ? users[page - 1].map( user => (<Candidato key={user.DPI} user={user}/>)) 
92
-                    : <Preview style={{ paddingTop:10}} lenght={10}/>
93
-                }
94
-                <Row style={{ padding : 5 }}>
95
-                    <Col>
96
-                        <Stack style={{ display : 'flex', flexDirection : 'row', alignItems: 'baseline'  }} spacing={2}>
97
-                            <Typography style={{ paddingTop : 15, paddingRight : 10 }}>Página: {page}</Typography>
98
-                            <Pagination 
99
-                                siblingCount={1} 
100
-                                boundaryCount={1}
101
-                                shape='rounded' 
102
-                                count={users.length} 
103
-                                page={page} 
104
-                                onChange={changePage} 
105
-                            />
106
-                        </Stack>
107
-                    </Col>
108
-                </Row>
109
-            </div>
26
+export default function Candidatos(props) {
27
+
28
+  let { passwords } = props;
29
+  const [page, setPage] = useState(1);
30
+  const [users, setUser] = useState([]);
31
+
32
+
33
+  const changePage = (_, value) => {
34
+    let page_numer = value;
35
+    Divide(users)
36
+    setPage(page_numer);
37
+  };
38
+
39
+  useEffect(() => {
40
+
41
+    let list = passwords.map(pwd => {
42
+      let { candidatospwds } = pwd
43
+      console.log(candidatospwds)
44
+      // let candi_info = candidatospwds.map( ({candi}) => candi?.nombre +" "+ candi?.apellidos   )
45
+      return {
46
+        password: fromBase64(pwd.pwd),
47
+        candidatos: candidatospwds
48
+      }
49
+    })
50
+
51
+    /*
52
+    let list = [{
53
+      password: 'tester',
54
+      puesto: "Piloto Repartidor",
55
+      DPI: 0,
56
+      // aplicacion : "27/12/2018 12:02 PM",
57
+      aplicacion: new Date().toUTCString(),
58
+      pendientes: "No"
59
+    }]
60
+
61
+    let a = 1;
62
+    for (let _ of new Array(USER_LENGTH)) {
63
+      if (_) break
64
+
65
+      let temp = {
66
+        ...list[0],
67
+        DPI: a * 1000,
68
+        password: Math.random().toString(36).slice(5),
69
+        aplicacion: new Date(10, 12, a).toUTCString(),
70
+      }
71
+
72
+      a = a + 1;
73
+      list.push(temp)
74
+    }
75
+
76
+*/
77
+
78
+    let divided = Divide(list);
79
+
80
+    setUser(divided)
81
+
82
+
83
+  }, [passwords])
84
+
85
+  return (
86
+    <div className="body_historial">
87
+      <div className="header_historial">
88
+        <UpdateIcon style={{ color: "white", fontSize: 25, margin: 0, marginRight: 15, marginLeft: 15 }} />
89
+        <p className="titlie_main">HISTORIAL DE ACCESO DE CANDIDATOS</p>
90
+      </div>
91
+      <div className="content_historial">
92
+        <p>Últimos candidatos que han ingresado al sistema:</p>
93
+        <div className="cabeceras">
94
+          <Row>
95
+            <div className="col20"><p>Contraseña</p></div>
96
+            <div className="col20"><p>Detalle</p> </div>
97
+          </Row>
110 98
         </div>
111
-    )
99
+        {
100
+          users.length
101
+            ? users[page - 1].map((user,i) => (<Candidato key={i} user={user} />))
102
+            : <Preview style={{ paddingTop: 10 }} lenght={10} />
103
+        }
104
+        <Row style={{ padding: 5 }}>
105
+          <Col>
106
+            <Stack style={{ display: 'flex', flexDirection: 'row', alignItems: 'baseline' }} spacing={2}>
107
+              <Typography style={{ paddingTop: 15, paddingRight: 10 }}>Página: {page}</Typography>
108
+              <Pagination
109
+                siblingCount={1}
110
+                boundaryCount={1}
111
+                shape='rounded'
112
+                count={users.length}
113
+                page={page}
114
+                onChange={changePage}
115
+              />
116
+            </Stack>
117
+          </Col>
118
+        </Row>
119
+      </div>
120
+    </div>
121
+  )
112 122
 }

+ 26 - 2
src/Pages/Home.jsx

@@ -6,11 +6,29 @@ import Actividades from '../Components/Home/Actividades'
6 6
 import Candidatos from '../Components/Home/Candidatos'
7 7
 import { Card } from '../Components/Card';
8 8
 import { useSelector } from 'react-redux';
9
+import { Service } from '../Utils/HTTP.js'
10
+import { useQuery } from 'react-query';
9 11
 
10 12
 export function Home() {
11 13
 
14
+  const auth = useSelector((state) => state.token)
12 15
   const profile = useSelector((state) => state.user.profile)
13 16
 
17
+  const getAllPwd = async () => {
18
+    let rest = new Service('/contrasenia/getallbyidUsr');
19
+    return await rest.getQuery(auth.token)
20
+  }
21
+
22
+  const { data, status } = useQuery('homepwd', getAllPwd);
23
+
24
+  let is_loading = status === "loading";
25
+  console.log({ is_loading })
26
+
27
+  //TODO:
28
+  //utilizar el servicio 
29
+  //http://psicoadmin.ditca.org:8081/plaza/getthis/212
30
+  //para renderizar informacion de cada pwd en la home
31
+
14 32
   return (
15 33
     <section >
16 34
       <div className="content-section">
@@ -24,7 +42,11 @@ export function Home() {
24 42
             <Row>
25 43
               <Col md="4">
26 44
                 <Card
27
-                  quantity={120} to='/dashboard/contrasenas' title='CONTRASEÑAS' icon={VerifiedUser} />
45
+                  quantity={data?.data?.length || 0} 
46
+                  to='/dashboard/contrasenas' 
47
+                  title='CONTRASEÑAS' 
48
+                  icon={VerifiedUser} 
49
+                />
28 50
               </Col>
29 51
               <Col md="4">
30 52
                 <Card
@@ -39,7 +61,9 @@ export function Home() {
39 61
           <div className="historial_candidatos">
40 62
             <Row>
41 63
               <Col md="8">
42
-                <Candidatos />
64
+                <Candidatos 
65
+                  passwords={data?.data || []}
66
+                />
43 67
               </Col>
44 68
               <Col md="4">
45 69
                 <Actividades />

+ 1 - 0
src/Pages/Login.jsx

@@ -64,6 +64,7 @@ export function Login() {
64 64
           let { token, nombre, apelidos, empresa } = response;
65 65
           toast.success(`Bienvenido ${nombre} ${apelidos} !!`)
66 66
           token = token.replace("Bearer ", "")
67
+          console.log("TOKEN: ", token)
67 68
           let body_token = jwt_decode(token);
68 69
           let timestamp = body_token.exp * 1000;
69 70
           let restante = timestamp - Date.now();

+ 4 - 3
src/Pages/Puestos.jsx

@@ -36,7 +36,6 @@ export function Puestos() {
36 36
 
37 37
   const auth = useSelector((state) => state.token)
38 38
   const [page, setPage] = useState(1);
39
-  const [temp, setTemp] = useState(null);
40 39
 
41 40
   const getAll = async () => {
42 41
     let rest = new Service("/plaza/getall")
@@ -131,7 +130,9 @@ export function Puestos() {
131 130
                             let isset = plaza.nombrepuesto.toUpperCase().includes(nombre.toUpperCase())
132 131
                             return isset
133 132
                           })
134
-                          console.log(temp)
133
+                          if(temp.lenght <= 0){
134
+                            setFilter(null)
135
+                          }
135 136
                           setFilter(temp)
136 137
                         } else {
137 138
                           setFilter(null)
@@ -234,7 +235,7 @@ export function Puestos() {
234 235
                       variant="standard"
235 236
                     />
236 237
 
237
-                    <Chip style={{ marginLeft: 10, margin: 5 }} label={"Total: " + (result ? result.data.length : 0)} />
238
+                    <Chip style={{ marginLeft: 10, margin: 5 }} label={"Total: " + ( filter?  filter.length :  ( result ? result.data.length : 0 ))} />
238 239
                   </div>
239 240
                 </Col>
240 241
               </Row>