diff --git a/src/server/models/TableModel.gs b/src/server/models/TableModel.gs index 379ba70..b2f541c 100644 --- a/src/server/models/TableModel.gs +++ b/src/server/models/TableModel.gs @@ -7,13 +7,14 @@ 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 "query": { // "index_pattern": "tbd", "source": "none", //, //^points to field to use ("global", "local") "global": { - "range_name": "sheet!range" + "range_name": "[sheet!]range" }, "local": { "position": "top" //(or "bottom") @@ -31,8 +32,11 @@ var defaultTableConfig_ = { } }, "status": { - "position": "top", //(or "bottom", "none") - "merge": false //(if false will be its own separate line, else will merge with query/pagination if they exist) + "position": "top", //(or "bottom", "none", "global") + "merge": false, //(if false will be its own separate line, else will merge with query/pagination if they exist) + "global": { + "range_name": "[sheet!]range" + } }, "headers": { "position": "top", //(or "bottom", "top_bottom", "none") .. NOT_SUPPORTED: "bottom", "top_bottom" diff --git a/src/server/utils/ElasticsearchRequestUtils.gs b/src/server/utils/ElasticsearchRequestUtils.gs index 6a935d5..87a8042 100644 --- a/src/server/utils/ElasticsearchRequestUtils.gs +++ b/src/server/utils/ElasticsearchRequestUtils.gs @@ -169,7 +169,10 @@ var ElasticsearchRequestUtils_ = (function() { statusCells.merge() break } - } + } else if (!testMode) { // Check for global status + var ss = SpreadsheetApp.getActive() + TableRangeUtils_.handleGlobalStatusInfo(ss, statusInfo, tableConfig) + } // Headers diff --git a/src/server/utils/ElasticsearchResponseUtils.gs b/src/server/utils/ElasticsearchResponseUtils.gs index 19f0db1..f5dfdaa 100644 --- a/src/server/utils/ElasticsearchResponseUtils.gs +++ b/src/server/utils/ElasticsearchResponseUtils.gs @@ -325,14 +325,16 @@ var ElasticsearchResponseUtils_ = (function() { json, rows, fullCols, supportsSize, numHits, numHitsOperator ) { - var ss = SpreadsheetApp.getActive() - var tableRange = TableRangeUtils_.findTableRange(ss, tableName) - var range = null - if (null == tableRange) { //(use current selection, test mode + var ss = SpreadsheetApp.getActive() + var tableRange = TableRangeUtils_.findTableRange(ss, tableName) + var range = null + if (null == tableRange) { //(use current selection, test mode range = ss.getActiveRange() - } else { - range = tableRange.getRange() - } + } else { + range = tableRange.getRange() + } + var globalStatus = + "global" == TableRangeUtils_.getJson(tableConfig, [ "common", "status", "position" ]) if (null != json.response) { /** Apply the global filters to the cols and re-order as desired */ @@ -490,13 +492,13 @@ var ElasticsearchResponseUtils_ = (function() { } // Write warnings to status (never to toaster) - if (context.table_meta.status_offset) { + if (context.table_meta.status_offset || globalStatus) { var warningText = "" if (warnings.length > 0) { warningText = ": (WARNINGS = " + warnings.map(function(x) { return "[" + x + "]" }).join(", ") + ")" } setQueryResponseInStatus_(range, context.table_meta.status_offset, - "SUCCESS [" + TableRangeUtils_.formatDate() + "]" + warningText) + "SUCCESS [" + TableRangeUtils_.formatDate() + "]" + warningText, tableConfig) } } else if (null != json.error_message) { // Write errors to status or toaster @@ -505,8 +507,8 @@ var ElasticsearchResponseUtils_ = (function() { : "ERROR [" + TableRangeUtils_.formatDate() + "]" + ": status = [" + json.status + "], msg = [" + json.error_message + "], query = [" + json.query_string + "]" - if (context.table_meta.status_offset) { - setQueryResponseInStatus_(range, context.table_meta.status_offset, requestError) + if (context.table_meta.status_offset || globalStatus) { + setQueryResponseInStatus_(range, context.table_meta.status_offset, requestError, tableConfig) } else { // pop up toaster showStatus("[" + tableName + "]: " + requestError, "Query Error") } @@ -685,8 +687,11 @@ var ElasticsearchResponseUtils_ = (function() { } /** Adds the error info the status, if necessary */ - function setQueryResponseInStatus_(range, statusLocation, errorString) { - range.getCell(statusLocation.row, statusLocation.col).setValue(errorString) + function setQueryResponseInStatus_(range, statusLocation, errorString, tableConfig) { + var ss = SpreadsheetApp.getActive() + if (!TableRangeUtils_.handleGlobalStatusInfo(ss, errorString, tableConfig)) { + range.getCell(statusLocation.row, statusLocation.col).setValue(errorString) + } } //////////////////////////////////////////////////////// diff --git a/src/server/utils/TableRangeUtils.gs b/src/server/utils/TableRangeUtils.gs index dae7312..6f2a42a 100644 --- a/src/server/utils/TableRangeUtils.gs +++ b/src/server/utils/TableRangeUtils.gs @@ -388,6 +388,24 @@ : null //(see above: also support named ranges, cf getJsonLookup) } + /** Utility function to write global status info out - returns true iff status _is_ global */ + function handleGlobalStatusInfo(ss, statusInfo, tableConfig) { + if ( //Global query, get from its external location: + "global" == TableRangeUtils_.getJson(tableConfig, [ "common", "status", "position" ]) + ) { + var globalSourceRef = TableRangeUtils_.getJson( + tableConfig, [ "common", "status", "global", "range_name" ] + ) + var globalSourceRange = globalSourceRef ? + TableRangeUtils_.getRangeFromName(ss, globalSourceRef) : null + if (globalSourceRange) { + globalSourceRange.getCell(1, 1).setValue(statusInfo) + return true + } + } + return false + } + //////////////////////////////////////////////////////// // 3] Internal utils @@ -438,6 +456,7 @@ doRangesIntersect: doRangesIntersect, getExternalTableRanges: getExternalTableRanges, getRangeFromName: getRangeFromName, + handleGlobalStatusInfo: handleGlobalStatusInfo, TESTONLY: { diff --git a/test/server/services/TestElasticsearchService.gs b/test/server/services/TestElasticsearchService.gs index 4a0dfd5..4b98df2 100644 --- a/test/server/services/TestElasticsearchService.gs +++ b/test/server/services/TestElasticsearchService.gs @@ -121,7 +121,10 @@ }, "status": { "position": "none", - "merge": false + "merge": false, + "global": { + "range_name": "TBD" + } }, "formatting": { "theme": "minimal" @@ -130,6 +133,7 @@ var defaultA1Notation = "A1:E10" var externalQueryNotation = "H20:H20" + var externalStatusNotation = "J22" TestService_.Utils.performTest(testResults, "no_special_rows_plus_check_es_meta", function() { var tableConfig = TestService_.Utils.deepCopyJson(baseTableConfig) @@ -217,7 +221,7 @@ "pagination_status": { status: "bottom", merge: true, noteMode: 3 }, "pagination_status_test": { status: "bottom", merge: true, testMode: true, noteMode: 3 }, "query_status_pagination_nomerge": { status: "bottom", merge: false, noteMode: 4 }, - "global_query": { noteMode: 4 } + "global_query_global_status": { noteMode: 4 } } var testRunner = function(testName, testConfig) { TestService_.Utils.performTest(testResults, testName, function() { @@ -229,9 +233,10 @@ var testMode = testConfig.testMode var globalQuery = testName.indexOf("global_query") >= 0 + var globalStatus = testName.indexOf("global_status") >= 0 var includeQueryBar = !globalQuery && testName.indexOf("query") >= 0 var includePagination = testName.indexOf("pagination") >= 0 - var includeStatus = testName.indexOf("status") >= 0 + var includeStatus = !globalStatus && testName.indexOf("status") >= 0 // Note tests: // 1: add note, replaces no note @@ -284,6 +289,10 @@ tableConfig.common.pagination.source = "local" } var statusPosition = { } + if (globalStatus) { + tableConfig.common.status.position = "global" + tableConfig.common.status.global.range_name = externalStatusNotation + } if (includeStatus) { if (!testConfig.merge) { expectedDataSize-- @@ -387,6 +396,14 @@ TestService_.Utils.assertEquals(expectedPage, range.getCell(pagePosition.row, pagePosition.col).getValue(), "page value" + extraTestCaseConfig) } } + if (globalStatus) { + var statusShouldBePending = testSheet.getRange(externalStatusNotation).getValue() + if (testMode) { + TestService_.Utils.assertEquals("", statusShouldBePending, "status value: " + statusShouldBePending + extraTestCaseConfig) + } else { + TestService_.Utils.assertEquals(true, 0 == statusShouldBePending.indexOf("PENDING"), "status value: " + statusShouldBePending + extraTestCaseConfig) + } + } if (includeStatus) { var statusShouldBePending = range.getCell(statusPosition.row, statusPosition.col).getValue() if (testMode) {