Merge branch 'master' of https://git.etud.insa-toulouse.fr/bamarty/Site-Proximo
This commit is contained in:
commit
44ae9f21d5
1 changed files with 40 additions and 38 deletions
|
@ -42,37 +42,38 @@ export default class Stock extends React.Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.getArticles()
|
this.getArticles()
|
||||||
}
|
}
|
||||||
|
|
||||||
sortArticles = (sortType) => {
|
// Implémenter la fonction sortArticles :
|
||||||
|
sortArticles = (sortType) => {
|
||||||
let sorted;
|
|
||||||
if (sortType === "name"){
|
let sorted;
|
||||||
this.setState({orderIsVisible: false})
|
if (sortType === "name"){
|
||||||
if (this.state.sortOrder === 0) {
|
this.setState({orderIsVisible: false})
|
||||||
//ordre alphabétique croissant
|
if (this.state.sortOrder === 0) {
|
||||||
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
//ordre alphabétique croissant
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
} else {
|
||||||
|
//ordre alphabétique décroissant
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//ordre alphabétique décroissant
|
this.setState({orderIsVisible: true})
|
||||||
sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name))
|
this.setState({sortOrder: 0})
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.setState({orderIsVisible: true})
|
|
||||||
this.setState({sortOrder: 0})
|
|
||||||
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sortType === 'category_id'){
|
if (sortType === 'category_id'){
|
||||||
|
this.setState({articles:sorted},() => {
|
||||||
|
this.setState({onSortedCategories:true})
|
||||||
|
})
|
||||||
|
}else{
|
||||||
this.setState({articles:sorted},() => {
|
this.setState({articles:sorted},() => {
|
||||||
this.setState({onSortedCategories:true})
|
console.log(this.state.articles)
|
||||||
|
this.setState({onSortedCategories:false})
|
||||||
})
|
})
|
||||||
}else{
|
}
|
||||||
this.setState({articles:sorted},() => {
|
|
||||||
console.log(this.state.articles)
|
|
||||||
this.setState({onSortedCategories:false})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
getArticles = () => {
|
getArticles = () => {
|
||||||
axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles')
|
axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles')
|
||||||
|
@ -187,24 +188,25 @@ sortArticles = (sortType) => {
|
||||||
|
|
||||||
closeWithEscape = (e) => {
|
closeWithEscape = (e) => {
|
||||||
if (e.keyCode === 27){
|
if (e.keyCode === 27){
|
||||||
if (this.state.onEditArticle){
|
if (this.state.onEditArticle){
|
||||||
this.handleCloseEditArticle()
|
this.handleCloseEditArticle()
|
||||||
} else if(this.state.onNewArticle){
|
} else if(this.state.onNewArticle){
|
||||||
this.handleCloseNewArticle()
|
this.handleCloseNewArticle()
|
||||||
} else if(this.state.onNewCategory){
|
} else if(this.state.onNewCategory){
|
||||||
this.handleCloseNewCategory()
|
this.handleCloseNewCategory()
|
||||||
} else if(this.state.onEditCategory){
|
} else if(this.state.onEditCategory){
|
||||||
this.handleCloseEditCategory()
|
this.handleCloseEditCategory()
|
||||||
} else if(this.state.onCategories){
|
} else if(this.state.onCategories){
|
||||||
this.handleCloseCategories()
|
this.handleCloseCategories()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!sessionStorage.getItem('token')){
|
if (!sessionStorage.getItem('token')){
|
||||||
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>)
|
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>)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div id="stock" tabIndex={-1} onKeyDown={this.closeWithEscape}>
|
<div id="stock" tabIndex={-1} onKeyDown={this.closeWithEscape}>
|
||||||
<Header title='Le Stock'/>
|
<Header title='Le Stock'/>
|
||||||
|
|
Loading…
Reference in a new issue