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."); alert("No video available for stream.");
return; return;
} }
document.data = data
desertBusStart = new Date(data.bustime_start); desertBusStart = new Date(data.bustime_start);
document.getElementById("VideoTitlePrefix").value = data.title_prefix; document.getElementById("VideoTitlePrefix").value = data.title_prefix;
document.getElementById("VideoTitle").setAttribute("maxlength", data.title_max_length); 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; document.getElementById('SubmitButton').disabled = true;
var discontinuities = mapDiscontinuities(); var discontinuities = mapDiscontinuities();
@ -250,11 +251,22 @@ thrimbletrimmerSubmit = function(state) {
video_channel:document.getElementById("StreamName").value, video_channel:document.getElementById("StreamName").value,
video_quality:document.getElementById('qualityLevel').options[document.getElementById('qualityLevel').options.selectedIndex].value, video_quality:document.getElementById('qualityLevel').options[document.getElementById('qualityLevel').options.selectedIndex].value,
uploader_whitelist:(document.getElementById('uploaderWhitelist').value ? document.getElementById('uploaderWhitelist').value.split(','):null), uploader_whitelist:(document.getElementById('uploaderWhitelist').value ? document.getElementById('uploaderWhitelist').value.split(','):null),
state:state, 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) { if (!!user) {
wubData.token = user.getAuthResponse().id_token wubData.token = user.getAuthResponse().id_token
} }
if (override_changes) {
wubData["override_changes"] = true;
}
console.log(wubData); console.log(wubData);
console.log(JSON.stringify(wubData)); console.log(JSON.stringify(wubData));
@ -262,8 +274,9 @@ thrimbletrimmerSubmit = function(state) {
if (!wubData.video_end) {alert("No end time set"); return;} if (!wubData.video_end) {alert("No end time set"); return;}
//Submit to thrimshim //Submit to thrimshim
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
fetch("/thrimshim/"+rowId, { path = "/thrimshim/" + rowId + "?override_changes=" + override_changes;
fetch(path, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
@ -275,7 +288,14 @@ thrimbletrimmerSubmit = function(state) {
if (!response.ok) { if (!response.ok) {
var error = response.statusText + ": " + text; var error = response.statusText + ": " + text;
console.log(error); console.log(error);
alert(error); if (response.status == 409) {
if (confirm(text)) {
thrimbletrimmerSubmit(state, true);
} else {
alert(error);
}
}
} else if (state == 'EDITED') { } else if (state == 'EDITED') {
// Only return to dashboard if submitted, not for save draft // Only return to dashboard if submitted, not for save draft
setTimeout(() => { window.location.href = '/thrimbletrimmer/dashboard.html'; }, 500); setTimeout(() => { window.location.href = '/thrimbletrimmer/dashboard.html'; }, 500);

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

Loading…
Cancel
Save