|
|
@@ -6,13 +6,38 @@ import { assignTo } from '../util/object'
|
|
|
import Calendar from '../Calendar'
|
|
|
|
|
|
export interface EventMutation {
|
|
|
- dateDelta?: Duration
|
|
|
+ startDelta?: Duration
|
|
|
endDelta?: Duration
|
|
|
standardProps?: any // for the def
|
|
|
extendedProps?: any // for the def
|
|
|
}
|
|
|
|
|
|
-export function computeEventDisplacement(eventStore: EventStore, instanceId: string, mutation: EventMutation, calendar: Calendar): EventStore {
|
|
|
+export function applyMutationToRelated(eventStore: EventStore, instanceId: string, mutation: EventMutation, calendar: Calendar): EventStore {
|
|
|
+ let relatedStore = getRelatedEvents(eventStore, instanceId)
|
|
|
+ relatedStore = applyMutationToAll(relatedStore, mutation, calendar)
|
|
|
+ return mergeStores(eventStore, relatedStore)
|
|
|
+}
|
|
|
+
|
|
|
+export function applyMutationToAll(eventStore: EventStore, mutation: EventMutation, calendar: Calendar): EventStore {
|
|
|
+ let newStore = { defs: {}, instances: {} }
|
|
|
+
|
|
|
+ for (let defId in eventStore.defs) {
|
|
|
+ let def = eventStore.defs[defId]
|
|
|
+
|
|
|
+ newStore.defs[defId] = applyMutationToDef(def, mutation)
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let instanceId in eventStore.instances) {
|
|
|
+ let instance = eventStore.instances[instanceId]
|
|
|
+ let def = eventStore.defs[instance.defId]
|
|
|
+
|
|
|
+ newStore.instances[instanceId] = applyMutationToInstance(instance, def, mutation, calendar)
|
|
|
+ }
|
|
|
+
|
|
|
+ return newStore
|
|
|
+}
|
|
|
+
|
|
|
+export function getRelatedEvents(eventStore: EventStore, instanceId: string): EventStore {
|
|
|
let newStore = { defs: {}, instances: {} } // TODO: better name
|
|
|
let eventInstance = eventStore.instances[instanceId]
|
|
|
let eventDef = eventStore.defs[eventInstance.defId]
|
|
|
@@ -24,19 +49,18 @@ export function computeEventDisplacement(eventStore: EventStore, instanceId: str
|
|
|
let def = eventStore.defs[defId]
|
|
|
|
|
|
if (def === eventDef || matchGroupId && matchGroupId === def.groupId) {
|
|
|
- newStore.defs[defId] = applyMutationToDef(def, mutation)
|
|
|
+ newStore.defs[defId] = def
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (let instanceId in eventStore.instances) {
|
|
|
let instance = eventStore.instances[instanceId]
|
|
|
- let def = newStore.defs[instance.defId] // the already-modified version
|
|
|
|
|
|
if (
|
|
|
instance === eventInstance ||
|
|
|
matchGroupId && matchGroupId === eventStore.defs[instance.defId].groupId
|
|
|
) {
|
|
|
- newStore.instances[instanceId] = applyMutationToInstance(instance, def, mutation, calendar)
|
|
|
+ newStore.instances[instanceId] = instance
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -44,14 +68,10 @@ export function computeEventDisplacement(eventStore: EventStore, instanceId: str
|
|
|
return newStore
|
|
|
}
|
|
|
|
|
|
-// Applying
|
|
|
-
|
|
|
-export function applyMutation(eventStore: EventStore, instanceId: string, mutation: EventMutation, calendar: Calendar): EventStore {
|
|
|
- let displacement = computeEventDisplacement(eventStore, instanceId, mutation, calendar)
|
|
|
-
|
|
|
+function mergeStores(store0: EventStore, store1: EventStore): EventStore {
|
|
|
return {
|
|
|
- defs: assignTo({}, eventStore.defs, displacement.defs),
|
|
|
- instances: assignTo({}, eventStore.instances, displacement.instances)
|
|
|
+ defs: assignTo({}, store0.defs, store1.defs),
|
|
|
+ instances: assignTo({}, store0.instances, store1.instances)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -62,6 +82,10 @@ function applyMutationToDef(eventDef: EventDef, mutation: EventMutation) {
|
|
|
assignTo(copy, mutation.standardProps)
|
|
|
}
|
|
|
|
|
|
+ if (mutation.startDelta || mutation.endDelta) {
|
|
|
+ copy.hasEnd = true
|
|
|
+ }
|
|
|
+
|
|
|
if (mutation.extendedProps) {
|
|
|
copy.extendedProps = assignTo({}, copy.extendedProps, mutation.extendedProps)
|
|
|
}
|
|
|
@@ -88,10 +112,10 @@ function applyMutationToInstance(
|
|
|
copy.range = new UnzonedRange(start, end)
|
|
|
}
|
|
|
|
|
|
- if (mutation.dateDelta) {
|
|
|
+ if (mutation.startDelta) {
|
|
|
copy.range = new UnzonedRange(
|
|
|
- dateEnv.add(copy.range.start, mutation.dateDelta),
|
|
|
- dateEnv.add(copy.range.end, mutation.dateDelta)
|
|
|
+ dateEnv.add(copy.range.start, mutation.startDelta),
|
|
|
+ copy.range.end
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -102,7 +126,7 @@ function applyMutationToInstance(
|
|
|
)
|
|
|
} else if (mutation.endDelta) {
|
|
|
copy.range = new UnzonedRange(
|
|
|
- copy.range.end,
|
|
|
+ copy.range.start,
|
|
|
dateEnv.add(copy.range.end, mutation.endDelta),
|
|
|
)
|
|
|
}
|