Skip to content

Commit

Permalink
[#65] Split global triggers into content and control so we can identi…
Browse files Browse the repository at this point in the history
…fy when table has been changed without immediately refreshing it
  • Loading branch information
AlexP-Elastic committed Sep 28, 2019
1 parent 0f758ab commit 528904b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/server/models/TableModel.gs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ var defaultTableConfig_ = {
// "timed": false,
// "refresh_s": 60
// },
//TODO: have content_global_triggers AND control_global_triggers
"global_triggers": [], //array of ranges ("sheet!range") to include when deciding whether to refresh the table
"global_content_triggers": [], //array of ranges ("sheet!range") to include when deciding whether to mark the table as edited
"global_control_triggers": [], //array of ranges ("sheet!range") to include when deciding whether to refresh the table
"query": {
// "index_pattern": "tbd",
"source": "none",
Expand Down
3 changes: 2 additions & 1 deletion src/server/services/ElasticsearchService.gs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ var ElasticsearchService_ = (function() {
})

// Also handle any global triggers (including queries):
var globalTriggerRanges = TableRangeUtils_.getExternalTableRanges(ss, tableConfig)
var globalTriggerRanges =
TableRangeUtils_.getExternalTableRanges(ss, tableConfig, /*controlOnly*/true)
modifiedOffsets = modifiedOffsets.concat(
globalTriggerRanges.filter(function(triggerRange) {
return TableRangeUtils_.doRangesIntersect(event.range, triggerRange)
Expand Down
3 changes: 2 additions & 1 deletion src/server/services/TableService.gs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ var TableService_ = (function(){
var retVal = {}
Object.keys(namedRangeMap).forEach(function(tableName) {
var tableConfig = tableMap[tableName]
var globalTriggerRanges = TableRangeUtils_.getExternalTableRanges(ss, tableConfig)
var globalTriggerRanges =
TableRangeUtils_.getExternalTableRanges(ss, tableConfig, /*controlOnly*/false)
var namedRange = namedRangeMap[tableName]
var allRangesToTest = globalTriggerRanges.concat([ namedRange.getRange() ])
for (rangeToTestIndex in allRangesToTest) {
Expand Down
8 changes: 6 additions & 2 deletions src/server/utils/TableRangeUtils.gs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,12 @@
/** For a given table, returns a list of ranges that the table monitors
* and treats like control changes
*/
function getExternalTableRanges(ss, tableConfig) {
var globalTriggers = TableRangeUtils_.getJson(tableConfig, [ "common", "global_triggers" ]) || []
function getExternalTableRanges(ss, tableConfig, controlOnly) {
var globalControlTriggers =
(TableRangeUtils_.getJson(tableConfig, [ "common", "global_control_triggers" ]) || [])
var globalContentTriggers = !controlOnly ?
(TableRangeUtils_.getJson(tableConfig, [ "common", "global_content_triggers" ]) || []) : []
var globalTriggers = globalControlTriggers.concat(globalContentTriggers)
var isGlobalQuery = "global" == TableRangeUtils_.getJson(tableConfig, [ "common", "query", "source" ])
var globalQuery = TableRangeUtils_.getJson(tableConfig, [ "common", "query", "global", "range_name" ])
if (isGlobalQuery) {
Expand Down
21 changes: 19 additions & 2 deletions test/server/services/TestElasticsearchService.gs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@
contentConfig.trigger = "content_change"

var triggerConfig = TestService_.Utils.deepCopyJson(baseTableConfig)
triggerConfig.common.global_triggers = [ "B25:C25" ]
triggerConfig.common.global_control_triggers = [ "B25:C25" ]
triggerConfig.common.global_content_triggers = [ testSheet.getName() + "!H25:H26" ]
triggerConfig.common.query.source = "global"
triggerConfig.common.query.global.range_name = "A25"
triggerConfig.trigger = "control_change"
Expand Down Expand Up @@ -676,7 +677,9 @@
{ p: 1, s: "AWAITING REFRESH", t: "control_change"}, resultsB[0], "tableB1=[" + resultsB[1] + "]"
)

// Other global triggers
// Other global triggers:

// Control:
resetTables()
ManagementService_.updateSavedObject("testb", TableRangeUtils_.shallowCopy(triggerConfig))
testSheet.getRange("G1").setValue("test status") //(no query bar)
Expand All @@ -689,6 +692,20 @@
TestService_.Utils.assertEquals(
{ p: 1, s: "AWAITING REFRESH", t: "control_change"}, resultsB[0], "tableB2=[" + resultsB[1] + "]"
)

// Content:
resetTables()
ManagementService_.updateSavedObject("testb", TableRangeUtils_.shallowCopy(triggerConfig))
testSheet.getRange("G1").setValue("test status") //(no query bar)
var changeEvent = { range: testSheet.getRange("H25:H26") }
var retVal = ElasticsearchService_.handleContentUpdates(changeEvent, /*triggerOverride*/null)
TestService_.Utils.assertEquals(
0, retVal, "check handleContentUpdates return value (triggerConfig, test 3)"
)
var resultsB = getResults("testb", "F1:J5", "G1", "G5")
TestService_.Utils.assertEquals(
{ p: 2, s: "HAND EDITED", t: ""}, resultsB[0], "tableB3=[" + resultsB[1] + "]"
)
})
}

Expand Down

0 comments on commit 528904b

Please sign in to comment.