Lucas ARRIESSE commited on
Commit
e4907af
Β·
1 Parent(s): 4036d98

Add timeline export real quick

Browse files
Files changed (3) hide show
  1. static/index.html +6 -2
  2. static/js/app.js +3 -2
  3. static/js/ui.js +47 -0
static/index.html CHANGED
@@ -8,6 +8,7 @@
8
  <!--See JS imports for ESM modules-->
9
  <link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css" />
10
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
 
11
  </head>
12
 
13
  <body class="bg-gray-100 min-h-screen">
@@ -376,9 +377,9 @@
376
  </textarea>
377
  </div>
378
  <div class="card-actions justify-end mt-6">
379
- <button id="fto-analysis-btn" class="btn btn-warning">Perform FTO on
380
  draft</button>
381
- <button id="refine-btn" class="btn btn-primary">Refine draft</button>
382
  </div>
383
  </div>
384
  </div>
@@ -397,6 +398,9 @@
397
  </ul>
398
  </div>
399
  </div>
 
 
 
400
  </div>
401
  </div>
402
  </div>
 
8
  <!--See JS imports for ESM modules-->
9
  <link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css" />
10
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
11
+ <script src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js "></script>
12
  </head>
13
 
14
  <body class="bg-gray-100 min-h-screen">
 
377
  </textarea>
378
  </div>
379
  <div class="card-actions justify-end mt-6">
380
+ <button id="fto-analysis-btn" class="btn btn-warning">πŸ”Ž Perform FTO on
381
  draft</button>
382
+ <button id="refine-btn" class="btn btn-primary">πŸ“ Refine draft</button>
383
  </div>
384
  </div>
385
  </div>
 
398
  </ul>
399
  </div>
400
  </div>
401
+ <div class="card-actions justify-center mt-6 mb-4">
402
+ <button id="export-timeline-btn" class="btn btn-primary">πŸ“¦ Export Timeline</button>
403
+ </div>
404
  </div>
405
  </div>
406
  </div>
static/js/app.js CHANGED
@@ -3,7 +3,7 @@ import {
3
  toggleElementsEnabled, toggleContainersVisibility, showLoadingOverlay, hideLoadingOverlay, populateSelect,
4
  populateCheckboxDropdown, populateDaisyDropdown, extractTableData, switchTab, enableTabSwitching, debounceAutoCategoryCount,
5
  bindTabs, checkPrivateLLMInfoAvailable, moveSolutionToDrafts, buildSolutionSubCategories, handleDraftRefine, renderDraftUI, populateLLMModelSelect,
6
- displayFullAssessment, handleSaveConfigFields, handleLoadConfigFields, handleFTOAnalysis, handleClearConfig
7
  } from "./ui.js";
8
  import { postWithSSE } from "./sse.js";
9
 
@@ -1096,4 +1096,5 @@ document.getElementById('read-assessment-button').addEventListener('click', _ =>
1096
 
1097
  // Events des boutons pour le drafting de solutions
1098
  document.getElementById('refine-btn').addEventListener('click', handleDraftRefine);
1099
- document.getElementById('fto-analysis-btn').addEventListener('click', handleFTOAnalysis);
 
 
3
  toggleElementsEnabled, toggleContainersVisibility, showLoadingOverlay, hideLoadingOverlay, populateSelect,
4
  populateCheckboxDropdown, populateDaisyDropdown, extractTableData, switchTab, enableTabSwitching, debounceAutoCategoryCount,
5
  bindTabs, checkPrivateLLMInfoAvailable, moveSolutionToDrafts, buildSolutionSubCategories, handleDraftRefine, renderDraftUI, populateLLMModelSelect,
6
+ displayFullAssessment, handleSaveConfigFields, handleLoadConfigFields, handleFTOAnalysis, handleClearConfig, handleExportDrafts
7
  } from "./ui.js";
8
  import { postWithSSE } from "./sse.js";
9
 
 
1096
 
1097
  // Events des boutons pour le drafting de solutions
1098
  document.getElementById('refine-btn').addEventListener('click', handleDraftRefine);
1099
+ document.getElementById('fto-analysis-btn').addEventListener('click', handleFTOAnalysis);
1100
+ document.getElementById('export-timeline-btn').addEventListener('click', handleExportDrafts)
static/js/ui.js CHANGED
@@ -1,4 +1,5 @@
1
  import { marked } from 'https://cdnjs.cloudflare.com/ajax/libs/marked/16.1.1/lib/marked.esm.js';
 
2
  import { assessSolution, getModelList, refineSolution, runFTOAnalysis } from "./gen.js"
3
  import { clearConfig, loadConfig, saveConfig } from "./persistence.js";
4
 
@@ -738,4 +739,50 @@ export function displayFullAssessment() {
738
  }
739
 
740
  modal.showModal();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
741
  }
 
1
  import { marked } from 'https://cdnjs.cloudflare.com/ajax/libs/marked/16.1.1/lib/marked.esm.js';
2
+ // import { JSZip } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
3
  import { assessSolution, getModelList, refineSolution, runFTOAnalysis } from "./gen.js"
4
  import { clearConfig, loadConfig, saveConfig } from "./persistence.js";
5
 
 
739
  }
740
 
741
  modal.showModal();
742
+ }
743
+
744
+ /**
745
+ * Exports asynchronously all drafts in the timeline
746
+ */
747
+ export async function handleExportDrafts() {
748
+ if (draftHistory.length === 0) {
749
+ alert("No drafts to export!");
750
+ return;
751
+ }
752
+
753
+ console.log("Starting ZIP export...");
754
+
755
+ const zip = new JSZip();
756
+
757
+ const separator = '-----------------------------------------';
758
+
759
+ // Loop through each draft in the history
760
+ draftHistory.forEach((draft, index) => {
761
+ const fileContent = `## Problem Description\n\n${draft.solution.solution_description}\n\n## Solution\n\n${draft.solution.solution_description}\n\n${separator}\n\n## Assessment \n\n${draft.assessment_full}`;
762
+ // Define a unique filename for each draft
763
+ const fileName = `${draft.type}_${index + 1}.txt`;
764
+ zip.file(fileName, fileContent);
765
+ });
766
+
767
+ // 5. Generate the complete zip file as a "blob"
768
+ // This is an asynchronous operation, so we use .then() or await
769
+ try {
770
+ const content = await zip.generateAsync({ type: "blob" });
771
+
772
+ // 6. Trigger the download in the browser
773
+ // Create a temporary link element
774
+ const link = document.createElement('a');
775
+ link.href = URL.createObjectURL(content);
776
+ link.download = "drafts_export.zip"; // The name of the downloaded zip file
777
+
778
+ // Append to the document, click, and then remove
779
+ document.body.appendChild(link);
780
+ link.click();
781
+ document.body.removeChild(link);
782
+
783
+ console.log("ZIP file generated and download triggered.");
784
+
785
+ } catch (error) {
786
+ console.error("Error exporting drafts to zip file:", error);
787
+ }
788
  }