11// too lazy to add types ;)
22export function buttonOptions ( todo : any ) {
3- let tooltips = todo . conflicts . time
4- let color = 'success '
3+ let tooltips : String [ ] = [ ]
4+ let color = 'grey '
55 let icon = 'mdi-plus'
66
77 let sameCourse = todo . conflicts . sameCourse
88 // course already added
99 if ( sameCourse ) {
1010 // same class
1111 if ( sameCourse . crn == todo . crn ) {
12- icon = 'mdi-minus '
12+ icon = 'mdi-check '
1313 tooltips = [ 'Remove' ]
14- color = 'red'
14+ color = 'success'
15+ } else if ( todo . conflicts . _any ) {
16+ icon = 'mdi-alert-circle'
17+ tooltips = todo . conflicts . time . map ( ( c : any ) => 'Conflict: ' + c . name )
18+ color = 'error'
1519 } else {
16- color = 'grey'
17- console . log ( sameCourse )
20+ color = 'lime'
1821 tooltips = [ 'Course added in Section: ' + sameCourse . section , 'Replace?' ]
1922 }
2023 }
@@ -27,14 +30,33 @@ export function buttonOptions(todo: any) {
2730 }
2831 return { ...todo , buttonOptions }
2932}
30- export function findConflicts ( checkClass : any , selectedClasses : any ) {
33+ export function findConflicts ( checkClass : any , selectedClasses : any [ ] ) {
3134 // same course
32- let time : String [ ] = [ ]
3335 let sameCourse : any = selectedClasses . filter (
3436 ( c : any ) => c . code == checkClass . code
3537 ) [ 0 ]
38+
39+ // get rid of memory leak!
40+ if ( sameCourse ) {
41+ sameCourse . conflicts = { }
42+ sameCourse . buttonOptions = { }
43+ }
44+
45+ // time conflicts
46+ let time : any [ ] = [ ]
47+ time = selectedClasses . filter ( ( sc ) => {
48+ return (
49+ checkConflict ( sc , checkClass ) &&
50+ // can't conflict with itself or other same courses
51+ ( sc . crn != checkClass . crn || sc . code != checkClass . code )
52+ )
53+ } )
3654 let _any = time . length > 0
3755 let conflicts = { _any, time, sameCourse }
3856
3957 return { ...checkClass , conflicts }
4058}
59+
60+ function checkConflict ( c1 : any , c2 : any ) : boolean {
61+ return JSON . stringify ( c1 . days ) == JSON . stringify ( c2 . days )
62+ }
0 commit comments