forked from unicode-org/cldr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLDR-14913 Add Download XML button to Survey Tool (unicode-org#4010)
- Loading branch information
Showing
14 changed files
with
765 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* cldrGenerateVxml: for Survey Tool feature "Generate VXML". The display logic is in GenerateVxml.vue. | ||
*/ | ||
import * as cldrAjax from "./cldrAjax.mjs"; | ||
import * as cldrAnnounce from "./cldrAnnounce.mjs"; | ||
import * as cldrNotify from "./cldrNotify.mjs"; | ||
import * as cldrStatus from "./cldrStatus.mjs"; | ||
|
||
const SECONDS_IN_MS = 1000; | ||
|
||
const NORMAL_RETRY = 10 * SECONDS_IN_MS; // "Normal" retry: starting or about to start | ||
|
||
const VXML_URL = "api/vxml"; | ||
|
||
// These must match the back end; used in requests | ||
class LoadingPolicy { | ||
static START = "START"; // start generating vxml | ||
static CONTINUE = "CONTINUE"; // continue generating vxml | ||
static STOP = "STOP"; // stop (cancel) generating vxml | ||
} | ||
|
||
// These must match the back end; used in responses | ||
class Status { | ||
static INIT = "INIT"; // before making a request (back end does not have INIT) | ||
static WAITING = "WAITING"; // waiting on other users/tasks | ||
static PROCESSING = "PROCESSING"; // in progress | ||
static READY = "READY"; // finished successfully | ||
static STOPPED = "STOPPED"; // due to error or cancellation (LoadingPolicy.STOP) | ||
} | ||
|
||
let canGenerate = false; | ||
|
||
let callbackToSetData = null; | ||
|
||
function canGenerateVxml() { | ||
return canGenerate; | ||
} | ||
|
||
function viewMounted(setData) { | ||
callbackToSetData = setData; | ||
const perm = cldrStatus.getPermissions(); | ||
canGenerate = Boolean(perm?.userIsAdmin); | ||
} | ||
|
||
function start() { | ||
// Disable announcements during VXML generation to reduce risk of interference | ||
cldrAnnounce.enableAnnouncements(false); | ||
requestVxml(LoadingPolicy.START); | ||
} | ||
|
||
function fetchStatus() { | ||
if (!canGenerate || "generate_vxml" !== cldrStatus.getCurrentSpecial()) { | ||
canGenerate = false; | ||
} else if (canGenerate) { | ||
requestVxml(LoadingPolicy.CONTINUE); | ||
} | ||
} | ||
|
||
function stop() { | ||
requestVxml(LoadingPolicy.STOP); | ||
} | ||
|
||
function requestVxml(loadingPolicy) { | ||
const args = { loadingPolicy: loadingPolicy }; | ||
const init = cldrAjax.makePostData(args); | ||
cldrAjax | ||
.doFetch(VXML_URL, init) | ||
.then(cldrAjax.handleFetchErrors) | ||
.then((r) => r.json()) | ||
.then(setVxmlData) | ||
.catch((e) => { | ||
cldrNotify.exception(e, "generating VXML"); | ||
}); | ||
} | ||
|
||
function setVxmlData(data) { | ||
if (!callbackToSetData) { | ||
return; | ||
} | ||
callbackToSetData(data); | ||
if (data.status === Status.WAITING || data.status === Status.PROCESSING) { | ||
window.setTimeout(fetchStatus.bind(this), NORMAL_RETRY); | ||
} else if (data.status === Status.READY || data.status === Status.STOPPED) { | ||
cldrAnnounce.enableAnnouncements(true); // restore | ||
} | ||
} | ||
|
||
export { Status, canGenerateVxml, start, stop, viewMounted }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<script setup> | ||
import { onMounted, ref } from "vue"; | ||
import * as cldrGenerateVxml from "../esm/cldrGenerateVxml.mjs"; | ||
const STATUS = cldrGenerateVxml.Status; | ||
let hasPermission = ref(false); | ||
let message = ref(""); | ||
let output = ref(""); | ||
let percent = ref(0); | ||
let status = ref(STATUS.INIT); | ||
function mounted() { | ||
cldrGenerateVxml.viewMounted(setData); | ||
hasPermission.value = Boolean(cldrGenerateVxml.canGenerateVxml()); | ||
} | ||
onMounted(mounted); | ||
function start() { | ||
if (hasPermission) { | ||
cldrGenerateVxml.start(); | ||
status.value = STATUS.WAITING; | ||
} | ||
} | ||
function stop() { | ||
cldrGenerateVxml.stop(); | ||
status.value = STATUS.STOPPED; | ||
} | ||
function canStop() { | ||
return status.value === STATUS.WAITING || status.value === STATUS.PROCESSING; | ||
} | ||
function setData(data) { | ||
message.value = data.message; | ||
percent.value = data.percent; | ||
status.value = data.status; | ||
output.value = data.output; | ||
} | ||
defineExpose({ | ||
setData, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div v-if="!hasPermission">Please log in as Admin to use this feature.</div> | ||
<div v-else> | ||
<p v-if="status != STATUS.INIT">Current Status: {{ status }}</p> | ||
<p v-if="message"> | ||
<span v-html="message"></span> | ||
</p> | ||
<p class="buttons"> | ||
<button v-if="canStop()" @click="stop()">Stop</button> | ||
<button v-else @click="start()">Generate VXML Now</button> | ||
</p> | ||
<p class="progressBar"> | ||
<a-progress :percent="percent" /> | ||
</p> | ||
<p v-html="output"></p> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.buttons { | ||
margin: 1em; | ||
} | ||
.progressBar { | ||
width: 50%; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.