fix list of locations in calendar

This commit is contained in:
Julien Fastré 2022-06-30 19:38:32 +02:00
parent d87c6305fd
commit 71b6b158ba
6 changed files with 19 additions and 18 deletions

View File

@ -17,7 +17,7 @@ const getLocations = () => fetchResults('/api/1.0/main/location.json');
const getLocationTypes = () => fetchResults('/api/1.0/main/location-type.json'); const getLocationTypes = () => fetchResults('/api/1.0/main/location-type.json');
const getUserCurrentLocation = const getUserCurrentLocation =
() => fetch('/api/1.0/main/user-current-location.json') () => fetch('/api/1.0/main/user-current-location.json')
.then(response => { .then(response => {
if (response.ok) { return response.json(); } if (response.ok) { return response.json(); }
@ -35,6 +35,13 @@ const getLocationTypeByDefaultFor = (entity) => {
); );
}; };
/**
* Post a location
*
* **NOTE**: also in use for Calendar
* @param body
* @returns {Promise<T>}
*/
const postLocation = (body) => { const postLocation = (body) => {
const url = `/api/1.0/main/location.json`; const url = `/api/1.0/main/location.json`;
return fetch(url, { return fetch(url, {

View File

@ -55,7 +55,7 @@ const makeAccompanyingPeriodLocation = (locationType, store) => {
export default function prepareLocations(store) { export default function prepareLocations(store) {
// find the locations // find the locations
let allLocations = getLocations().then( let allLocations = getLocations().then(
(results) => { (results) => {
store.commit('addAvailableLocationGroup', { store.commit('addAvailableLocationGroup', {
@ -111,7 +111,7 @@ export default function prepareLocations(store) {
if (window.default_location_id) { if (window.default_location_id) {
for (let group of store.state.availableLocations) { for (let group of store.state.availableLocations) {
let location = group.locations.find((l) => l.id === window.default_location_id); let location = group.locations.find((l) => l.id === window.default_location_id);
if (location !== undefined & store.state.activity.location === null) { if (location !== undefined && store.state.activity.location === null) {
store.dispatch('updateLocation', location); store.dispatch('updateLocation', location);
break; break;
} }

View File

@ -1,14 +1,13 @@
import {toRaw} from "vue";
import { import {
addIdToValue, addIdToValue,
removeIdFromValue, removeIdFromValue,
mapEntity
} from './utils'; } from './utils';
import { import {
fetchCalendarRangeForUser, fetchCalendarRangeForUser,
fetchCalendarRemoteForUser, fetchCalendarRemoteForUser,
} from './../api'; } from './../api';
import {datetimeToISO} from 'ChillMainAssets/chill/js/date'; import {datetimeToISO} from 'ChillMainAssets/chill/js/date';
import {postLocation} from 'ChillActivityAssets/vuejs/Activity/api';
/** /**
* This will store a unique key for each value, and prevent to launch the same * This will store a unique key for each value, and prevent to launch the same

View File

@ -1,17 +1,12 @@
import 'es6-promise/auto'; import 'es6-promise/auto';
import { createStore } from 'vuex'; import { createStore } from 'vuex';
import { toRaw } from 'vue';
import { postLocation } from 'ChillActivityAssets/vuejs/Activity/api'; import { postLocation } from 'ChillActivityAssets/vuejs/Activity/api';
import getters from './getters'; import getters from './getters';
import actions from './actions'; import actions from './actions';
import mutations from './mutations'; import mutations from './mutations';
import { mapEntity } from './utils'; import { mapEntity } from './utils';
import { whoami } from '../api'; import { whoami } from '../api';
import prepareLocations from "ChillActivityAssets/vuejs/Activity/store.locations";
import {
getLocations, getLocationTypeByDefaultFor,
getUserCurrentLocation
} from "ChillActivityAssets/vuejs/Activity/api";
const debug = process.env.NODE_ENV !== 'production'; const debug = process.env.NODE_ENV !== 'production';
@ -59,4 +54,6 @@ for (let u of store.state.activity.users) {
store.commit('showUserOnCalendar', {ranges: false, remotes: false, user: u}); store.commit('showUserOnCalendar', {ranges: false, remotes: false, user: u});
} }
prepareLocations(store);
export default store; export default store;

View File

@ -162,15 +162,12 @@ export default {
userData.remotes = userData.remotes.concat(eventRemotes); userData.remotes = userData.remotes.concat(eventRemotes);
userData.remotesLoaded.push({start, end}); userData.remotesLoaded.push({start, end});
}, },
/*
// Calendar
setEvents(state, payload) {
console.log(payload)
state.currentEvent = {start: payload.start, end: payload.end}
},*/
// Location // Location
updateLocation(state, value) { updateLocation(state, value) {
console.log('### mutation: updateLocation', value); console.log('### mutation: updateLocation', value);
state.activity.location = value; state.activity.location = value;
} },
addAvailableLocationGroup(state, group) {
state.availableLocations.push(group);
},
}; };

View File

@ -18,6 +18,7 @@
{{ encore_entry_script_tags('mod_pickentity_type') }} {{ encore_entry_script_tags('mod_pickentity_type') }}
<script type="text/javascript"> <script type="text/javascript">
window.entity = {{ entity_json|json_encode|raw }}; window.entity = {{ entity_json|json_encode|raw }};
{% if app.user.currentLocation is not null %}window.default_location_id = {{ app.user.currentLocation.id }};{% endif %};
</script> </script>
{{ encore_entry_script_tags('vue_calendar') }} {{ encore_entry_script_tags('vue_calendar') }}
{% endblock %} {% endblock %}