From 2dfe0f3ff2cf3b36a3826ff0de14ede0594a5af5 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 22 Sep 2020 12:49:20 +0200 Subject: [PATCH] queue [add|edit]Annotation calls addAnnotation was called multiple times creating multiple annotations editAnnotation calls might overwrite later calls depending on response time. --- static/js/editor.js | 68 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/static/js/editor.js b/static/js/editor.js index 3d53d89a..16da2d01 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -205,9 +205,9 @@ pandora.ui.editor = function(data) { }).open(); }, editannotation: function(data) { - Ox.Log('', 'editAnnotation', data); + Ox.Log('', 'editAnnotation', data.id, data); function callback(result) { - Ox.Log('', 'editAnnotation result', result); + Ox.Log('', 'editAnnotation result', result.data.id, result); if (!Ox.isEmpty(result.data)) { result.data.date = Ox.formatDate( result.data.modified.slice(0, 10), '%B %e, %Y' @@ -222,21 +222,56 @@ pandora.ui.editor = function(data) { pandora.UI.set('videoPoints.' + ui.item + '.annotation', result.data.id.split('/')[1] || ''); Ox.Request.clearCache(); }; + var edit = { + 'in': data['in'], + out: data.out, + value: data.value + } if (data.id[0] == '_') { - pandora.api.addAnnotation({ - 'in': data['in'], - item: ui.item, - layer: data.layer, - out: data.out, - value: data.value - }, callback); + edit.item = ui.item; + edit.layer = data.layer; + + if (queue[data.id]) { + queue[data.id].push(edit); + } else { + queue[data.id] = []; + pandora.api.addAnnotation(edit, function(result) { + callback(result); + var id = data.id, + pending = queue[id]; + delete queue[id]; + pending.length && Ox.serialForEach(pending, function(edit, index, array, callback) { + edit.id = id + Ox.Log('', 'process pending editAnnotation request', id, edit); + pandora.api.editAnnotation(edit, function(result) { + callback(); + }) + }, function() { + Ox.Request.clearCache(); + }); + }); + } } else { - pandora.api.editAnnotation({ - id: data.id, - 'in': data['in'], - out: data.out, - value: data.value - }, callback); + edit.id = data.id; + if (queue[data.id]) { + queue[data.id].push(edit); + } else { + queue[data.id] = []; + pandora.api.editAnnotation(edit, function(result) { + callback(result); + var pending = queue[edit.id]; + delete queue[edit.id]; + pending.length && Ox.serialForEach(pending, function(edit, index, array, cb) { + Ox.Log('', 'process pending editAnnotation request', edit.id, edit); + pandora.api.editAnnotation(edit, function(result) { + callback(result); + cb(); + }) + }, function() { + Ox.Request.clearCache(); + }); + }); + } } }, embedselection: function() { @@ -387,7 +422,8 @@ pandora.ui.editor = function(data) { pandora_videotimeline: function(data) { that.options({timeline: data.value}); } - }); + }), + queue = []; pandora._dontSelectResult = false;