edit location on existing ranges

This commit is contained in:
2022-06-29 23:47:12 +02:00
parent adad4313a6
commit 9e93e2a3f9
7 changed files with 144 additions and 49 deletions

View File

@@ -53,7 +53,7 @@ export default <Module<CalendarRangesState, State>>{
}
return founds;
}
},
},
mutations: {
addRanges(state: CalendarRangesState, ranges: CalendarRange[]) {
@@ -83,11 +83,7 @@ export default <Module<CalendarRangesState, State>>{
},
addLoaded(state: CalendarRangesState, payload: { start: Date, end: Date }) {
state.rangesLoaded.push({start: payload.start.getTime(), end: payload.end.getTime()});
},/*
setRangesToCopy(state: State, payload: CalendarRange[]) {
state.rangesToCopy = payload
},*/
},
addRange(state: CalendarRangesState, payload: CalendarRange) {
const asEvent = calendarRangeToFullCalendarEvent(payload);
state.ranges.push({...asEvent, backgroundColor: 'white', borderColor: '#3788d8', textColor: 'black'});
@@ -116,6 +112,8 @@ export default <Module<CalendarRangesState, State>>{
if (found !== undefined) {
found.start = newEvent.start;
found.end = newEvent.end;
found.locationId = range.location.id;
found.locationName = range.location.name;
}
state.key = state.key + 1;
@@ -194,7 +192,7 @@ export default <Module<CalendarRangesState, State>>{
ctx.commit('removeRange', calendarRangeId);
});
},
patchRangeTime(ctx, {calendarRangeId, start, end}: {calendarRangeId: number, start: Date, end: Date}): void {
patchRangeTime(ctx, {calendarRangeId, start, end}: {calendarRangeId: number, start: Date, end: Date}): Promise<null> {
const url = `/api/1.0/calendar/calendar-range/${calendarRangeId}.json`;
const body = {
startDate: {
@@ -205,12 +203,33 @@ export default <Module<CalendarRangesState, State>>{
},
} as CalendarRangeEdit;
makeFetch<CalendarRangeEdit, CalendarRange>('PATCH', url, body)
return makeFetch<CalendarRangeEdit, CalendarRange>('PATCH', url, body)
.then((range) => {
ctx.commit('updateRange', range);
return Promise.resolve(null);
})
.catch((error) => {
console.error(error);
return Promise.resolve(null);
})
},
patchRangeLocation(ctx, {location, calendarRangeId}: {location: Location, calendarRangeId: number}): Promise<null> {
const url = `/api/1.0/calendar/calendar-range/${calendarRangeId}.json`;
const body = {
location: {
id: location.id,
type: "location"
},
} as CalendarRangeEdit;
return makeFetch<CalendarRangeEdit, CalendarRange>('PATCH', url, body)
.then((range) => {
ctx.commit('updateRange', range);
return Promise.resolve(null);
})
.catch((error) => {
console.error(error);
return Promise.resolve(null);
})
},
copyFromDayToAnotherDay(ctx, {from, to}: {from: Date, to: Date}): Promise<null> {

View File

@@ -51,43 +51,18 @@ export default <Module<CalendarRemotesState, State>> {
},
addLoaded(state: CalendarRemotesState, payload: {start: Date, end: Date}) {
state.remotesLoaded.push({start: payload.start.getTime(), end: payload.end.getTime()});
},/*
setRangesToCopy(state: State, payload: CalendarRange[]) {
state.rangesToCopy = payload
},*/
addRemote(state: CalendarRemotesState, payload: CalendarRemote) {
const asEvent = remoteToFullCalendarEvent(payload);
state.remotes.push(asEvent);
state.remotesIndex.add(asEvent.id);
state.key = state.key + 1;
},
removeRemote(state: CalendarRemotesState, payload: EventInput) {
/*
state.ranges = state.ranges.filter(
(r) => r.id !== payload.id
);
if (typeof payload.id === "string") {
state.rangesIndex.delete(payload.id);
}
state.key = state.key + 1;
*/
},
},
actions: {
fetchRemotes(ctx: Context, payload: {start: Date, end: Date}): Promise<null> {
console.log('fetchRanges', payload);
const start = payload.start;
const end = payload.end;
if (ctx.rootGetters['me/getMe'] === null) {
console.log('me is not there');
return Promise.resolve(null);
}
if (ctx.getters.isRemotesLoaded({start, end})) {
console.log('range already loaded');
return Promise.resolve(ctx.getters.getRangeSource);
}
@@ -102,6 +77,7 @@ export default <Module<CalendarRemotesState, State>> {
end
)
.then((remotes: CalendarRemote[]) => {
// to be add when reactivity problem will be solve ?
//ctx.commit('addRemotes', remotes);
const inputs = remotes
.map(cr => remoteToFullCalendarEvent(cr))

View File

@@ -19,6 +19,11 @@ export default <Module<LocationState, State>>{
currentLocation: null,
}
},
getters: {
getLocationById: (state) => (id: number): Location|undefined => {
return state.locations.find(l => l.id === id);
},
},
mutations: {
setLocations(state, locations): void {
state.locations = locations;