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-16835 Non-TC locales and extended locales remain open longer #3795

Merged
merged 10 commits into from
Jun 13, 2024
28 changes: 27 additions & 1 deletion tools/cldr-apps/js/src/esm/cldrLoad.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,10 +1049,30 @@ function getLocaleDir(locale) {
return localeDir;
}

/** @returns true if locmap has been loaded from data */
function localeMapReady() {
return !!locmap.locmap;
}

/** event ID for localeMap changes */
const LOCALEMAP_EVENT = "localeMapReady";

/**
* Calls the callback when the localeMap is ready (with real data).
* Calls right away if the localeMap was already loaded.
*/
function onLocaleMapReady(callback) {
if (localeMapReady()) {
callback();
} else {
cldrStatus.on(LOCALEMAP_EVENT, callback);
}
}

function setTheLocaleMap(lm) {
locmap = lm;
cldrStatus.dispatchEvent(new Event(LOCALEMAP_EVENT));
}

/**
* Convenience for calling getTheLocaleMap().getLocaleName(loc)
* @param {String} loc
Expand All @@ -1062,6 +1082,10 @@ function getLocaleName(loc) {
return locmap.getLocaleName(loc);
}

function getLocaleInfo(loc) {
return locmap.getLocaleInfo(loc);
}

/**
* Get the window location hash
*
Expand Down Expand Up @@ -1145,13 +1169,15 @@ export {
flipToOtherDiv,
getHash,
getLocaleDir,
getLocaleInfo,
getLocaleName,
getTheLocaleMap,
handleCoverageChanged,
insertLocaleSpecialNote,
linkToLocale,
localeSpecialNote,
myLoad,
onLocaleMapReady,
parseHashAndUpdate,
reloadV,
replaceHash,
Expand Down
18 changes: 18 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrStatus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function on(type, callback) {
getStatusTarget().addEventListener(type, callback);
}

/**
* Fire off an event manually
* @param type the type to dispatch
*/
function dispatchEvent(type) {
return getStatusTarget().dispatchEvent(type);
}
Expand All @@ -75,6 +79,9 @@ function updateAll(status) {
if (status.phase) {
setPhase(status.phase);
}
if (status.ddlPhase) {
setDdlPhase(status.ddlPhase);
}
if (status.specialHeader) {
setSpecialHeader(status.specialHeader);
}
Expand Down Expand Up @@ -296,9 +303,17 @@ function getPhase() {
return phase;
}

let ddlPhase = "";
function setPhase(p) {
phase = p;
}
function getDdlPhase() {
return ddlPhase;
}

function setDdlPhase(p) {
ddlPhase = p;
}

/**
* Is this a "beta" phase of Survey Tool? (Boolean)
Expand Down Expand Up @@ -466,6 +481,7 @@ function setAutoImportBusy(busy) {
}

export {
dispatchEvent,
getAutoImportBusy,
getContextPath,
getCurrentId,
Expand All @@ -479,6 +495,7 @@ export {
getNewVersion,
getOrganizationName,
getPermissions,
getDdlPhase,
getPhase,
getRunningStamp,
getSessionId,
Expand Down Expand Up @@ -507,6 +524,7 @@ export {
setOrganizationName,
setPermissions,
setPhase,
setDdlPhase,
setSessionId,
setSessionMessage,
setSpecialHeader,
Expand Down
54 changes: 43 additions & 11 deletions tools/cldr-apps/js/src/views/MainHeader.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<template>
<header id="st-header">
<a-spin v-if="!loaded" :delay="250" />
<ul>
<li>{{ stVersionPhase }}</li>
<li>
{{ stVersion }} {{ stPhase }}
<span
class="ddlException"
v-if="ddlException"
title="Note: As a non-TC DDL locale, this phase has been extended."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally this title might include ddlPhase, since "extended" is vague -- extended to what?

>
(extended)
</span>
</li>
<li>
<a href="#menu///"><span class="main-menu-icon">☰</span></a>
</li>
Expand Down Expand Up @@ -79,6 +89,7 @@
<script>
import * as cldrAnnounce from "../esm/cldrAnnounce.mjs";
import * as cldrCoverage from "../esm/cldrCoverage.mjs";
import * as cldrLoad from "../esm/cldrLoad.mjs";
import * as cldrMenu from "../esm/cldrMenu.mjs";
import * as cldrStatus from "../esm/cldrStatus.mjs";
import * as cldrText from "../esm/cldrText.mjs";
Expand All @@ -87,6 +98,7 @@ import * as cldrVote from "../esm/cldrVote.mjs";
export default {
data() {
return {
loaded: false,
announcementsTitle: null,
coverageLevel: null,
coverageMenu: [],
Expand All @@ -96,7 +108,10 @@ export default {
orgCoverage: null,
sessionMessage: null,
specialHeader: null,
stVersionPhase: null,
stPhase: null,
stVersion: null,
tcLocale: true,
ddlException: false,
unreadAnnouncementCount: 0,
userName: null,
voteCountMenu: null,
Expand All @@ -105,7 +120,12 @@ export default {
},

mounted() {
this.updateData();
// load after the localemap is ready
cldrLoad.onLocaleMapReady(() => {
this.updateData();
});
// reload if locale changes
cldrStatus.on("locale", () => this.updateData());
},

methods: {
Expand All @@ -114,9 +134,9 @@ export default {
* This function is called both locally, to initialize, and from other module(s), to update.
*/
updateData() {
const orgCoverage = cldrCoverage.getSurveyOrgCov(
cldrStatus.getCurrentLocale()
);
this.loaded = true;
const loc = cldrStatus.getCurrentLocale();
const orgCoverage = cldrCoverage.getSurveyOrgCov(loc);
if (orgCoverage != this.orgCoverage) {
this.orgCoverage = orgCoverage;
}
Expand Down Expand Up @@ -155,11 +175,19 @@ export default {
}
this.sessionMessage = cldrStatus.getSessionMessage();
this.specialHeader = cldrStatus.getSpecialHeader();
this.stVersionPhase =
"Survey Tool " +
cldrStatus.getNewVersion() +
" " +
cldrStatus.getPhase();
this.stVersion = "Survey Tool " + cldrStatus.getNewVersion();
this.tcLocale = cldrLoad?.getLocaleInfo(loc)?.tc;
btangmu marked this conversation as resolved.
Show resolved Hide resolved
if (!loc || this.tcLocale) {
this.stPhase = cldrStatus.getPhase();
this.ddlException = false;
} else {
this.stPhase = cldrStatus.getDdlPhase();
if (cldrStatus.getDdlPhase() != cldrStatus.getPhase()) {
this.ddlException = true;
} else {
this.ddlException = false;
}
}
cldrAnnounce.getUnreadCount(this.setUnreadCount);
},

Expand Down Expand Up @@ -261,4 +289,8 @@ label {
#coverageLevel {
width: 16ch;
}

.ddlException {
background-color: yellow;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ public CheckCLDR.Phase getPhase() {
return SurveyMain.phase().getCPhase();
}

@Override
public CheckCLDR.Phase getDDLPhase() {
return SurveyMain.getDDLPhase().getCPhase();
}

@Override
public CLDRURLS internalGetUrls() {
if (contextUrl == null) contextUrl = CLDRURLS.DEFAULT_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,7 @@ public Map<String, String> getNonDistinguishingAttributes() {
*/
public StatusAction getStatusAction(InputMethod inputMethod) {
// null because this is for display.
return SurveyMain.phase()
.getCPhase()
return SurveyMain.getCPhase(locale)
.getShowRowAction(this, inputMethod, getPathHeader(), userForVotelist);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ private static JSONObject createJSONLocMap(SurveyMain sm) throws JSONException {
// locales will have info about each locale, including name
JSONObject locales = new JSONObject();
SupplementalDataInfo sdi = sm.getSupplementalDataInfo();
final StandardCodes sc = StandardCodes.make();
srl295 marked this conversation as resolved.
Show resolved Hide resolved

Factory disk = sm.getDiskFactory();

Expand All @@ -1118,6 +1119,7 @@ private static JSONObject createJSONLocMap(SurveyMain sm) throws JSONException {
locale.put("highestParent", loc.getHighestNonrootParent());
locale.put("dcParent", dcParent);
locale.put("dcChild", dcChild);
locale.put("tc", SubmissionLocales.isTcLocale(loc));
locale.put(
"type",
Factory.getSourceTreeType(disk.getSourceDirectoryForLocale(loc.getBaseName())));
Expand Down Expand Up @@ -2656,7 +2658,7 @@ public static void handleBulkSubmit(
final List<CheckCLDR.CheckStatus> checkResult = new ArrayList<>();
TestCache.TestResultBundle cc = stf.getTestResult(loc, DataPage.getOptions(cs, loc));
UserRegistry.User u = theirU;
CheckCLDR.Phase cPhase = CLDRConfig.getInstance().getPhase();
CheckCLDR.Phase cPhase = SurveyMain.getCPhase(loc);
Set<String> allValidPaths = stf.getPathsForFile(loc);
CLDRProgressTask progress = sm.openProgress("Bulk:" + loc, all.size());
CLDRFile cldrUnresolved = cf.getUnresolved();
Expand Down
47 changes: 42 additions & 5 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.unicode.cldr.test.CheckCLDR;
import org.unicode.cldr.test.ExampleGenerator;
import org.unicode.cldr.test.HelpMessages;
import org.unicode.cldr.test.SubmissionLocales;
import org.unicode.cldr.util.CLDRCacheDir;
import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRConfigImpl;
Expand Down Expand Up @@ -209,6 +210,7 @@ public String display() {

// ===== Configuration state
private static Phase currentPhase = Phase.VETTING;
private static Phase currentDdlPhase = Phase.VETTING;
/** set by CLDR_PHASE property. * */
private static String oldVersion = "OLDVERSION";

Expand Down Expand Up @@ -2077,9 +2079,9 @@ public String getLocaleLink(WebContext ctx, CLDRLocale locale, String n) {
if (canModify) {
rv = rv + (modifyThing(ctx));
int odisp;
if ((SurveyMain.phase() == Phase.VETTING
|| SurveyMain.phase() == Phase.SUBMIT
|| isPhaseVettingClosed())
if ((SurveyMain.phase(locale) == Phase.VETTING
|| SurveyMain.phase(locale) == Phase.SUBMIT
|| isPhaseVettingClosed(locale))
&& ((odisp = DisputePageManager.getOrgDisputeCount(ctx)) > 0)) {
rv = rv + ctx.iconHtml("disp", "(" + odisp + " org disputes)");
}
Expand Down Expand Up @@ -2823,6 +2825,24 @@ private void doStartup() {
+ phaseString);
}
currentPhase = newPhase;
String ddlPhaseString = survprops.getProperty("CLDR_DDL_PHASE", null);
Phase ddlPhase = null;
try {
if (ddlPhaseString != null && !ddlPhaseString.isEmpty()) {
if (currentPhase == Phase.READONLY) {
busted(
"Error: Cannot have a CLDR_DDL_PHASE when CLDR_PHASE=READONLY. Remove the CLDR_DDL_PHASE.");
btangmu marked this conversation as resolved.
Show resolved Hide resolved
}
ddlPhase = (Phase.valueOf(ddlPhaseString));
}
} catch (IllegalArgumentException iae) {
logger.warning("Error trying to parse CLDR_DDL_PHASE: " + iae);
}
if (ddlPhase == null) {
ddlPhase = newPhase;
logger.warning("CLDR_DDL_PHASE matches main phase " + ddlPhase);
}
currentDdlPhase = ddlPhase;
}
logger.info("Phase: " + phase() + ", cPhase: " + phase().getCPhase());
progress.update("Setup props..");
Expand Down Expand Up @@ -3554,8 +3574,8 @@ public static String localhost() {

// ============= Following have to do with phases

public static boolean isPhaseVettingClosed() {
return phase() == Phase.VETTING_CLOSED;
public static boolean isPhaseVettingClosed(CLDRLocale locale) {
return phase(locale) == Phase.VETTING_CLOSED;
}

public static boolean isPhaseReadonly() {
Expand All @@ -3570,6 +3590,21 @@ public static Phase phase() {
return currentPhase;
}

public static Phase phase(CLDRLocale locale) {
return (SubmissionLocales.isTcLocale(locale) ? phase() : getDDLPhase());
}

/**
* @returns the current phase for the locale. This is the preferred API.
*/
public static CheckCLDR.Phase getCPhase(CLDRLocale loc) {
return phase(loc).getCPhase();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"C" for "current" is a little cryptic; I didn't know what it stood for until I got here. How about getCurrentPhase? Or a name that clarifies this method is appropriate for both DDL and non-DDL locales?

It seems like a terminology is needed, distinguishing 3 categories:

  1. methods/data specifically for DDL
  2. methods/data specifically for non-DDL
  3. methods/data that apply to either DDL or non-DDL, depending on the specified locale

There's also the long-standing confusion between CheckCLDR.Phase and SurveyMain.Phase, which still makes my head spin. Of course, fixing that is out of the scope of this ticket, but as long as new methods are being named, it would SO helpful for the new methods/data to use a naming convention that distinguishes them -- maybe checkPhase vs stPhase?

Also, it seems error prone to have three public methods: phase(), phase(locale), and getCPhase(loc). If the no-argument phase() ignores the existence of DDL, what ensures that various modules are consistent in treating DDL differently from non-DDL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not current, it's CheckCLDR. CheckCLDR added its own 'Phase' enum distinct from ST's, and they haven't been fully reconciled yet. It's the "long-standing confusion between CheckCLDR.Phase and SurveyMain.Phase".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will work on making these more clearer and consistent. Perhaps phase() could be renamed to overallPhase() or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that would need to be overallPhase(locale), right? Without the locale, it can't be overall. So ideally, phase() without a locale parameter might be private? currently it has about 14 callers (before this PR) (not counting jsp)

}

public static Phase getDDLPhase() {
return currentDdlPhase;
}

public static String getOldVersion() {
return oldVersion;
}
Expand Down Expand Up @@ -3642,6 +3677,7 @@ private class StatusForFrontEnd implements JSONString {
private final int pages = SurveyMain.pages;
private Object permissions = null;
private final Phase phase = phase();
private final Phase ddlPhase = getDDLPhase();
private String sessionId = null;
private final String specialHeader = getSpecialHeaderText();
private final long surveyRunningStamp = SurveyMain.surveyRunningStamp.current();
Expand Down Expand Up @@ -3675,6 +3711,7 @@ private JSONObject toJSONObject() throws JSONException {
.put("pages", pages)
.put("permissions", permissions)
.put("phase", phase)
.put("ddlPhase", ddlPhase)
.put("sessionId", sessionId)
.put("sessionMessage", sessionMessage)
.put("specialHeader", specialHeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ public static ModifyDenial userCanModifyLocaleWhy(User u, CLDRLocale locale) {
if (userIsAdmin(u) || userIsTC(u)) return null;

// Otherwise, if closed, deny
if (SurveyMain.isPhaseVettingClosed()) return ModifyDenial.DENY_PHASE_CLOSED;
if (SurveyMain.isPhaseVettingClosed(locale)) return ModifyDenial.DENY_PHASE_CLOSED;
if (SurveyMain.isPhaseReadonly()) return ModifyDenial.DENY_PHASE_READONLY;

return null;
Expand Down
Loading
Loading