diff --git a/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs b/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs index 07403473526..a0c5dd68fa1 100644 --- a/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs +++ b/tools/cldr-apps/js/src/esm/cldrAnnounce.mjs @@ -5,6 +5,15 @@ import * as cldrAjax from "./cldrAjax.mjs"; import * as cldrStatus from "./cldrStatus.mjs"; +/** + * This should be false for production. It can be made true during debugging, which + * may be useful for performance testing. Also, there is a bug where "announce" requests + * (as well as "completion" requests) are not only made too often (every 15 seconds synced + * with status requests), but are made in pairs where one "announce" request immediately follows + * another, see https://unicode-org.atlassian.net/browse/CLDR-16900 + */ +const DISABLE_ANNOUNCEMENTS = false; + let thePosts = null; let callbackSetData = null; @@ -16,6 +25,9 @@ async function getUnreadCount(setUnreadCount) { } async function refresh(viewCallbackSetData) { + if (DISABLE_ANNOUNCEMENTS) { + return; + } if (!cldrStatus.getSurveyUser()) { if (viewCallbackSetData) { viewCallbackSetData(null); diff --git a/tools/cldr-apps/js/src/esm/cldrLoad.mjs b/tools/cldr-apps/js/src/esm/cldrLoad.mjs index 86625079217..ab4d2c9d2d1 100644 --- a/tools/cldr-apps/js/src/esm/cldrLoad.mjs +++ b/tools/cldr-apps/js/src/esm/cldrLoad.mjs @@ -611,6 +611,11 @@ function specialLoad(itemLoadInfo, curSpecial, theDiv) { cldrInfo.closePanel(); // Most special.load() functions do not use a parameter; an exception is // cldrGenericVue.load() which expects the special name as a parameter + if (CLDR_LOAD_DEBUG) { + console.log( + "cldrLoad.specialLoad: running special.load(" + curSpecial + ")" + ); + } special.load(curSpecial); } else if (curSpecial !== "general") { // Avoid recursion. @@ -628,10 +633,16 @@ function unspecialLoad(itemLoadInfo, theDiv) { const curPage = cldrStatus.getCurrentPage(); const curId = cldrStatus.getCurrentId(); if (!curPage && !curId) { + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.unspecialLoad: running specialLoad(general)"); + } cldrStatus.setCurrentSpecial("general"); specialLoad(itemLoadInfo, "general", theDiv); } else if (curId === "!") { // TODO: clarify when and why this would happen + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.unspecialLoad: running loadExclamationPoint"); + } loadExclamationPoint(); } else { if (!cldrSurvey.isInputBusy()) { @@ -639,10 +650,20 @@ function unspecialLoad(itemLoadInfo, theDiv) { * Make “all rows” requests only when !isInputBusy, to avoid wasted requests * if the user leaves the input box open for an extended time. */ + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.unspecialLoad: running loadAllRows"); + } loadAllRows(itemLoadInfo, theDiv); + } else if (CLDR_LOAD_DEBUG) { + console.log( + "cldrLoad.unspecialLoad: skipping loadAllRows because input is busy" + ); } } } else if (curSpecial) { + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.unspecialLoad: calling handleMissingSpecial"); + } handleMissingSpecial(curSpecial); } } @@ -774,6 +795,10 @@ function loadAllRows(itemLoadInfo, theDiv) { ); const url = cldrTable.getPageUrl(curLocale, curPage, curId); $("#nav-page").show(); // make top "Prev/Next" buttons visible while loading, cf. '#nav-page-footer' below + + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.loadAllRows sending request"); + } cldrAjax .doFetch(url) .then((response) => response.json()) @@ -786,6 +811,9 @@ function loadAllRows(itemLoadInfo, theDiv) { } function loadAllRowsFromJson(json, theDiv) { + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.loadAllRowsFromJson got response"); + } isLoading = false; cldrSurvey.showLoader(cldrText.get("loading2")); if (json.err) { @@ -826,6 +854,9 @@ function loadAllRowsFromJson(json, theDiv) { } else { cldrStatus.setCurrentPage(""); } + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.loadAllRowsFromJson got json.page.nocontent"); + } cldrSurvey.showLoader(null); updateHashAndMenus(); // find out why there's no content. (locmap) } else if (!json.page.rows) { @@ -846,6 +877,9 @@ function loadAllRowsFromJson(json, theDiv) { updateHashAndMenus(); // now that we have a pageid if (!cldrSurvey.isInputBusy()) { cldrSurvey.showLoader(cldrText.get("loading3")); + if (CLDR_LOAD_DEBUG) { + console.log("cldrLoad.loadAllRowsFromJson calling insertRows"); + } cldrTable.insertRows( theDiv, json.pageId, @@ -860,6 +894,10 @@ function loadAllRowsFromJson(json, theDiv) { if (!cldrStatus.getCurrentId()) { cldrInfo.showMessage(getGuidanceMessage(json.canModify)); } + } else if (CLDR_LOAD_DEBUG) { + console.log( + "cldrLoad.loadAllRowsFromJson skipping insertRows because isInputBusy" + ); } } } diff --git a/tools/cldr-apps/js/src/esm/cldrSurvey.mjs b/tools/cldr-apps/js/src/esm/cldrSurvey.mjs index 85f2b094b69..48d4591d11a 100644 --- a/tools/cldr-apps/js/src/esm/cldrSurvey.mjs +++ b/tools/cldr-apps/js/src/esm/cldrSurvey.mjs @@ -21,6 +21,9 @@ import { XpathMap } from "./cldrXpathMap.mjs"; */ const INHERITANCE_MARKER = "↑↑↑"; +const DEBUG_SHOWER = false; +const DEBUG_LOCALE_STAMP = false; + let xpathMap = null; let wasBusted = false; @@ -30,7 +33,7 @@ let loadOnOk = null; // TODO: SurveyMain.java writes scripts that try to referen let clickContinue = null; // TODO: SurveyMain.java writes scripts that try to reference clickContinue -let surveyNextLocaleStamp = 0; +let surveyNextLocaleStamp = NaN; let showers = {}; @@ -107,9 +110,6 @@ function getXpathMap() { * "popover-content" identifies the little input window, created using bootstrap, that appears when the * user clicks an add ("+") button. Added "popover-content" per https://unicode.org/cldr/trac/ticket/11265. * - * TODO: clarify dependence on "dijitInp"; is that still used here, and if so, when? - * Add automated regression testing to anticipate future changes to bootstrap/dojo/dijit/etc. - * * Called only from CldrSurveyVettingLoader.js */ function isInputBusy() { @@ -118,9 +118,6 @@ function isInputBusy() { } var sel = window.getSelection(); if (sel && sel.anchorNode && sel.anchorNode.className) { - if (sel.anchorNode.className.indexOf("dijitInp") != -1) { - return true; - } if (sel.anchorNode.className.indexOf("popover-content") != -1) { return true; } @@ -162,16 +159,34 @@ function unbust() { } /** - * Process that the locale has changed under us. + * Process that the locale may have changed, which is indicated by receiving a timestamp + * from the server different than was previously recorded as surveyNextLocaleStamp + * + * The special case where surveyNextLocaleStamp is NaN is handled the same as the case + * where stamp != surveyNextLocaleStamp. The server response is assumed not to have NaN. * - * @param {String} stamp timestamp + * The rare case where stamp < surveyNextLocaleStamp (presumably due to wrap-around or + * server restart) is handled the same as the case where stamp > surveyNextLocaleStamp. + * + * @param {String} stamp the timestamp received from the server * @param {String} name locale name */ function handleChangedLocaleStamp(stamp, name) { - if (cldrStatus.isDisconnected()) { + if (stamp == surveyNextLocaleStamp) { + if (DEBUG_LOCALE_STAMP) { + console.log( + "cldrSurvey.handleChangedLocaleStamp: surveyNextLocaleStamp is unchanged from " + + surveyNextLocaleStamp + ); + } return; } - if (stamp <= surveyNextLocaleStamp) { + if (cldrStatus.isDisconnected()) { + if (DEBUG_LOCALE_STAMP) { + console.log( + "cldrSurvey.handleChangedLocaleStamp: returning early since cldrStatus.isDisconnected" + ); + } return; } /* @@ -179,6 +194,11 @@ function handleChangedLocaleStamp(stamp, name) { * requests (e.g., vote or single-row WHAT_GETROW requests) are pending. */ if (cldrVote.isBusy()) { + if (DEBUG_LOCALE_STAMP) { + console.log( + "cldrSurvey.handleChangedLocaleStamp: returning early since cldrVote.isBusy" + ); + } return; } if (Object.keys(showers).length == 0) { @@ -186,6 +206,9 @@ function handleChangedLocaleStamp(stamp, name) { * TODO: explain this code. When, if ever, is it executed, and why? * Typically Object.keys(showers).length != 0. */ + if (DEBUG_SHOWER || DEBUG_LOCALE_STAMP) { + console.log("cldrSurvey.handleChangedLocaleStamp: no showers!"); + } cldrDom.updateIf("stchanged_loc", name); var locDiv = document.getElementById("stchanged"); if (locDiv) { @@ -195,10 +218,21 @@ function handleChangedLocaleStamp(stamp, name) { for (let i in showers) { const fn = showers[i]; if (fn) { + if (DEBUG_SHOWER || DEBUG_LOCALE_STAMP) { + console.log( + "cldrSurvey.handleChangedLocaleStamp: running showers[" + i + "]" + ); + } fn(); } } } + if (DEBUG_LOCALE_STAMP) { + console.log( + "cldrSurvey.handleChangedLocaleStamp: setting surveyNextLocaleStamp = " + + stamp + ); + } surveyNextLocaleStamp = stamp; } @@ -554,15 +588,8 @@ function updateStatusLoadHandler(json) { } } updateStatusBox(json); - if (json.localeStamp) { - if (surveyNextLocaleStamp == 0) { - surveyNextLocaleStamp = json.localeStamp; - } else { - if (json.localeStamp > surveyNextLocaleStamp) { - handleChangedLocaleStamp(json.localeStamp, json.localeStampName); - } - } + handleChangedLocaleStamp(json.localeStamp, json.localeStampName); } if (wasBusted == false && json.status.isSetup && loadOnOk != null) { window.location.replace(loadOnOk);