Browse Source

add color

Kongzibapt 3 years ago
parent
commit
7b8f9c68d0
4 changed files with 110 additions and 103 deletions
  1. 80
    94
      src/js/Components/ArticleDetails.js
  2. 27
    2
      src/js/Components/Articles.js
  3. 3
    4
      src/js/Components/Sort.js
  4. 0
    3
      src/js/Views/Stock.js

+ 80
- 94
src/js/Components/ArticleDetails.js View File

@@ -21,6 +21,9 @@ class ArticleDetails extends React.Component {
21 21
         
22 22
     }
23 23
 
24
+    componentDidMount = () => {
25
+        
26
+    }
24 27
 
25 28
     handleDesc = () => {
26 29
         this.setState({currentArticle:this.props.id})
@@ -68,31 +71,75 @@ class ArticleDetails extends React.Component {
68 71
         })
69 72
     }
70 73
 
71
-    plusQuantity = () => {
74
+    plusQuantity = (element) => {
72 75
         this.setState({quantity:this.state.quantity+1},()=>{
73 76
             this.updateArticle();
77
+            if (this.state.quantity > 0 ){
78
+                if (this.state.selected){
79
+                    this.props.colorArticle("white",element)
80
+                } else {
81
+                    this.props.colorArticle("grey",element)
82
+                }
83
+            }
74 84
     })
75 85
     }
76 86
 
77
-    minusQuantity = () => {
87
+    minusQuantity = (element) => {
78 88
         if(this.state.quantity > 0){
79 89
             this.setState({quantity:this.state.quantity-1},()=>{
80 90
                 this.updateArticle();
91
+                if (this.state.quantity === 0){
92
+                    if (this.state.selected){
93
+                        this.props.colorArticle("red&white",element)
94
+                    } else {
95
+                        this.props.colorArticle("red",element)
96
+                    }
97
+                }
81 98
         })
82
-        }
99
+        } 
83 100
     }
84 101
 
102
+    // OnClick : selon si on clique sur tel ou tel element : on va colorer en blanc et selectionner 
103
+    // on va minus ou plus quantity et colorer en rouge
104
+
85 105
     selectArticles = (e) => {
86
-        console.log(e.target.id)
87
-        if ((e.target.id !==  "categoryIcon") && (e.target.id !== "penblue") && (e.target.id !== "crossred") && (e.target.id !== "") && (e.target.id !== "bluepen") && (e.target.id !== "redcross") && (e.target.id !== "no")){
106
+        let currentElement = e.target;
107
+        let iconElement;
108
+        if (e.target.tagName === "path"){
109
+            currentElement = e.target.parentElement
110
+            iconElement = currentElement
111
+        }
112
+        if ((e.target.id === "minusIcon") || (e.target.id === "plusIcon")){
113
+            iconElement = currentElement
114
+        }
115
+        while (currentElement.id !== "bulle"){
116
+            currentElement = currentElement.parentElement
117
+        }
118
+        
119
+        console.log(currentElement); 
120
+        if ((e.target.id !==  "categoryIcon") && (e.target.id !== "penblue") && (e.target.id !== "crossred") && (e.target.id !== "") && (e.target.id !== "bluepen") && (e.target.id !== "redcross")  && (e.target.id !== "no") && (e.target.id !== "minusIcon") && (e.target.id !== "plusIcon")){
88 121
         this.setState({selected:!this.state.selected},()=>{
89 122
             console.log(this.state.selected)
90 123
             if (this.state.selected){
91 124
                 this.props.select(this.props.id)
125
+                if (this.state.quantity === 0){
126
+                    this.props.colorArticle("red&white",currentElement)
127
+                } else {
128
+                    this.props.colorArticle("white",currentElement)
129
+                }
92 130
             } else {
93 131
                 this.props.deselect(this.props.id)
132
+                if (this.state.quantity === 0){
133
+                    this.props.colorArticle("red",currentElement)
134
+                } else {
135
+                this.props.colorArticle("grey",currentElement)
136
+                }
94 137
             }
95 138
         })   
139
+        } else if (iconElement.id === "minusIcon"){
140
+            this.minusQuantity(currentElement)
141
+        } else if (iconElement.id === "plusIcon"){
142
+            this.plusQuantity(currentElement)
96 143
         }
97 144
     }   
98 145
 
@@ -105,11 +152,7 @@ class ArticleDetails extends React.Component {
105 152
 
106 153
             // SQUARE
107 154
 
108
-            this.state.selected ?
109
-
110
-                // SELECTED
111
-
112
-                <div onClick={this.selectArticles} id="bulleSelect" onMouseEnter={this.handleDesc} onMouseLeave={this.handlePhoto}> 
155
+            <div onClick={this.selectArticles} id="bulle" onMouseEnter={this.handleDesc} onMouseLeave={this.handlePhoto}> 
113 156
                 {this.state.redcrossPressed ?
114 157
                 <div id="confirmation">
115 158
                     <div id="confirmationTxt">Tu veux vraiment supprimer cet article ?</div>
@@ -119,102 +162,45 @@ class ArticleDetails extends React.Component {
119 162
                     </div>
120 163
                 </div> 
121 164
                 : 
122
-                <>
123
-                <div id="imageordescblock">
124
-                {this.state.currentArticle === this.props.id ? 
125
-                <>
126
-                <div id="icons">
127
-                    <div id="bluepen" onClick={() => this.props.editArticle(this.props)}>
128
-                        <Icon id="penblue" icon={editSolid} style={{color: '#ffffff', fontSize: '25px'}} rotate="270deg" />
129
-                    </div>
130
-                    <div id="redcross" onClick={this.handleRedCross}>
131
-                        <Icon id="crossred" icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '25px'}} />
132
-                    </div>
133
-                </div>
134
-                <div id="categoryDiv">
135
-                    <img onClick={() => this.props.handleCategories(this.props.category)} id="categoryIcon" alt="bonjour" src={`https://etud.insa-toulouse.fr/~proximo/api_proximo/storage/app/public/icon/${this.props.category.icon}`}/>
136
-                </div>
137
-                <div id="descandprice">
138
-                    <h1 id="desc">{this.props.desc}</h1>
139
-                    <p id ="price">{this.props.price} €</p>
140
-                </div>
141
-                </>
142
-                : <img id="image" src={`https://etud.insa-toulouse.fr/~proximo/api_proximo/storage/app/public/img/${this.props.img}`} alt='bonjour'/>
143
-                }
144
-                </div>
145
-                        <h1 id="name">{this.props.name}</h1>
146
-                        <div id="count">
147
-                            <Icon onClick={this.minusQuantity} icon={minusIcon} style={{color: '#ffffff', fontSize: '18.558874130249023px',cursor:'pointer'}} />
148
-                            <div id="countNumber">
149
-                                <p id="countNumberTxt">{this.state.quantity}</p>
165
+                <div id="bulleContainer">
166
+                    <div id="imageordescblock">
167
+                        {this.state.currentArticle === this.props.id ? 
168
+                        <>
169
+                            <div id="icons">
170
+                                <div id="bluepen" onClick={() => this.props.editArticle(this.props)}>
171
+                                    <Icon icon={editSolid} style={{color: '#ffffff', fontSize: '25px'}} rotate="270deg" />
172
+                                </div>
173
+                                <div id="redcross" onClick={this.handleRedCross}>
174
+                                    <Icon icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '25px'}} />
175
+                                </div>
150 176
                             </div>
151
-                            <Icon onClick={this.plusQuantity} icon={plusIcon} style={{color: '#ffffff', fontSize: '18.558874130249023px',cursor:'pointer'}} />
152
-                        </div>
153
-                </>        
154
-                }
155
-                </div>
156
-
157
-            : 
158
-
159
-                // NOT SELECTED
160
-
161
-                <div onClick={this.selectArticles} id="bulle" onMouseEnter={this.handleDesc} onMouseLeave={this.handlePhoto}> 
162
-                {this.state.redcrossPressed ?
163
-                <div id="confirmation">
164
-                    <div id="confirmationTxt">Tu veux vraiment supprimer cet article ?</div>
165
-                    <div id="choice">
166
-                        <div id="yes" onClick={this.deleteArticle}>Oui</div>
167
-                        <div id="no" onClick={this.handleNoDelete}>Non</div>
168
-                    </div>
169
-                </div> 
170
-                : 
171
-                <>
172
-                <div id="imageordescblock">
173
-                {this.state.currentArticle === this.props.id ? 
174
-                <>
175
-                <div id="icons">
176
-                    <div id="bluepen" onClick={() => this.props.editArticle(this.props)}>
177
-                        <Icon icon={editSolid} style={{color: '#ffffff', fontSize: '25px'}} rotate="270deg" />
178
-                    </div>
179
-                    <div id="redcross" onClick={this.handleRedCross}>
180
-                        <Icon icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '25px'}} />
177
+                            <div id="categoryDiv">
178
+                                <img onClick={() => this.props.handleCategories(this.props.category)} id="categoryIcon" alt="bonjour" src={`https://etud.insa-toulouse.fr/~proximo/api_proximo/storage/app/public/icon/${this.props.category.icon}`}/>
179
+                            </div>
180
+                            <div id="descandprice">
181
+                                <h1 id="desc">{this.props.desc}</h1>
182
+                                <p id ="price">{this.props.price} €</p>
183
+                            </div>
184
+                        </>
185
+                        : <img id="image" src={`https://etud.insa-toulouse.fr/~proximo/api_proximo/storage/app/public/img/${this.props.img}`} alt='bonjour'/>
186
+                        }
181 187
                     </div>
