Commit 49a4a86d authored by GuiΩ's avatar GuiΩ
Browse files

Deal with no classes

parent efc804e4
Pipeline #503358 failed with stages
in 3 minutes and 48 seconds
......@@ -29,10 +29,13 @@ Events:
@show-question-tooltip="$emit('show-question-tooltip', $event)"/>
</template>
</div>
<button type="button" class="newfeuille-btn"
<button v-if="classe" type="button" class="newfeuille-btn"
@click="$store.dispatch('feuilles/addFeuille')">
Ajouter une feuille
</button>
<span v-if="! classe">
Commencez par ajouter vos classes en cliquant sur "Configuration" en haut à gauche.
</span>
</div>
</template>
......@@ -47,6 +50,9 @@ export default {
computed: {
feuilles() {
return this.$store.getters['feuilles/feuilles']
},
classe() {
return this.$store.getters['classes/currClasse']
}
},
}
......
......@@ -22,12 +22,12 @@
<router-link to="/am/configuration">Configuration</router-link>
</div>
<div class="center">
<select :value="annee" @input="setCurrentAnnee($event.target.value)">
<select v-if="annees.length" :value="annee" @input="setCurrentAnnee($event.target.value)">
<option v-for="annee in annees" :value="annee">
{{ annee }} - {{ annee + 1 }}
</option>
</select>
<select :value="classe_id" @input="setCurrentClasse($event.target.value)">
<select v-if="annees.length" :value="classe_id" @input="setCurrentClasse($event.target.value)">
<option v-for="classe_id in classes"
:key="classe_id"
:value="classe_id">
......
......@@ -39,7 +39,10 @@ const getters = {
* @returns the currently selected classe
*/
currClasse: (state) => {
return state.classes[state.curr_classe_id]
if (state.curr_classe_id)
return state.classes[state.curr_classe_id]
else
return null
},
}
......@@ -136,18 +139,23 @@ const actions = {
* @returns {Promise<void>}
*/
loadCurrClasses({commit, state}) {
return $axios.get("api/classe/?annee=" + state.curr_annee)
.then(response => {
let ids = []
for (const classe of response.data) {
ids.push(classe.id)
commit('CLASSE', classe);
}
commit('CURR_CLASSE_IDS', ids)
return this.dispatch('classes/setCurrentClasse', response.data[0].id)
}).catch(error => {
console.error(error);
});
if (state.curr_annee) {
return $axios.get("api/classe/?annee=" + state.curr_annee)
.then(response => {
let ids = []
for (const classe of response.data) {
ids.push(classe.id)
commit('CLASSE', classe);
}
commit('CURR_CLASSE_IDS', ids);
return this.dispatch('classes/setCurrentClasse', response.data[0].id)
}).catch(error => {
console.error(error);
});
} else {
commit('CURR_CLASSE_IDS', []);
return this.dispatch('classes/setCurrentClasse', null);
}
},
/**
......
......@@ -139,14 +139,16 @@ const actions = {
* @returns {Promise<void>}
*/
loadFeuilles({commit, state, rootState}) {
return $axios.get("api/feuille/?classe_id=" + rootState.classes.curr_classe_id)
.then(response => {
for (const feuille of response.data)
commit('FEUILLE', feuille);
})
.catch(error => {
console.error(error);
});
if (rootState.classes.curr_classe_id) {
return $axios.get("api/feuille/?classe_id=" + rootState.classes.curr_classe_id)
.then(response => {
for (const feuille of response.data)
commit('FEUILLE', feuille);
})
.catch(error => {
console.error(error);
});
}
},
/**
......@@ -288,13 +290,15 @@ const actions = {
},
loadSeances({commit, state, rootState}) {
return $axios.get('api/seancer/?classe_id=' + rootState.classes.curr_classe_id)
.then(result => {
for (const seance of result.data)
commit('SEANCE', seance);
}).catch(error => {
console.log(error);
})
if (rootState.classes.curr_classe_id) {
return $axios.get('api/seancer/?classe_id=' + rootState.classes.curr_classe_id)
.then(result => {
for (const seance of result.data)
commit('SEANCE', seance);
}).catch(error => {
console.log(error);
})
}
},
/**
*
......
......@@ -129,13 +129,15 @@ const actions = {
.catch(error => console.error(error))
},
loadQuestionsOfClasse({commit, state, rootState}) {
return $axios.get("api/question/?classe_id=" + rootState.classes.curr_classe_id)
.then(response => {
for (let question of response.data) {
commit('QUESTION', question)
}
})
.catch(error => console.error(error))
if (rootState.classes.curr_classe_id) {
return $axios.get("api/question/?classe_id=" + rootState.classes.curr_classe_id)
.then(response => {
for (let question of response.data) {
commit('QUESTION', question)
}
})
.catch(error => console.error(error))
}
},
loadQuestionsOfTheme({commit, state}, theme_id) {
return $axios.get('api/theme/' + theme_id + '/question_list/')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment