@@ -52,10 +52,10 @@ export class DropGroupDirective implements OnInit {
52
52
} else {
53
53
switch ( event . container . id ) {
54
54
case 'Exclusion' :
55
- this . moveCriterionInExclusion ( event . previousIndex , event . currentIndex ) ;
55
+ this . moveCriterionInExclusion ( droppedCriterion , event . previousIndex , event . currentIndex ) ;
56
56
break ;
57
57
case 'Inclusion' :
58
- this . moveCriterionInInclusion ( event . previousIndex , event . currentIndex ) ;
58
+ this . moveCriterionInInclusion ( droppedCriterion , event . previousIndex , event . currentIndex ) ;
59
59
break ;
60
60
default :
61
61
break ;
@@ -70,12 +70,12 @@ export class DropGroupDirective implements OnInit {
70
70
}
71
71
private addToInclusion ( droppedCriterion : string , currentIndex : number ) : void {
72
72
this . criteria = this . feasibilityQuery . getInclusionCriteria ( ) ;
73
- this . criteria . splice ( currentIndex , 0 , [ droppedCriterion ] ) ;
73
+ this . addCriterionToInnerArray ( this . criteria , droppedCriterion , currentIndex ) ;
74
74
this . queryProviderService . setInclusionCriteria ( this . criteria ) ;
75
75
}
76
76
private addToExclusion ( droppedCriterion : string , currentIndex : number ) : void {
77
77
this . criteria = this . feasibilityQuery . getExclusionCriteria ( ) ;
78
- this . criteria . splice ( currentIndex , 0 , [ droppedCriterion ] ) ;
78
+ this . addCriterionToInnerArray ( this . criteria , droppedCriterion , currentIndex ) ;
79
79
this . queryProviderService . setExclusionCriteria ( this . criteria ) ;
80
80
}
81
81
@@ -104,14 +104,55 @@ export class DropGroupDirective implements OnInit {
104
104
inexclusion = inexclusion . filter ( ( item ) => item . length > 0 ) ;
105
105
return inexclusion ;
106
106
}
107
- private moveCriterionInInclusion ( previousIndex : number , currentIndex : number ) : void {
107
+ private moveCriterionInInclusion (
108
+ criterionID : string ,
109
+ previousIndex : number ,
110
+ currentIndex : number
111
+ ) : void {
108
112
this . criteria = this . feasibilityQuery . getInclusionCriteria ( ) ;
109
- moveItemInArray ( this . criteria , previousIndex , currentIndex ) ;
113
+ this . criteria = this . deleteCriterion ( this . criteria , criterionID ) ;
114
+ this . addCriterionToInnerArray ( this . criteria , criterionID , currentIndex ) ;
110
115
this . queryProviderService . setInclusionCriteria ( this . criteria ) ;
111
116
}
112
- private moveCriterionInExclusion ( previousIndex : number , currentIndex : number ) : void {
117
+ private moveCriterionInExclusion (
118
+ criterionID : string ,
119
+ previousIndex : number ,
120
+ currentIndex : number
121
+ ) : void {
113
122
this . criteria = this . feasibilityQuery . getExclusionCriteria ( ) ;
114
- moveItemInArray ( this . criteria , previousIndex , currentIndex ) ;
123
+ this . criteria = this . deleteCriterion ( this . criteria , criterionID ) ;
124
+ this . addCriterionToInnerArray ( this . criteria , criterionID , currentIndex ) ;
115
125
this . queryProviderService . setExclusionCriteria ( this . criteria ) ;
116
126
}
127
+
128
+ private addCriterionToInnerArray (
129
+ criteria : string [ ] [ ] ,
130
+ criterionID : string ,
131
+ currentIndex : number
132
+ ) : void {
133
+ const position = this . getPosition ( criteria , currentIndex ) ;
134
+ if ( currentIndex >= criteria . length ) {
135
+ this . criteria . push ( [ criterionID ] ) ;
136
+ } else {
137
+ if ( criteria [ position [ 0 ] ] ?. length > 1 ) {
138
+ this . criteria [ 0 ] . splice ( position [ 1 ] , 0 , criterionID ) ;
139
+ } else {
140
+ this . criteria . splice ( position [ 0 ] , 0 , [ criterionID ] ) ;
141
+ }
142
+ }
143
+ }
144
+
145
+ private getPosition ( criteria : string [ ] [ ] , currentIndex : number ) : [ number , number ] {
146
+ let position : [ number , number ] = [ 0 , 0 ] ;
147
+ let count = 0 ;
148
+ criteria . forEach ( ( outer , outerIndex ) => {
149
+ outer . forEach ( ( inner , innerIndex ) => {
150
+ if ( count === currentIndex ) {
151
+ position = [ outerIndex , innerIndex ] ;
152
+ }
153
+ count ++ ;
154
+ } ) ;
155
+ } ) ;
156
+ return position ;
157
+ }
117
158
}
0 commit comments