Adam Shaw 7 anni fa
parent
commit
8ff6db5725
3 ha cambiato i file con 27 aggiunte e 18 eliminazioni
  1. 1 1
      src/interactions/DateSelecting.ts
  2. 13 9
      src/structs/date-span.ts
  3. 13 8
      src/validation.ts

+ 1 - 1
src/interactions/DateSelecting.ts

@@ -64,7 +64,7 @@ export default class DateSelecting {
       )
 
       if (!this.component.isSelectionValid(dragSelection)) {
-        isInvalid = false
+        isInvalid = true
         dragSelection = null
       }
     }

+ 13 - 9
src/structs/date-span.ts

@@ -86,17 +86,20 @@ export function parseOpenDateSpan(raw: OpenDateSpanInput, dateEnv: DateEnv): Ope
 }
 
 export function isDateSpansEqual(span0: DateSpan, span1: DateSpan): boolean {
-  return rangesEqual(span0.range, span1.range) && isDateSpanPropsEqual(span0, span1)
+  return rangesEqual(span0.range, span1.range) &&
+    span0.isAllDay === span1.isAllDay &&
+    isSpanPropsEqual(span0, span1)
 }
 
-// besides range
-export function isDateSpanPropsEqual(span0: DateSpan, span1: DateSpan): boolean {
+// the NON-DATE-RELATED props
+export function isSpanPropsEqual(span0: DateSpan, span1: DateSpan): boolean {
 
-  if (!isDateSpanPropsWithin(span0, span1)) {
+  if (!isSpanPropsMatching(span0, span1)) {
     return false
   }
 
   // are there any props that span0 has that span1 DOESN'T have?
+  // both have range/allDay, so no need to special-case.
   for (let propName in span0) {
     if (!(propName in span1)) {
       return false
@@ -106,12 +109,13 @@ export function isDateSpanPropsEqual(span0: DateSpan, span1: DateSpan): boolean
   return true
 }
 
-// does subjectSpan have all the props that validationSpan has? (subjectSpan can be a superset)
-export function isDateSpanPropsWithin(subjectSpan: DateSpan, validationSpan: DateSpan): boolean {
+// does subjectSpan have all the props/values that matchSpan does?
+// subjectSpan is allowed to have more
+export function isSpanPropsMatching(subjectSpan: DateSpan, matchSpan: DateSpan): boolean {
 
-  for (let propName in validationSpan) {
-    if (propName !== 'range') {
-      if (subjectSpan[propName] !== validationSpan[propName]) {
+  for (let propName in matchSpan) {
+    if (propName !== 'range' && propName !== 'isAllDay') {
+      if (subjectSpan[propName] !== matchSpan[propName]) {
         return false
       }
     }

+ 13 - 8
src/validation.ts

@@ -1,6 +1,6 @@
 import { EventStore, getRelatedEvents, expandRecurring, getStoreRange } from './structs/event-store'
 import Calendar from './Calendar'
-import { DateSpan, parseOpenDateSpan, OpenDateSpanInput, isDateSpanPropsWithin, isDateSpanPropsEqual, OpenDateSpan } from './structs/date-span'
+import { DateSpan, parseOpenDateSpan, OpenDateSpanInput, OpenDateSpan, isSpanPropsEqual, isSpanPropsMatching } from './structs/date-span'
 import { EventInstance, EventDef, EventTuple } from './structs/event'
 import { EventSource, EventSourceHash } from './structs/event-source'
 import { rangeContainsRange, rangesIntersect } from './datelib/date-range'
@@ -64,7 +64,14 @@ function isEntitiesValid(
 
   for (let subjectEntity of entities) {
     for (let eventEntity of eventEntities) {
-      if (dateSpansCollide(subjectEntity.dateSpan, eventEntity.dateSpan)) {
+      if (
+        (
+          !subjectEntity.event ||
+          !eventEntity.event ||
+          subjectEntity.event.def.defId !== eventEntity.event.def.defId
+        ) &&
+        dateSpansCollide(subjectEntity.dateSpan, eventEntity.dateSpan)
+      ) {
         if (
           subjectEntity.overlap === false ||
           eventEntity.overlap === false ||
@@ -161,10 +168,7 @@ function constraintToSpans(constraint: Constraint, subjectSpan: DateSpan, calend
     return eventStoreToDateSpans(store)
 
   } else if (typeof constraint === 'object' && constraint) { // non-null object
-    let parsedSpan = parseOpenDateSpan(constraint, calendar.dateEnv)
-    if (parsedSpan) {
-      return [ parsedSpan ]
-    }
+    return [ constraint ] // already parsed
   }
 
   return []
@@ -199,11 +203,12 @@ function isDateSpanAllowed(dateSpan: DateSpan, moving: EventTuple | null, allow:
 }
 
 function dateSpansCollide(span0: DateSpan, span1: DateSpan): boolean {
-  return rangesIntersect(span0.range, span1.range) && isDateSpanPropsEqual(span0, span1)
+  return rangesIntersect(span0.range, span1.range) && isSpanPropsEqual(span0, span1)
 }
 
 function dateSpanContainsOther(outerSpan: DateSpan, subjectSpan: DateSpan): boolean {
-  return rangeContainsRange(outerSpan.range, subjectSpan.range) && isDateSpanPropsWithin(subjectSpan, outerSpan)
+  return rangeContainsRange(outerSpan.range, subjectSpan.range) &&
+    isSpanPropsMatching(subjectSpan, outerSpan) // subjectSpan has all the props that outerSpan has?
 }
 
 function eventStoreToDateSpans(store: EventStore): DateSpan[] {