|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
// TODO: could get path constants from DOM in jinja template
|
|
|
|
// TODO: could get path constants from DOM in jinja template
|
|
|
|
const FOLDER_CONTENTS_PATH = '/pvdb/file_listing/folder_contents'; |
|
|
|
const FOLDER_CONTENTS_PATH = '/pvdb/file_listing/folder_contents_json/'; |
|
|
|
const QUERY_PATH = '/pvdb/tmdb/query_movie' |
|
|
|
const QUERY_PATH = '/pvdb/tmdb/query_movie' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -31,8 +31,10 @@ function addContents(node, json) { |
|
|
|
element.removeChild(element.querySelector('ul')); |
|
|
|
element.removeChild(element.querySelector('ul')); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (a.dataset.is_dir == 'true') { |
|
|
|
if (a.dataset.is_dir == 'true') { |
|
|
|
fetchJSON(FOLDER_CONTENTS_PATH + a.dataset.rel_path, parseResponse, e); |
|
|
|
fetchJSON(FOLDER_CONTENTS_PATH + a.dataset.rel_path, parseResponse, element); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
// TODO: would be nice to have a modal here to select the metadata
|
|
|
|
|
|
|
|
// TODO: also need a way to display file paths that are already stored
|
|
|
|
window.location = QUERY_PATH |
|
|
|
window.location = QUERY_PATH |
|
|
|
+ '?query=' + a.dataset.base_name |
|
|
|
+ '?query=' + a.dataset.base_name |
|
|
|
+ '&rel_path=' + a.dataset.rel_path; |
|
|
|
+ '&rel_path=' + a.dataset.rel_path; |
|
|
|
@ -41,7 +43,7 @@ function addContents(node, json) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function parseResponse(json, event) { |
|
|
|
function parseResponse(json, node) { |
|
|
|
if (json.errors.length > 0) { |
|
|
|
if (json.errors.length > 0) { |
|
|
|
for (let err of json.errors) |
|
|
|
for (let err of json.errors) |
|
|
|
logError(err); |
|
|
|
logError(err); |
|
|
|
@ -53,7 +55,8 @@ function parseResponse(json, event) { |
|
|
|
for (let path of json.paths) |
|
|
|
for (let path of json.paths) |
|
|
|
addContents(ul, path); |
|
|
|
addContents(ul, path); |
|
|
|
|
|
|
|
|
|
|
|
event.target.parentNode.appendChild(frag); |
|
|
|
console.log(node); |
|
|
|
|
|
|
|
node.appendChild(frag); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -67,24 +70,7 @@ window.onload = function() { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: remove the top level links from jinja template, and just load as JSON
|
|
|
|
fetchJSON(FOLDER_CONTENTS_PATH, parseResponse, document.querySelector('#videolist')); |
|
|
|
// to avoid duplicate code.
|
|
|
|
|
|
|
|
// TODO: should probably look at flask routes as well
|
|
|
|
|
|
|
|
// TODO: will need to update the addContents function
|
|
|
|
|
|
|
|
// NOTE: replace top level links with event listeners that fetch json directory listings
|
|
|
|
|
|
|
|
for (let link of document.querySelectorAll('#videolist > li > a')) { |
|
|
|
|
|
|
|
let href = link.getAttribute('href') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
link.addEventListener('click', function(e) { |
|
|
|
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
let element = e.target.parentNode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (element.querySelector('ul')) |
|
|
|
|
|
|
|
element.removeChild(element.querySelector('ul')); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
fetchJSON(FOLDER_CONTENTS_PATH + href, parseResponse, e); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -102,7 +88,7 @@ function removeAllChildren(node) { |
|
|
|
node.removeChild(node.lastChild); |
|
|
|
node.removeChild(node.lastChild); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function fetchJSON(url, responseFunc, event) { |
|
|
|
function fetchJSON(url, responseFunc, node) { |
|
|
|
fetch(url) |
|
|
|
fetch(url) |
|
|
|
.then(function(response) { |
|
|
|
.then(function(response) { |
|
|
|
if (!response.ok) |
|
|
|
if (!response.ok) |
|
|
|
@ -111,7 +97,7 @@ function fetchJSON(url, responseFunc, event) { |
|
|
|
return response.json(); |
|
|
|
return response.json(); |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then(function(json) { |
|
|
|
.then(function(json) { |
|
|
|
responseFunc(json, event); |
|
|
|
responseFunc(json, node); |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch(function(error) { |
|
|
|
.catch(function(error) { |
|
|
|
logError('fetch error: ' + error); |
|
|
|
logError('fetch error: ' + error); |
|
|
|
|