-
Notifications
You must be signed in to change notification settings - Fork 384
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
-Front end: new GenerateVxml.vue, cldrGenerateVxml.mjs -Back end: new GenerateVxml.java, VxmlQueue.java, VxmlGenerator.java -Run the task in its own thread, with multiple http requests fetching status until done -Partly imitate implementation of Priority Items Summary: GenerateVxml.java corresponds to Summary.java; VxmlGenerator.java corresponds to VettingViewer.java; VxmlQueue.java corresponds to VettingViewerQueue.java -Revise OutputFileManager.java as needed and also to fix some (not all) compiler warnings -Disable Announce requests while VXML generation is in progress (only on front end; only affects the browser of the Admin user, not other users if running on remote server) -Remove common/annotations/ff.xml at least temporarily; it is essentially empty and leads to verification failure: present in baseline but not in vxml -Fix bug in XPathTable.loadXPaths, DB connection without commit, change getDBConnection to getAConnection for auto-commit (pre-existing bug was especially problematic throwing exception when generating VXML) -Improve debugging feature in DBUtils.java slightly and add comment about remaining imperfection -Use auto-commit in STFactory.setupDB and make the related boolean dbIsSetup private -Remove dead code -Comments
- Loading branch information
Showing
15 changed files
with
766 additions
and
191 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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.