@@ -104,6 +104,9 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
104104 if ( ! report . subjectFieldName )
105105 return 'This report cannot be used with the selected filter type, because the report does not contain a ' + this . nounSingular + ' Id field' ;
106106
107+ if ( this . subjects . length === 0 )
108+ return 'Must enter at least one valid Subject ID.'
109+
107110 return null ;
108111 } ,
109112
@@ -143,7 +146,11 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
143146 for ( var alias in this . aliases ) {
144147 if ( this . aliases . hasOwnProperty ( alias ) ) {
145148 Ext4 . each ( this . aliases [ alias ] , function ( id ) {
146- msg += "<div class='labkey-error'>Alias " + alias + " mapped to ID " + id + "</div>" ;
149+ msg += "<div class='labkey-error'>Alias " + alias + " mapped to ID " + id ;
150+ if ( this . subjects . indexOf ( alias ) !== - 1 ) {
151+ msg += " and is a real ID" ;
152+ }
153+ msg += "</div>" ;
147154 } , this ) ;
148155 }
149156 }
@@ -165,7 +172,8 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
165172 // results than necessary in some cases, however those results are filtered to match the user input and non-matching
166173 // results are not used.
167174 var filterType = this . caseInsensitive ? LABKEY . Filter . Types . CONTAINS_ONE_OF : LABKEY . Filter . Types . EQUALS_ONE_OF ;
168- this . aliasTable . filterArray = [ LABKEY . Filter . create ( 'alias' , subjectArray . join ( ';' ) , filterType ) ] ;
175+ var filterCol = this . aliasTable . aliasColumn ? this . aliasTable . aliasColumn : this . aliasTable . idColumn ;
176+ this . aliasTable . filterArray = [ LABKEY . Filter . create ( filterCol , subjectArray . join ( ';' ) , filterType ) ] ;
169177 this . aliasTable . columns = this . aliasTable . idColumn + ( Ext4 . isDefined ( this . aliasTable . aliasColumn ) ? ',' + this . aliasTable . aliasColumn : '' ) ;
170178 } ,
171179
@@ -183,15 +191,21 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
183191
184192 handleAliasResults : function ( results ) {
185193 this . notFound = Ext4 . clone ( this . subjects ) ;
194+ var updatedSubjects = [ ] ;
186195 Ext4 . each ( results . rows , function ( row ) {
187196
197+ var rowId = row [ this . aliasTable . idColumn ] ;
198+ updatedSubjects . push ( rowId ) ;
199+
188200 if ( this . aliasTable . aliasColumn ) {
189201
202+ var rowAlias = row [ this . aliasTable . aliasColumn ] ;
203+
190204 // Remove from notFound array if found
191- var subjIndex = this . notFound . indexOf ( row [ this . aliasTable . aliasColumn ] ) ;
205+ var subjIndex = this . notFound . indexOf ( rowAlias ) ;
192206 if ( subjIndex === - 1 && this . caseInsensitive ) {
193207 for ( var i = 0 ; i < this . notFound . length ; i ++ ) {
194- if ( row [ this . aliasTable . aliasColumn ] . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
208+ if ( rowAlias . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
195209 subjIndex = i ;
196210 break ;
197211 }
@@ -202,74 +216,64 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
202216 this . notFound . splice ( subjIndex , 1 ) ;
203217 }
204218
205- var index = this . subjects . indexOf ( row [ this . aliasTable . aliasColumn ] ) ;
219+ var index = this . subjects . indexOf ( rowAlias ) ;
206220 if ( index === - 1 && this . caseInsensitive ) {
207221 for ( var i = 0 ; i < this . subjects . length ; i ++ ) {
208- if ( row [ this . aliasTable . aliasColumn ] . toLowerCase ( ) === this . subjects [ i ] . toString ( ) . toLowerCase ( ) ) {
222+ if ( rowAlias . toLowerCase ( ) === this . subjects [ i ] . toString ( ) . toLowerCase ( ) ) {
209223 index = i ;
210224 break ;
211225 }
212226 }
213227 }
214228
215- if ( index !== - 1 ) {
216- this . subjects . splice ( index , 1 , row [ this . aliasTable . idColumn ] ) ;
217- }
218-
219229 // Resolve aliases
220- if ( row [ this . aliasTable . idColumn ] !== row [ this . aliasTable . aliasColumn ] ) {
230+ if ( rowId !== rowAlias ) {
221231
222- if ( index !== - 1 ) {
223- this . aliases [ row [ this . aliasTable . aliasColumn ] ] = [ row [ this . aliasTable . idColumn ] ] ;
232+ var aliasList = this . aliases [ rowAlias ] ;
233+ if ( aliasList ) {
234+ aliasList . push ( rowId ) ;
224235 }
225- // In case an alias matches multiple ID's
226236 else {
227- for ( var alias in this . aliases ) {
228- if ( this . aliases . hasOwnProperty ( alias ) && row [ this . aliasTable . aliasColumn ] == alias ) {
229- this . aliases [ row [ this . aliasTable . aliasColumn ] ] . push ( row [ this . aliasTable . idColumn ] ) ;
230- index = this . subjects . indexOf ( this . aliases [ row [ this . aliasTable . aliasColumn ] ] [ 0 ] ) ;
231- this . subjects . splice ( index , 0 , row [ this . aliasTable . idColumn ] ) ;
232- }
233- }
237+ this . aliases [ rowAlias ] = [ rowId ] ;
234238 }
235239 }
236240 }
237241 else {
238242 // Remove from notFound array if found
239- var idIndex = this . notFound . indexOf ( row [ this . aliasTable . idColumn ] ) ;
243+ var idIndex = this . notFound . indexOf ( rowId ) ;
240244 if ( idIndex === - 1 && this . caseInsensitive ) {
241245 for ( var i = 0 ; i < this . notFound . length ; i ++ ) {
242- if ( row [ this . aliasTable . idColumn ] . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
246+ if ( rowId . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
243247 idIndex = i ;
244248 break ;
245249 }
246250 }
247251 }
248252
249253 // TODO: Update this and LDK.Utils.splitIds when the case sensitive cache issues are fixed
250- if ( idIndex == - 1 ) {
254+ if ( idIndex === - 1 ) {
251255 for ( var nfIndex = 0 ; nfIndex < this . notFound . length ; nfIndex ++ ) {
252- if ( this . notFound [ nfIndex ] . toString ( ) . toUpperCase ( ) == row [ this . aliasTable . idColumn ] ) {
256+ if ( this . notFound [ nfIndex ] . toString ( ) . toUpperCase ( ) === rowId ) {
253257 idIndex = nfIndex ;
254258 break ;
255259 }
256260 }
257261 }
258262
259- if ( idIndex != - 1 ) {
263+ if ( idIndex !== - 1 ) {
260264 this . notFound . splice ( idIndex , 1 ) ;
261265 }
262266 }
263267 } , this ) ;
264268
265269 // Remove any not found
266270 Ext4 . each ( this . notFound , function ( id ) {
267- var found = this . subjects . indexOf ( id ) ;
268- if ( found != - 1 )
269- this . subjects . splice ( found , 1 ) ;
271+ var found = updatedSubjects . indexOf ( id ) ;
272+ if ( found !== - 1 )
273+ updatedSubjects . splice ( found , 1 ) ;
270274 } , this ) ;
271275
272- this . subjects = Ext4 . unique ( this . subjects ) ;
276+ this . subjects = Ext4 . unique ( updatedSubjects ) ;
273277 this . subjects . sort ( ) ;
274278 } ,
275279
0 commit comments