diff --git a/src/js/Components/Sort.js b/src/js/Components/Sort.js index 6a05b59..54d20be 100644 --- a/src/js/Components/Sort.js +++ b/src/js/Components/Sort.js @@ -20,13 +20,14 @@ class Sort extends Component {
- diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index e629b53..d3f21ec 100644 --- a/src/js/Views/Stock.js +++ b/src/js/Views/Stock.js @@ -17,7 +17,6 @@ import EditCategory from '../Components/EditCategory'; import Sort from '../Components/Sort'; import { Link } from 'react-router-dom'; import Selected from '../Components/Selected'; -import BarcodeReader from 'react-barcode-reader' export default class Stock extends React.Component { @@ -67,8 +66,9 @@ export default class Stock extends React.Component { sortArticles = (sortType) => { let sorted; + //TRI PAR ORDRE ALPHABETIQUE OU PRIX if (sortType === "name"){ - this.setState({orderIsVisible: false}) + this.setState({orderIsHidden: false}) //choix d'ordre possible if (this.state.lowToHigh) { //ordre alphabétique croissant sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name)) @@ -76,17 +76,31 @@ export default class Stock extends React.Component { //ordre alphabétique décroissant sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name)) } + } else if (sortType === "price") { + console.log('tri pix') + this.setState({orderIsHidden: false}) //choix d'ordre possible + if (this.state.lowToHigh) { + //ordre croissant + sorted = [...this.state.articles].sort((a, b) => a.price - b.price) + } else { + //ordre décroissant + sorted = [...this.state.articles].sort((a, b) => b.price - a.price) + } + } else { - this.setState({orderIsVisible: true}) + console.log('autre 1') + this.setState({orderIsHidden: true}) this.setState({lowToHigh: false}) sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]); } + //TRI PAR CATEGORIE if (sortType === 'category_id'){ - this.setState({articles:sorted},() => { - this.setState({onSortedCategories:true}) - }) + this.setState({articles:sorted},() => { + this.setState({onSortedCategories:true}) + }) }else{ + console.log('autre 2') this.setState({articles:sorted},() => { console.log(this.state.articles) this.setState({onSortedCategories:false}) @@ -153,23 +167,34 @@ export default class Stock extends React.Component { this.setState({onEditCategory:false}) } - handleChangeSortType = (e) => { - this.setState({sortType:e.target.value},()=>{ - if (this.state.sortType === "Ordre Alphabétique"){ - this.sortArticles("name") - } else if(this.state.sortType === "Catégorie"){ - this.sortArticles("category_id") - } else if(this.state.sortType === "Quantité"){ - this.sortArticles("quantity") - } + // handleChangeSortType = (e) => { + // console.log(e.target.value) + // this.setState({sortType:e.target.value},()=>{ + // if (this.state.sortType === "Ordre Alphabétique"){ + // this.sortArticles("name") + // } else if(this.state.sortType === "Catégorie"){ + // this.sortArticles("category_id") + // } else if(this.state.sortType === "Quantité"){ + // this.sortArticles("quantity") + // } else if(this.state.sortType === "Prix"){ + // this.sortArticles("price"); + // } + // }) + // } + + handleChangeSortType = (e) => { + console.log(e.target.value) + this.setState({sortType: e.target.value}, () => { + this.sortArticles(this.state.sortType) }) } //Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel handleChangeSortOrder = e => { this.setState({lowToHigh: (this.state.lowToHigh + 1) % 2},() => { - this.sortArticles("name"); + console.log(this.state.sortType) + this.sortArticles(this.state.sortType); }); } @@ -216,19 +241,12 @@ export default class Stock extends React.Component { } } - handleScan = (data) => { - this.setState({code:data},()=>{ - console.log(this.state.code) - }) - } - render() { if (!sessionStorage.getItem('token')){ return (
ERREUR

Vous n'êtes pas connecté

Retourner à l'Accueil
) } else { return (
-
{this.state.onNewArticle ? @@ -236,7 +254,7 @@ export default class Stock extends React.Component { : null}
- +
diff --git a/src/js/Views/Ticket.js b/src/js/Views/Ticket.js index 69371c8..c7a513f 100644 --- a/src/js/Views/Ticket.js +++ b/src/js/Views/Ticket.js @@ -6,34 +6,76 @@ import 'react-perfect-scrollbar/dist/css/styles.css'; import Footer from '../Components/Footer'; import { Link } from 'react-router-dom'; import SearchBar from '../Components/SearchBar'; +import BarcodeReader from 'react-barcode-reader'; +import axios from 'axios'; export default class Stock extends React.Component { constructor(props){ super(props) this.state = { + articles: [], + scannedCode: '' } + + this.handleScan = this.handleScan.bind(this); + } + + + getArticles = () => { + axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles') + .then(res => { + this.setState({articles : res.data}, () => { + console.log(this.state.articles) + }) + }) + .catch(error => { + console.log(error.response) + }) } componentDidMount() { -} - - render() { - if (!sessionStorage.getItem('token')){ - return (
ERREUR

Vous n'êtes pas connecté

Retourner à l'Accueil
) - } else { - return ( -
-
- - -
-

- Scanne tes articles pour remplir le ticket de caisse ! -

-
-
-
- )} + this.getArticles(); + } + + // RECHERCHE DE L'ARTICLE + getArticleByCode() { + let i=0; + let current = this.state.articles[i]; + let trouve = current === this.state.scannedCode ? true : false; + while(!trouve) { + i++; + current = this.state.articles[i]; + if (current.scannedCode === this.state.scannedCode) { + trouve = !trouve; + } } - } \ No newline at end of file + console.log(current); + } + + handleScan(code) { + this.setState({result: code}, () => { + console.log(this.state.result); + }); + } + + render() { + if (!sessionStorage.getItem('token')){ + return (
ERREUR

Vous n'êtes pas connecté

Retourner à l'Accueil
) + } else { + return ( +
+
+ + + +
+

+ Scanne tes articles pour remplir le ticket de caisse ! +

+
+
+ )} + } +} \ No newline at end of file