Skip to content

Commit

Permalink
CLDR-16835 update form for sending announcements
Browse files Browse the repository at this point in the history
- radio button for all, ddl, choose locales
- validation, where the Post button doesn't show if validation fails.
- documentation of ddl vs non-ddl locales
  • Loading branch information
srl295 committed Jun 14, 2024
1 parent 8add514 commit ec3774a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
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
48 changes: 35 additions & 13 deletions tools/cldr-apps/js/src/views/AnnounceForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,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, '!' for non-TC)"
@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 @@ -76,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 @@ -86,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 @@ -98,6 +108,7 @@ export default defineComponent({
locs: "",
orgs: "Mine",
subject: "",
localeType: "all",
});
const onFinish = (values) => {
Expand All @@ -123,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 @@ -171,14 +190,17 @@ export default defineComponent({
},
describeLocs() {
if (this.formState.locs === "!") return "Non-TC locales";
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() {
if (this.formState.locs === "!") return;
cldrAnnounce.combineAndValidateLocales(
this.formState.locs,
this.updateValidatedLocales
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,10 +27,18 @@ 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 =
Expand Down Expand Up @@ -245,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 @@ -253,7 +266,14 @@ public boolean isValid() {
}

public void normalize() {
if (locs != null && !locs.equals(LOCS_NON_TC)) {
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

0 comments on commit ec3774a

Please sign in to comment.