From 6bef738581bd7650d457d97e55eb24f03d30eea7 Mon Sep 17 00:00:00 2001 From: labkey-martyp Date: Tue, 26 Jul 2022 17:49:01 -0700 Subject: [PATCH 1/2] Find matching subjects in results --- .../web/LDK/panel/SingleSubjectFilterType.js | 62 +++++++++++++++---- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js b/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js index 4dcfdd9c..02dcb936 100644 --- a/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js +++ b/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js @@ -189,10 +189,60 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', { LABKEY.Query.selectRows(this.aliasTable); }, + // This looks for rows that match subjects case insensitively. This is called due to the filter in the case insensitive + // case being "contains" instead of "equals" to get all possible casings. This also gets Ids that just contain the + // subject id as a substring. Thus we need this to filter out the non-matching rows. + getCaseInsensitiveMatches: function(results) { + var hasAlias = !!this.aliasTable.aliasColumn; + var updatedResults = []; + + Ext4.each(results.rows, function (row) { + if (hasAlias) { + var rowAlias = row[this.aliasTable.aliasColumn]; + + var aliasIndex = this.subjects.indexOf(rowAlias); + if (aliasIndex === -1) { + for (var i = 0; i < this.subjects.length; i++) { + if (rowAlias.toLowerCase() === this.subjects[i].toString().toLowerCase()) { + aliasIndex = i; + break; + } + } + } + + if (aliasIndex !== -1) { + updatedResults.push(row); + } + } + else { + var rowId = row[this.aliasTable.idColumn]; + + var rowIndex = this.subjects.indexOf(rowId); + if (rowIndex === -1) { + for (var i = 0; i < this.subjects.length; i++) { + if (rowId.toLowerCase() === this.subjects[i].toString().toLowerCase()) { + rowIndex = i; + break; + } + } + } + + if (rowIndex !== -1) { + updatedResults.push(row); + } + } + }, this) + return updatedResults; + }, + + handleAliasResults: function (results) { this.notFound = Ext4.clone(this.subjects); + + var rows = this.caseInsensitive ? this.getCaseInsensitiveMatches(results) : results.rows; var updatedSubjects = []; - Ext4.each(results.rows, function (row) { + + Ext4.each(rows, function (row) { var rowId = row[this.aliasTable.idColumn]; updatedSubjects.push(rowId); @@ -216,16 +266,6 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', { this.notFound.splice(subjIndex, 1); } - var index = this.subjects.indexOf(rowAlias); - if (index === -1 && this.caseInsensitive) { - for (var i = 0; i < this.subjects.length; i++) { - if (rowAlias.toLowerCase() === this.subjects[i].toString().toLowerCase()) { - index = i; - break; - } - } - } - // Resolve aliases if (rowId !== rowAlias) { From b14dd932cc343260c6f18ce314edffc6998dbec3 Mon Sep 17 00:00:00 2001 From: labkey-martyp Date: Wed, 27 Jul 2022 11:34:14 -0700 Subject: [PATCH 2/2] CR feedback --- .../web/LDK/panel/SingleSubjectFilterType.js | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js b/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js index 02dcb936..ee02c1d4 100644 --- a/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js +++ b/LDK/resources/web/LDK/panel/SingleSubjectFilterType.js @@ -197,39 +197,20 @@ Ext4.define('LDK.panel.SingleSubjectFilterType', { var updatedResults = []; Ext4.each(results.rows, function (row) { - if (hasAlias) { - var rowAlias = row[this.aliasTable.aliasColumn]; - - var aliasIndex = this.subjects.indexOf(rowAlias); - if (aliasIndex === -1) { - for (var i = 0; i < this.subjects.length; i++) { - if (rowAlias.toLowerCase() === this.subjects[i].toString().toLowerCase()) { - aliasIndex = i; - break; - } + var rowValue = hasAlias ? row[this.aliasTable.aliasColumn] : row[this.aliasTable.idColumn]; + var index = this.subjects.indexOf(rowValue); + + if (index === -1) { + for (var i = 0; i < this.subjects.length; i++) { + if (rowValue.toLowerCase() === this.subjects[i].toString().toLowerCase()) { + index = i; + break; } } - - if (aliasIndex !== -1) { - updatedResults.push(row); - } } - else { - var rowId = row[this.aliasTable.idColumn]; - var rowIndex = this.subjects.indexOf(rowId); - if (rowIndex === -1) { - for (var i = 0; i < this.subjects.length; i++) { - if (rowId.toLowerCase() === this.subjects[i].toString().toLowerCase()) { - rowIndex = i; - break; - } - } - } - - if (rowIndex !== -1) { - updatedResults.push(row); - } + if (index !== -1) { + updatedResults.push(row); } }, this) return updatedResults;