mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
show household suggestion in household members editor
This commit is contained in:
parent
a8bf478ee8
commit
9aa3974071
@ -23,6 +23,21 @@ const householdMove = (payload) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchHouseholdSuggestionByAccompanyingPeriod = (personId) => {
|
||||||
|
const url = `/api/1.0/person/household/suggest/by-person/${personId}/through-accompanying-period-participation.json`;
|
||||||
|
return window.fetch(url)
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Error ({m: 'Error while fetching household suggestion', status: response.status});
|
||||||
|
}).then(data => Promise.resolve(data.results))
|
||||||
|
.catch(e => console.err(e));
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
householdMove,
|
householdMove,
|
||||||
|
fetchHouseholdSuggestionByAccompanyingPeriod,
|
||||||
};
|
};
|
||||||
|
@ -14,6 +14,23 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul v-if="allowChangeHousehold" class="record_actions">
|
<ul v-if="allowChangeHousehold" class="record_actions">
|
||||||
|
<li v-if="!showHouseholdSuggestion">
|
||||||
|
<button
|
||||||
|
class="sc-button"
|
||||||
|
@click="toggleHouseholdSuggestion"
|
||||||
|
>
|
||||||
|
{{ $tc('household_members_editor.show_household_suggestion',
|
||||||
|
countHouseholdSuggestion) }}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li v-if="showHouseholdSuggestion">
|
||||||
|
<button
|
||||||
|
class="sc-button"
|
||||||
|
@click="toggleHouseholdSuggestion"
|
||||||
|
>
|
||||||
|
{{ $t('household_members_editor.hide_household_suggestion') }}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
<li v-if="allowHouseholdCreate">
|
<li v-if="allowHouseholdCreate">
|
||||||
<button class="sc-button bt-create" @click="createHousehold">
|
<button class="sc-button bt-create" @click="createHousehold">
|
||||||
{{ $t('household_members_editor.household.create_household') }}
|
{{ $t('household_members_editor.household.create_household') }}
|
||||||
@ -30,12 +47,56 @@
|
|||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<div class="householdSuggestions">
|
||||||
|
<div v-if="showHouseholdSuggestion">
|
||||||
|
<p>{{ $t('household_members_editor.household_for_participants_accompanying_period') }}:</p>
|
||||||
|
<div class="householdSuggestionList">
|
||||||
|
<div
|
||||||
|
v-for="h in filterHouseholdSuggestionByAccompanyingPeriod"
|
||||||
|
class="item"
|
||||||
|
>
|
||||||
|
<household-viewer :household="h"></household-viewer>
|
||||||
|
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<button class="sc-button" @click="selectHousehold(h)">
|
||||||
|
{{ $t('household_members_editor.select_household') }}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div >
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
|
||||||
|
.householdSuggestionList {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
& > .item {
|
||||||
|
margin-bottom: 0.8rem;
|
||||||
|
width: calc(50% - 1rem);
|
||||||
|
border: 1px solid var(--chill-light-gray);
|
||||||
|
padding: 0.5rem 0.5rem 0 0.5rem;
|
||||||
|
|
||||||
|
ul.record_actions {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters, mapState } from 'vuex';
|
||||||
import HouseholdViewer from 'ChillPersonAssets/vuejs/_components/Household/Household.vue';
|
import HouseholdViewer from 'ChillPersonAssets/vuejs/_components/Household/Household.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -47,6 +108,12 @@ export default {
|
|||||||
...mapGetters([
|
...mapGetters([
|
||||||
'hasHousehold',
|
'hasHousehold',
|
||||||
'isHouseholdNew',
|
'isHouseholdNew',
|
||||||
|
'hasHouseholdSuggestion',
|
||||||
|
'countHouseholdSuggestion',
|
||||||
|
'filterHouseholdSuggestionByAccompanyingPeriod',
|
||||||
|
]),
|
||||||
|
...mapState([
|
||||||
|
'showHouseholdSuggestion',
|
||||||
]),
|
]),
|
||||||
household() {
|
household() {
|
||||||
return this.$store.state.household;
|
return this.$store.state.household;
|
||||||
@ -74,6 +141,12 @@ export default {
|
|||||||
},
|
},
|
||||||
forceLeaveWithoutHousehold() {
|
forceLeaveWithoutHousehold() {
|
||||||
this.$store.dispatch('forceLeaveWithoutHousehold');
|
this.$store.dispatch('forceLeaveWithoutHousehold');
|
||||||
|
},
|
||||||
|
toggleHouseholdSuggestion() {
|
||||||
|
this.$store.commit('toggleHouseholdSuggestion');
|
||||||
|
},
|
||||||
|
selectHousehold(h) {
|
||||||
|
this.$store.dispatch('selectHousehold', h);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -29,6 +29,10 @@ const appMessages = {
|
|||||||
remove_position: "Retirer des {position}",
|
remove_position: "Retirer des {position}",
|
||||||
remove_concerned: "Ne plus transférer",
|
remove_concerned: "Ne plus transférer",
|
||||||
household_part: "Ménage de destination",
|
household_part: "Ménage de destination",
|
||||||
|
hide_household_suggestion: "Masquer les suggestions",
|
||||||
|
show_household_suggestion: 'Aucune suggestion | Afficher une suggestion | Afficher {count} suggestions',
|
||||||
|
household_for_participants_accompanying_period: "Ces ménages partagent le même parcours",
|
||||||
|
select_household: "Choisir ce ménage",
|
||||||
dates_title: "Période de validité",
|
dates_title: "Période de validité",
|
||||||
dates: {
|
dates: {
|
||||||
start_date: "Début de validité",
|
start_date: "Début de validité",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
import { householdMove, householdMoveTest } from './../api.js';
|
import { householdMove, fetchHouseholdSuggestionByAccompanyingPeriod } from './../api.js';
|
||||||
import { datetimeToISO } from 'ChillMainAssets/js/date.js';
|
import { datetimeToISO } from 'ChillMainAssets/js/date.js';
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
@ -33,11 +33,16 @@ const store = createStore({
|
|||||||
allowHouseholdSearch: window.household_members_editor_data.allowHouseholdSearch,
|
allowHouseholdSearch: window.household_members_editor_data.allowHouseholdSearch,
|
||||||
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
|
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
|
||||||
forceLeaveWithoutHousehold: false,
|
forceLeaveWithoutHousehold: false,
|
||||||
|
householdSuggestionByAccompanyingPeriod: [],
|
||||||
|
showHouseholdSuggestion: false,
|
||||||
warnings: [],
|
warnings: [],
|
||||||
errors: []
|
errors: []
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
isHouseholdNew(state) {
|
isHouseholdNew(state) {
|
||||||
|
if (state.household === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return !Number.isInteger(state.household.id);
|
return !Number.isInteger(state.household.id);
|
||||||
},
|
},
|
||||||
hasHousehold(state) {
|
hasHousehold(state) {
|
||||||
@ -46,6 +51,21 @@ const store = createStore({
|
|||||||
hasHouseholdOrLeave(state) {
|
hasHouseholdOrLeave(state) {
|
||||||
return state.household !== null || state.forceLeaveWithoutHousehold;
|
return state.household !== null || state.forceLeaveWithoutHousehold;
|
||||||
},
|
},
|
||||||
|
hasHouseholdSuggestion(state, getters) {
|
||||||
|
return getters.filterHouseholdSuggestionByAccompanyingPeriod.length > 0;
|
||||||
|
},
|
||||||
|
countHouseholdSuggestion(state, getters) {
|
||||||
|
return getters.filterHouseholdSuggestionByAccompanyingPeriod.length;
|
||||||
|
},
|
||||||
|
filterHouseholdSuggestionByAccompanyingPeriod(state) {
|
||||||
|
if (state.household === null) {
|
||||||
|
return state.householdSuggestionByAccompanyingPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
return state.householdSuggestionByAccompanyingPeriod
|
||||||
|
.filter(h => h.id !== state.household.id)
|
||||||
|
;
|
||||||
|
},
|
||||||
hasPersonsWellPositionnated(state, getters) {
|
hasPersonsWellPositionnated(state, getters) {
|
||||||
return getters.needsPositionning === false
|
return getters.needsPositionning === false
|
||||||
|| (getters.persons.length > 0 && getters.concUnpositionned.length === 0);
|
|| (getters.persons.length > 0 && getters.concUnpositionned.length === 0);
|
||||||
@ -172,9 +192,25 @@ const store = createStore({
|
|||||||
state.household = null;
|
state.household = null;
|
||||||
state.forceLeaveWithoutHousehold = true;
|
state.forceLeaveWithoutHousehold = true;
|
||||||
},
|
},
|
||||||
|
selectHousehold(state, household) {
|
||||||
|
state.household = household;
|
||||||
|
state.forceLeaveWithoutHousehold = false;
|
||||||
|
},
|
||||||
|
setHouseholdSuggestionByAccompanyingPeriod(state, households) {
|
||||||
|
let existingIds = state.householdSuggestionByAccompanyingPeriod
|
||||||
|
.map(h => h.id);
|
||||||
|
for (let i in households) {
|
||||||
|
if (!existingIds.includes(households[i].id)) {
|
||||||
|
state.householdSuggestionByAccompanyingPeriod.push(households[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
setStartDate(state, dateI) {
|
setStartDate(state, dateI) {
|
||||||
state.startDate = dateI;
|
state.startDate = dateI;
|
||||||
},
|
},
|
||||||
|
toggleHouseholdSuggestion(state) {
|
||||||
|
state.showHouseholdSuggestion = !state.showHouseholdSuggestion;
|
||||||
|
},
|
||||||
setWarnings(state, warnings) {
|
setWarnings(state, warnings) {
|
||||||
state.warnings = warnings;
|
state.warnings = warnings;
|
||||||
// reset errors, which should come from servers
|
// reset errors, which should come from servers
|
||||||
@ -213,6 +249,10 @@ const store = createStore({
|
|||||||
commit('forceLeaveWithoutHousehold');
|
commit('forceLeaveWithoutHousehold');
|
||||||
dispatch('computeWarnings');
|
dispatch('computeWarnings');
|
||||||
},
|
},
|
||||||
|
selectHousehold({ commit }, h) {
|
||||||
|
commit('selectHousehold', h);
|
||||||
|
dispatch('computeWarnings');
|
||||||
|
},
|
||||||
setStartDate({ commit, dispatch }, date) {
|
setStartDate({ commit, dispatch }, date) {
|
||||||
commit('setStartDate', date);
|
commit('setStartDate', date);
|
||||||
dispatch('computeWarnings');
|
dispatch('computeWarnings');
|
||||||
@ -220,6 +260,12 @@ const store = createStore({
|
|||||||
setComment({ commit }, payload) {
|
setComment({ commit }, payload) {
|
||||||
commit('setComment', payload);
|
commit('setComment', payload);
|
||||||
},
|
},
|
||||||
|
fetchHouseholdSuggestionForConcerned({ commit, state }, person) {
|
||||||
|
fetchHouseholdSuggestionByAccompanyingPeriod(person.id)
|
||||||
|
.then(households => {
|
||||||
|
commit('setHouseholdSuggestionByAccompanyingPeriod', households);
|
||||||
|
});
|
||||||
|
},
|
||||||
computeWarnings({ commit, state, getters }) {
|
computeWarnings({ commit, state, getters }) {
|
||||||
let warnings = [],
|
let warnings = [],
|
||||||
payload;
|
payload;
|
||||||
@ -274,4 +320,10 @@ const store = createStore({
|
|||||||
|
|
||||||
store.dispatch('computeWarnings');
|
store.dispatch('computeWarnings');
|
||||||
|
|
||||||
|
if (concerned.length > 0) {
|
||||||
|
concerned.forEach(c => {
|
||||||
|
store.dispatch('fetchHouseholdSuggestionForConcerned', c.person);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export { store };
|
export { store };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user