From 6f5c75f1dfdfd17fa2b9bcedfd5eb92ed0c479ec Mon Sep 17 00:00:00 2001 From: hayden-t Date: Mon, 24 Apr 2017 08:16:35 +1000 Subject: [PATCH 1/5] Column Label and Join Grouping Support Now joined columns go in their respective join titled array, to get around columns with same names from different joins clashing. Also (more for saved searches), a column assigned a label will override its default name, useful for preserving multiple same type formula columns. --- lib/search.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/search.js b/lib/search.js index 77e5098..7902890 100644 --- a/lib/search.js +++ b/lib/search.js @@ -325,7 +325,32 @@ this.Searcher = (function() { * @return {null} */ Searcher.prototype.appendResults = function(resultsBlock) { - this.results = this.results.concat(resultsBlock); + var newResultsBlock = []; + for ( var i = 0; resultsBlock != null && i < resultsBlock.length; i++ ) + { + var newResult = {"id":resultsBlock[i].getId(), "recordtype":resultsBlock[i].getRecordType(), "columns":{}}; + var result = resultsBlock[i]; + var columns = result.getAllColumns(); + var columnLen = columns.length; + + for (x = 0; x < columnLen; x++) + { + var column = columns[x]; + var name = column.getName(); + var label = column.getLabel(); + var join = column.getJoin(); + var value = result.getValue(column); + var nameOrLabel = (label ? label : name); + if(join && !label){ + join += 'Join'; + if(!(join in newResult.columns))newResult.columns[join] = {}; + newResult.columns[join][nameOrLabel] = value; + } + else newResult.columns[nameOrLabel] = value; + } + newResultsBlock.push(newResult); + } + this.results = this.results.concat(newResultsBlock); } /** From c7923b3781cbdac7c1a84b39ce413815f1e242c5 Mon Sep 17 00:00:00 2001 From: hayden-t Date: Mon, 24 Apr 2017 08:18:25 +1000 Subject: [PATCH 2/5] Column Label and Join Grouping Support Now joined columns go in their respective join titled array, to get around columns with same names from different joins clashing. Also (more for saved searches), a column assigned a label will override its default name, useful for preserving multiple same type formula columns. --- lib/saved_search.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/saved_search.js b/lib/saved_search.js index bfa50fc..3db35e2 100644 --- a/lib/saved_search.js +++ b/lib/saved_search.js @@ -158,7 +158,32 @@ this.SavedSearch = (function() { * @return {null} */ SavedSearch.prototype.appendResults = function(resultsBlock) { - this.results = this.results.concat(resultsBlock); + var newResultsBlock = []; + for ( var i = 0; resultsBlock != null && i < resultsBlock.length; i++ ) + { + var newResult = {"id":resultsBlock[i].getId(), "recordtype":resultsBlock[i].getRecordType(), "columns":{}}; + var result = resultsBlock[i]; + var columns = result.getAllColumns(); + var columnLen = columns.length; + + for (x = 0; x < columnLen; x++) + { + var column = columns[x]; + var name = column.getName(); + var label = column.getLabel(); + var join = column.getJoin(); + var value = result.getValue(column); + var nameOrLabel = (label ? label : name); + if(join && !label){ + join += 'Join'; + if(!(join in newResult.columns))newResult.columns[join] = {}; + newResult.columns[join][nameOrLabel] = value; + } + else newResult.columns[nameOrLabel] = value; + } + newResultsBlock.push(newResult); + } + this.results = this.results.concat(newResultsBlock); } /** From d52904e9395a40483332b36bb97083c7fcc6986c Mon Sep 17 00:00:00 2001 From: hayden-t Date: Mon, 24 Apr 2017 08:59:27 +1000 Subject: [PATCH 3/5] support for column values having Text and Value Text and Value Support --- lib/search.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/search.js b/lib/search.js index 7902890..406d77e 100644 --- a/lib/search.js +++ b/lib/search.js @@ -340,15 +340,18 @@ this.Searcher = (function() { var label = column.getLabel(); var join = column.getJoin(); var value = result.getValue(column); - var nameOrLabel = (label ? label : name); + var text = result.getText(column); + var joinTitle = join + 'Join'; + var columnTitle = (label ? label : name); + if(text && (text !== value))var columnData = {'name':text, 'internalid':value}; + else columnData = value; if(join && !label){ - join += 'Join'; - if(!(join in newResult.columns))newResult.columns[join] = {}; - newResult.columns[join][nameOrLabel] = value; + if(!(joinTitle in newResult.columns))newResult.columns[joinTitle] = {}; + newResult.columns[joinTitle][columnTitle] = columnData; } - else newResult.columns[nameOrLabel] = value; + else newResult.columns[columnTitle] = columnData; } - newResultsBlock.push(newResult); + newResultsBlock.push(newResult); } this.results = this.results.concat(newResultsBlock); } From 2614c3d8f9aeefd847608f699be50abcb59e1a5f Mon Sep 17 00:00:00 2001 From: hayden-t Date: Mon, 24 Apr 2017 10:27:46 +1000 Subject: [PATCH 4/5] camel case for internalId I decided i need to keep conformity with the way the API returns variables rather than how this library has been specifying them (all lower case) Also a note, to really make things similar all the non-joined fields should be in a ['basic'] named array --- lib/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search.js b/lib/search.js index 406d77e..c4c565b 100644 --- a/lib/search.js +++ b/lib/search.js @@ -343,7 +343,7 @@ this.Searcher = (function() { var text = result.getText(column); var joinTitle = join + 'Join'; var columnTitle = (label ? label : name); - if(text && (text !== value))var columnData = {'name':text, 'internalid':value}; + if(text && (text !== value))var columnData = {'name':text, 'internalId':value}; else columnData = value; if(join && !label){ if(!(joinTitle in newResult.columns))newResult.columns[joinTitle] = {}; From 15320c970a873af3b62748e4920abc21cfcd0064 Mon Sep 17 00:00:00 2001 From: hayden-t Date: Mon, 24 Apr 2017 10:29:30 +1000 Subject: [PATCH 5/5] brought up to speed with changes in search.js really they should/could be merged.... --- lib/saved_search.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/saved_search.js b/lib/saved_search.js index 3db35e2..ef67197 100644 --- a/lib/saved_search.js +++ b/lib/saved_search.js @@ -173,15 +173,18 @@ this.SavedSearch = (function() { var label = column.getLabel(); var join = column.getJoin(); var value = result.getValue(column); - var nameOrLabel = (label ? label : name); + var text = result.getText(column); + var joinTitle = join + 'Join'; + var columnTitle = (label ? label : name); + if(text && (text !== value))var columnData = {'name':text, 'internalId':value}; + else columnData = value; if(join && !label){ - join += 'Join'; - if(!(join in newResult.columns))newResult.columns[join] = {}; - newResult.columns[join][nameOrLabel] = value; + if(!(joinTitle in newResult.columns))newResult.columns[joinTitle] = {}; + newResult.columns[joinTitle][columnTitle] = columnData; } - else newResult.columns[nameOrLabel] = value; + else newResult.columns[columnTitle] = columnData; } - newResultsBlock.push(newResult); + newResultsBlock.push(newResult); } this.results = this.results.concat(newResultsBlock); }