2023-03-25 16:31:36 +01:00
|
|
|
<search>
|
2023-03-28 13:06:28 +02:00
|
|
|
<div class="box p-1 m-2">
|
|
|
|
<div class="columns m-1">
|
2023-03-29 17:42:04 +02:00
|
|
|
<input onkeyup={filterSearch} class="input" type="input" placeholder={state.placeholder}>
|
|
|
|
<button class="button ml-1" disabled={!state.currentStep || state.updating} onclick={cruiseBack}><</button>
|
2023-03-28 13:06:28 +02:00
|
|
|
</div>
|
2023-03-25 16:31:36 +01:00
|
|
|
<div id="list-formations">
|
2023-03-26 15:03:06 +02:00
|
|
|
<ul>
|
2023-03-28 13:06:28 +02:00
|
|
|
<li class="m-1" each={item in this.state.items}>
|
2023-03-29 22:56:14 +02:00
|
|
|
<button class="button is-fullwidth p-2" disabled={state.updating} onclick={()=>cruiseForward(item.name)}>
|
|
|
|
<span style="font-size: .75em; max-size: 90%"><strong>{item.name}</strong></span>
|
|
|
|
<div style="margin-left: auto;"></div>
|
2023-03-28 13:06:28 +02:00
|
|
|
<span class="tag is-primary">{item.count}</span>
|
|
|
|
</button>
|
2023-03-26 15:03:06 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
2023-03-25 16:31:36 +01:00
|
|
|
</div>
|
2023-03-28 13:06:28 +02:00
|
|
|
</div>
|
2023-03-25 16:31:36 +01:00
|
|
|
<script>
|
2023-03-28 00:48:55 +02:00
|
|
|
import PAPI from '../javascript/parcoursup-link.js'
|
2023-03-26 15:03:06 +02:00
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
const PLACEHOLDERS = [
|
|
|
|
"Formation",
|
|
|
|
"Filière",
|
|
|
|
"Spécialité"
|
|
|
|
]
|
2023-03-29 16:50:48 +02:00
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
export default {
|
2023-03-29 16:50:48 +02:00
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
updateList() {
|
|
|
|
let promise
|
2023-03-29 16:50:48 +02:00
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
switch (this.state.currentStep) {
|
|
|
|
case 0:
|
|
|
|
promise = PAPI.fetchFilieres()
|
|
|
|
break
|
|
|
|
case 1:
|
2023-03-29 22:01:50 +02:00
|
|
|
promise = PAPI.fetchFiliere(this.state.course.fili)
|
2023-03-29 17:42:04 +02:00
|
|
|
break
|
|
|
|
case 2:
|
2023-03-29 22:01:50 +02:00
|
|
|
promise = PAPI.fetchSpecialites(this.state.course.sousfili)
|
2023-03-29 17:42:04 +02:00
|
|
|
break
|
2023-03-30 00:54:13 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return
|
2023-03-29 17:42:04 +02:00
|
|
|
}
|
2023-03-29 16:50:48 +02:00
|
|
|
|
2023-03-30 00:54:13 +02:00
|
|
|
this.update({
|
|
|
|
updating: true
|
|
|
|
})
|
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
promise.then((response) => {
|
|
|
|
this.state.allItems = response
|
|
|
|
this.filterSearch()
|
2023-03-29 22:56:14 +02:00
|
|
|
this.update({
|
|
|
|
updating: false
|
|
|
|
})
|
|
|
|
}, () => {
|
|
|
|
if (!this.state.currentStep) {
|
|
|
|
this.cruiseBack()
|
|
|
|
}
|
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
this.update({
|
|
|
|
updating: false
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2023-03-29 16:50:48 +02:00
|
|
|
|
2023-03-29 22:56:14 +02:00
|
|
|
clearSearch() {
|
|
|
|
this.$("input").value = ""
|
|
|
|
},
|
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
filterSearch() {
|
|
|
|
let input = this.$("input")
|
|
|
|
if (!input) return
|
|
|
|
|
|
|
|
let finalArray = []
|
|
|
|
|
|
|
|
//On évite de trier avant d'avoir plus de 1 lettres.
|
|
|
|
if (input.value.length > 1) {
|
|
|
|
finalArray = this.state.allItems.filter((item) => {
|
|
|
|
return item.name.toLowerCase().includes(input.value.toLowerCase())
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
finalArray = this.state.allItems
|
|
|
|
}
|
|
|
|
|
|
|
|
this.update({
|
|
|
|
items: finalArray
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
cruiseForward(selection) {
|
|
|
|
switch (this.state.currentStep) {
|
|
|
|
case 0:
|
2023-03-29 22:01:50 +02:00
|
|
|
this.state.course.fili = selection
|
2023-03-29 17:42:04 +02:00
|
|
|
break
|
|
|
|
|
|
|
|
case 1:
|
2023-03-29 22:01:50 +02:00
|
|
|
this.state.course.sousfili = selection
|
|
|
|
break
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
this.state.course.soussousfili = selection
|
2023-03-30 00:54:13 +02:00
|
|
|
this.props.updateCourse(this.state.course)
|
2023-03-29 22:56:14 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
2023-03-29 17:42:04 +02:00
|
|
|
this.state.currentStep++
|
|
|
|
|
|
|
|
this.updateList()
|
2023-03-29 22:56:14 +02:00
|
|
|
this.clearSearch()
|
2023-03-29 17:42:04 +02:00
|
|
|
this.update({
|
|
|
|
placeholder: PLACEHOLDERS[this.state.currentStep]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
cruiseBack() {
|
|
|
|
if (!this.state.currentStep) return
|
|
|
|
this.state.currentStep--
|
|
|
|
|
|
|
|
this.updateList()
|
2023-03-29 22:56:14 +02:00
|
|
|
this.clearSearch()
|
2023-03-29 17:42:04 +02:00
|
|
|
this.update({
|
|
|
|
placeholder: PLACEHOLDERS[this.state.currentStep]
|
|
|
|
})
|
|
|
|
},
|
2023-03-29 16:50:48 +02:00
|
|
|
|
|
|
|
onBeforeMount(props, state) {
|
|
|
|
//Initial state
|
|
|
|
this.state = {
|
2023-03-29 17:42:04 +02:00
|
|
|
placeholder: PLACEHOLDERS[0],
|
2023-03-29 16:50:48 +02:00
|
|
|
currentStep: 0,
|
|
|
|
allItems: null,
|
2023-03-29 17:42:04 +02:00
|
|
|
items: null,
|
2023-03-30 00:54:13 +02:00
|
|
|
course: {},
|
2023-03-29 22:56:14 +02:00
|
|
|
updating: false,
|
2023-03-29 16:50:48 +02:00
|
|
|
}
|
2023-03-29 17:42:04 +02:00
|
|
|
},
|
2023-03-29 16:50:48 +02:00
|
|
|
|
2023-03-29 22:56:14 +02:00
|
|
|
onMounted(props, state) {
|
2023-03-29 17:42:04 +02:00
|
|
|
this.updateList()
|
2023-03-29 16:50:48 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-25 16:31:36 +01:00
|
|
|
</script>
|
|
|
|
</search>
|