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 DDL announcement #3796

Merged
merged 2 commits into from
Aug 21, 2024
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
3 changes: 3 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrAnnounce.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ function canChooseAllOrgs() {
return cldrStatus.getPermissions()?.userIsTC || false;
}

/**
* @param localeState 'ddl' or 'all' or 'choose'
*/
async function compose(formState, viewCallbackComposeResult) {
resetSchedule();
const init = cldrAjax.makePostData(formState);
Expand Down
51 changes: 40 additions & 11 deletions tools/cldr-apps/js/src/views/AnnounceForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<a-radio-group v-model:value="formState.orgs">
<a-radio value="Mine" title="Only your own organization">Mine</a-radio>
<a-radio value="TC" title="All TC organizations">TC Orgs</a-radio>
<a-radio value="NonTC" title="Non-TC organizations"
>Non-TC Orgs</a-radio
>
<a-radio value="All" title="All organizations">All</a-radio>
</a-radio-group>
</a-form-item>
Expand All @@ -40,11 +43,17 @@
</a-form-item>

<a-form-item class="formItems" label="Locales" name="locs">
<a-input
v-model:value="formState.locs"
placeholder="Optional list of locales (like: aa fr zh) (fr implies fr_CA/etc.) (empty for all locales)"
@blur="validateLocales()"
/>
<a-radio-group v-model:value="formState.localeType">
<a-radio value="all">All</a-radio>
<a-radio value="ddl">All DDL (non-TC) Locales</a-radio>
<a-radio value="choose">Choose…</a-radio>
<a-input
v-if="formState.localeType === 'choose'"
v-model:value="formState.locs"
placeholder="Required: list of locales, such as: “aa fr zh”. (fr implies fr_CA/etc.)"
@blur="validateLocales()"
/>
</a-radio-group>
</a-form-item>
<a-form-item
class="formItems"
Expand Down Expand Up @@ -73,7 +82,11 @@
<a-form-item>
<a-button html-type="cancel" @click="onCancel">Cancel</a-button>
&nbsp;
<a-button type="primary" html-type="submit" @click="onPost"
<a-button
type="primary"
:disabled="!okToPost()"
html-type="submit"
@click="onPost"
>Post</a-button
>
</a-form-item>
Expand All @@ -83,7 +96,7 @@

<script>
import * as cldrAnnounce from "../esm/cldrAnnounce.mjs";
import { defineComponent, reactive } from "vue";
import { defineComponent, reactive, ref } from "vue";

export default defineComponent({
props: ["formHasAllOrgs", "postOrCancel"],
Expand All @@ -95,6 +108,7 @@ export default defineComponent({
locs: "",
orgs: "Mine",
subject: "",
localeType: "all",
});

const onFinish = (values) => {
Expand All @@ -120,11 +134,19 @@ export default defineComponent({
onPost() {
// onFinish or onFinishFailed should be called for validation.
// Double-check that subject and body aren't empty.
if (this.formState.subject && this.formState.body) {
if (this.okToPost()) {
this.postOrCancel(this.formState);
}
},

/** @returns true only when the post button should be enabled */
okToPost() {
if (!this.formState.subject || !this.formState.body) return false;
if (this.formState.localeType != "choose") return true;
if (this.formState.locs != "") return true;
return false;
},

whatWillHappen() {
return (
"You are about to post an announcement to " +
Expand Down Expand Up @@ -158,6 +180,8 @@ export default defineComponent({
return "all organizations";
case "TC":
return "TC organizations";
case "NonTC":
return "Non-TC organizations";
case "Mine":
return "your organization only";
default:
Expand All @@ -166,9 +190,14 @@ export default defineComponent({
},

describeLocs() {
return this.formState.locs === "" || this.formState.locs === "*"
? "all locales"
: "the following locale(s): " + this.formState.locs;
if (this.formState.localeType === "ddl") return "DDL (Non-TC) locales";
if (
this.formState.localeType === "all" ||
this.formState.locs === "" ||
this.formState.locs === "*"
)
return "all locales";
return "the following locale(s): " + this.formState.locs;
},

validateLocales() {
Expand Down
9 changes: 6 additions & 3 deletions tools/cldr-apps/js/src/views/AnnouncePost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
<section class="announcementToFrom">
To: {{ announcement.audience }} •
{{ "Organization(s): " + announcement.orgs }} •
{{
announcement.locs ? "Locale(s): " + announcement.locs : "All locales"
}}
{{ localeText }}
</section>
<section class="announcementSubject">
{{ announcement.subject }}
Expand Down Expand Up @@ -50,6 +48,11 @@ export default {
.replaceAll("\n", "\n<br>\n")
.replaceAll(/(http\S+)/g, "<a href='$1'>$1</a>");
},
localeText() {
if (!this.announcement.locs) return "All locales";
if (this.announcement.locs === "!") return "DDL Locales";
srl295 marked this conversation as resolved.
Show resolved Hide resolved
return "Locale(s): " + this.announcement.locs;
},
},
};
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.ibm.icu.dev.util.ElapsedTimer;
import java.sql.*;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.unicode.cldr.test.SubmissionLocales;
import org.unicode.cldr.util.*;
import org.unicode.cldr.web.api.Announcements;

Expand Down Expand Up @@ -148,6 +149,7 @@ private static void emailNotify(
}
String subject = "CLDR Survey Tool announcement: " + request.subject;
String locs = (request.locs == null || request.locs.isEmpty()) ? "All" : request.locs;
if (locs.equals(Announcements.LOCS_NON_TC)) locs = "(DDL Locales)";
srl295 marked this conversation as resolved.
Show resolved Hide resolved
String body =
"From: "
+ poster.name
Expand Down Expand Up @@ -223,7 +225,16 @@ private static void addRecipientIfPasses(
AnnouncementFilter aFilter = new AnnouncementFilter(user);
Announcements.Announcement a =
new Announcements.Announcement(0, poster.id, null, null, null);
a.setFilters(request.locs, request.orgs, request.audience);
String filterLocs = request.locs;
if (filterLocs != null && filterLocs.equals(Announcements.LOCS_NON_TC)) {
// expand the filter
filterLocs =
SurveyMain.getLocalesSet().stream()
.filter(loc -> !SubmissionLocales.isTcLocale(loc))
.map(l -> l.getBaseName())
.collect(Collectors.joining(" "));
}
a.setFilters(filterLocs, request.orgs, request.audience);
if (aFilter.passes(a)) {
logger.fine("In AnnouncementData.addRecipientIfPasses, adding recipient: " + user.id);
recipients.add(user.id);
Expand Down Expand Up @@ -470,6 +481,8 @@ private boolean matchOrg(String orgs, int posterId) {
return true;
} else if (Announcements.ORGS_TC.equals(orgs)) {
return user.getOrganization().isTCOrg();
} else if (Announcements.ORGS_NON_TC.equals(orgs)) {
return !user.getOrganization().isTCOrg();
} else if (Announcements.ORGS_MINE.equals(orgs)) {
UserRegistry.User posterUser = CookieSession.sm.reg.getInfo(posterId);
return posterUser != null && posterUser.isSameOrg(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.unicode.cldr.test.SubmissionLocales;
import org.unicode.cldr.util.LocaleNormalizer;
import org.unicode.cldr.util.LocaleSet;
import org.unicode.cldr.util.Organization;
import org.unicode.cldr.web.*;

@ApplicationScoped
Expand All @@ -25,15 +27,26 @@ public class Announcements {
public static final String AUDIENCE_EVERYONE = "Everyone";

public static final String ORGS_MINE = "Mine";
/** all TC orgs, as defined by {@link Organization#isTCOrg()} */
public static final String ORGS_TC = "TC";
/** excluding TC orgs, as defined by {@link Organization#isTCOrg()} */
public static final String ORGS_NON_TC = "NonTC";
/** All organizations */
public static final String ORGS_ALL = "All";

/**
* Special value for ddl (non tc) locales. This special value for locales sends to all locales,
* but only those which are currently not defined as TC Locales by the SubmissionLocales class.
* {@link SubmissionLocales#isTcLocale(org.unicode.cldr.util.CLDRLocale)}
*/
public static final String LOCS_NON_TC = "!";

private static final Set<String> validAudiences =
new HashSet<>(
Arrays.asList(
AUDIENCE_TC, AUDIENCE_MANAGERS, AUDIENCE_VETTERS, AUDIENCE_EVERYONE));
private static final Set<String> validOrgs =
new HashSet<>(Arrays.asList(ORGS_MINE, ORGS_TC, ORGS_ALL));
new HashSet<>(Arrays.asList(ORGS_MINE, ORGS_NON_TC, ORGS_TC, ORGS_ALL));

@GET
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -242,6 +255,9 @@ public SubmissionRequest() {
@Schema(description = "locales")
public String locs = null;

@Schema(description = "localeType: one of 'all', 'ddl', or 'choose'", example = "choose")
public String localeType = null;

@Schema(description = "orgs")
public String orgs = null;

Expand All @@ -250,7 +266,14 @@ public boolean isValid() {
}

public void normalize() {
if (locs != null) {
if ("ddl".equals(localeType)) {
// special value for ddl (non-tc) locales.
// "ddl" means non-tc locales.
locs = LOCS_NON_TC;
} else if ("all".equals(localeType)) {
// all locales
locs = null;
} else if (locs != null) {
String normalized = LocaleNormalizer.normalizeQuietly(locs);
LocaleSet locSet = LocaleNormalizer.setFromStringQuietly(normalized, null);
LocaleSet langSet = locSet.combineRegionalVariants();
Expand Down
Loading