Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#15] As an interim measure, allow a skip param to be used as a blank column #71

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/models/TableModel.gs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var defaultTableConfig_ = {
"position": "top", //(or "bottom", "top_bottom", "none") .. NOT_SUPPORTED: "bottom", "top_bottom"
"field_filters": [
"# eg -x.*.y / +x.y (start with -s where possible)",
"# pre-built groups: $$<name>",
"# pre-built groups: $$<name> ($$skipN for blank cols)",
"#(note fields are laid out in match order)"
], //(# to ignore an entry, [+-] to be +ve/-ve selection, // for regex else * for full wildcard)
"exclude_filtered_fields_from_autocomplete": true,
Expand Down
45 changes: 31 additions & 14 deletions src/server/utils/ElasticsearchResponseUtils.gs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ var ElasticsearchResponseUtils_ = (function() {
var cell = range.getCell(specialRows.headers, i + 1)
if (i < numDataCols) {
var nameOrAliasObj = fullCols[filteredCols[i]]
var nameOrAlias = nameOrAliasObj.alias || nameOrAliasObj.name
var nameOrAlias =
(null != nameOrAliasObj.alias) ? nameOrAliasObj.alias : nameOrAliasObj.name
cell.setValue(nameOrAlias)
} else {
cell.clearContent()
Expand Down Expand Up @@ -402,13 +403,17 @@ var ElasticsearchResponseUtils_ = (function() {
if (i < numDataCols) {
if (rowIsArray) {
var index = fullCols[filteredCols[i]].index
colArray.push(row[index])
if (index < row.size) {
colArray.push(row[index])
} else {
colArray.push("") //(probably a skip col)
}
} else {
var colName = fullCols[filteredCols[i]].name
if (row.hasOwnProperty(colName)) {
colArray.push(row[colName])
} else {
colArray.push("")
colArray.push("") //(probably a skip col)
}
}
} else {
Expand Down Expand Up @@ -553,12 +558,21 @@ var ElasticsearchResponseUtils_ = (function() {
isFieldWanted_(mutableCol.name, fieldFilters, onMatch)
})

//Add any $$skipN from the field filters to the mutableCols
fieldFilters.filter(function(fieldFilter) {
return fieldFilter.indexOf("$$skip") == 0
}).forEach(function(fieldFilter) {
var index = mutableCols.length
var col = { alias: "", name: fieldFilter, index: index }
matchState[fieldFilter] = [ col ]
mutableCols.push(col)
})

// Order within each group and apply aliases at the same time
var globalList = []
fieldFilters.concat([ defaultMatchField ]).forEach(function(fieldFilter) {
var fields = matchState[fieldFilter] || []
var startOfList = []
var endOfList = []
fieldAliases.forEach(function(alias) {
fields.forEach(function(mutableCol) {
if (mutableCol.name == alias.from) {
Expand Down Expand Up @@ -598,25 +612,28 @@ var ElasticsearchResponseUtils_ = (function() {
).replace(
"$$docmeta_fields", "/^(_id|_index|_score|_type)$/"
)
})
.forEach(function(elArrayStr) {
}).forEach(function(elArrayStr) {
((elArrayStr.indexOf("/") >= 0)
? [ elArrayStr ] //(1 regex per line)
: elArrayStr.split(","))
.map(function(el) { return el.trim() })
.filter(function(el) { return el && ('+' != el) && ('-' != el) })
.filter(function(el) { return el })
.forEach(function(el) {
var firstEl = ('-' == el[0]) ? '-' : '+'
if (('+' == el[0]) || ('-' == el[0])) {
el = el.substring(1)
}
if (('/' == el[0]) && ('/' == el[el.length - 1])) { //already a regex
el = el.substring(1, el.length - 1)
if (0 == el.indexOf("$$skip")) {
filterFields.push(el)
} else {
el = "^" + escapeRegExpNotStar(el).replace(/[*]/g, ".*") + "($|[.].*)"
var firstEl = ('-' == el[0]) ? '-' : '+'
if (('+' == el[0]) || ('-' == el[0])) {
el = el.substring(1)
}
if (('/' == el[0]) && ('/' == el[el.length - 1])) { //already a regex
el = el.substring(1, el.length - 1)
} else {
el = "^" + escapeRegExpNotStar(el).replace(/[*]/g, ".*") + "($|[.].*)"
}
filterFields.push(firstEl + el)
}
filterFields.push(firstEl + el)
})
})
return filterFields
Expand Down
15 changes: 9 additions & 6 deletions test/server/utils/TestElasticsearchResponseUtils.gs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ var TestElasticsearchResponseUtils_ = (function() {
TestService_.Utils.performTest(testResults, "various_usages", function() {
var filters1 = [
"/col[34]/",
"$$skip1",
"+/col[12][ab]?/",
"-filter_out"
"-filter_out",
"$$skip2"
]
var testCols = [
{ name: "col1" }, //there will match on group2
Expand All @@ -100,6 +102,7 @@ var TestElasticsearchResponseUtils_ = (function() {
{ name: "col4" }
]
var aliases = [
"$$skip2=Blank",
"col4=Column4",
"col2b=Column2b",
"col2a=Column2a",
Expand All @@ -112,15 +115,15 @@ var TestElasticsearchResponseUtils_ = (function() {
"col1", "Column2a", "Column2b", "col3", "filter_out", "Column4"
]
var testCols1 = TestService_.Utils.deepCopyJson(testCols)
var reorderedList = [ 5, 3, 2, 1, 0 ]
var reorderedList = [ 5, 3, 6, 2, 1, 0, 7 ] //(6 and 7 are the two skip fields)
var result = ElasticsearchResponseUtils_.calculateFilteredCols(testCols1, headerMeta)
var renamed = testCols1.map(function(el) { return el.alias || el.name })
var renamed = testCols1.map(function(el) { return (null != el.alias) ? el.alias : el.name })

TestService_.Utils.assertEquals(
reorderedList, result, "column order (+ve and -ve)"
)
TestService_.Utils.assertEquals(
renamedTestCols, renamed, "column names (+ve and -ve)"
renamedTestCols.concat("", "Blank"), renamed, "column names (+ve and -ve)"
)

// Check no field filters
Expand All @@ -137,8 +140,8 @@ var TestElasticsearchResponseUtils_ = (function() {
renamedTestCols, renamed, "column names (no field filters)"
)

// Check no field aliases
headerMeta.field_filters = filters1
// Check no field aliases (+remove skip indices)
headerMeta.field_filters = filters1.filter(function(x) { return x.indexOf("$$skip") != 0 })
headerMeta.field_aliases = []

var testCols3 = TestService_.Utils.deepCopyJson(testCols)
Expand Down