Adam Shaw пре 7 година
родитељ
комит
0396ccfc7c
3 измењених фајлова са 20 додато и 16 уклоњено
  1. 15 12
      src/api/EventApi.ts
  2. 2 1
      src/structs/event.ts
  3. 3 3
      tests/automated/event-data/Event.source.js

+ 15 - 12
src/api/EventApi.ts

@@ -6,6 +6,7 @@ import { diffDates, computeAlignedDayRange } from '../util/misc'
 import { subtractDurations, DurationInput, createDuration } from '../datelib/duration'
 import { subtractDurations, DurationInput, createDuration } from '../datelib/duration'
 import { createFormatter, FormatterInput } from '../datelib/formatting'
 import { createFormatter, FormatterInput } from '../datelib/formatting'
 import EventSourceApi from './EventSourceApi'
 import EventSourceApi from './EventSourceApi'
+import { parseClassName } from '../util/html'
 
 
 export default class EventApi implements EventTuple {
 export default class EventApi implements EventTuple {
 
 
@@ -19,16 +20,6 @@ export default class EventApi implements EventTuple {
     this.instance = instance || null
     this.instance = instance || null
   }
   }
 
 
-  getSource(): EventSourceApi | null {
-    if (this.def.sourceId) {
-      return new EventSourceApi(
-        this.calendar,
-        this.calendar.state.eventSources[this.def.sourceId]
-      )
-    }
-    return null
-  }
-
   setProp(name: string, val: string) {
   setProp(name: string, val: string) {
     if (name.match(/^(start|end|date|allDay)$/)) {
     if (name.match(/^(start|end|date|allDay)$/)) {
       // error. date-related props need other methods
       // error. date-related props need other methods
@@ -40,6 +31,8 @@ export default class EventApi implements EventTuple {
         props = { startEditable: val, durationEditable: val }
         props = { startEditable: val, durationEditable: val }
       } else if (name === 'color') {
       } else if (name === 'color') {
         props = { backgroundColor: val, borderColor: val }
         props = { backgroundColor: val, borderColor: val }
+      } else if (name === 'classNames') {
+        props = { classNames: parseClassName(val) }
       } else {
       } else {
         props = { [name]: val }
         props = { [name]: val }
       }
       }
@@ -215,6 +208,16 @@ export default class EventApi implements EventTuple {
     })
     })
   }
   }
 
 
+  get source(): EventSourceApi | null {
+    if (this.def.sourceId) {
+      return new EventSourceApi(
+        this.calendar,
+        this.calendar.state.eventSources[this.def.sourceId]
+      )
+    }
+    return null
+  }
+
   get start(): Date | null {
   get start(): Date | null {
     return this.instance ?
     return this.instance ?
       this.calendar.dateEnv.toDate(this.instance.range.start) :
       this.calendar.dateEnv.toDate(this.instance.range.start) :
@@ -239,12 +242,12 @@ export default class EventApi implements EventTuple {
   get constraint(): any { return this.def.constraint }
   get constraint(): any { return this.def.constraint }
   get overlap(): any { return this.def.overlap }
   get overlap(): any { return this.def.overlap }
   get rendering(): string { return this.def.rendering }
   get rendering(): string { return this.def.rendering }
-  get classNames(): string[] { return this.def.classNames }
   get backgroundColor(): string { return this.def.backgroundColor }
   get backgroundColor(): string { return this.def.backgroundColor }
   get borderColor(): string { return this.def.borderColor }
   get borderColor(): string { return this.def.borderColor }
   get textColor(): string { return this.def.textColor }
   get textColor(): string { return this.def.textColor }
 
 
-  // NOTE: user can't modify extendedProps because Object.freeze was called in event-def parsing
+  // NOTE: user can't modify these because Object.freeze was called in event-def parsing
+  get classNames(): string[] { return this.def.classNames }
   get extendedProps(): any { return this.def.extendedProps }
   get extendedProps(): any { return this.def.extendedProps }
 
 
 }
 }

+ 2 - 1
src/structs/event.ts

@@ -170,7 +170,8 @@ export function parseEventDef(raw: EventNonDateInput, sourceId: string, allDay:
   def.hasEnd = hasEnd
   def.hasEnd = hasEnd
   def.extendedProps = assignTo(leftovers, def.extendedProps || {})
   def.extendedProps = assignTo(leftovers, def.extendedProps || {})
 
 
-  // help out EventApi::extendedProps from having user modify props
+  // help out EventApi from having user modify props
+  Object.freeze(def.classNames)
   Object.freeze(def.extendedProps)
   Object.freeze(def.extendedProps)
 
 
   return def
   return def

+ 3 - 3
tests/automated/event-data/Event.getSource.js → tests/automated/event-data/Event.source.js

@@ -1,4 +1,4 @@
-describe('Event::getSource', function() {
+describe('Event::source', function() {
 
 
   it('returns the correct source', function() {
   it('returns the correct source', function() {
     initCalendar({
     initCalendar({
@@ -10,7 +10,7 @@ describe('Event::getSource', function() {
       } ]
       } ]
     })
     })
     let event = currentCalendar.getEventById('eventA')
     let event = currentCalendar.getEventById('eventA')
-    let source = event.getSource()
+    let source = event.source
     expect(source.id).toBe('sourceA')
     expect(source.id).toBe('sourceA')
   })
   })
 
 
@@ -18,7 +18,7 @@ describe('Event::getSource', function() {
     initCalendar()
     initCalendar()
     currentCalendar.addEvent({ id: 'eventA', start: '2018-09-07' })
     currentCalendar.addEvent({ id: 'eventA', start: '2018-09-07' })
     let event = currentCalendar.getEventById('eventA')
     let event = currentCalendar.getEventById('eventA')
-    let source = event.getSource()
+    let source = event.source
     expect(source).toBe(null)
     expect(source).toBe(null)
   })
   })