Browse Source

buscar puestos funcionality

amenpunk 2 years ago
parent
commit
351737321c
4 changed files with 121 additions and 42 deletions
  1. 22 5
      src/App.css
  2. 1 1
      src/Components/Puestos/GridMode.jsx
  3. 97 35
      src/Pages/Puestos.jsx
  4. 1 1
      src/Utils/Paginate.js

+ 22 - 5
src/App.css

251
 }
251
 }
252
 
252
 
253
 #pagi_bottom{
253
 #pagi_bottom{
254
-    width:100%;
255
-    display:flex;
256
-    flex-direction:row;
257
-    align-items:baseline;
258
-    justify-content:space-between;
254
+  margin-left:15px;
255
+  margin-right:15px;
256
+  width:100%;
257
+  display:flex;
258
+  flex-direction:row;
259
+  align-items:baseline;
260
+  justify-content:space-between;
261
+  flex-wrap:wrap;
259
 }
262
 }
260
 
263
 
261
 .css-19kzrtu{
264
 .css-19kzrtu{
368
     justify-content: center;
371
     justify-content: center;
369
     align-items: center;
372
     align-items: center;
370
 }
373
 }
374
+
375
+#search_plaza_input{
376
+  width:200px;
377
+  padding-left:20px !important;
378
+  margin-left:20px !important;
379
+}
380
+
381
+.chip_and_search{
382
+  display:flex;
383
+  flex-direction:row;
384
+  flex-wrap:wrap;
385
+  justify-content: center;
386
+  align-items: center;
387
+}

+ 1 - 1
src/Components/Puestos/GridMode.jsx

