Skip to content

Commit dd4a0bd

Browse files
authored
CLDR-17461 Improve visibility of forum posts in vetting view (#3675)
1 parent ec34be5 commit dd4a0bd

File tree

6 files changed

+76
-5
lines changed

6 files changed

+76
-5
lines changed

tools/cldr-apps/js/src/esm/cldrErrorSubtypes.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function reloadMapHandler(json) {
147147
}
148148
el.innerHTML = html;
149149
if (json.err) {
150-
const b = cldrDom.createLinkToFn('special_error_subtypes', load, 'button');
150+
const b = cldrDom.createLinkToFn("special_error_subtypes", load, "button");
151151
el.appendChild(b);
152152
}
153153
}

tools/cldr-apps/js/src/esm/cldrTable.mjs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ function updateRowEnglishComparisonCell(tr, theRow, cell) {
763763
}
764764
const TRANS_HINT_ID = "en"; // expected to match SurveyMain.TRANS_HINT_ID
765765
cldrSurvey.setLang(cell, TRANS_HINT_ID);
766-
if (theRow.displayExample || trHint) {
766+
if (theRow.displayExample || trHint || theRow.forumStatus.hasPosts) {
767767
const infos = document.createElement("div");
768768
infos.className = "infos-code";
769769
if (trHint) {
@@ -772,6 +772,9 @@ function updateRowEnglishComparisonCell(tr, theRow, cell) {
772772
if (theRow.displayExample) {
773773
appendExampleIcon(infos, theRow.displayExample, TRANS_HINT_ID);
774774
}
775+
if (theRow.forumStatus.hasPosts) {
776+
appendForumStatus(infos, theRow.forumStatus, TRANS_HINT_ID);
777+
}
775778
cell.appendChild(infos);
776779
}
777780
cldrInfo.listen(null, tr, cell, null);
@@ -1114,6 +1117,19 @@ function appendTranslationHintIcon(parent, text, loc) {
11141117
return el;
11151118
}
11161119

1120+
function appendForumStatus(parent, forumStatus, loc) {
1121+
const el = document.createElement("span");
1122+
el.textContent = "💬" + (forumStatus.hasOpenPosts ? "?" : ".");
1123+
el.title =
1124+
cldrText.get("forum_path_has_posts") +
1125+
(forumStatus.hasOpenPosts
1126+
? cldrText.get("forum_path_has_open_posts")
1127+
: cldrText.get("forum_path_has_only_closed_posts"));
1128+
cldrSurvey.setLang(el, loc);
1129+
parent.appendChild(el);
1130+
return el;
1131+
}
1132+
11171133
function appendExampleIcon(parent, text, loc) {
11181134
const el = appendExample(parent, text, loc);
11191135
const img = document.createElement("img");

tools/cldr-apps/js/src/esm/cldrText.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ const strings = {
360360
forum_remember_vote:
361361
"⚠️ Please remember to vote – submitting a forum post does NOT cause any actual vote to be made.",
362362

363+
forum_path_has_posts: "This item has forum posts, ",
364+
forum_path_has_open_posts: "some of which are open",
365+
forum_path_has_only_closed_posts: "all of which are closed",
366+
363367
generic_nolocale: "No locale chosen.",
364368
defaultContent_msg:
365369
"This locale, ${name} is the <i><a target='CLDR-ST-DOCS' href='https://cldr.unicode.org/translation/translation-guide-general/default-content'>default content locale</a></i> for <b><a class='notselected' href='#/${dcParent}'>${dcParentName}</a></b>, and thus editing or viewing is disabled.",

tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyForum.java

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static String HTMLUnsafe(String s) {
9090

9191
private synchronized int getForumNumber(CLDRLocale locale) {
9292
String forum = localeToForum(locale);
93-
if (forum.length() == 0 || LocaleNames.ROOT.equals(forum)) {
93+
if (forum.isEmpty() || LocaleNames.ROOT.equals(forum)) {
9494
return NO_FORUM; // all forums
9595
}
9696
// make sure it is a valid src!
@@ -198,7 +198,7 @@ private void gatherUsersInterestedInLocale(
198198
UserRegistry.User u = sm.reg.getInfo(uid);
199199
if (u != null
200200
&& u.email != null
201-
&& u.email.length() > 0
201+
&& !u.email.isEmpty()
202202
&& !(UserRegistry.userIsLocked(u)
203203
|| UserRegistry.userIsExactlyAnonymous(u))) {
204204
if (UserRegistry.userIsVetter(u)) {
@@ -1559,7 +1559,7 @@ public void setSendEmail(boolean sendEmail) {
15591559
}
15601560

15611561
/** Status values associated with forum posts and threads */
1562-
enum PostType {
1562+
public enum PostType {
15631563
CLOSE(0, "Close"),
15641564
DISCUSS(1, "Discuss"),
15651565
REQUEST(2, "Request"),
@@ -1628,4 +1628,52 @@ public static PostType fromName(String name, PostType defaultStatus) {
16281628
return defaultStatus;
16291629
}
16301630
}
1631+
1632+
public static class PathForumStatus {
1633+
public boolean hasPosts, hasOpenPosts;
1634+
1635+
public PathForumStatus(CLDRLocale locale, String xpath) {
1636+
Connection conn = null;
1637+
PreparedStatement ps = null;
1638+
final String tableName = DBUtils.Table.FORUM_POSTS.toString();
1639+
final String localeId = locale.getBaseName();
1640+
final int xpathId = CookieSession.sm.xpt.getByXpath(xpath);
1641+
try {
1642+
conn = DBUtils.getInstance().getAConnection();
1643+
if (conn == null) {
1644+
return;
1645+
}
1646+
// Expect most paths have NO posts, so check first for ANY posts (open or not).
1647+
// "LIMIT 1" may improve performance; no need to distinguish 1 from larger numbers
1648+
ps =
1649+
DBUtils.prepareForwardReadOnly(
1650+
conn,
1651+
"SELECT ID FROM " + tableName + " WHERE loc=? and xpath=? LIMIT 1");
1652+
ps.setString(1, localeId);
1653+
ps.setInt(2, xpathId);
1654+
if (DBUtils.sqlCount(ps) <= 0) { // sqlCount returns -1 (not 0) for none!
1655+
this.hasPosts = this.hasOpenPosts = false;
1656+
return;
1657+
}
1658+
this.hasPosts = true;
1659+
// Check for OPEN posts
1660+
ps =
1661+
DBUtils.prepareForwardReadOnly(
1662+
conn,
1663+
"SELECT ID FROM "
1664+
+ tableName
1665+
+ " WHERE loc=? and xpath=? AND is_open=1 LIMIT 1");
1666+
ps.setString(1, localeId);
1667+
ps.setInt(2, xpathId);
1668+
this.hasOpenPosts = DBUtils.sqlCount(ps) > 0;
1669+
} catch (SQLException e) {
1670+
SurveyLog.logException(
1671+
logger,
1672+
e,
1673+
"PathForumStatus for " + tableName + " " + locale + ":" + xpathId);
1674+
} finally {
1675+
DBUtils.close(ps, conn);
1676+
}
1677+
}
1678+
}
16311679
}

tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/VoteAPI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.unicode.cldr.web.Dashboard;
2828
import org.unicode.cldr.web.DataPage;
2929
import org.unicode.cldr.web.SubtypeToURLMap;
30+
import org.unicode.cldr.web.SurveyForum;
3031
import org.unicode.cldr.web.api.VoteAPIHelper.VoteEntry;
3132

3233
@Path("/voting")
@@ -181,6 +182,7 @@ public static final class VotingResults<T> {
181182
public String rawEnglish;
182183
public Map<String, String> extraAttributes;
183184
public boolean flagged;
185+
public SurveyForum.PathForumStatus forumStatus;
184186
public boolean hasVoted;
185187
public String helpHtml;
186188
public String inheritedLocale;

tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/VoteAPIHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ private static RowResponse.Row calculateRow(final DataRow r, boolean redacted) {
243243
row.rawEnglish = r.getRawEnglish();
244244
row.extraAttributes = r.getNonDistinguishingAttributes();
245245
row.flagged = r.isFlagged();
246+
row.forumStatus = new SurveyForum.PathForumStatus(r.getLocale(), xpath);
246247
row.hasVoted = r.userHasVoted();
247248
row.helpHtml = r.getHelpHTML();
248249
row.inheritedLocale = r.getInheritedLocaleName();

0 commit comments

Comments
 (0)