Browse Source

pdf mok fix

amenpunk 2 years ago
parent
commit
0060f8d9a2
4 changed files with 176 additions and 78 deletions
  1. 9 11
      src/Components/Generics/loading.jsx
  2. 8 44
      src/Pages/Puestos.jsx
  3. 79 23
      src/Pages/Resultados.jsx
  4. 80 0
      src/pdf.css

+ 9 - 11
src/Components/Generics/loading.jsx

13
   return (
13
   return (
14
     <div className="content-section">
14
     <div className="content-section">
15
       <Paper>
15
       <Paper>
16
-      <div className="main">
17
-        <Box className="loadingGeneric">
18
-
19
-              <div className="loading_or_content">
20
-                <div className="snippet" data-title=".dot-pulse">
21
-                  <div className="stage">
22
-                    <div className={types[0]}></div>
23
-                  </div>
16
+        <div className="main">
17
+          <Box className="loadingGeneric">
18
+            <div className="loading_or_content">
19
+              <div className="snippet" data-title=".dot-pulse">
20
+                <div className="stage">
21
+                  <div className={types[0]}></div>
24
                 </div>
22
                 </div>
25
               </div>
23
               </div>
26
-
27
-        </Box>
28
-      </div>
24
+            </div>
25
+          </Box>
26
+        </div>
29
       </Paper>
27
       </Paper>
30
     </div>
28
     </div>
31
 
29
 

+ 8 - 44
src/Pages/Puestos.jsx

110
   const total_items = Divide(filter ? filter : result.data).length
110
   const total_items = Divide(filter ? filter : result.data).length
111
 
111
 
112
   return (
112
   return (
113
-    <div  className="content-section">
113
+    <div className="content-section">
114
       <div className="main">
114
       <div className="main">
115
         <Box>
115
         <Box>
116
           <Paper sx={{ mb: 2, padding: 2, }}>
116
           <Paper sx={{ mb: 2, padding: 2, }}>
117
-            <Row style={{ alignItems: 'center', padding : 10 }}>
118
-              <Col md="6" sm="12" xs="12">
117
+            <Row style={{ alignItems: 'center', padding: 10, justifyContent: 'space-between' }}>
118
+              <Col md="4" sm="4" xs="4">
119
                 <div className="breadcrumb-header">
119
                 <div className="breadcrumb-header">
120
                   <Box sx={{ float: 'left', display: 'flex', flexDirection: 'row', alignItems: 'center' }} >
120
                   <Box sx={{ float: 'left', display: 'flex', flexDirection: 'row', alignItems: 'center' }} >
121
                     <ToggleButtonGroup style={{ marginRight: 20 }} size="small" {...control}>
121
                     <ToggleButtonGroup style={{ marginRight: 20 }} size="small" {...control}>
122
                       {children}
122
                       {children}
123
                     </ToggleButtonGroup>
123
                     </ToggleButtonGroup>
124
-
125
-
126
-                    {/*
127
-                      <TextField
128
-                        id="search_plaza_input"
129
-                        onChange={(event) => {
130
-                          let nombre = event.target.value
131
-                          if (nombre) {
132
-                            let temp = result.data.filter(plaza => {
133
-                              let isset = plaza.nombrepuesto.toUpperCase().includes(nombre.toUpperCase())
134
-                              return isset
135
-                            })
136
-                            if(temp.lenght <= 0){
137
-                              setFilter(null)
138
-                            }
139
-                            setFilter(temp)
140
-                          } else {
141
-                            setFilter(null)
142
-                          }
143
-                        }}
144
-                        InputProps={{
145
-                          startAdornment: (
146
-                            <InputAdornment position="start">
147
-                              <SearchIcon />
148
-                            </InputAdornment>
149
-                          ),
150
-                        }}
151
-                        variant="standard"
152
-                      />
153
-*/}
154
-
155
-
156
-
157
-
158
                   </Box>
124
                   </Box>
159
-
160
                 </div>
125
                 </div>
161
               </Col>
126
               </Col>
162
-              <Col md="6" sm='12' xs="12">
127
+              <Col md="8" sm='8' xs="4">
163
                 <div className="add_producto">
128
                 <div className="add_producto">
164
                   <div onClick={() => setManual(true)} className="btn_add_producto">
129
                   <div onClick={() => setManual(true)} className="btn_add_producto">
165
                     <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small" /></span>
130
                     <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small" /></span>
172
                 </div>
137
                 </div>
173
               </Col>
138
               </Col>
174
             </Row>
139
             </Row>
175
-
176
-            <div style={{padding:7}}>
140
+            <div style={{ padding: 7 }}>
177
               <div className={` main_grid_plazas main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
141
               <div className={` main_grid_plazas main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
178
-                <Row style={{minHeight:'75vh'}}>
142
+                <Row style={{ minHeight: '75vh' }}>
179
                   <GridMode
143
                   <GridMode
180
                     toggle={toggle}
144
                     toggle={toggle}
181
                     showing={alignment}
145
                     showing={alignment}
185
                 </Row>
149
                 </Row>
186
               </div>
150
               </div>
187
               <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
151
               <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
188
-                <Row style={{minHeight:'75vh'}}>
152
+                <Row style={{ minHeight: '75vh' }}>
189
                   <ListMode
153
                   <ListMode
190
                     toggle={toggle}
154
                     toggle={toggle}
191
                     showing={alignment}
155
                     showing={alignment}
239
                       variant="standard"
203
                       variant="standard"
240
                     />
204
                     />
241
 
205
 
242
-                    <Chip style={{ marginLeft: 10, margin: 5 }} label={"Total: " + ( filter?  filter.length :  ( result ? result.data.length : 0 ))} />
206
+                    <Chip style={{ marginLeft: 10, margin: 5 }} label={"Total: " + (filter ? filter.length : (result ? result.data.length : 0))} />
243
                   </div>
207
                   </div>
244
                 </Col>
208
                 </Col>
245
               </Row>
209
               </Row>

+ 79 - 23
src/Pages/Resultados.jsx

2
 import { useParams } from 'react-router-dom'
2
 import { useParams } from 'react-router-dom'
3
 import { Service } from '../Utils/HTTP';
3
 import { Service } from '../Utils/HTTP';
4
 import { useSelector } from 'react-redux';
4
 import { useSelector } from 'react-redux';
5
-import { Button, Box, Paper } from '@mui/material'
6
 import { Document, Page, pdfjs } from 'react-pdf/dist/esm/entry.webpack';
5
 import { Document, Page, pdfjs } from 'react-pdf/dist/esm/entry.webpack';
7
-// import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
6
+import { Loading } from '../Components/Generics/loading'
7
+import DownloadIcon from '@mui/icons-material/Download';
8
 import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
8
 import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
9
 import 'react-pdf/dist/esm/Page/TextLayer.css';
9
 import 'react-pdf/dist/esm/Page/TextLayer.css';
10
+import '../pdf.css'
11
+// import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
12
+import { 
13
+  Button, Box, Paper,LinearProgress,
14
+  Typography
15
+} from '@mui/material'
10
 
16
 
11
-const Cargando = () => <div><h2>loading...</h2></div>
17
+function LinearProgressWithLabel(props) {
18
+  return (
19
+    <Box sx={{ display: 'flex', alignItems: 'center' }}>
20
+      <Box sx={{ width: '100%', mr: 1 }}>
21
+        <LinearProgress variant="determinate" {...props} />
22
+      </Box>
23
+      <Box sx={{ minWidth: 35 }}>
24
+        <Typography variant="body2" color="text.secondary">{`${Math.round(
25
+          props.value,
26
+        )}%`}</Typography>
27
+      </Box>
28
+    </Box>
29
+  );
30
+}
12
 
31
 
13
-// Create Document Component
14
 const MyDocument = (props) => {
32
 const MyDocument = (props) => {
15
 
33
 
16
   let { pdf } = props;
34
   let { pdf } = props;
22
     setNumPages(numPages);
40
     setNumPages(numPages);
23
   }
41
   }
24
 
42
 
25
-  function onLoadError(error) {
26
-    console.log('error: ', error)
43
+  const [progress, setProgress] = useState(10);
44
+
45
+  if(!pdf){
46
+    <Loading/>
27
   }
47
   }
28
 
48
 
49
+  console.log(progress)
50
+
29
   return (
51
   return (
30
     <div>
52
     <div>
53
+
54
+        {
55
+          progress < 100 ?
56
+          <LinearProgressWithLabel value={progress}/>
57
+            : null
58
+        }
59
+
31
       <div className="pdf_controls">
60
       <div className="pdf_controls">
32
-        <Button variant="contained" onClick={() => pageNumber > 1 ? setPageNumber(pageNumber - 1) : null} >
61
+
62
+
63
+      <div className="btn_pdfcontrol">
64
+        <Button 
65
+            className="btnmain"
66
+            style={{ margin: 2 }} 
67
+            variant="contained" 
68
+            onClick={() => pageNumber > 1 ? setPageNumber(pageNumber - 1) : null} >
33
           Anterior
69
           Anterior
34
         </Button>
70
         </Button>
35
-        <Button style={{ margin: 5 }} variant="contained" onClick={() => pageNumber + 1 <= numPages   ? setPageNumber(pageNumber + 1) : null} >
71
+        <Button 
72
+            className="btnmain"
73
+            style={{ margin: 2 }} 
74
+            variant="contained" 
75
+            onClick={() => pageNumber + 1 <= numPages   ? setPageNumber(pageNumber + 1) : null} >
36
           Siguiente
76
           Siguiente
37
         </Button>
77
         </Button>
78
+      </div>
79
+
80
+        <div>
81
+          <b style={{marginRight : 15}}>
82
+            Página {pageNumber} de {numPages}
83
+          </b>
38
 
84
 
39
-        <p>
40
-          Página {pageNumber} de {numPages}
41
-        </p>
85
+          <Button 
86
+            className="btnmain"
87
+            variant="contained" 
88
+            onClick={() => console.log('download')} >
89
+            <DownloadIcon/>
90
+          </Button>
91
+        </div>
42
 
92
 
43
       </div>
93
       </div>
44
 
94
 
45
-      <div className="Example__container__document">
46
-        <Document renderMode="canvas" file={pdf.data} onLoadSuccess={onDocumentLoadSuccess} onLoadError={onLoadError}>
47
-          <Page width={800} pageNumber={pageNumber} loading={<Cargando />} />
48
-        </Document>
95
+      <div className="Example__container">
96
+        <div className="Example__container__document">
97
+          <Document 
98
+            renderMode="canvas" 
99
+            file={pdf?.data} 
100
+            onLoadSuccess={onDocumentLoadSuccess} 
101
+            loading={Loading}
102
+            onLoadProgress={({loaded, total}) => {
103
+              setProgress((loaded / total) * 100)
104
+            }}
105
+          >
106
+              <Page loading={Loading} pageNumber={pageNumber} />
107
+          </Document>
108
+        </div>
49
       </div>
109
       </div>
50
     </div>
110
     </div>
51
   )
111
   )
76
     <div className="content-section">
136
     <div className="content-section">
77
       <div className="main">
137
       <div className="main">
78
         <Box sx={{ width: '100%' }}>
138
         <Box sx={{ width: '100%' }}>
79
-          <Paper elevation={0} sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
80
-            <h1>Resultados {id}</h1>
81
-            <hr />
82
-            {
83
-              pdf ?
84
-                <MyDocument pdf={pdf} />
85
-                : <div> <h5> loading...</h5></div>
86
-            }
139
+          <Paper 
140
+            elevation={2} 
141
+            sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
142
+            <MyDocument pdf={pdf} />
87
           </Paper>
143
           </Paper>
88
         </Box>
144
         </Box>
89
       </div>
145
       </div>

+ 80 - 0
src/pdf.css

1
+body {
2
+  margin: 0;
3
+  background-color: #525659;
4
+  font-family: Segoe UI, Tahoma, sans-serif;
5
+}
6
+
7
+.Example input,
8
+.Example button {
9
+  font: inherit;
10
+}
11
+
12
+.Example header {
13
+  background-color: #323639;
14
+  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
15
+  padding: 20px;
16
+  color: white;
17
+}
18
+
19
+.Example header h1 {
20
+  font-size: inherit;
21
+  margin: 0;
22
+}
23
+
24
+.Example__container {
25
+  display: flex;
26
+  flex-direction: column;
27
+  align-items: center;
28
+  margin: 0px;
29
+  padding: 0px;
30
+}
31
+
32
+.Example__container__load {
33
+  margin-top: 1em;
34
+  color: white;
35
+}
36
+
37
+.Example__container__document {
38
+  margin: 1em 0;
39
+}
40
+
41
+.Example__container__document .react-pdf__Document {
42
+  display: flex;
43
+  flex-direction: column;
44
+  align-items: center;
45
+}
46
+
47
+.Example__container__document .react-pdf__Page {
48
+  max-width: calc(100% - 2em);
49
+  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
50
+  margin: 1em;
51
+}
52
+
53
+.Example__container__document .react-pdf__Page canvas {
54
+  max-width: 100%;
55
+  height: auto !important;
56
+}
57
+
58
+.Example__container__document .react-pdf__message {
59
+  padding: 20px;
60
+  color: white;
61
+}
62
+
63
+.pdf_controls{
64
+  display: flex;
65
+  align-items: baseline;
66
+  justify-content: space-between;
67
+  align-content: stretch;
68
+}
69
+.btnmain:hover{
70
+  background:var(--main) !important;
71
+  color:white !important;
72
+}
73
+.btn_pdfcontrol{
74
+  display:flex;
75
+  gap:1
76
+}
77
+.btnmain{
78
+  color:white !important;
79
+  background:var(--main) !important;
80
+}