@@ -143,7 +143,11 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
143143 for ( var alias in this . aliases ) {
144144 if ( this . aliases . hasOwnProperty ( alias ) ) {
145145 Ext4 . each ( this . aliases [ alias ] , function ( id ) {
146- msg += "<div class='labkey-error'>Alias " + alias + " mapped to ID " + id + "</div>" ;
146+ msg += "<div class='labkey-error'>Alias " + alias + " mapped to ID " + id ;
147+ if ( this . subjects . indexOf ( alias ) !== - 1 ) {
148+ msg += " and is a real ID" ;
149+ }
150+ msg += "</div>" ;
147151 } , this ) ;
148152 }
149153 }
@@ -183,15 +187,21 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
183187
184188 handleAliasResults : function ( results ) {
185189 this . notFound = Ext4 . clone ( this . subjects ) ;
190+ var updatedSubjects = [ ] ;
186191 Ext4 . each ( results . rows , function ( row ) {
187192
193+ var rowId = row [ this . aliasTable . idColumn ] ;
194+ updatedSubjects . push ( rowId ) ;
195+
188196 if ( this . aliasTable . aliasColumn ) {
189197
198+ var rowAlias = row [ this . aliasTable . aliasColumn ] ;
199+
190200 // Remove from notFound array if found
191- var subjIndex = this . notFound . indexOf ( row [ this . aliasTable . aliasColumn ] ) ;
201+ var subjIndex = this . notFound . indexOf ( rowAlias ) ;
192202 if ( subjIndex === - 1 && this . caseInsensitive ) {
193203 for ( var i = 0 ; i < this . notFound . length ; i ++ ) {
194- if ( row [ this . aliasTable . aliasColumn ] . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
204+ if ( rowAlias . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
195205 subjIndex = i ;
196206 break ;
197207 }
@@ -202,74 +212,64 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', {
202212 this . notFound . splice ( subjIndex , 1 ) ;
203213 }
204214
205- var index = this . subjects . indexOf ( row [ this . aliasTable . aliasColumn ] ) ;
215+ var index = this . subjects . indexOf ( rowAlias ) ;
206216 if ( index === - 1 && this . caseInsensitive ) {
207217 for ( var i = 0 ; i < this . subjects . length ; i ++ ) {
208- if ( row [ this . aliasTable . aliasColumn ] . toLowerCase ( ) === this . subjects [ i ] . toString ( ) . toLowerCase ( ) ) {
218+ if ( rowAlias . toLowerCase ( ) === this . subjects [ i ] . toString ( ) . toLowerCase ( ) ) {
209219 index = i ;
210220 break ;
211221 }
212222 }
213223 }
214224
215- if ( index !== - 1 ) {
216- this . subjects . splice ( index , 1 , row [ this . aliasTable . idColumn ] ) ;
217- }
218-
219225 // Resolve aliases
220- if ( row [ this . aliasTable . idColumn ] !== row [ this . aliasTable . aliasColumn ] ) {
226+ if ( rowId !== rowAlias ) {
221227
222- if ( index !== - 1 ) {
223- this . aliases [ row [ this . aliasTable . aliasColumn ] ] = [ row [ this . aliasTable . idColumn ] ] ;
228+ var aliasList = this . aliases [ rowAlias ] ;
229+ if ( aliasList ) {
230+ aliasList . push ( rowId ) ;
224231 }
225- // In case an alias matches multiple ID's
226232 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- }
233+ this . aliases [ rowAlias ] = [ rowId ] ;
234234 }
235235 }
236236 }
237237 else {
238238 // Remove from notFound array if found
239- var idIndex = this . notFound . indexOf ( row [ this . aliasTable . idColumn ] ) ;
239+ var idIndex = this . notFound . indexOf ( rowId ) ;
240240 if ( idIndex === - 1 && this . caseInsensitive ) {
241241 for ( var i = 0 ; i < this . notFound . length ; i ++ ) {
242- if ( row [ this . aliasTable . idColumn ] . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
242+ if ( rowId . toLowerCase ( ) === this . notFound [ i ] . toString ( ) . toLowerCase ( ) ) {
243243 idIndex = i ;
244244 break ;
245245 }
246246 }
247247 }
248248
249249 // TODO: Update this and LDK.Utils.splitIds when the case sensitive cache issues are fixed
250- if ( idIndex == - 1 ) {
250+ if ( idIndex === - 1 ) {
251251 for ( var nfIndex = 0 ; nfIndex < this . notFound . length ; nfIndex ++ ) {
252- if ( this . notFound [ nfIndex ] . toString ( ) . toUpperCase ( ) == row [ this . aliasTable . idColumn ] ) {
252+ if ( this . notFound [ nfIndex ] . toString ( ) . toUpperCase ( ) === rowId ) {
253253 idIndex = nfIndex ;
254254 break ;
255255 }
256256 }
257257 }
258258
259- if ( idIndex != - 1 ) {
259+ if ( idIndex !== - 1 ) {
260260 this . notFound . splice ( idIndex , 1 ) ;
261261 }
262262 }
263263 } , this ) ;
264264
265265 // Remove any not found
266266 Ext4 . each ( this . notFound , function ( id ) {
267- var found = this . subjects . indexOf ( id ) ;
268- if ( found != - 1 )
269- this . subjects . splice ( found , 1 ) ;
267+ var found = updatedSubjects . indexOf ( id ) ;
268+ if ( found !== - 1 )
269+ updatedSubjects . splice ( found , 1 ) ;
270270 } , this ) ;
271271
272- this . subjects = Ext4 . unique ( this . subjects ) ;
272+ this . subjects = Ext4 . unique ( updatedSubjects ) ;
273273 this . subjects . sort ( ) ;
274274 } ,
275275
0 commit comments