浏览代码

buscar puestos funcionality

amenpunk 2 年之前
父节点
当前提交
351737321c
共有 4 个文件被更改,包括 121 次插入42 次删除
  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,11 +251,14 @@
251 251
 }
252 252
 
253 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 264
 .css-19kzrtu{
@@ -368,3 +371,17 @@
368 371
     justify-content: center;
369 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,7 +15,7 @@ export function GridMode(props) {
15 15
             return (
16 16
               <Grow in={true} style={{ transformOrigin: '0 0 0' }} timeout={500} key={plaza.id} >
17 17
                 <Col lg="4" md="6" sm="6" xs="12" >
18
-                  <div style={{ padding: 15 }}>
18
+                  <div style={{ padding: 5 }}>
19 19
                     <PuestoCard toggle={toggle} plaza={plaza} />
20 20
                   </div>
21 21
                 </Col>

+ 97 - 35
src/Pages/Puestos.jsx

@@ -4,10 +4,13 @@ import { Toaster } from 'react-hot-toast';
4 4
 
5 5
 import {
6 6
   ToggleButton, ToggleButtonGroup, Box,
7
-  Paper, Pagination, Chip
7
+  Paper, Pagination, Chip, TextField, InputAdornment,
8 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 15
 import { Service } from '../Utils/HTTP';
13 16
 import { Divide } from '../Utils/Paginate';
@@ -33,6 +36,7 @@ export function Puestos() {
33 36
 
34 37
   const auth = useSelector((state) => state.token)
35 38
   const [page, setPage] = useState(1);
39
+  const [temp, setTemp] = useState(null);
36 40
 
37 41
   const getAll = async () => {
38 42
     let rest = new Service("/plaza/getall")
@@ -67,9 +71,9 @@ export function Puestos() {
67 71
   let [edit, setEdit] = React.useState(null);
68 72
   let [del, setDelete] = React.useState(null);
69 73
   let [show, setShow] = React.useState(null);
74
+  let [filter, setFilter] = React.useState(null);
70 75
 
71 76
   const toggle = useCallback((type, puesto) => {
72
-   // console.log('usecall: ',puesto)
73 77
     setPuesto(puesto)
74 78
     switch (type) {
75 79
       case "VER": {
@@ -89,9 +93,9 @@ export function Puestos() {
89 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,25 +108,53 @@ export function Puestos() {
104 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 113
   return (
110 114
     <div className="content-section">
111 115
       <div className="main">
112 116
         <Box>
113 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 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 123
                       {children}
121 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 153
                   </Box>
154
+
123 155
                 </div>
124 156
               </Col>
125
-              <Col md="10" sm='10' xs="10">
157
+              <Col md="6" sm='12' xs="12">
126 158
                 <div className="add_producto">
127 159
                   <div onClick={() => setManual(true)} className="btn_add_producto">
128 160
                     <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small" /></span>
@@ -136,13 +168,13 @@ export function Puestos() {
136 168
               </Col>
137 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 173
                 <Row>
142 174
                   <GridMode
143 175
                     toggle={toggle}
144 176
                     showing={alignment}
145
-                    data={Divide(result.data)}
177
+                    data={filter ? Divide(filter) : Divide(result.data)}
146 178
                     index={page - 1}
147 179
                   />
148 180
                 </Row>
@@ -152,30 +184,60 @@ export function Puestos() {
152 184
                   <ListMode
153 185
                     toggle={toggle}
154 186
                     showing={alignment}
155
-                    data={Divide(result.data)}
187
+                    data={filter ? Divide(filter) : Divide(result.data)}
156 188
                     index={page - 1}
157 189
                   />
158 190
                 </Row>
159 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 242
             </div>
181 243
           </Paper>

+ 1 - 1
src/Utils/Paginate.js

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