|
@@ -39,7 +39,7 @@ export default class Stock extends React.Component {
|
39
|
39
|
selectedArticles:[],
|
40
|
40
|
counter:0,
|
41
|
41
|
code:'',
|
42
|
|
-
|
|
42
|
+ dividedArticles:[]
|
43
|
43
|
}
|
44
|
44
|
}
|
45
|
45
|
|
|
@@ -297,6 +297,7 @@ updateArticle = (index,id) => {
|
297
|
297
|
//TRI PAR CATEGORIE
|
298
|
298
|
if (sortType === 'category_id'){
|
299
|
299
|
this.setState({articles:sorted},() => {
|
|
300
|
+ this.splitArticlesCategories()
|
300
|
301
|
this.setState({onSortedCategories:true})
|
301
|
302
|
})
|
302
|
303
|
}else{
|
|
@@ -393,7 +394,9 @@ updateArticle = (index,id) => {
|
393
|
394
|
axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/articles',bodyFormData)
|
394
|
395
|
.then(res => {
|
395
|
396
|
this.setState({articles : res.data}, () => {
|
396
|
|
- console.log(this.state.articles)
|
|
397
|
+ if (this.state.sortType === "category_id"){
|
|
398
|
+ this.splitArticlesCategories()
|
|
399
|
+ }
|
397
|
400
|
})
|
398
|
401
|
})
|
399
|
402
|
.catch(error => {
|
|
@@ -401,6 +404,35 @@ updateArticle = (index,id) => {
|
401
|
404
|
})
|
402
|
405
|
}
|
403
|
406
|
|
|
407
|
+ splitArticlesCategories = () => {
|
|
408
|
+ let counterTab = 0;
|
|
409
|
+ let divided = [];
|
|
410
|
+ divided.push([this.state.articles[0]])
|
|
411
|
+ for (let i = 1; i<this.state.articles.length;i++){
|
|
412
|
+ if (this.state.articles[i].category_id === this.state.articles[i-1].category_id){
|
|
413
|
+ divided[counterTab].push(this.state.articles[i])
|
|
414
|
+ } else {
|
|
415
|
+ counterTab++
|
|
416
|
+ divided.push([this.state.articles[i]])
|
|
417
|
+ }
|
|
418
|
+ }
|
|
419
|
+ this.setState({dividedArticles:divided},()=>{
|
|
420
|
+ this.getElementandColor()
|
|
421
|
+ })
|
|
422
|
+
|
|
423
|
+ }
|
|
424
|
+
|
|
425
|
+ getElementandColor () {
|
|
426
|
+ let articles = document.getElementById("articles")
|
|
427
|
+ for (let i = 0; i<articles.childElementCount;i++){
|
|
428
|
+ for (let j = 0; j<articles.children[i].children[2].childElementCount; j++){
|
|
429
|
+ if (this.state.dividedArticles[i][j].quantity === 0){
|
|
430
|
+ this.colorArticle("red",articles.children[i].children[2].children[j])
|
|
431
|
+ }
|
|
432
|
+ }
|
|
433
|
+ }
|
|
434
|
+ }
|
|
435
|
+
|
404
|
436
|
handleSearchChange = event => {
|
405
|
437
|
this.setState({search : event.target.value},()=>
|
406
|
438
|
{
|
|
@@ -451,7 +483,7 @@ updateArticle = (index,id) => {
|
451
|
483
|
<div id="articleBlock">
|
452
|
484
|
{this.state.articles && this.state.articles[0] ?
|
453
|
485
|
this.state.onSortedCategories ?
|
454
|
|
- <ArticlesByCategory onSearch={this.state.onSearch} handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
|
486
|
+ <ArticlesByCategory selectArticles={this.selectArticles} colorArticle={this.colorArticle} handleCategories={this.handleCategories} articles={this.state.dividedArticles} editionArticle={this.handleArticleEdition}/>
|
455
|
487
|
: <Articles selectArticles={this.selectArticles} colorArticle={this.colorArticle} plus={this.plusQuantity} minus={this.minusQuantity} deselect={this.deselect} select={this.select} handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
456
|
488
|
: <AppLoader/>
|
457
|
489
|
}
|