15
             return (
15
             return (
16
               <Grow in={true} style={{ transformOrigin: '0 0 0' }} timeout={500} key={plaza.id} >
16
               <Grow in={true} style={{ transformOrigin: '0 0 0' }} timeout={500} key={plaza.id} >
17
                 <Col lg="4" md="6" sm="6" xs="12" >
17
                 <Col lg="4" md="6" sm="6" xs="12" >
18
-                  <div style={{ padding: 15 }}>
18
+                  <div style={{ padding: 5 }}>
19
                     <PuestoCard toggle={toggle} plaza={plaza} />
19
                     <PuestoCard toggle={toggle} plaza={plaza} />
20
                   </div>
20
                   </div>
21
                 </Col>
21
                 </Col>

+ 97 - 35
src/Pages/Puestos.jsx

4
 
4
 
5
 import {
5
 import {
6
   ToggleButton, ToggleButtonGroup, Box,
6
   ToggleButton, ToggleButtonGroup, Box,
7
-  Paper, Pagination, Chip
7
+  Paper, Pagination, Chip, TextField, InputAdornment,
8
 } from '@mui/material';
8
 } from '@mui/material';
9
 
9
 
10
-import { ViewList as ViewListIcon, ViewModule as ViewModuleIcon, } from '@mui/icons-material';
10
+import {
11
+  ViewList as ViewListIcon, ViewModule as ViewModuleIcon,
12
+  Search as SearchIcon
13
+} from '@mui/icons-material';
11
 
14
 
12
 import { Service } from '../Utils/HTTP';
15
 import { Service } from '../Utils/HTTP';
13
 import { Divide } from '../Utils/Paginate';
16
 import { Divide } from '../Utils/Paginate';
33
 
36
 
34
   const auth = useSelector((state) => state.token)
37
   const auth = useSelector((state) => state.token)
35
   const [page, setPage] = useState(1);
38
   const [page, setPage] = useState(1);
39
+  const [temp, setTemp] = useState(null);
36
 
40
 
37
   const getAll = async () => {
41
   const getAll = async () => {
38
     let rest = new Service("/plaza/getall")
42
     let rest = new Service("/plaza/getall")
67
   let [edit, setEdit] = React.useState(null);
71
   let [edit, setEdit] = React.useState(null);
68
   let [del, setDelete] = React.useState(null);
72
   let [del, setDelete] = React.useState(null);
69
   let [show, setShow] = React.useState(null);
73
   let [show, setShow] = React.useState(null);
74
+  let [filter, setFilter] = React.useState(null);
70
 
75
 
71
   const toggle = useCallback((type, puesto) => {
76
   const toggle = useCallback((type, puesto) => {
72
-   // console.log('usecall: ',puesto)
73
     setPuesto(puesto)
77
     setPuesto(puesto)
74
     switch (type) {
78
     switch (type) {
75
       case "VER": {
79
       case "VER": {
89
   }, [del, show])
93
   }, [del, show])
90
 
94
 
91
 
95
 
92
-  if(isLoading){
93
-    return(
94
-      <Loading/>
96
+  if (isLoading) {
97
+    return (
98
+      <Loading />
95
     )
99
     )
96
   }
100
   }
97
 
101
 
104
       </Paper>
108
       </Paper>
105
     )
109
     )
106
   }
110
   }
107
-  const total_items = Divide(result.data).length
111
+  const total_items = Divide(filter ? filter : result.data).length
108
 
112
 
109
   return (
113
   return (
110
     <div className="content-section">
114
     <div className="content-section">
111
       <div className="main">
115
       <div className="main">
112
         <Box>
116
         <Box>
113
           <Paper sx={{ mb: 2, padding: 2, }}>
117
           <Paper sx={{ mb: 2, padding: 2, }}>
114
-
115
-            <Row style={{ paddingBottom: 15 }}>
116
-              <Col md="2" sm="2" xs="2">
118
+            <Row style={{ alignItems: 'center', padding : 10 }}>
119
+              <Col md="6" sm="12" xs="12">
117
                 <div className="breadcrumb-header">
120
                 <div className="breadcrumb-header">
118
-                  <Box sx={{ float: 'left', display: 'flex', flexDirection: 'column', alignItems: 'center', '& > :not(style) + :not(style)': { mt: 2 }, }} >
119
-                    <ToggleButtonGroup size="small" {...control}>
121
+                  <Box sx={{ float: 'left', display: 'flex', flexDirection: 'row', alignItems: 'center' }} >
122
+                    <ToggleButtonGroup style={{ marginRight: 20 }} size="small" {...control}>
120
                       {children}
123
                       {children}
121
                     </ToggleButtonGroup>
124
                     </ToggleButtonGroup>
125
+                    <TextField
126
+                      id="search_plaza_input"
127
+                      onChange={(event) => {
128
+                        let nombre = event.target.value
129
+                        if (nombre) {
130
+                          let temp = result.data.filter(plaza => {
131
+                            let isset = plaza.nombrepuesto.toUpperCase().includes(nombre.toUpperCase())
132
+                            return isset
133
+                          })
134
+                          console.log(temp)
135
+                          setFilter(temp)
136
+                        } else {
137
+                          setFilter(null)
138
+                        }
139
+                      }}
140
+                      InputProps={{
141
+                        startAdornment: (
142
+                          <InputAdornment position="start">
143
+                            <SearchIcon />
144
+                          </InputAdornment>
145
+                        ),
146
+                      }}
147
+                      variant="standard"
148
+                    />
149
+
150
+
151
+
152
+
122
                   </Box>
153
                   </Box>
154
+
123
                 </div>
155
                 </div>
124
               </Col>
156
               </Col>
125
-              <Col md="10" sm='10' xs="10">
157
+              <Col md="6" sm='12' xs="12">
126
                 <div className="add_producto">
158
                 <div className="add_producto">
127
                   <div onClick={() => setManual(true)} className="btn_add_producto">
159
                   <div onClick={() => setManual(true)} className="btn_add_producto">
128
                     <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small" /></span>
160
                     <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small" /></span>
136
               </Col>
168
               </Col>
137
             </Row>
169
             </Row>
138
 
170
 
139
-            <div>
140
-              <div className={`main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
171
+            <div >
172
+              <div className={` main_grid_plazas main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
141
                 <Row>
173
                 <Row>
142
                   <GridMode
174
                   <GridMode
143
                     toggle={toggle}
175
                     toggle={toggle}
144
                     showing={alignment}
176
                     showing={alignment}
145
-                    data={Divide(result.data)}
177
+                    data={filter ? Divide(filter) : Divide(result.data)}
146
                     index={page - 1}
178
                     index={page - 1}
147
                   />
179
                   />
148
                 </Row>
180
                 </Row>
152
                   <ListMode
184
                   <ListMode
153
                     toggle={toggle}
185
                     toggle={toggle}
154
                     showing={alignment}
186
                     showing={alignment}
155
-                    data={Divide(result.data)}
187
+                    data={filter ? Divide(filter) : Divide(result.data)}
156
                     index={page - 1}
188
                     index={page - 1}
157
                   />
189
                   />
158
                 </Row>
190
                 </Row>
159
               </div>
191
               </div>
160
 
192
 
161
-              <div id="pagi_bottom">
162
-                <Pagination
163
-                  sx={{
164
-                    "& ul": {
165
-                      paddingTop: "20px",
166
-                      justifyContent: "center"
167
-                    }
168
-                  }}
169
-                  siblingCount={2}
170
-                  boundaryCount={2}
171
-                  shape='rounded'
172
-                  count={total_items}
173
-                  page={page}
174
-                  onChange={changePage}
175
-                />
176
-
177
-                <Chip label={"Total: " + (result ? result.data.length : 0)} />
178
-              </div>
193
+              <Row className="mamo">
194
+                <Col id="pagi_bottom" >
195
+
196
+                  <Pagination
197
+                    sx={{
198
+                      "& ul": {
199
+                        paddingTop: "20px",
200
+                        justifyContent: "center"
201
+                      }
202
+                    }}
203
+                    siblingCount={2}
204
+                    boundaryCount={2}
205
+                    shape='rounded'
206
+                    count={total_items}
207
+                    page={page}
208
+                    onChange={changePage}
209
+                  />
210
+                  <div className="chip_and_search">
211
+
212
+                    <TextField
213
+                      id="search_plaza_input"
214
+                      onChange={(event) => {
215
+                        let nombre = event.target.value
216
+                        if (nombre) {
217
+                          let temp = result.data.filter(plaza => {
218
+                            let isset = plaza.nombrepuesto.toUpperCase().includes(nombre.toUpperCase())
219
+                            return isset
220
+                          })
221
+                          console.log(temp)
222
+                          setFilter(temp)
223
+                        } else {
224
+                          setFilter(null)
225
+                        }
226
+                      }}
227
+                      InputProps={{
228
+                        startAdornment: (
229
+                          <InputAdornment position="start">
230
+                            <SearchIcon />
231
+                          </InputAdornment>
232
+                        ),
233
+                      }}
234
+                      variant="standard"
235
+                    />
236
+
237
+                    <Chip style={{ marginLeft: 10, margin: 5 }} label={"Total: " + (result ? result.data.length : 0)} />
238
+                  </div>
239
+                </Col>
240
+              </Row>
179
 
241
 
180
             </div>
242
             </div>
181
           </Paper>
243
           </Paper>

+ 1 - 1
src/Utils/Paginate.js

1
 export function Divide(arregloOriginal){
1
 export function Divide(arregloOriginal){
2
-    const LONGITUD_PEDAZOS = 9;
2
+    const LONGITUD_PEDAZOS = 6;
3
     let arregloDeArreglos = [];
3
     let arregloDeArreglos = [];
4
     for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
4
     for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
5
         let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);
5
         let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);