1// DOMContentLoadedã¨turbo:loadã®ä¸¡æ¹ã§ã¤ãã³ããç£è¦ 2document.addEventListener('DOMContentLoaded', initializeAutoReload); 3document.addEventListener('turbo:load', initializeAutoReload); 4 5// ã°ãã¼ãã«ã¹ã³ã¼ãã§å¤æ°ã管ç 6let autoReloadInitialized = false; 7let currentReloadType = null; // 'inventory', 'check', null 8let reloadIntervalId = null; 9 10function initializeAutoReload() { 11 console.log('ð initializeAutoReload called'); 12 13 // æ¢åã®ãªãã¼ãã忢 14 stopAllAutoReload(); 15 16 // URLãã¼ã¹ã§ãã¼ã¸ã¿ã¤ããå¤å® 17 const urlParams = new URLSearchParams(window.location.search); 18 const currentTab = urlParams.get('tab'); 19 20 console.log('ð Current tab:', currentTab); 21 console.log('ð Current URL:', window.location.href); 22 23 // ãã¼ã¸ã¿ã¤ãã«å¿ãã¦é©åãªãªãã¼ãæ©è½ãéå§ 24 if (window.location.href.includes('/inventory_updates')) { 25 if (currentTab === 'check') { 26 setupCheckPageAutoReload(); 27 } else if (!currentTab || currentTab === 'update' || currentTab === 'log') { 28 setupInventoryPageAutoReload(); 29 } 30 } 31 32 autoReloadInitialized = true; 33} 34 35function stopAllAutoReload() { 36 if (reloadIntervalId) { 37 console.log('â¹ï¸ Stopping existing auto-reload'); 38 clearInterval(reloadIntervalId); 39 reloadIntervalId = null; 40 } 41 currentReloadType = null; 42} 43 44//-------------------------------------- 45// ãã§ãã¯ãã¼ã¸ï¼quick_check/bulk_checkï¼ç¨ã®èªåãªãã¼ã 46//-------------------------------------- 47function setupCheckPageAutoReload() { 48 console.log('â¡ Setting up check page auto-reload'); 49 currentReloadType = 'check'; 50 51 function startCheckAutoReload() { 52 stopAllAutoReload(); 53 currentReloadType = 'check'; 54 reloadIntervalId = setInterval(reloadCheckContent, 3000); 55 console.log('ð Check auto-reload started'); 56 } 57 58 function reloadCheckContent() { 59 console.log('ð Reloading check content...'); 60 fetch(window.location.href) 61 .then(response => response.text()) 62 .then(html => { 63 const parser = new DOMParser(); 64 const doc = parser.parseFromString(html, 'text/html'); 65 66 // quick_check 㨠bulk_check ã®ä¸¡æ¹ã®ç¶æ ããã§ã㯠67 const quickCheckStatus = getQuickCheckStatus(doc); 68 const bulkCheckStatus = getBulkCheckStatus(doc); 69 70 console.log('ð Status check:', { quickCheckStatus, bulkCheckStatus }); 71 72 // ã©ã¡ãããå¦çä¸ã®å ´åã¯ç¶ç¶ã両æ¹å®äº/失æãªã忢 73 const shouldContinue = quickCheckStatus === 'processing' || bulkCheckStatus === 'processing'; 74 75 if (!shouldContinue) { 76 console.log('â All checks completed, stopping auto-reload'); 77 stopAllAutoReload(); 78 } 79 80 // çµæã¨ãªã¢ãæ´æ° 81 updateCheckResults(doc); 82 83 }) 84 .catch(error => { 85 console.error('â Check reload error:', error); 86 stopAllAutoReload(); 87 }); 88 } 89 90 function getQuickCheckStatus(doc) { 91 const statusElement = doc.querySelector('.quick-check-status'); 92 const status = statusElement?.dataset.status || null; 93 console.log('ð Quick check status:', status); 94 return status; 95 } 96 97 function getBulkCheckStatus(doc) { 98 const statusElement = doc.querySelector('.bulk-check-status'); 99 const status = statusElement?.dataset.status || null; 100 console.log('ð Bulk check status:', status); 101 return status; 102 } 103 104 function updateCheckResults(doc) { 105 // quick-checkçµæãæ´æ° 106 updateElement('#quick-check-result-container', doc); 107 108 // bulk-checkçµæãæ´æ° 109 updateElement('#bulk-check-result', doc); 110 111 // ã¹ãã¼ã¿ã¹è¦ç´ ãæ´æ° 112 updateElement('.quick-check-status', doc); 113 updateElement('.bulk-check-status', doc); 114 115 // ãã¿ã³ã®ç¶æ ãæ´æ° 116 updateButtonStates(doc); 117 } 118 119 function updateButtonStates(doc) { 120 // ã¯ã¤ãã¯ãã§ãã¯ãã¿ã³ã®æ´æ° 121 const quickCheckButton = document.querySelector('#quick-check-form input[type="submit"]'); 122 const newQuickCheckButton = doc.querySelector('#quick-check-form input[type="submit"]'); 123 if (quickCheckButton && newQuickCheckButton) { 124 quickCheckButton.disabled = newQuickCheckButton.disabled; 125 quickCheckButton.value = newQuickCheckButton.value; 126 quickCheckButton.className = newQuickCheckButton.className; 127 console.log(`â Quick check button updated: disabled=${quickCheckButton.disabled}, value=${quickCheckButton.value}`); 128 } 129 130 // 䏿¬ãã§ãã¯ãã¿ã³ã®æ´æ° 131 const bulkCheckButton = document.querySelector('form[action*="bulk_check"] input[type="submit"]'); 132 const newBulkCheckButton = doc.querySelector('form[action*="bulk_check"] input[type="submit"]'); 133 if (bulkCheckButton && newBulkCheckButton) { 134 bulkCheckButton.disabled = newBulkCheckButton.disabled; 135 bulkCheckButton.value = newBulkCheckButton.value; 136 bulkCheckButton.className = newBulkCheckButton.className; 137 console.log(`â Bulk check button updated: disabled=${bulkCheckButton.disabled}, value=${bulkCheckButton.value}`); 138 } 139 } 140 141 function updateElement(selector, doc) { 142 const newElement = doc.querySelector(selector); 143 const currentElement = document.querySelector(selector); 144 if (newElement && currentElement) { 145 currentElement.innerHTML = newElement.innerHTML; 146 // ãã¼ã¿å±æ§ãæ´æ° 147 if (newElement.dataset && currentElement.dataset) { 148 Object.keys(newElement.dataset).forEach(key => { 149 currentElement.dataset[key] = newElement.dataset[key]; 150 }); 151 } 152 console.log(`â Updated: ${selector}`); 153 } 154 } 155 156 function checkInitialCheckState() { 157 const quickCheckElement = document.querySelector('.quick-check-status'); 158 const bulkCheckElement = document.querySelector('.bulk-check-status'); 159 160 const quickStatus = quickCheckElement?.dataset.status || null; 161 const bulkStatus = bulkCheckElement?.dataset.status || null; 162 163 console.log('ð Initial check states:', { quickStatus, bulkStatus }); 164 165 if (quickStatus === 'processing' || bulkStatus === 'processing') { 166 console.log('ð Processing detected, starting auto-reload'); 167 startCheckAutoReload(); 168 } else { 169 console.log('â¸ï¸ No processing detected'); 170 } 171 } 172 173 // åæç¶æ ããã§ã㯠174 checkInitialCheckState(); 175} 176 177//-------------------------------------- 178// å¨åº«æ´æ°ãã¼ã¸ç¨ã®èªåãªãã¼ãï¼æ¢åæ©è½ï¼ 179//-------------------------------------- 180function setupInventoryPageAutoReload() { 181 console.log('ð Setting up inventory page auto-reload'); 182 currentReloadType = 'inventory'; 183 184 // å¨åº«æ´æ°ãã¼ã¸ã®å¦çç¶æ³è¦ç´ ãåå¨ããããã§ã㯠185 const processingStatusElement = document.querySelector('.processing-status'); 186 if (!processingStatusElement) { 187 console.log('â No processing status element found'); 188 return; 189 } 190 191 function startInventoryAutoReload() { 192 stopAllAutoReload(); 193 currentReloadType = 'inventory'; 194 reloadIntervalId = setInterval(reloadInventoryContent, 5000); 195 console.log('ð Inventory auto-reload started'); 196 } 197 198 function reloadInventoryContent() { 199 fetch(window.location.href) 200 .then(response => response.text()) 201 .then(html => { 202 const parser = new DOMParser(); 203 const doc = parser.parseFromString(html, 'text/html'); 204 205 const statusText = doc.querySelector('.processing-status')?.textContent || ''; 206 207 if (statusText.includes('å®äº') || statusText.includes('失æ')) { 208 console.log('â Inventory processing completed'); 209 stopAllAutoReload(); 210 } 211 212 // å¨åº«æ´æ°é¢é£ã®è¦ç´ ãæ´æ° 213 updateElement('.processing-status', doc); 214 updateElement('#log-content', doc); 215 updateElement('#history-content', doc); 216 updateInventoryButton(statusText); 217 218 function updateElement(selector, doc) { 219 const newElement = doc.querySelector(selector); 220 const currentElement = document.querySelector(selector); 221 if (newElement && currentElement) { 222 currentElement.innerHTML = newElement.innerHTML; 223 } 224 } 225 226 function updateInventoryButton(status) { 227 const submitButton = document.querySelector('#single-update-form input[type="submit"]'); 228 if (submitButton) { 229 if (status.includes('å®äº') || status.includes('失æ')) { 230 submitButton.disabled = false;
231 submitButton.classList.remove('opacity-50'); 232 } else { 233 submitButton.disabled = true; 234 submitButton.classList.add('opacity-50'); 235 } 236 } 237 } 238 }) 239 .catch(error => { 240 console.error('â Inventory reload error:', error); 241 stopAllAutoReload(); 242 }); 243 } 244 245 function checkInitialInventoryState() { 246 const statusText = document.querySelector('.processing-status')?.textContent || ''; 247 248 if (statusText.includes('å¦çä¸') || statusText.includes('å¦çå¾ ã¡')) { 249 console.log('ð Inventory processing detected, starting auto-reload'); 250 startInventoryAutoReload(); 251 } else { 252 console.log('â¸ï¸ Inventory not in processing state'); 253 } 254 } 255 256 // åæç¶æ ããã§ã㯠257 checkInitialInventoryState(); 258} 259 260// ãã¼ã¸é¢è±æã®ã¯ãªã¼ã³ã¢ãã 261document.addEventListener('turbo:before-visit', () => { 262 console.log('ðª Page leaving, cleaning up all auto-reload'); 263 stopAllAutoReload(); 264 autoReloadInitialized = false; 265});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.