diff --git a/src/server/models/TableModel.gs b/src/server/models/TableModel.gs index b2f541c..f7e8b74 100644 --- a/src/server/models/TableModel.gs +++ b/src/server/models/TableModel.gs @@ -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", diff --git a/src/server/services/ElasticsearchService.gs b/src/server/services/ElasticsearchService.gs index bcf40a7..47b65c8 100644 --- a/src/server/services/ElasticsearchService.gs +++ b/src/server/services/ElasticsearchService.gs @@ -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) diff --git a/src/server/services/TableService.gs b/src/server/services/TableService.gs index d2a2e59..cc44044 100644 --- a/src/server/services/TableService.gs +++ b/src/server/services/TableService.gs @@ -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) { diff --git a/src/server/utils/TableRangeUtils.gs b/src/server/utils/TableRangeUtils.gs index 6f2a42a..f6c28ae 100644 --- a/src/server/utils/TableRangeUtils.gs +++ b/src/server/utils/TableRangeUtils.gs @@ -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) { diff --git a/test/server/services/TestElasticsearchService.gs b/test/server/services/TestElasticsearchService.gs index 4b98df2..d080a7b 100644 --- a/test/server/services/TestElasticsearchService.gs +++ b/test/server/services/TestElasticsearchService.gs @@ -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" @@ -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) @@ -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] + "]" + ) }) }