182
-                </div>
183
-                <div id="categoryDiv">
184
-                    <img onClick={() => this.props.handleCategories(this.props.category)} id="categoryIcon" alt="bonjour" src={`https://etud.insa-toulouse.fr/~proximo/api_proximo/storage/app/public/icon/${this.props.category.icon}`}/>
185
-                </div>
186
-                <div id="descandprice">
187
-                    <h1 id="desc">{this.props.desc}</h1>
188
-                    <p id ="price">{this.props.price} €</p>
189
-                </div>
190
-                </>
191
-                : <img id="image" src={`https://etud.insa-toulouse.fr/~proximo/api_proximo/storage/app/public/img/${this.props.img}`} alt='bonjour'/>
192
-                }
193
-                </div>
194
-                        <h1 id="name">{this.props.name}</h1>
195
-                        <div id="count">
196
-                            <Icon onClick={this.minusQuantity} icon={minusIcon} style={{color: '#ffffff', fontSize: '18.558874130249023px',cursor:'pointer'}} />
188
+                    <h1 id="name">{this.props.name}</h1>
189
+                    <div id="count">
190
+                            <Icon id="minusIcon" icon={minusIcon} style={{color: '#ffffff', fontSize: '18.558874130249023px',cursor:'pointer'}} />
197 191
                             <div id="countNumber">
