From a5dd635cc4d86e39f02f448744ddf2506cf0ff1e Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Tue, 4 Nov 2025 09:08:09 -0500 Subject: [PATCH] updates: fixes for imdb manual add and manual add dates --- VERSION | 2 +- nfoguard-web/static/js/app.js | 113 ++++++++++++++++++++++++---------- 2 files changed, 81 insertions(+), 34 deletions(-) diff --git a/VERSION b/VERSION index 567de8f..572a4ef 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.10.0-skipped-imdb-edit-v2 +2.10.0-skipped-imdb-edit-v3 diff --git a/nfoguard-web/static/js/app.js b/nfoguard-web/static/js/app.js index 5a6936c..361ff06 100644 --- a/nfoguard-web/static/js/app.js +++ b/nfoguard-web/static/js/app.js @@ -1065,7 +1065,7 @@ function showEnhancedEditModal(mediaType, options, currentDateadded, currentSour const modal = document.getElementById('edit-modal'); const title = document.getElementById('modal-title'); const modalBody = document.querySelector('#edit-modal .modal-body'); - + if (mediaType === 'movie') { title.textContent = `Edit Movie: ${options.imdb_id}`; } else { @@ -1074,9 +1074,10 @@ function showEnhancedEditModal(mediaType, options, currentDateadded, currentSour const episode = options.episode || 0; title.textContent = `Edit Episode: ${options.imdb_id} S${season.toString().padStart(2, '0')}E${episode.toString().padStart(2, '0')}`; } - + // Build enhanced edit form with date options let formHtml = ` +
${mediaType === 'episode' ? ` @@ -1086,21 +1087,21 @@ function showEnhancedEditModal(mediaType, options, currentDateadded, currentSour `} - +
`; - + // Add available date options options.options.forEach((option, index) => { const isSelected = option.source === currentSource ? 'checked' : ''; const optionId = `date-option-${index}`; - + formHtml += `
- +
Adjust the date/time as needed
- +
- +
- +
+ `; - + modalBody.innerHTML = formHtml; - - + + // Set current values if (currentDateadded && currentDateadded !== '-') { try { @@ -1152,12 +1154,12 @@ function showEnhancedEditModal(mediaType, options, currentDateadded, currentSour document.getElementById('edit-dateadded').value = ''; } } - + document.getElementById('edit-source').value = currentSource || 'manual'; - + // Store options for later use modal.dataset.options = JSON.stringify(options); - + modal.classList.add('active'); } @@ -1219,35 +1221,51 @@ function updateEditDateFromOption(optionIndex, option) { async function handleEnhancedEditSubmit(event) { event.preventDefault(); - + + console.log('🔍 Enhanced Edit Submit called'); + const modal = document.getElementById('edit-modal'); const options = JSON.parse(modal.dataset.options); const imdbId = options.imdb_id; const mediaType = document.getElementById('edit-media-type').value; const dateadded = document.getElementById('edit-dateadded').value; const source = document.getElementById('edit-source').value; - + + console.log('🔍 Form values:', { + imdbId, + mediaType, + dateadded, + dateaddedType: typeof dateadded, + dateaddedLength: dateadded ? dateadded.length : 0, + source + }); + if (!dateadded) { + console.log('❌ Date field is empty!'); showToast('Please enter a date', 'warning'); return; } - + // Convert datetime-local to ISO string with error handling let isoDateadded = null; try { isoDateadded = new Date(dateadded).toISOString(); + console.log('✅ Converted to ISO:', isoDateadded); } catch (e) { + console.error('❌ Date conversion error:', e); showToast('Invalid date format', 'error'); return; } - + try { if (mediaType === 'movie') { + console.log('📤 Calling updateMovieDate with:', { imdbId, isoDateadded, source }); await updateMovieDate(imdbId, isoDateadded, source); } else { + console.log('📤 Calling updateEpisodeDate with:', { imdbId, season: options.season, episode: options.episode, isoDateadded, source }); await updateEpisodeDate(imdbId, options.season, options.episode, isoDateadded, source); } - + closeModal(); } catch (error) { console.error('Enhanced edit failed:', error); @@ -1280,24 +1298,39 @@ function closeModal() { async function handleEditSubmit(event) { event.preventDefault(); - + + console.log('🔍 Basic Edit Submit called (OLD HANDLER)'); + const imdbId = document.getElementById('edit-imdb-id').value; const mediaType = document.getElementById('edit-media-type').value; const season = document.getElementById('edit-season').value; const episode = document.getElementById('edit-episode').value; const dateadded = document.getElementById('edit-dateadded').value; const source = document.getElementById('edit-source').value; - + + console.log('🔍 OLD Form values:', { + imdbId, + mediaType, + dateadded, + dateaddedType: typeof dateadded, + dateaddedLength: dateadded ? dateadded.length : 0, + source + }); + // Convert datetime-local to ISO string const isoDateadded = dateadded ? new Date(dateadded).toISOString() : null; - + + console.log('🔍 OLD isoDateadded:', isoDateadded); + try { if (mediaType === 'movie') { + console.log('📤 OLD calling updateMovieDate with:', { imdbId, isoDateadded, source }); await updateMovieDate(imdbId, isoDateadded, source); } else { + console.log('📤 OLD calling updateEpisodeDate'); await updateEpisodeDate(imdbId, parseInt(season), parseInt(episode), isoDateadded, source); } - + closeModal(); } catch (error) { console.error('Update failed:', error); @@ -1306,22 +1339,36 @@ async function handleEditSubmit(event) { // Update functions async function updateMovieDate(imdbId, dateadded, source) { + console.log('🔍 updateMovieDate called with:', { + imdbId, + dateadded, + dateaddedType: typeof dateadded, + dateaddedValue: dateadded, + source + }); + try { + const payload = { + dateadded: dateadded, + source: source + }; + + console.log('📤 Sending API request with payload:', JSON.stringify(payload)); + const result = await apiCall(`/api/movies/${imdbId}`, { method: 'PUT', - body: JSON.stringify({ - dateadded: dateadded, - source: source - }) + body: JSON.stringify(payload) }); - + + console.log('✅ API response:', result); + showToast(result.message, 'success'); - + // Refresh current view if (currentTab === 'movies') loadMovies(currentMoviesPage); if (currentTab === 'reports') loadReport(); if (currentTab === 'dashboard') loadDashboard(); - + } catch (error) { console.error('Movie update failed:', error); }