@@ -95,11 +95,13 @@ export class DropGroupDirective implements OnInit {
95
95
}
96
96
97
97
private deleteCriterion ( inexclusion : string [ ] [ ] , criterionID : string ) : string [ ] [ ] {
98
- inexclusion . forEach ( ( idArray ) => {
98
+ inexclusion . every ( ( idArray ) => {
99
99
const index = idArray . indexOf ( criterionID ) ;
100
100
if ( index > - 1 ) {
101
101
idArray . splice ( index , 1 ) ;
102
+ return false ;
102
103
}
104
+ return true ;
103
105
} ) ;
104
106
inexclusion = inexclusion . filter ( ( item ) => item . length > 0 ) ;
105
107
return inexclusion ;
@@ -110,8 +112,7 @@ export class DropGroupDirective implements OnInit {
110
112
currentIndex : number
111
113
) : void {
112
114
this . criteria = this . feasibilityQuery . getInclusionCriteria ( ) ;
113
- this . criteria = this . deleteCriterion ( this . criteria , criterionID ) ;
114
- this . addCriterionToInnerArray ( this . criteria , criterionID , currentIndex ) ;
115
+ this . moveCriterion ( criterionID , previousIndex , currentIndex ) ;
115
116
this . queryProviderService . setInclusionCriteria ( this . criteria ) ;
116
117
}
117
118
private moveCriterionInExclusion (
@@ -120,11 +121,45 @@ export class DropGroupDirective implements OnInit {
120
121
currentIndex : number
121
122
) : void {
122
123
this . criteria = this . feasibilityQuery . getExclusionCriteria ( ) ;
123
- this . criteria = this . deleteCriterion ( this . criteria , criterionID ) ;
124
- this . addCriterionToInnerArray ( this . criteria , criterionID , currentIndex ) ;
124
+ this . moveCriterion ( criterionID , previousIndex , currentIndex ) ;
125
125
this . queryProviderService . setExclusionCriteria ( this . criteria ) ;
126
126
}
127
127
128
+ private moveCriterion ( criterionID : string , previousIndex : number , currentIndex : number ) : void {
129
+ const positionPrev = this . getPosition ( this . criteria , previousIndex ) ;
130
+ const positionCurr = this . getPosition ( this . criteria , currentIndex ) ;
131
+ let position = positionCurr ;
132
+ if ( previousIndex < currentIndex ) {
133
+ if ( positionPrev [ 0 ] < positionCurr [ 0 ] ) {
134
+ position = [ positionCurr [ 0 ] + 1 , positionCurr [ 1 ] ] ;
135
+ } else {
136
+ position = [ positionCurr [ 0 ] , positionCurr [ 1 ] + 1 ] ;
137
+ }
138
+ this . addCriterionToPosition ( this . criteria , criterionID , position ) ;
139
+ this . criteria = this . deleteCriterion ( this . criteria , criterionID ) ;
140
+ } else {
141
+ const addToInnerArray = positionPrev [ 1 ] > 0 || positionCurr [ 1 ] > 0 ;
142
+ this . criteria = this . deleteCriterion ( this . criteria , criterionID ) ;
143
+ this . addCriterionToPosition ( this . criteria , criterionID , positionCurr , addToInnerArray ) ;
144
+ }
145
+ }
146
+ private addCriterionToPosition (
147
+ criteria : string [ ] [ ] ,
148
+ criterionID : string ,
149
+ position : [ number , number ] ,
150
+ addToInnerArray ?: boolean
151
+ ) : void {
152
+ if ( position [ 0 ] >= criteria . length ) {
153
+ this . criteria . push ( [ criterionID ] ) ;
154
+ } else {
155
+ if ( criteria [ position [ 0 ] ] ?. length > 1 || addToInnerArray ) {
156
+ this . criteria [ position [ 0 ] ] . splice ( position [ 1 ] , 0 , criterionID ) ;
157
+ } else {
158
+ this . criteria . splice ( position [ 0 ] , 0 , [ criterionID ] ) ;
159
+ }
160
+ }
161
+ }
162
+
128
163
private addCriterionToInnerArray (
129
164
criteria : string [ ] [ ] ,
130
165
criterionID : string ,
0 commit comments