Browse Source

change op edit method alternative

amenpunk 2 years ago
parent
commit
4642323bbe

+ 0 - 1
src/App.css

373
 }
373
 }
374
 
374
 
375
 #search_plaza_input{
375
 #search_plaza_input{
376
-  width:200px;
377
   padding-left:20px !important;
376
   padding-left:20px !important;
378
   margin-left:20px !important;
377
   margin-left:20px !important;
379
 }
378
 }

+ 2 - 89
src/Components/Password/Operation.jsx

1
 import * as React from 'react';
1
 import * as React from 'react';
2
-
3
-import { Edit as EditIcon, Send as SendIcon } from '@mui/icons-material'
4
 import {
2
 import {
5
   Button, Dialog, DialogActions, DialogContent, //DialogTitle,
3
   Button, Dialog, DialogActions, DialogContent, //DialogTitle,
6
   FormControlLabel, Checkbox,
4
   FormControlLabel, Checkbox,
20
 import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
18
 import { DesktopDatePicker } from '@mui/x-date-pickers/DesktopDatePicker';
21
 import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
19
 import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
22
 
20
 
23
-
21
+export function ModalEdit(props) {
24
-export function Operation(props) {
25
-
26
-  let [open, setOpen] = React.useState(false);
27
-  const handleOpen = (status) => setOpen(status);
28
-
29
-  return (
30
-    <div>
31
-      <div className="operation_buttons">
32
-        <EditIcon onClick={() => setOpen(true)} className="icon_op" />
33
-        <SendIcon className="icon_op" />
34
-      </div>
35
-      {
36
-        open ?
37
-          <ModalEdit
38
-            password={props}
39
-            open={open}
40
-            handleOpen={handleOpen}
41
-          />
42
-          : null
43
-      }
44
-    </div>
45
-  )
46
-}
47
-
48
-function ModalEdit(props) {
49
-
50
   let { password, open, handleOpen } = props
22
   let { password, open, handleOpen } = props
51
-  const now = React.useRef(new Date());
52
   let { pwd, plz } = password
23
   let { pwd, plz } = password
53
   const auth = useSelector((state) => state.token)
24
   const auth = useSelector((state) => state.token)
54
   const getPassword = async () => {
25
   const getPassword = async () => {
55
-    let rest = new Service(`/contrasenia/${pwd}/${plz}`)
26
+    let rest = new Service(`/contrasenia/${btoa(pwd)}/${plz}`)
56
     return await rest.getQuery(auth.token)
27
     return await rest.getQuery(auth.token)
57
   }
28
   }
58
 
29
 
59
   let { data: result } = useQuery('contra', getPassword);
30
   let { data: result } = useQuery('contra', getPassword);
60
   console.log('PWD INFO ', result)
31
   console.log('PWD INFO ', result)
61
 
32
 
62
-  let initialValues = {
63
-    id: result?.data?.id,
64
-    pwd: result?.data?.pwd,
65
-    deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
66
-    state: result?.data?.state,
67
-    dateToActived: result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
68
-    plaza_id: result?.data?.plaza_id,
69
-    candidato_id: result?.data?.candidato_id
70
-  }
71
-
72
   return (
33
   return (
73
     <Dialog
34
     <Dialog
74
       open={open}
35
       open={open}
78
     >
39
     >
79
       <DialogContent>
40
       <DialogContent>
80
         <ModalForm
41
         <ModalForm
81
-          //puestos={puestos}
82
-          initialValues={initialValues}
83
           handleOpen={handleOpen}
42
           handleOpen={handleOpen}
84
           token={auth.token}
43
           token={auth.token}
85
         />
44
         />
140
 
99
 
141
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
100
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
142
 
101
 
143
-  function fromBase64(text){
144
-    try{
145
-      return atob(text)
146
-    }catch(_e){
147
-      return text
148
-    }
149
-  }
150
-
151
-  React.useEffect(() => {
152
-    setValues({
153
-      ...props.initialValues,
154
-      pwd: props.initialValues.pwd ? fromBase64(props.initialValues.pwd) : 'loading'
155
-    })
156
-  }, [props, setValues])
157
-
158
   return (
102
   return (
159
     <FormikProvider value={formik}>
103
     <FormikProvider value={formik}>
160
       <Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
104
       <Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
193
               }
137
               }
194
               label="Activa"
138
               label="Activa"
195
             />
139
             />
196
-
197
           </Stack>
140
           </Stack>
198
 
141
 
199
 
142
 
239
                 />}
182
                 />}
240
             />
183
             />
241
           </LocalizationProvider>
184
           </LocalizationProvider>
242
-
243
-
244
-          {/*
245
-                    <Autocomplete
246
-                        {...getFieldProps('plaza_id')}
247
-                        onChange={(_a,current_list,_c,_individual,_f) => {
248
-                            console.log("CURRENT LIST : ",current_list)
249
-                            setValues({
250
-                                ...values,
251
-                                plaza_id:current_list
252
-                            })
253
-                        }}
254
-                        value={props.puestos.filter(p=> p.id=== values.plaza_id ).shift()}
255
-                        id="combo-box-demo"
256
-                        options={props.puestos}
257
-                        isOptionEqualToValue={
258
-                            (option, value) => option.nombrepuesto === value.nombrepuesto
259
-                        }
260
-                        getOptionLabel={(option) => {
261
-                            return option.nombrepuesto
262
-                        }}
263
-                        renderInput={(params) =>
264
-                            <TextField
265
-                                {...params}
266
-                                label="Puesto"
267
-                            />
268
-                        }
269
-                    />
270
-*/}
271
-
272
           <DialogActions>
185
           <DialogActions>
273
             <Button onClick={() => props.handleOpen(false)}>
186
             <Button onClick={() => props.handleOpen(false)}>
274
               Cerrar
187
               Cerrar

+ 21 - 13
src/Components/Password/Rows.js

1
-import { Operation } from './Operation'
2
-
3
 function fromBase64(text){
1
 function fromBase64(text){
4
   try{
2
   try{
5
     return atob(text)
3
     return atob(text)
11
 
9
 
12
 export const Encabezados = [
10
 export const Encabezados = [
13
   {
11
   {
12
+    name: 'id',
13
+    numeric: true,
14
+    label: 'ID',
15
+    options:{
16
+      display:false
17
+    }
18
+  },
19
+  {
14
     name: 'name',
20
     name: 'name',
15
     numeric: false,
21
     numeric: false,
16
     disablePadding: true,
22
     disablePadding: true,
28
     disablePadding: true,
34
     disablePadding: true,
29
     label: 'Fecha vencimiento',
35
     label: 'Fecha vencimiento',
30
   },
36
   },
31
-  {
37
+  // {
32
-    name: 'op',
38
+  //   name: 'op',
33
-    numeric: false,
39
+  //   numeric: false,
34
-    disablePadding: true,
40
+  //   disablePadding: true,
35
-    label: 'Operación',
41
+  //   label: 'Operación',
36
-    options: {
42
+  //   options: {
37
-      filter: false,
43
+  //     filter: false,
38
-      sort: false,
44
+  //     sort: false,
39
-    }
45
+  //   }
40
-  },
46
+  // },
41
 ]
47
 ]
42
 
48
 
43
 export const niveles_educativos = [
49
 export const niveles_educativos = [
54
 ]
60
 ]
55
 
61
 
56
 export function Build(pwds) {
62
 export function Build(pwds) {
63
+
57
   return pwds.map(password => {
64
   return pwds.map(password => {
65
+    console.log(password)
58
     let { pwd, plaza_id } = password
66
     let { pwd, plaza_id } = password
59
     return {
67
     return {
68
+      id: plaza_id,
60
       name: fromBase64( pwd ),//atob( pwd ),
69
       name: fromBase64( pwd ),//atob( pwd ),
61
       activacion: new Date().toUTCString(),//dateToActived, 
70
       activacion: new Date().toUTCString(),//dateToActived, 
62
       dead: new Date().toUTCString(), //deadpwd,
71
       dead: new Date().toUTCString(), //deadpwd,
63
-      op: <Operation plz={plaza_id} pwd={pwd} />
64
     }
72
     }
65
   })
73
   })
66
 }
74
 }

+ 27 - 26
src/Components/Password/Steps/password.jsx

52
     <FormikProvider style={{ padding: 25, paddingTop: 5 }} value={formik}>
52
     <FormikProvider style={{ padding: 25, paddingTop: 5 }} value={formik}>
53
       <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
53
       <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
54
         <Stack spacing={3}>
54
         <Stack spacing={3}>
55
-
55
+          <Stack spacing={2}>
56
-          <TextField
56
+            <TextField
57
-            value={uid ? uid : btoa(values.pwd)}
57
+              fullWidth
58
-            disabled
58
+              type="text"
59
-            fullWidth
59
+              label="Nombre o identificador"
60
-            type="text"
60
+              {...getFieldProps('pwd')}
61
-            label="Identificador Codificado"
61
+              onChange={(event) => {
62
-            variant="standard"
62
+                let value = event.target.value
63
-          />
63
+                setUID(btoa(value));
64
-
64
+                setValues({
65
-          <TextField
65
+                  ...values,
66
-            fullWidth
66
+                  pwd: value
67
-            type="text"
67
+                })
68
-            label="Nombre o identificador"
68
+              }}
69
-            {...getFieldProps('pwd')}
69
+              error={Boolean(touched.pwd && errors.pwd)}
70
-            onChange={(event) => {
70
+              helperText={touched.pwd && errors.pwd}
71
-              let value = event.target.value
71
+            />
72
-              setUID(btoa(value));
72
+
73
-              setValues({
73
+            <TextField
74
-                ...values,
74
+              value={uid ? uid : btoa(values.pwd)}
75
-                pwd: value
75
+              disabled
76
-              })
76
+              fullWidth
77
-            }}
77
+              type="text"
78
-            error={Boolean(touched.pwd && errors.pwd)}
78
+              label="Identificador Codificado"
79
-            helperText={touched.pwd && errors.pwd}
79
+              variant="standard"
80
-          />
80
+            />
81
+          </Stack>
81
 
82
 
82
 
83
 
83
           <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
84
           <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>

+ 119 - 58
src/Components/Password/TableStyle.js

1
 import { createTheme } from '@mui/material';
1
 import { createTheme } from '@mui/material';
2
 
2
 
3
+
4
+// MuiTableCell-root MuiTableCell-body MuiTableCell-paddingCheckbox MuiTableCell-sizeMedium tss-12o2szd-MUIDataTableSelectCell-root tss-1fz4yw6-MUIDataTableSelectCell-fixedLeft css-1nf681w-MuiTableCell-root
5
+
3
 export const TableStyle = () => createTheme({
6
 export const TableStyle = () => createTheme({
4
-    components: {
7
+  components: {
5
-        MUIDataTableToolbar: {
6
-            styleOverrides: {
7
-                root: {
8
-                    paddingLeft: 15
9
-                }
10
-            }
11
-        },
12
-        MuiPaper: {
13
-            styleOverrides: {
14
-                root: {
15
-                    boxShadow: 'none'
16
-                }
17
-            }
18
 
8
 
19
-        },
9
+    MuiSvgIcon: {
20
-        MUIDataTableBodyCell: {
10
+      styleOverrides: {
21
-            styleOverrides: {
11
+        root: {
22
-                root: {
12
+          color: 'var(--main)'
23
-                    backgroundColor: "#FFF"
24
-                }
25
-            }
26
-        },
27
-        MuiTablePagination: {
28
-            styleOverrides: {
29
-                toolbar: {
30
-                    paddingTop: 7,
31
-                    alignItems: 'baseline'
32
-                }
33
-            }
34
         }
13
         }
35
-    }
14
+      }
36
-})
15
+    },
37
 
16
 
38
-export const TextLabels = {
17
+    MUIDataTableSelectCell: {
39
-    body: {
18
+      styleOverrides: {
40
-        noMatch: "No se encontró ningún elemento",
19
+        root: {
41
-        toolTip: "Ordenar",
20
+          backgroundColor: '#FFF'
42
-        columnHeaderTooltip: column => `Ordenar por ${column.label}`
21
+        }
22
+      }
23
+    },
24
+    MuiCheckbox: {
25
+      styleOverrides: {
26
+        root: {
27
+          color: 'var(--main)'
28
+        }
29
+      }
30
+    },
31
+    MuiChecked: {
32
+      styleOverrides: {
33
+        root: {
34
+          color: 'red'
35
+        }
36
+      }
37
+    },
38
+    MUIDataTableToolbar: {
39
+      styleOverrides: {
40
+        root: {
41
+          paddingLeft: 15
42
+        }
43
+      }
43
     },
44
     },
44
-    pagination: {
45
+    MuiRowSelected: {
45
-        next: "Siguiente Pagina",
46
+      styleOverrides: {
46
-        previous: "Pagina Anterior",
47
+        root: {
47
-        rowsPerPage: "Elementos por Página",
48
+          backgroundColor: "#FFF"
48
-        displayRows: "de",
49
+        }
50
+      }
49
     },
51
     },
50
-    toolbar: {
52
+    MuiPaper: {
51
-        search: "Buscar",
53
+      styleOverrides: {
52
-        downloadCsv: "Descargar CSV",
54
+        root: {
53
-        print: "Imprimir",
55
+          boxShadow: 'none'
54
-        viewColumns: "Seleccionar Columnas",
56
+        }
55
-        filterTable: "Filtrar Tabla",
57
+      }
58
+
56
     },
59
     },
57
-    filter: {
60
+    MUIDataTableSelectedCell: {
58
-        all: "Todos",
61
+      styleOverrides: {
59
-        title: "FILTROS",
62
+        root: {
60
-        reset: "Limpiar",
63
+          backgroundColor: "#FFF"
64
+        }
65
+      }
61
     },
66
     },
62
-    viewColumns: {
67
+    MUITableCell: {
63
-        title: "Mostrar Columnas",
68
+      styleOverrides: {
64
-        titleAria: "Mostrar/Ocultar Columnas",
69
+        root: {
70
+          backgroundColor: "#FFF"
71
+        }
72
+      }
65
     },
73
     },
66
-    selectedRows: {
74
+    MUIDataTableBodyRow: {
67
-        text: "Elemento(s) selecionado",
75
+      styleOverrides: {
68
-        delete: "Eliminar",
76
+        root: {
69
-        deleteAria: "Eliminar Columnas Seleccionadas",
77
+          backgroundColor: "#FFF"
78
+        }
79
+      }
70
     },
80
     },
81
+    MUIDataTableBodyCell: {
82
+      styleOverrides: {
83
+        root: {
84
+          backgroundColor: "#FFF"
85
+        }
86
+      }
87
+    },
88
+    MuiTablePagination: {
89
+      styleOverrides: {
90
+        toolbar: {
91
+          paddingTop: 7,
92
+          alignItems: 'baseline'
93
+        }
94
+      }
95
+    }
96
+  }
97
+})
98
+
99
+export const TextLabels = {
100
+  body: {
101
+    noMatch: "No se encontró ningún elemento",
102
+    toolTip: "Ordenar",
103
+    columnHeaderTooltip: column => `Ordenar por ${column.label}`
104
+  },
105
+  pagination: {
106
+    next: "Siguiente Pagina",
107
+    previous: "Pagina Anterior",
108
+    rowsPerPage: "Elementos por Página",
109
+    displayRows: "de",
110
+  },
111
+  toolbar: {
112
+    search: "Buscar",
113
+    downloadCsv: "Descargar CSV",
114
+    print: "Imprimir",
115
+    viewColumns: "Seleccionar Columnas",
116
+    filterTable: "Filtrar Tabla",
117
+  },
118
+  filter: {
119
+    all: "Todos",
120
+    title: "FILTROS",
121
+    reset: "Limpiar",
122
+  },
123
+  viewColumns: {
124
+    title: "Mostrar Columnas",
125
+    titleAria: "Mostrar/Ocultar Columnas",
126
+  },
127
+  selectedRows: {
128
+    text: "Elemento(s) selecionado",
129
+    delete: "Eliminar",
130
+    deleteAria: "Eliminar Columnas Seleccionadas",
131
+  },
71
 }
132
 }

+ 26 - 5
src/Pages/ContrasV2.jsx

9
 import { useQuery } from 'react-query';
9
 import { useQuery } from 'react-query';
10
 import { Service } from '../Utils/HTTP.js'
10
 import { Service } from '../Utils/HTTP.js'
11
 import { useSelector } from 'react-redux';
11
 import { useSelector } from 'react-redux';
12
+import {  ModalEdit } from '../Components/Password/Operation'
12
 
13
 
13
 export function Contrasv2() {
14
 export function Contrasv2() {
14
 
15
 
15
   const auth = useSelector((state) => state.token)
16
   const auth = useSelector((state) => state.token)
17
+  const [visible,setVisible] = React.useState(false)
18
+  const [password,setPassword] = React.useState(null)
16
 
19
 
17
   const getAllPwd = async () => {
20
   const getAllPwd = async () => {
18
     let rest = new Service('/contrasenia/getallbyidUsr');
21
     let rest = new Service('/contrasenia/getallbyidUsr');
19
     return await rest.getQuery(auth.token)
22
     return await rest.getQuery(auth.token)
20
   }
23
   }
21
-  
24
+
22
-  const { data, status  } = useQuery('passwords', getAllPwd );
25
+  const { data, status } = useQuery('passwords', getAllPwd);
26
+
23
   const options = {
27
   const options = {
24
     filterType: 'checkbox',
28
     filterType: 'checkbox',
25
     customToolbar: () => {
29
     customToolbar: () => {
27
         <CustomToolbar />
31
         <CustomToolbar />
28
       );
32
       );
29
     },
33
     },
30
-    textLabels: TextLabels
34
+    textLabels: TextLabels,
35
+    onRowClick: (password) => {
36
+      let [plaza, pwd] = password;
37
+      setPassword({pwd,plz:plaza});
38
+      console.log('password: ',password)
39
+      setVisible(true);
40
+    },
41
+    elevation:9
31
   };
42
   };
32
 
43
 
33
   return (
44
   return (
39
               <MUIDataTable
50
               <MUIDataTable
40
                 sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
51
                 sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
41
                 title={"Contraseñas"}
52
                 title={"Contraseñas"}
42
-                data={Build( status ==='success' ? data.data : [])}
53
+                data={Build(status === 'success' ? data.data : [])}
43
                 columns={Encabezados}
54
                 columns={Encabezados}
44
                 options={options}
55
                 options={options}
45
-                />
56
+              />
46
             </ThemeProvider>
57
             </ThemeProvider>
47
           </Paper>
58
           </Paper>
48
         </Box>
59
         </Box>
60
+        {
61
+          password ?
62
+            (
63
+              <ModalEdit
64
+                password={password}
65
+                open={visible}
66
+                handleOpen={setVisible}
67
+              />
68
+            ): null
69
+        }
49
       </div>
70
       </div>
50
     </div>
71
     </div>
51
   );
72
   );

+ 0 - 1
src/Pages/Home.jsx

11
 export function Home() {
11
 export function Home() {
12
 
12
 
13
   const auth = useSelector((state) => state.token)
13
   const auth = useSelector((state) => state.token)
14
-  // const profile = useSelector((state) => state.user.profile)
15
 
14
 
16
   const getAllPwd = async () => {
15
   const getAllPwd = async () => {
17
     let rest = new Service('/contrasenia/getallbyidUsr');
16
     let rest = new Service('/contrasenia/getallbyidUsr');