kan0621 commited on
Commit
4ba2056
·
verified ·
1 Parent(s): fe4bee3

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +38 -12
static/script.js CHANGED
@@ -1674,8 +1674,15 @@ function checkGenerationStatus() {
1674
  link.download = currentFile;
1675
  document.body.appendChild(link); // Add to DOM
1676
 
1677
- // Show success message
1678
- alert('Stimulus generation complete!');
 
 
 
 
 
 
 
1679
 
1680
  // Download file
1681
  setTimeout(() => {
@@ -1698,12 +1705,30 @@ function checkGenerationStatus() {
1698
  resetUI();
1699
  }
1700
  } else if (data.status === 'stopped') {
1701
- // Clear stop status and reset UI
1702
- console.log("Generation has been stopped by user");
 
 
1703
  resetUI();
1704
  } else if (data.status === 'running') {
1705
  updateProgress(data.progress);
1706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1707
  // Add extra check - if progress is 100 but status is still running
1708
  if (data.progress >= 100) {
1709
  console.log("Progress is 100% but status is still running, waiting for file...");
@@ -1757,21 +1782,22 @@ function checkGenerationStatus() {
1757
 
1758
  stopButton.addEventListener('click', () => {
1759
  // Add confirmation dialogue box
1760
- const confirmStop = confirm('Are you sure you want to stop?');
1761
 
1762
  // Only execute stop operation when user clicks "Yes"
1763
  if (confirmStop) {
1764
  fetch(getApiUrl('stop_generation'), { method: 'POST' })
1765
  .then(response => response.json())
1766
  .then(data => {
1767
- alert(data.message);
1768
- // Immediately stop progress polling to prevent unexpected status check
1769
- if (window.statusCheckTimer) {
1770
- clearTimeout(window.statusCheckTimer);
 
 
 
 
1771
  }
1772
- resetUI();
1773
- // Ensure stop status is displayed
1774
- updateProgress(0);
1775
  })
1776
  .catch(error => {
1777
  console.error('Error stopping generation:', error);
 
1674
  link.download = currentFile;
1675
  document.body.appendChild(link); // Add to DOM
1676
 
1677
+ // Show success message based on whether it's partial or complete
1678
+ if (data.partial) {
1679
+ alert('Generation stopped. Partial data saved and will be downloaded.');
1680
+ } else {
1681
+ alert('Stimulus generation complete!');
1682
+ }
1683
+
1684
+ // Clear waiting flag
1685
+ window.waitingForStopData = false;
1686
 
1687
  // Download file
1688
  setTimeout(() => {
 
1705
  resetUI();
1706
  }
1707
  } else if (data.status === 'stopped') {
1708
+ // Generation stopped with no partial data available
1709
+ console.log("Generation has been stopped by user with no data to save");
1710
+ window.waitingForStopData = false;
1711
+ alert('Generation stopped. No data was generated.');
1712
  resetUI();
1713
  } else if (data.status === 'running') {
1714
  updateProgress(data.progress);
1715
 
1716
+ // Check if we're in stopping state (waiting for partial data to be saved)
1717
+ if (data.stopping) {
1718
+ console.log("Stopping... waiting for partial data to be saved");
1719
+ // Show stopping status
1720
+ const statusTextElement = document.getElementById('generation-status-text');
1721
+ if (statusTextElement) {
1722
+ statusTextElement.textContent = 'Stopping... Saving partial data...';
1723
+ statusTextElement.style.display = 'block';
1724
+ }
1725
+ // Poll more frequently while stopping
1726
+ window.statusCheckTimer = setTimeout(function () {
1727
+ checkGenerationStatus();
1728
+ }, 500);
1729
+ return;
1730
+ }
1731
+
1732
  // Add extra check - if progress is 100 but status is still running
1733
  if (data.progress >= 100) {
1734
  console.log("Progress is 100% but status is still running, waiting for file...");
 
1782
 
1783
  stopButton.addEventListener('click', () => {
1784
  // Add confirmation dialogue box
1785
+ const confirmStop = confirm('Are you sure you want to stop? Partial data will be saved if available.');
1786
 
1787
  // Only execute stop operation when user clicks "Yes"
1788
  if (confirmStop) {
1789
  fetch(getApiUrl('stop_generation'), { method: 'POST' })
1790
  .then(response => response.json())
1791
  .then(data => {
1792
+ console.log('Stop response:', data.message);
1793
+ // Don't immediately stop polling - continue to wait for partial data
1794
+ // The status check will handle the download when partial data is ready
1795
+ // Set a flag to indicate we're waiting for stop to complete
1796
+ window.waitingForStopData = true;
1797
+ // Continue polling for a bit to get partial data
1798
+ if (!window.statusCheckTimer) {
1799
+ checkGenerationStatus();
1800
  }
 
 
 
1801
  })
1802
  .catch(error => {
1803
  console.error('Error stopping generation:', error);