From 4f47f96b4c011685b914651cb0932817801810fb Mon Sep 17 00:00:00 2001 From: Flo E Date: Fri, 5 Feb 2021 18:47:17 +0100 Subject: [PATCH 1/3] debut ajout tri par prix --- src/js/Components/Sort.js | 3 +- src/js/Views/Stock.js | 29 +++++++------- src/js/Views/Ticket.js | 82 +++++++++++++++++++++++++++++---------- 3 files changed, 79 insertions(+), 35 deletions(-) diff --git a/src/js/Components/Sort.js b/src/js/Components/Sort.js index 6a05b59..93f7dad 100644 --- a/src/js/Components/Sort.js +++ b/src/js/Components/Sort.js @@ -23,10 +23,11 @@ class Sort extends Component { + - diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index 67789da..9b3bec1 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 if (sortType === "name"){ - this.setState({orderIsVisible: false}) + this.setState({orderIsHidden: false}) if (this.state.lowToHigh) { //ordre alphabétique croissant sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name)) @@ -77,21 +77,27 @@ export default class Stock extends React.Component { sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name)) } } else { - this.setState({orderIsVisible: true}) + 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{ this.setState({articles:sorted},() => { console.log(this.state.articles) this.setState({onSortedCategories:false}) }) } + + //TRI PAR PRIX + if (sortType === 'price') { + + } } getArticles = () => { @@ -161,6 +167,8 @@ export default class Stock extends React.Component { this.sortArticles("category_id") } else if(this.state.sortType === "Quantité"){ this.sortArticles("quantity") + } else if(this.state.sortType === "Prix"){ + this.sortArticles("price"); } }) @@ -216,19 +224,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 +237,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 From 1de84726e09046bd97d3a5af761ea61bfdc4da36 Mon Sep 17 00:00:00 2001 From: Flo E Date: Sat, 6 Feb 2021 00:40:59 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Les=20tris=20ordre=20croissant/decroissant?= =?UTF-8?q?=20fonctionnent=20ind=C3=A9pendamment,=20il=20faut=20rendre=20?= =?UTF-8?q?=C3=A7a=20generique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/Components/Sort.js | 2 +- src/js/Views/Stock.js | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/js/Components/Sort.js b/src/js/Components/Sort.js index 93f7dad..38c2d2d 100644 --- a/src/js/Components/Sort.js +++ b/src/js/Components/Sort.js @@ -23,7 +23,7 @@ class Sort extends Component { - +
diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index 9b3bec1..699d758 100644 --- a/src/js/Views/Stock.js +++ b/src/js/Views/Stock.js @@ -66,7 +66,7 @@ export default class Stock extends React.Component { sortArticles = (sortType) => { let sorted; - //TRI PAR ORDRE ALPHABETIQUE + //TRI PAR ORDRE ALPHABETIQUE OU PRIX if (sortType === "name"){ this.setState({orderIsHidden: false}) if (this.state.lowToHigh) { @@ -76,7 +76,19 @@ 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}) + 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 { + console.log('autre 1') this.setState({orderIsHidden: true}) this.setState({lowToHigh: false}) sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]); @@ -88,16 +100,12 @@ export default class Stock extends React.Component { this.setState({onSortedCategories:true}) }) }else{ + console.log('autre 2') this.setState({articles:sorted},() => { console.log(this.state.articles) this.setState({onSortedCategories:false}) }) } - - //TRI PAR PRIX - if (sortType === 'price') { - - } } getArticles = () => { @@ -160,6 +168,7 @@ export default class Stock extends React.Component { } handleChangeSortType = (e) => { + console.log(e.target.value) this.setState({sortType:e.target.value},()=>{ if (this.state.sortType === "Ordre Alphabétique"){ this.sortArticles("name") From cdf43438ccf40af273d7d4efb8c76b707c8c3994 Mon Sep 17 00:00:00 2001 From: Flo E Date: Sat, 6 Feb 2021 11:07:46 +0100 Subject: [PATCH 3/3] =?UTF-8?q?choix=20d'ordre=20fonctionne=20pour=20tous?= =?UTF-8?q?=20les=20tris=20qui=20en=20demandent,=20changement=20des=20valu?= =?UTF-8?q?e=20dans=20les=20options=20=C3=A0=20valider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/Components/Sort.js | 8 ++++---- src/js/Views/Stock.js | 36 ++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/js/Components/Sort.js b/src/js/Components/Sort.js index 38c2d2d..54d20be 100644 --- a/src/js/Components/Sort.js +++ b/src/js/Components/Sort.js @@ -20,10 +20,10 @@ class Sort extends Component {
diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index 699d758..195102d 100644 --- a/src/js/Views/Stock.js +++ b/src/js/Views/Stock.js @@ -68,7 +68,7 @@ export default class Stock extends React.Component { let sorted; //TRI PAR ORDRE ALPHABETIQUE OU PRIX if (sortType === "name"){ - this.setState({orderIsHidden: 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)) @@ -78,7 +78,7 @@ export default class Stock extends React.Component { } } else if (sortType === "price") { console.log('tri pix') - this.setState({orderIsHidden: false}) + 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) @@ -167,26 +167,34 @@ export default class Stock extends React.Component { this.setState({onEditCategory:false}) } + // 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},()=>{ - 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"); - } - + 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); }); }