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

CLDR-13970 ST Examples used in patterns; fix front end refresh bug #3406

Merged
merged 1 commit into from
Dec 5, 2023
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
12 changes: 12 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrAnnounce.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +25,9 @@ async function getUnreadCount(setUnreadCount) {
}

async function refresh(viewCallbackSetData) {
if (DISABLE_ANNOUNCEMENTS) {
return;
}
if (!cldrStatus.getSurveyUser()) {
if (viewCallbackSetData) {
viewCallbackSetData(null);
Expand Down
38 changes: 38 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrLoad.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -628,21 +633,37 @@ 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()) {
/*
* 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);
}
}
Expand Down Expand Up @@ -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())
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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"
);
}
}
}
Expand Down
65 changes: 46 additions & 19 deletions tools/cldr-apps/js/src/esm/cldrSurvey.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = {};

Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -162,30 +159,56 @@ 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;
}
/*
* For performance, postpone the all-row WHAT_GETROW update if multiple
* 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) {
/*
* 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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tools/cldr-apps/js/src/esm/cldrVote.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function handleVoteErr(tr, message, button) {
* @returns the sanitized string
*/
function makeSafe(s) {
return s.replace(/[<>&]/g, '');
return s.replace(/[<>&]/g, "");
}

function logVote(rowHash, vHash, value) {
Expand Down
Loading