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() {
|
||||
this.getArticles()
|
||||
}
|
||||
}
|
||||
|
||||
sortArticles = (sortType) => {
|
||||
|
||||
let sorted;
|
||||
if (sortType === "name"){
|
||||
this.setState({orderIsVisible: false})
|
||||
if (this.state.sortOrder === 0) {
|
||||
//ordre alphabétique croissant
|
||||
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
||||
// Implémenter la fonction sortArticles :
|
||||
sortArticles = (sortType) => {
|
||||
|
||||
let sorted;
|
||||
if (sortType === "name"){
|
||||
this.setState({orderIsVisible: false})
|
||||
if (this.state.sortOrder === 0) {
|
||||
//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 {
|
||||
//ordre alphabétique décroissant
|
||||
sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name))
|
||||
this.setState({orderIsVisible: true})
|
||||
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({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 = () => {
|
||||
axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles')
|
||||
|
@ -187,24 +188,25 @@ sortArticles = (sortType) => {
|
|||
|
||||
closeWithEscape = (e) => {
|
||||
if (e.keyCode === 27){
|
||||
if (this.state.onEditArticle){
|
||||
this.handleCloseEditArticle()
|
||||
} else if(this.state.onNewArticle){
|
||||
this.handleCloseNewArticle()
|
||||
} else if(this.state.onNewCategory){
|
||||
this.handleCloseNewCategory()
|
||||
} else if(this.state.onEditCategory){
|
||||
this.handleCloseEditCategory()
|
||||
} else if(this.state.onCategories){
|
||||
this.handleCloseCategories()
|
||||
if (this.state.onEditArticle){
|
||||
this.handleCloseEditArticle()
|
||||
} else if(this.state.onNewArticle){
|
||||
this.handleCloseNewArticle()
|
||||
} else if(this.state.onNewCategory){
|
||||
this.handleCloseNewCategory()
|
||||
} else if(this.state.onEditCategory){
|
||||
this.handleCloseEditCategory()
|
||||
} else if(this.state.onCategories){
|
||||
this.handleCloseCategories()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
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>)
|
||||
} else {
|
||||
render() {
|
||||
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>)
|
||||
} else {
|
||||
return (
|
||||
<div id="stock" tabIndex={-1} onKeyDown={this.closeWithEscape}>
|
||||
<Header title='Le Stock'/>
|
||||
|
|
Loading…
Reference in a new issue