From 66a809c56046db8161cd5dc694ab4f62cb9c508d Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Fri, 27 Sep 2019 17:29:14 -0400 Subject: [PATCH] start on async file mapping --- video_metadata/static/file_listing.js | 23 +++++++++++++++++++++-- video_metadata/views/tmdb.py | 1 - 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/video_metadata/static/file_listing.js b/video_metadata/static/file_listing.js index d94e3fd..4615cca 100644 --- a/video_metadata/static/file_listing.js +++ b/video_metadata/static/file_listing.js @@ -75,8 +75,9 @@ function openQueryDialog(dataset) { description.appendChild(document.createTextNode(result.overview)); let map_link = qtclone.querySelector('.mapping_link'); - map_link.href = CREATE_MAPPING_PATH + '?movie_id=' + json.id - + '&rel_path=' + dataset.rel_path; + map_link.addEventListener('click', function(e) { + submitFileMapping(e, result.id, dataset.rel_path); + }); tclone.querySelector('#query_result_container').appendChild(qtclone); } @@ -86,6 +87,23 @@ function openQueryDialog(dataset) { }); } +function submitFileMapping(click_event, movie_id, rel_path) { + click_event.preventDefault(); + console.log('movie_id: ' + movie_id); + console.log('rel_path: ' + rel_path); + // TODO: + // - make query with POST + // - display errors + // - display success + // - update link class to file_stored + // - close query box + + query_str = CREATE_MAPPING_PATH + '?movie_id=' + movie_id + '&rel_path=' + rel_path; + fetchJSON(query_str, function(json) { + console.log(json); + }); +} + function parseResponse(json, node) { if (node == null) { logError('parent node cannot be null'); @@ -151,6 +169,7 @@ function fetchJSON(url, responseFunc, node=null) { .then(function(json) { (node == null) ? responseFunc(json) : responseFunc(json, node); }) + // TODO: don't catch errors in responseFunc .catch(function(error) { logError('fetch error: ' + error); return null; diff --git a/video_metadata/views/tmdb.py b/video_metadata/views/tmdb.py index ec604dd..af6ec32 100644 --- a/video_metadata/views/tmdb.py +++ b/video_metadata/views/tmdb.py @@ -202,7 +202,6 @@ def create_mapping(): current_app.logger.error(e) return jsonify({'errors':errors, 'message':message}) - # TODO: query_movie() will no longer need rel_path argument ###################