mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 16:13:50 +00:00
Address selection: add store + addressSuggestion
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Endpoint chill_main_address_reference_api_show
|
||||
* method GET, get AddressReference Object
|
||||
* @returns {Promise} a promise containing all AddressReference object
|
||||
*
|
||||
*/
|
||||
export const getReferenceAddress = () => {
|
||||
const url = `/api/1.0/main/address-reference.json`;
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
@@ -1,32 +1,22 @@
|
||||
import { createApp } from 'vue'
|
||||
import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'
|
||||
import { appMessages } from './js/i18n'
|
||||
import { addressMessages } from './js/i18n'
|
||||
import { getDataPromise } from './store'
|
||||
|
||||
import App from './App.vue';
|
||||
|
||||
// getDataPromise.then(store => {
|
||||
getDataPromise.then(store => {
|
||||
|
||||
// console.log('store address', store.state.address);
|
||||
console.log('store address', store.state.referenceAddresses);
|
||||
|
||||
// const i18n = _createI18n(appMessages);
|
||||
// console.log(i18n)
|
||||
const i18n = _createI18n(addressMessages);
|
||||
|
||||
// const app = createApp({
|
||||
// template: `<app></app>`,
|
||||
// })
|
||||
// .use(store)
|
||||
// .use(i18n)
|
||||
// .component('app', App)
|
||||
// .mount('#address');
|
||||
const app = createApp({
|
||||
template: `<app></app>`,
|
||||
})
|
||||
.use(store)
|
||||
.use(i18n)
|
||||
.component('app', App)
|
||||
.mount('#address');
|
||||
|
||||
// });
|
||||
|
||||
const i18n = _createI18n(appMessages);
|
||||
|
||||
const app = createApp({
|
||||
template: `<app></app>`,
|
||||
})
|
||||
.use(i18n)
|
||||
.component('app', App)
|
||||
.mount('#address');
|
||||
});
|
||||
|
@@ -1,15 +1,13 @@
|
||||
// import { mainMessages } from 'ChillMainAssets/vuejs/_js/i18n'
|
||||
|
||||
const appMessages = {
|
||||
const addressMessages = {
|
||||
fr: {
|
||||
address: {
|
||||
id: "id",
|
||||
},
|
||||
add_an_address: 'Ajouter une adresse'
|
||||
}
|
||||
};
|
||||
|
||||
// Object.assign(appMessages.fr, mainMessages.fr);
|
||||
|
||||
export {
|
||||
appMessages
|
||||
addressMessages
|
||||
};
|
||||
|
@@ -0,0 +1,115 @@
|
||||
import 'es6-promise/auto';
|
||||
import { createStore } from 'vuex';
|
||||
import { getReferenceAddress } from '../api';
|
||||
//import { searchPersons } from 'ChillPersonAssets/vuejs/_api/AddPersons'
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
// const id = window.accompanyingCourseId; //tmp TODO
|
||||
|
||||
const getDataPromise = getReferenceAddress()
|
||||
.then(referenceAddresses => new Promise((resolve, reject) => {
|
||||
|
||||
const store = createStore({
|
||||
strict: debug,
|
||||
state: {
|
||||
referenceAddresses: referenceAddresses.results,
|
||||
countries: ['france', 'belgium'] //TODO fetch countries from CHILL API
|
||||
// add_persons: {
|
||||
// query: "",
|
||||
// suggested: [],
|
||||
// selected: []
|
||||
// },
|
||||
// errorMsg: []
|
||||
},
|
||||
getters: {
|
||||
getCountries: state => state.countries,
|
||||
getReferenceAddresses: state => state.referenceAddresses,
|
||||
// getReferenceAddressesCities: state => {}, //TODO get unique cities from addressReference
|
||||
},
|
||||
mutations: {
|
||||
// removeParticipation(state, item) {
|
||||
// //console.log('mutation: remove item', item.id);
|
||||
// state.accompanying_course.participations = state.accompanying_course.participations.filter(participation => participation !== item);
|
||||
// },
|
||||
// closeParticipation(state, { participation, payload }) {
|
||||
// console.log('### mutation: close item', { participation, payload });
|
||||
// // temporaire, le temps que le backend ajoute la enddate
|
||||
// participation.endDate = { datetime: "2021-05-06T10:49:00+0200" };
|
||||
// // trouve dans le state le payload et le supprime du state
|
||||
// state.accompanying_course.participations = state.accompanying_course.participations.filter(participation => participation !== payload);
|
||||
// // pousse la participation
|
||||
// state.accompanying_course.participations.push(participation);
|
||||
// },
|
||||
// addParticipation(state, { participation, payload }) {
|
||||
// //console.log('### mutation: add participation', participation);
|
||||
// state.accompanying_course.participations.push(participation);
|
||||
// //console.log('count participations from state', state.accompanying_course.participations.length);
|
||||
// //console.log('avant', state.add_persons.selected);
|
||||
// state.add_persons.selected = state.add_persons.selected.filter(value => value !== payload);
|
||||
// //console.log('après', state.add_persons.selected);
|
||||
// state.add_persons.query = "";
|
||||
// state.add_persons.suggested = [];
|
||||
// },
|
||||
// setQuery(state, query) {
|
||||
// //console.log('q=', query);
|
||||
// state.add_persons = Object.assign({}, state.add_persons, query);
|
||||
// },
|
||||
// loadSuggestions(state, suggested) {
|
||||
// state.add_persons.suggested = suggested;
|
||||
// },
|
||||
// updateSelected(state, value) {
|
||||
// state.add_persons.selected = value;
|
||||
// }
|
||||
},
|
||||
actions: {
|
||||
// removeParticipation({ commit }, payload) {
|
||||
// commit('removeParticipation', payload);
|
||||
// },
|
||||
// closeParticipation({ commit }, payload) {
|
||||
// console.log('## action: fetch delete participation: payload', payload.person.id);
|
||||
// postParticipation(id, payload.person.id, 'DELETE')
|
||||
// .then(participation => new Promise((resolve, reject) => {
|
||||
// //console.log('payload', payload);
|
||||
// commit('closeParticipation', { participation, payload });
|
||||
// resolve();
|
||||
// }))
|
||||
// .catch((error) => {
|
||||
// console.log('error', error);
|
||||
// state.errorMsg.push(error.message);
|
||||
// });
|
||||
// },
|
||||
// addParticipation({ commit }, payload) {
|
||||
// console.log('## action: fetch post participation: payload', payload.id);
|
||||
// postParticipation(id, payload.id, 'POST')
|
||||
// .then(participation => new Promise((resolve, reject) => {
|
||||
// commit('addParticipation', { participation, payload });
|
||||
// resolve();
|
||||
// }))
|
||||
// .catch((error) => {
|
||||
// state.errorMsg.push(error.message);
|
||||
// });
|
||||
// },
|
||||
// setQuery({ commit }, payload) {
|
||||
// commit('setQuery', payload);
|
||||
// //console.log('## action: setquery: payload', payload);
|
||||
// if (payload.query.length >= 3) {
|
||||
// searchPersons(payload.query)
|
||||
// .then(suggested => new Promise((resolve, reject) => {
|
||||
// commit('loadSuggestions', suggested.results);
|
||||
// resolve();
|
||||
// }));
|
||||
// } else {
|
||||
// commit('loadSuggestions', []);
|
||||
// }
|
||||
// },
|
||||
// updateSelected({ commit }, payload) {
|
||||
// //console.log('## action: update selected values: payload', payload);
|
||||
// commit('updateSelected', payload);
|
||||
// }
|
||||
}
|
||||
});
|
||||
resolve(store);
|
||||
}));
|
||||
|
||||
export { getDataPromise };
|
||||
|
Reference in New Issue
Block a user