more refactoring

This commit is contained in:
Sundog Jones 2024-09-03 12:09:42 -04:00
parent 1552236601
commit 24e410f81a

View File

@ -399,12 +399,17 @@
}); });
} }
const secs_to_human_duration = (secs) => {
// date and time munging using substring? it's more likely than you think
return new Date(secs * 1000).toISOString().substring(11, 19);
}
const populate_media_library = (rows) => { const populate_media_library = (rows) => {
const media_library_target = document.querySelector("#media_library_contents"); const media_library_target = document.querySelector("#media_library_contents");
media_library_target.innerHTML = ""; media_library_target.innerHTML = "";
rows.forEach((row) => { rows.forEach((row) => {
const duration = new Date(row['duration_secs'] * 1000).toISOString().substring(11, 19); const duration = secs_to_human_duration(row['duration_secs']);
const template = document.getElementById("media_item_template"); const template = document.getElementById("media_item_template");
const template_clone = template.content.firstElementChild.cloneNode(true); const template_clone = template.content.firstElementChild.cloneNode(true);
template_clone.querySelector(".media_item_title").innerHTML = row['title']; template_clone.querySelector(".media_item_title").innerHTML = row['title'];
@ -468,7 +473,7 @@
const current_timecode = document.getElementById("media_item_preview").currentTime; const current_timecode = document.getElementById("media_item_preview").currentTime;
const template = document.getElementById("media_item_edl_insert_listitem"); const template = document.getElementById("media_item_edl_insert_listitem");
const template_clone = template.content.cloneNode(true); const template_clone = template.content.cloneNode(true);
const formatted_timestamp = new Date(current_timecode * 1000).toISOString().substring(11, 19); const formatted_timestamp = secs_to_human_duration(current_timecode);
template_clone.querySelector('input[name="media_item_edl_insert"]').value = formatted_timestamp; template_clone.querySelector('input[name="media_item_edl_insert"]').value = formatted_timestamp;
template_clone.firstElementChild.setAttribute('data-timestamp', current_timecode); template_clone.firstElementChild.setAttribute('data-timestamp', current_timecode);
const target = document.querySelector("#media_item_edl_outpoint_listitem"); const target = document.querySelector("#media_item_edl_outpoint_listitem");