mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
load suggestion WIP
This commit is contained in:
parent
05b2b2f9b8
commit
c179649c56
@ -0,0 +1,46 @@
|
|||||||
|
const _fetchHouseholdByAddressReference = (reference, page) => {
|
||||||
|
const perPage = 50;
|
||||||
|
const url = `/api/1.0/person/household/by-address-reference/${reference.id}.json?`
|
||||||
|
+ new URLSearchParams({item_per_page: perPage, page });
|
||||||
|
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json;charset=utf-8'
|
||||||
|
},
|
||||||
|
}).then(response => {
|
||||||
|
if (response.ok()) { return response.json(); }
|
||||||
|
throw Error({m: response.statusText });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchHouseholdByAddressReference = async (reference) => {
|
||||||
|
const url = `/api/1.0/person/household/by-address-reference/${reference.id}.json?`
|
||||||
|
+ new URLSearchParams({});
|
||||||
|
|
||||||
|
return _fetchHouseholdByAddressReference(reference, 1).then(data => {
|
||||||
|
let promises = [];
|
||||||
|
promises.push(Promise.resolve(data.results));
|
||||||
|
if (data.pagination.more) {
|
||||||
|
let count = data.count;
|
||||||
|
let per_page = data.pagination.item_per_page;
|
||||||
|
let at_end = data.count
|
||||||
|
let page = 1;
|
||||||
|
while ((at_end + per_page) < count) {
|
||||||
|
page = page + 1;
|
||||||
|
at_end = at_end + per_page;
|
||||||
|
promises.push(_fetchHouseholdByAddressReference(reference, page).then(data => {
|
||||||
|
return Promise.resolve(data.results);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return Promise.all(promises).then(results => {
|
||||||
|
return results.flat();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
fetchHouseholdByAddressReference
|
||||||
|
};
|
@ -1,5 +1,6 @@
|
|||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
import { householdMove, fetchHouseholdSuggestionByAccompanyingPeriod, fetchAddressSuggestionByPerson} from './../api.js';
|
import { householdMove, fetchHouseholdSuggestionByAccompanyingPeriod, fetchAddressSuggestionByPerson} from './../api.js';
|
||||||
|
import { fetchHouseholdByAddressReference } from 'ChillPersonAssets/chill/lib/household.js';
|
||||||
import { datetimeToISO } from 'ChillMainAssets/chill/js/date.js';
|
import { datetimeToISO } from 'ChillMainAssets/chill/js/date.js';
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
@ -42,7 +43,12 @@ 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: [],
|
/**
|
||||||
|
* Household suggestions
|
||||||
|
*
|
||||||
|
* (this is not restricted to "suggestion by accompanying periods")
|
||||||
|
*/
|
||||||
|
householdSuggestionByAccompanyingPeriod: [], // TODO rename into householdsSuggestion
|
||||||
showHouseholdSuggestion: window.household_members_editor_expand_suggestions === 1,
|
showHouseholdSuggestion: window.household_members_editor_expand_suggestions === 1,
|
||||||
addressesSuggestion: [],
|
addressesSuggestion: [],
|
||||||
showAddressSuggestion: true,
|
showAddressSuggestion: true,
|
||||||
@ -426,6 +432,13 @@ const store = createStore({
|
|||||||
fetchAddressSuggestionByPerson(state.concerned[i].person.id)
|
fetchAddressSuggestionByPerson(state.concerned[i].person.id)
|
||||||
.then(addresses => {
|
.then(addresses => {
|
||||||
commit('addAddressesSuggestion', addresses);
|
commit('addAddressesSuggestion', addresses);
|
||||||
|
let promises = [];
|
||||||
|
addresses.forEach(a => {
|
||||||
|
if (a.addressReference !== null) {
|
||||||
|
let households = fetchHouseholdByAddressReference(a.addressReference);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user