Add ability to submit video as MODIFIED to thrimbletrimmer

pull/295/head
Mike Lang 2 years ago committed by Mike Lang
parent f06be1f391
commit ac6612fb85

@ -196,6 +196,7 @@
<div id="submission-toolbar"> <div id="submission-toolbar">
<button id="submit-button">Submit</button> <button id="submit-button">Submit</button>
<button id="save-button">Save Draft</button> <button id="save-button">Save Draft</button>
<button id="submit-changes-button">Submit Changes</button>
<a id="advanced-submission" href="#">Advanced Submission Options</a> <a id="advanced-submission" href="#">Advanced Submission Options</a>
</div> </div>
<div id="advanced-submission-options" class="hidden"> <div id="advanced-submission-options" class="hidden">

@ -202,6 +202,9 @@ window.addEventListener("DOMContentLoaded", async (event) => {
document.getElementById("save-button").addEventListener("click", (_event) => { document.getElementById("save-button").addEventListener("click", (_event) => {
saveVideoDraft(); saveVideoDraft();
}); });
document.getElementById("submit-changes-button").addEventListener("click", (_event) => {
submitVideoChanges();
});
document.getElementById("advanced-submission").addEventListener("click", (_event) => { document.getElementById("advanced-submission").addEventListener("click", (_event) => {
const advancedOptionsContainer = document.getElementById("advanced-submission-options"); const advancedOptionsContainer = document.getElementById("advanced-submission-options");
@ -406,6 +409,15 @@ async function initializeVideoInfo() {
uploaderAllowlistBox.value = videoInfo.uploader_whitelist.join(","); uploaderAllowlistBox.value = videoInfo.uploader_whitelist.join(",");
} }
if (videoInfo.state === "DONE") {
const submitButton = document.getElementById("submit-button");
submitButton.classList.add("hidden");
const saveButton = document.getElementById("save-button");
saveButton.classList.add("hidden");
const submitChangesButton = document.getElementById("submit-changes-button");
submitChangesButton.classList.remove("hidden");
}
if (modifiedAdvancedOptions) { if (modifiedAdvancedOptions) {
const advancedSubmissionContainer = document.getElementById("advanced-submission-options"); const advancedSubmissionContainer = document.getElementById("advanced-submission-options");
advancedSubmissionContainer.classList.remove("hidden"); advancedSubmissionContainer.classList.remove("hidden");
@ -611,14 +623,18 @@ async function submitVideo() {
} }
} }
return sendVideoData(true, false); return sendVideoData("EDITED", false);
} }
async function saveVideoDraft() { async function saveVideoDraft() {
return sendVideoData(false, false); return sendVideoData("UNEDITED", false);
}
async function submitVideoChanges() {
return sendVideoData("MODIFIED", false);
} }
async function sendVideoData(edited, overrideChanges) { async function sendVideoData(newState, overrideChanges) {
let videoDescription = document.getElementById("video-info-description").value; let videoDescription = document.getElementById("video-info-description").value;
if (videoDescription.indexOf(CHAPTER_MARKER_DELIMITER_PARTIAL) !== -1) { if (videoDescription.indexOf(CHAPTER_MARKER_DELIMITER_PARTIAL) !== -1) {
addError( addError(
@ -627,6 +643,8 @@ async function sendVideoData(edited, overrideChanges) {
return; return;
} }
const edited = newState === "EDITED";
const submissionResponseElem = document.getElementById("submission-response"); const submissionResponseElem = document.getElementById("submission-response");
submissionResponseElem.classList.value = ["submission-response-pending"]; submissionResponseElem.classList.value = ["submission-response-pending"];
submissionResponseElem.innerText = "Submitting video..."; submissionResponseElem.innerText = "Submitting video...";
@ -771,7 +789,6 @@ async function sendVideoData(edited, overrideChanges) {
"advanced-submission-option-uploader-allow" "advanced-submission-option-uploader-allow"
).value; ).value;
const uploaderAllowlist = uploaderAllowlistValue ? uploaderAllowlistValue.split(",") : null; const uploaderAllowlist = uploaderAllowlistValue ? uploaderAllowlistValue.split(",") : null;
const state = edited ? "EDITED" : "UNEDITED";
const editData = { const editData = {
video_ranges: ranges, video_ranges: ranges,
@ -784,7 +801,7 @@ async function sendVideoData(edited, overrideChanges) {
video_channel: globalStreamName, video_channel: globalStreamName,
video_quality: videoInfo.video_quality, video_quality: videoInfo.video_quality,
uploader_whitelist: uploaderAllowlist, uploader_whitelist: uploaderAllowlist,
state: state, state: newState,
// We also provide some sheet column values to verify data hasn't changed. // We also provide some sheet column values to verify data hasn't changed.
sheet_name: videoInfo.sheet_name, sheet_name: videoInfo.sheet_name,
@ -815,7 +832,7 @@ async function sendVideoData(edited, overrideChanges) {
if (submitResponse.ok) { if (submitResponse.ok) {
submissionResponseElem.classList.value = ["submission-response-success"]; submissionResponseElem.classList.value = ["submission-response-success"];
if (edited) { if (newState === "EDITED") {
submissionResponseElem.innerText = "Submitted edit"; submissionResponseElem.innerText = "Submitted edit";
const submissionTimesListContainer = document.createElement("ul"); const submissionTimesListContainer = document.createElement("ul");
for (const range of rangesData) { for (const range of rangesData) {
@ -828,8 +845,13 @@ async function sendVideoData(edited, overrideChanges) {
submissionTimesListContainer.appendChild(submissionTimeResponse); submissionTimesListContainer.appendChild(submissionTimeResponse);
} }
submissionResponseElem.appendChild(submissionTimesListContainer); submissionResponseElem.appendChild(submissionTimesListContainer);
} else { } else if (newState === "UNEDITED") {
submissionResponseElem.innerText = "Saved draft"; submissionResponseElem.innerText = "Saved draft";
} else if (newState === "MODIFIED") {
submissionResponseElem.innerText = "Submitted changes";
} else {
// should never happen but shrug
submissionResponseElem.innerText = `Submitted state ${newState}`;
} }
} else { } else {
submissionResponseElem.classList.value = ["submission-response-error"]; submissionResponseElem.classList.value = ["submission-response-error"];
@ -838,7 +860,7 @@ async function sendVideoData(edited, overrideChanges) {
const submitButton = document.createElement("button"); const submitButton = document.createElement("button");
submitButton.innerText = "Submit Anyway"; submitButton.innerText = "Submit Anyway";
submitButton.addEventListener("click", (_event) => { submitButton.addEventListener("click", (_event) => {
sendVideoData(edited, true); sendVideoData(newState, true);
}); });
submissionResponseElem.innerHTML = ""; submissionResponseElem.innerHTML = "";
submissionResponseElem.appendChild(serverErrorNode); submissionResponseElem.appendChild(serverErrorNode);

Loading…
Cancel
Save