198 192
                                 <p id="countNumberTxt">{this.state.quantity}</p>
199 193
                             </div>
200
-                            <Icon onClick={this.plusQuantity} icon={plusIcon} style={{color: '#ffffff', fontSize: '18.558874130249023px',cursor:'pointer'}} />
194
+                            <Icon id="plusIcon" icon={plusIcon} style={{color: '#ffffff', fontSize: '18.558874130249023px',cursor:'pointer'}} />
201 195
                         </div>
202
-                </>        
196
+                </div>        
203 197
                 }
204
-                </div>
198
+            </div>
205 199
             
206 200
             :
207 201
 
208 202
             // INLINE
209 203
 
210
-            this.state.selected ?
211
-
212
-                // SELECTED
213
-            
214
-                <div>Ok</div>
215
-
216
-            :
217
-
218 204
                 // NOT SELECTED
219 205
                 
220 206
                 <div id="line">

+ 27
- 2
src/js/Components/Articles.js View File

@@ -11,9 +11,34 @@ class Articles extends React.Component {
11 11
     }
12 12
 
13 13
     componentDidMount(){
14
-      
14
+      let articles = document.getElementById("articles")
15
+        console.log(articles);
16
+        for (let i = 0; i<articles.childElementCount; i++){
17
+          if (this.props.articles[i].quantity === 0){
18
+            this.colorArticle("red",articles.children[i])
19
+          }
20
+        }
15 21
     } 
