Fixed: loading of main user through pick entity in calendar form

This commit is contained in:
Julien Fastré 2023-03-30 16:29:02 +02:00
parent 331443ae12
commit 866b92f7e5
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
5 changed files with 30 additions and 5 deletions

View File

@ -92,6 +92,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
/** /**
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod", inversedBy="calendars") * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod", inversedBy="calendars")
* @Serializer\Groups({"calendar:read", "read"})
*/ */
private ?AccompanyingPeriod $accompanyingPeriod = null; private ?AccompanyingPeriod $accompanyingPeriod = null;

View File

@ -15,6 +15,7 @@
:picked="null !== this.$store.getters.getMainUser ? [this.$store.getters.getMainUser] : []" :picked="null !== this.$store.getters.getMainUser ? [this.$store.getters.getMainUser] : []"
:removableIfSet="false" :removableIfSet="false"
:displayPicked="false" :displayPicked="false"
:suggested="this.suggestedUsers"
@addNewEntity="setMainUser" @addNewEntity="setMainUser"
></pick-entity> ></pick-entity>
</div> </div>
@ -143,6 +144,7 @@ export default {
slotMinTime: '09:00:00', slotMinTime: '09:00:00',
slotMaxTime: '18:00:00', slotMaxTime: '18:00:00',
hideWeekEnds: true, hideWeekEnds: true,
previousUser: [],
} }
}, },
computed: { computed: {
@ -188,11 +190,23 @@ export default {
users.push(this.$store.getters.getUserDataById(id).user); users.push(this.$store.getters.getUserDataById(id).user);
} }
return users; return users;
} },
suggestedUsers() {
const suggested = [];
this.$data.previousUser.forEach(u => {
if (u.id !== this.$store.getters.getMainUser.id) {
suggested.push(u)
}
});
return suggested;
},
}, },
methods: { methods: {
setMainUser(user) { setMainUser({entity}) {
console.log('setMainUser APP', user); const user = entity;
console.log('setMainUser APP', entity);
if (user.id !== this.$store.getters.getMainUser && ( if (user.id !== this.$store.getters.getMainUser && (
this.$store.state.activity.calendarRange !== null this.$store.state.activity.calendarRange !== null
@ -205,6 +219,14 @@ export default {
} }
} }
// add the previous user, if any, in the previous user list (in use for suggestion)
if (null !== this.$store.getters.getMainUser) {
const suggestedUids = new Set(this.$data.previousUser.map(u => u.id));
if (!suggestedUids.has(this.$store.getters.getMainUser.id)){
this.$data.previousUser.push(this.$store.getters.getMainUser);
}
}
this.$store.dispatch('setMainUser', user); this.$store.dispatch('setMainUser', user);
this.$store.commit('showUserOnCalendar', {user, ranges: true, remotes: true}); this.$store.commit('showUserOnCalendar', {user, ranges: true, remotes: true});
}, },

View File

@ -202,6 +202,8 @@ export default {
return dispatch('associateCalendarToRange', { range: null }).then(() => { return dispatch('associateCalendarToRange', { range: null }).then(() => {
commit('setMainUser', mainUser); commit('setMainUser', mainUser);
return dispatch('fetchCalendarEvents');
}); });
}, },

View File

@ -54,7 +54,7 @@ export const mapEntity = (entity: EventInput): EventInput => {
export const createUserData = (user: User, colorIndex: number): UserData => { export const createUserData = (user: User, colorIndex: number): UserData => {
const colorId = colorIndex % COLORS.length; const colorId = colorIndex % COLORS.length;
console.log('colorId', colorId);
return { return {
user: user, user: user,
calendarRanges: [], calendarRanges: [],

@ -1 +1 @@
Subproject commit 5b35e7ccd0735e5593835e28acbf82386c18e1b6 Subproject commit 5e478fdfbf429baf3ce852ae69eb1f7101b1b416