Ver Fonte

fill in api object implementations

Adam Shaw há 7 anos atrás
pai
commit
167532f8f9

+ 47 - 1
src/api/EventApi.ts

@@ -13,9 +13,55 @@ export default class EventApi {
     this.instance = instance || null
   }
 
+  updateProp(name: string, val: string) {
+    let { instance } = this
+
+    if (instance) {
+      if (name.match(/^(start|end|date|isAllDay)$/)) {
+        // error. date-related props need other methods
+      } else {
+        let props
+
+        if (name === 'color') { // TODO: consolidate this logic with event struct?
+          props = { backgroundColor: val, borderColor: val }
+        } else {
+          props = { [name]: val }
+        }
+
+        this.calendar.dispatch({
+          type: 'MUTATE_EVENTS',
+          instanceId: instance.instanceId,
+          mutation: {
+            standardProps: props
+          }
+        })
+      }
+    }
+  }
+
+  updateExtendedProp(name: string, val: string) {
+    let { instance } = this
+
+    if (instance) {
+      this.calendar.dispatch({
+        type: 'MUTATE_EVENTS',
+        instanceId: instance.instanceId,
+        mutation: {
+          extendedProps: { [name]: val }
+        }
+      })
+    }
+  }
 
   remove() {
-    // TODO
+    let { instance } = this
+
+    if (instance) {
+      this.calendar.dispatch({
+        type: 'REMOVE_EVENT_INSTANCES',
+        instances: { [instance.instanceId]: instance }
+      })
+    }
   }
 
 }

+ 8 - 2
src/api/EventSourceApi.ts

@@ -12,11 +12,17 @@ export default class EventSourceApi {
   }
 
   remove() {
-    // TODO
+    this.calendar.dispatch({
+      type: 'REMOVE_EVENT_SOURCES',
+      sourceIds: [ this.internalEventSource.sourceId ]
+    })
   }
 
   refetch() {
-    // TODO
+    this.calendar.dispatch({
+      type: 'FETCH_EVENT_SOURCES',
+      sourceIds: [ this.internalEventSource.sourceId ]
+    })
   }
 
 }

+ 2 - 2
src/interactions/EventDragging.ts

@@ -178,8 +178,8 @@ export default class EventDragging {
       // TODO: more public triggers
       } else if (receivingCalendar) {
         initialCalendar.dispatch({
-          type: 'REMOVE_EVENTS',
-          eventStore: this.mutatedRelatedEvents!
+          type: 'REMOVE_EVENT_INSTANCES',
+          instances: this.mutatedRelatedEvents!.instances
         })
         receivingCalendar.dispatch({
           type: 'ADD_EVENTS',

+ 5 - 5
src/reducers/eventStore.ts

@@ -1,7 +1,7 @@
 import Calendar from '../Calendar'
 import { filterHash, arrayToHash } from '../util/object'
 import { EventMutation, applyMutationToEventStore } from '../structs/event-mutation'
-import { EventDef, EventInstance, EventInput } from '../structs/event'
+import { EventDef, EventInstance, EventInput, EventInstanceHash } from '../structs/event'
 import { EventStore, parseEventStore, mergeEventStores, getRelatedEvents } from '../structs/event-store'
 import { Action } from './types'
 import { EventSourceHash, EventSource } from '../structs/event-source'
@@ -26,8 +26,8 @@ export default function(eventStore: EventStore, action: Action, sourceHash: Even
     case 'MUTATE_EVENTS':
       return applyMutationToRelated(eventStore, action.instanceId, action.mutation, calendar)
 
-    case 'REMOVE_EVENTS':
-      return excludeInstances(eventStore, action.eventStore)
+    case 'REMOVE_EVENT_INSTANCES':
+      return excludeInstances(eventStore, action.instances)
 
     case 'REMOVE_EVENT_SOURCES':
       if (action.sourceIds) {
@@ -67,11 +67,11 @@ function receiveEvents(
   return eventStore
 }
 
-function excludeInstances(eventStore: EventStore, removals: EventStore): EventStore {
+function excludeInstances(eventStore: EventStore, removals: EventInstanceHash): EventStore {
   return {
     defs: eventStore.defs,
     instances: filterHash(eventStore.instances, function(instance: EventInstance) {
-      return !removals.instances[instance.instanceId]
+      return !removals[instance.instanceId]
     })
   }
 }

+ 2 - 2
src/reducers/types.ts

@@ -1,4 +1,4 @@
-import { EventInput } from '../structs/event'
+import { EventInput, EventInstanceHash } from '../structs/event'
 import { DateRange } from '../datelib/date-range'
 import { EventStore } from '../structs/event-store'
 import { EventMutation } from '../structs/event-mutation'
@@ -42,4 +42,4 @@ export type Action =
 
   { type: 'ADD_EVENTS', eventStore: EventStore, stick: boolean } | // TODO: use stick param
   { type: 'MUTATE_EVENTS', instanceId: string, mutation: EventMutation } |
-  { type: 'REMOVE_EVENTS', eventStore: EventStore }
+  { type: 'REMOVE_EVENT_INSTANCES', instances: EventInstanceHash }