16 22
 
23
+    colorArticle = (color,element) => {
24
+      
25
+      switch (color) {
26
+          case "white":
27
+              element.style.cssText = "background-color:rgba(255, 255, 255, 0.75);"
28
+              break;
29
+          case "grey" :
30
+              element.style.cssText = "background-color:rgba(105, 105, 105, 0.28);"
31
+              break;
32
+          case "red" :
33
+              element.style.cssText = "background-color:rgba(255, 21, 21, 0.28);"
34
+              break;
35
+          case "red&white" :
36
+            element.style.cssText = "background-color:rgba(255, 107, 107, 0.28);"
37
+            break;
38
+      }
39
+  }
40
+
41
+  
17 42
 
18 43
     render() {
19 44
       return (
@@ -21,7 +46,7 @@ class Articles extends React.Component {
21 46
             <div id="articles">
22 47
               {
23 48
                 this.props.articles.map((article) => 
24
-                <ArticleDetails squaredBubble={true} deselect={this.props.deselect} select={this.props.select} handleCategories={this.props.handleCategories} editArticle={this.props.editionArticle} key={article.id} id={article.id} name={article.name} img={article.image} desc={article.description} price={article.price} quantity={article.quantity} code={article.code} category={article.category}/>    
49
+                <ArticleDetails colorArticle={this.colorArticle} squaredBubble={true} deselect={this.props.deselect} select={this.props.select} handleCategories={this.props.handleCategories} editArticle={this.props.editionArticle} key={article.id} id={article.id} name={article.name} img={article.image} desc={article.description} price={article.price} quantity={article.quantity} code={article.code} category={article.category}/>    
25 50
             )}
26 51
             </div>
27 52
           </div>

+ 3
- 4
src/js/Components/Sort.js View File

@@ -13,7 +13,6 @@ class Sort extends Component {
13 13
     }
14 14
 
15 15
     changeArrowDirection = () => {
16
-        console.log('ok');
17 16
         this.setState({unwound:!this.state.unwound})
18 17
     }
19 18
 
@@ -62,9 +61,9 @@ class Sort extends Component {
62 61
     }
63 62
 
64 63
     render() {
65
-        console.log(this.state.orderText)
66
-        console.log(this.state.orderText.split(""))
67
-        console.log(document.getElementById("sortOrder"))
64
+        // console.log(this.state.orderText)
65
+        // console.log(this.state.orderText.split(""))
66
+        // console.log(document.getElementById("sortOrder"))
68 67
         return (
69 68
             <div id="sortBox">
70 69
                 <div id="sortTxt">

+ 0
- 3
src/js/Views/Stock.js View File

@@ -205,7 +205,6 @@ export default class Stock extends React.Component {
205 205
 
206 206
   //ATTENTION ça a changé, on passe directement le string en argument (j'avais besoin d'utiliser cette fonction autrement, voir dans Sort.js)
207 207
   handleChangeSortType = (type) => {
208
-    console.log(type)
209 208
     this.setState({sortType: type}, () => {
210 209
       this.sortArticles(this.state.sortType)
211 210
     })
@@ -214,7 +213,6 @@ export default class Stock extends React.Component {
214 213
   //Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel
215 214
   handleChangeSortOrder = e => {
216 215
     this.setState({lowToHigh: !this.state.lowToHigh},() => {
217
-      console.log(this.state.sortType)
218 216
       this.sortArticles(this.state.sortType);
219 217
     });
220 218
   }
@@ -264,7 +262,6 @@ export default class Stock extends React.Component {
264 262
 
265 263
 
266 264
   render() {
267
-    console.log("rendered");
268 265
     if (!sessionStorage.getItem('token')){
269 266
       return (<div id="errorRouteBlock"><div id="errorRouteTitle">ERREUR </div><br/><div id="errorRouteTxt">Vous n'êtes pas connecté</div><br/><Link id="link" to='/'>Retourner à l'Accueil</Link></div>)
270 267
     } else {

Loading…
Cancel
Save