Checking for changes in the sheet now working in the thrimbletrimmer

pull/195/head
Christopher Usher 4 years ago
parent 1216c8e8a5
commit b21a520d3a

@ -11,6 +11,7 @@ pageSetup = function(isEditor) {
alert("No video available for stream.");
return;
}
document.data = data
desertBusStart = new Date(data.bustime_start);
document.getElementById("VideoTitlePrefix").value = data.title_prefix;
document.getElementById("VideoTitle").setAttribute("maxlength", data.title_max_length);
@ -230,7 +231,7 @@ loadPlaylist = function(isEditor, startTrim, endTrim, defaultQuality) {
});
};
thrimbletrimmerSubmit = function(state) {
thrimbletrimmerSubmit = function(state, override_changes=false) {
document.getElementById('SubmitButton').disabled = true;
var discontinuities = mapDiscontinuities();
@ -251,10 +252,21 @@ thrimbletrimmerSubmit = function(state) {
video_quality:document.getElementById('qualityLevel').options[document.getElementById('qualityLevel').options.selectedIndex].value,
uploader_whitelist:(document.getElementById('uploaderWhitelist').value ? document.getElementById('uploaderWhitelist').value.split(','):null),
state:state,
//pass back the sheet columns to check if any have changed
sheet_name:document.data.sheet_name,
event_start:document.data.event_start,
event_end:document.data.event_end,
category:document.data.category,
description:document.data.description,
notes:document.data.notes,
};
if (!!user) {
wubData.token = user.getAuthResponse().id_token
}
if (override_changes) {
wubData["override_changes"] = true;
}
console.log(wubData);
console.log(JSON.stringify(wubData));
@ -263,7 +275,8 @@ thrimbletrimmerSubmit = function(state) {
//Submit to thrimshim
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
fetch("/thrimshim/"+rowId, {
path = "/thrimshim/" + rowId + "?override_changes=" + override_changes;
fetch(path, {
method: 'POST',
headers: {
'Accept': 'application/json',
@ -275,7 +288,14 @@ thrimbletrimmerSubmit = function(state) {
if (!response.ok) {
var error = response.statusText + ": " + text;
console.log(error);
if (response.status == 409) {
if (confirm(text)) {
thrimbletrimmerSubmit(state, true);
} else {
alert(error);
}
}
} else if (state == 'EDITED') {
// Only return to dashboard if submitted, not for save draft
setTimeout(() => { window.location.href = '/thrimbletrimmer/dashboard.html'; }, 500);

@ -182,8 +182,9 @@ def get_row(ident):
@app.route('/thrimshim/<uuid:ident>', methods=['POST'])
@request_stats
@authenticate
def update_row(ident, editor=None, override_changes=False):
def update_row(ident, editor=None):
new_row = flask.request.json
override_changes = 'override_changes' in new_row
"""Updates row of database with id = ident with the edit columns in
new_row."""
@ -240,7 +241,7 @@ def update_row(ident, editor=None, override_changes=False):
if isinstance(old_row[column], datetime.datetime):
old_row[column] = old_row[column].isoformat()
if new_row[column] != old_row[column]:
changes += '{}:: Database: {} Thrimbletrimmer: {}\n'.format(column, old_row[column], new_row[column])
changes += '{}: Database: {} Thrimbletrimmer: {}\n'.format(column, old_row[column], new_row[column])
if changes and not override_changes:
return 'Sheet columns have changed since editing has begun. Please review changes\n' + changes, 409
@ -272,7 +273,7 @@ def update_row(ident, editor=None, override_changes=False):
).format(sql.SQL(", ").join(
sql.SQL("{} = {}").format(
sql.Identifier(column), sql.Placeholder(column),
) for column in new_row.keys()
) for column in new_row.keys() if column not in sheet_columns
))
result = database.query(conn, build_query, id=ident, **new_row)
if result.rowcount != 1:

Loading…
Cancel
Save