Compare commits
3 commits
a7884d9a3b
...
0f7ba3bedd
Author | SHA1 | Date | |
---|---|---|---|
0f7ba3bedd | |||
d6c7c56f4e | |||
b934e694de |
3 changed files with 108 additions and 72 deletions
|
@ -2,7 +2,7 @@
|
||||||
display:flex;
|
display:flex;
|
||||||
flex:1;
|
flex:1;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sortTxt{
|
#sortTxt{
|
||||||
|
@ -12,51 +12,64 @@
|
||||||
margin-right:1vw;
|
margin-right:1vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
#selectBlock{
|
#selectAndOrder{
|
||||||
background:#057B26;
|
display: flex;
|
||||||
margin-left:1vw;
|
flex-direction: column;
|
||||||
border-radius: 1.8vw;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#selectBox{
|
|
||||||
background: url("../../img/arrow_select.png") no-repeat;
|
|
||||||
background-size: 2.5vw;
|
|
||||||
background-position-y: center;
|
|
||||||
background-position-x: 16vw;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#sortOrder{
|
||||||
|
color: white;
|
||||||
|
font-family:'Wellfleet',cursive;
|
||||||
|
font-size: 1.2vw;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#sortSelect{
|
#selectBlock{
|
||||||
background: transparent;
|
background:#057B26;
|
||||||
appearance: none;
|
margin-left:1vw;
|
||||||
-webkit-appearance: none;
|
border-radius: 1.8vw;
|
||||||
-moz-appearance: none;
|
}
|
||||||
|
|
||||||
color:white;
|
#selectBox{
|
||||||
font-family:'Wellfleet',cursive;
|
background: url("../../img/arrow_select.png") no-repeat;
|
||||||
font-size:1.5vw;
|
background-size: 2.5vw;
|
||||||
cursor: pointer;
|
background-position-y: center;
|
||||||
padding:0.3vw 3vw 0.3vw 1vw;
|
background-position-x: 16vw;
|
||||||
border: 0.2vw solid black;
|
|
||||||
border-radius: 1.8vw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#sortSelect:focus{
|
#sortSelect{
|
||||||
background: transparent;
|
background: transparent;
|
||||||
appearance: none;
|
appearance: none;
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
-moz-appearance: none;
|
-moz-appearance: none;
|
||||||
|
|
||||||
|
color:white;
|
||||||
|
font-family:'Wellfleet',cursive;
|
||||||
|
font-size:1.5vw;
|
||||||
|
cursor: pointer;
|
||||||
|
padding:0.3vw 3vw 0.3vw 1vw;
|
||||||
|
border: 0.2vw solid black;
|
||||||
|
border-radius: 1.8vw;
|
||||||
|
}
|
||||||
|
|
||||||
outline:none;
|
#sortSelect:focus{
|
||||||
color:white;
|
background: transparent;
|
||||||
font-family:'Wellfleet',cursive;
|
appearance: none;
|
||||||
font-size:1.5vw;
|
-webkit-appearance: none;
|
||||||
cursor: pointer;
|
-moz-appearance: none;
|
||||||
padding:0.3vw 3vw 0.3vw 1vw;
|
|
||||||
border: 0.2vw solid black;
|
|
||||||
border-radius: 1.8vw;
|
|
||||||
}
|
|
||||||
|
|
||||||
.optionSort{
|
outline:none;
|
||||||
background:#057B26 ;
|
color:white;
|
||||||
}
|
font-family:'Wellfleet',cursive;
|
||||||
|
font-size:1.5vw;
|
||||||
|
cursor: pointer;
|
||||||
|
padding:0.3vw 3vw 0.3vw 1vw;
|
||||||
|
border: 0.2vw solid black;
|
||||||
|
border-radius: 1.8vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
.optionSort{
|
||||||
|
background:#057B26 ;
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ class Sort extends Component {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,13 +16,18 @@ class Sort extends Component {
|
||||||
<div id="sortTxt">
|
<div id="sortTxt">
|
||||||
Trier par
|
Trier par
|
||||||
</div>
|
</div>
|
||||||
<div id="selectBlock">
|
<div id="selectAndOrder">
|
||||||
<div id="selectBox">
|
<div id="selectBlock">
|
||||||
<select id="sortSelect" onChange={this.props.handleChangeSortType}>
|
<div id="selectBox">
|
||||||
<option className="optionSort" value="Ordre Alphabétique">Ordre Alphabétique</option>
|
<select id="sortSelect" onChange={this.props.handleChangeSortType}>
|
||||||
<option className="optionSort" value="Catégorie">Catégorie</option>
|
<option className="optionSort" value="Ordre Alphabétique">Ordre Alphabétique</option>
|
||||||
<option className="optionSort" value="Quantité">Quantité</option>
|
<option className="optionSort" value="Catégorie">Catégorie</option>
|
||||||
</select>
|
<option className="optionSort" value="Quantité">Quantité</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="sortOrder" onClick={this.props.handleChangeSortOrder} hidden={this.props.orderIsVisible}>
|
||||||
|
A-Z
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -35,6 +35,7 @@ export default class Stock extends React.Component {
|
||||||
categorySorted:false,
|
categorySorted:false,
|
||||||
onSortedCategories:false,
|
onSortedCategories:false,
|
||||||
onSearch:false,
|
onSearch:false,
|
||||||
|
sortOrder: 0,
|
||||||
selectedArticles:[]
|
selectedArticles:[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,13 +44,22 @@ export default class Stock extends React.Component {
|
||||||
this.getArticles()
|
this.getArticles()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implémenter la fonction sortArticles :
|
||||||
sortArticles = (sortType) => {
|
sortArticles = (sortType) => {
|
||||||
|
|
||||||
let sorted;
|
let sorted;
|
||||||
if (sortType === "name"){
|
if (sortType === "name"){
|
||||||
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.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 {
|
} else {
|
||||||
|
this.setState({orderIsVisible: true})
|
||||||
|
this.setState({sortOrder: 0})
|
||||||
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +73,6 @@ sortArticles = (sortType) => {
|
||||||
this.setState({onSortedCategories:false})
|
this.setState({onSortedCategories:false})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getArticles = () => {
|
getArticles = () => {
|
||||||
|
@ -127,7 +134,7 @@ sortArticles = (sortType) => {
|
||||||
this.setState({onEditCategory:false})
|
this.setState({onEditCategory:false})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeSortType = e => {
|
handleChangeSortType = (e) => {
|
||||||
this.setState({sortType:e.target.value},()=>{
|
this.setState({sortType:e.target.value},()=>{
|
||||||
if (this.state.sortType === "Ordre Alphabétique"){
|
if (this.state.sortType === "Ordre Alphabétique"){
|
||||||
this.sortArticles("name")
|
this.sortArticles("name")
|
||||||
|
@ -140,6 +147,18 @@ sortArticles = (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({sortOrder: (this.state.sortOrder + 1) % 2});
|
||||||
|
console.log(this.state.sortOrder)
|
||||||
|
if (this.state.sortOrder === 1) {
|
||||||
|
e.target.innerHTML = "Z-A"
|
||||||
|
} else {
|
||||||
|
e.target.innerHTML = "A-Z"
|
||||||
|
}
|
||||||
|
this.sortArticles("name");
|
||||||
|
}
|
||||||
|
|
||||||
searchArticles = () => {
|
searchArticles = () => {
|
||||||
this.setState({onSearch:true})
|
this.setState({onSearch:true})
|
||||||
let bodyFormData = new FormData()
|
let bodyFormData = new FormData()
|
||||||
|
@ -163,23 +182,22 @@ sortArticles = (sortType) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = event => {
|
handleSubmit = event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
this.searchArticles();
|
this.searchArticles();
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +214,7 @@ sortArticles = (sortType) => {
|
||||||
: null}
|
: null}
|
||||||
<SearchBar handleSubmit={this.handleSubmit} handleSearchChange={this.handleSearchChange}/>
|
<SearchBar handleSubmit={this.handleSubmit} handleSearchChange={this.handleSearchChange}/>
|
||||||
<div id="sortBlock">
|
<div id="sortBlock">
|
||||||
<Sort handleChangeSortType={this.handleChangeSortType}/>
|
<Sort handleChangeSortType={this.handleChangeSortType} handleChangeSortOrder={this.handleChangeSortOrder} orderIsVisible={this.state.orderIsVisible}/>
|
||||||
</div>
|
</div>
|
||||||
<div id="selectedBlock">
|
<div id="selectedBlock">
|
||||||
<Selected/>
|
<Selected/>
|
||||||
|
|
Loading…
Reference in a new issue