Ajout de ArticlesByCategory
This commit is contained in:
parent
a806dfd31e
commit
3756e90ee5
6 changed files with 114 additions and 8 deletions
|
@ -0,0 +1,14 @@
|
||||||
|
#emptyTicketBox{
|
||||||
|
height:50vh;
|
||||||
|
display:flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#emptyTicket{
|
||||||
|
color : white;
|
||||||
|
text-align: center;
|
||||||
|
font-family: 'Wellfleet', cursive;
|
||||||
|
font-size:max(2.5vw,30px);
|
||||||
|
width:25%;
|
||||||
|
}
|
|
@ -10,16 +10,16 @@ class Articles extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div id="articleContainer">
|
<div id="articleContainer">
|
||||||
<div id="articles">
|
<div id="articles">
|
||||||
{
|
{
|
||||||
this.props.articles.map((article) =>
|
this.props.articles.map((article) =>
|
||||||
<ArticleDetails 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}/>
|
<ArticleDetails 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}/>
|
||||||
)}
|
)}
|
||||||
|
|
58
src/js/Components/ArticlesByCategory.js
Normal file
58
src/js/Components/ArticlesByCategory.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
import React from 'react';
|
||||||
|
import '../../css/Components/articles.css'
|
||||||
|
import ArticleDetails from './ArticleDetails'
|
||||||
|
|
||||||
|
class ArticlesByCategory extends React.Component {
|
||||||
|
constructor(props){
|
||||||
|
super(props)
|
||||||
|
this.state = {
|
||||||
|
mouseEnter:false,
|
||||||
|
articles:this.props.articles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(){
|
||||||
|
console.log(this.props.articles)
|
||||||
|
this.splitArticlesCategories()
|
||||||
|
}
|
||||||
|
|
||||||
|
splitArticlesCategories = () => {
|
||||||
|
let counterTab = 0;
|
||||||
|
let divided = [];
|
||||||
|
divided.push([this.state.articles[0]])
|
||||||
|
for (let i = 1; i<this.state.articles.length;i++){
|
||||||
|
if (this.state.articles[i].category_id === this.state.articles[i-1].category_id){
|
||||||
|
divided[counterTab].push(this.state.articles[i])
|
||||||
|
} else {
|
||||||
|
counterTab++
|
||||||
|
divided.push([this.state.articles[i]])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setState({articles:divided},()=>{
|
||||||
|
console.log(this.state.articles)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div id="articleContainer">
|
||||||
|
<div id="articles">
|
||||||
|
{this.state.articles[0][0] &&
|
||||||
|
this.state.articles.map((divided) =>
|
||||||
|
<>
|
||||||
|
<p>{divided[0].category.name}</p>
|
||||||
|
{divided.map((article) =>
|
||||||
|
<ArticleDetails 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}/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ArticlesByCategory
|
|
@ -1,4 +1,3 @@
|
||||||
import axios from 'axios';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import '../../css/Components/searchbar.css';
|
import '../../css/Components/searchbar.css';
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||||
import '../../css/Views/stock.css';
|
import '../../css/Views/stock.css';
|
||||||
import Header from '../Components/Header';
|
import Header from '../Components/Header';
|
||||||
import Articles from '../Components/Articles';
|
import Articles from '../Components/Articles';
|
||||||
|
import ArticlesByCategory from '../Components/ArticlesByCategory';
|
||||||
import Navbar from '../Components/Navbar';
|
import Navbar from '../Components/Navbar';
|
||||||
import CreateArticle from '../Components/CreateArticle';
|
import CreateArticle from '../Components/CreateArticle';
|
||||||
import 'react-perfect-scrollbar/dist/css/styles.css';
|
import 'react-perfect-scrollbar/dist/css/styles.css';
|
||||||
|
@ -29,7 +30,10 @@ export default class Stock extends React.Component {
|
||||||
article:{},
|
article:{},
|
||||||
imageFile:{},
|
imageFile:{},
|
||||||
articles:[],
|
articles:[],
|
||||||
categoryToModify:''
|
categoryToModify:'',
|
||||||
|
categorySorted:false,
|
||||||
|
dividedArticles:[],
|
||||||
|
onSortedCategories:false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +42,29 @@ export default class Stock extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implémenter la fonction sortArticles :
|
// Implémenter la fonction sortArticles :
|
||||||
|
sortArticles = (sortType) => {
|
||||||
|
|
||||||
|
let sorted;
|
||||||
|
if (sortType === "name"){
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
} else {
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortType === 'category_id'){
|
||||||
|
this.setState({articles:sorted},() => {
|
||||||
|
this.setState({onSortedCategories:true})
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
this.setState({articles:sorted},() => {
|
||||||
|
console.log(this.state.articles)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
getArticles = () => {
|
getArticles = () => {
|
||||||
axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles')
|
axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles')
|
||||||
|
@ -137,6 +164,7 @@ export default class Stock extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -155,8 +183,10 @@ export default class Stock extends React.Component {
|
||||||
<Sort handleChangeSortType={this.handleChangeSortType}/>
|
<Sort handleChangeSortType={this.handleChangeSortType}/>
|
||||||
</div>
|
</div>
|
||||||
<div id="articleBlock">
|
<div id="articleBlock">
|
||||||
{this.state.articles && this.state.articles[0]?
|
{this.state.articles && this.state.articles[0] ?
|
||||||
<Articles handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
this.state.onSortedCategories ?
|
||||||
|
<ArticlesByCategory handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
||||||
|
: <Articles handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
||||||
: <AppLoader/>
|
: <AppLoader/>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -27,6 +27,11 @@ export default class Stock extends React.Component {
|
||||||
<Header title='Le Ticket de Caisse'/>
|
<Header title='Le Ticket de Caisse'/>
|
||||||
<Navbar redirect="/stock" left="Monnaie" right="Le Stock"/>
|
<Navbar redirect="/stock" left="Monnaie" right="Le Stock"/>
|
||||||
<SearchBar/>
|
<SearchBar/>
|
||||||
|
<div id="emptyTicketBox">
|
||||||
|
<p id="emptyTicket">
|
||||||
|
Scanne tes articles pour remplir le ticket de caisse !
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<Footer/>
|
<Footer/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in a new issue