Lucas ARRIESSE commited on
Commit
730ea19
·
1 Parent(s): ed93d85

Add ability to bulk download files sorted by agenda item or not

Browse files
Files changed (4) hide show
  1. api/docs.py +3 -1
  2. schemas.py +1 -0
  3. static/index.html +18 -4
  4. static/js/app.js +4 -1
api/docs.py CHANGED
@@ -383,7 +383,9 @@ async def download_docs(req: DownloadDocsRequest, http_client: AsyncClient = Dep
383
  failed = "failed" in task
384
  doc_id = task["doc_id"]
385
  base_filename = f"failed_{doc_id}.txt" if failed else f"{doc_id}.txt"
386
- full_file_path = f"{directory_name}/{base_filename}"
 
 
387
  zip_file.writestr(full_file_path, task["content"])
388
 
389
  zip_buffer.seek(0)
 
383
  failed = "failed" in task
384
  doc_id = task["doc_id"]
385
  base_filename = f"failed_{doc_id}.txt" if failed else f"{doc_id}.txt"
386
+
387
+ # sort by agenda item if enabled
388
+ full_file_path = f"{directory_name}/{base_filename}" if req.sort_by_agenda_item else base_filename
389
  zip_file.writestr(full_file_path, task["content"])
390
 
391
  zip_buffer.seek(0)
schemas.py CHANGED
@@ -40,6 +40,7 @@ class DocInfo(BaseModel):
40
  class DownloadDocsRequest(BaseModel):
41
  documents: List[DocInfo] = Field(
42
  description="List of documents to download")
 
43
 
44
  # --------------------------------------
45
 
 
40
  class DownloadDocsRequest(BaseModel):
41
  documents: List[DocInfo] = Field(
42
  description="List of documents to download")
43
+ sort_by_agenda_item: bool = Field(default=False, description="Whether to sort the files by their agenda item.")
44
 
45
  # --------------------------------------
46
 
static/index.html CHANGED
@@ -158,14 +158,28 @@
158
  <div class="flex gap-2 items-center">
159
  <div class="tooltip" data-tip="Extract requirements from selected pCR / CR documents">
160
  <button id="extract-requirements-btn"
161
- class="bg-orange-300 text-white text-sm rounded px-3 py-1 shadow hover:bg-orange-600">💉
162
  Extract Requirements from CRs
163
  </button>
164
  </div>
165
  <div class="tooltip" data-tip="Download all selected docs as text files">
166
- <button id="download-tdocs-btn" class="text-sm rounded px-3 py-1 shadow cursor-pointer">
167
- 📦 Download Selected Docs
168
- </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  </div>
170
  </div>
171
 
 
158
  <div class="flex gap-2 items-center">
159
  <div class="tooltip" data-tip="Extract requirements from selected pCR / CR documents">
160
  <button id="extract-requirements-btn"
161
+ class="btn bg-orange-300 text-white text-sm rounded px-3 py-1 shadow hover:bg-orange-600">💉
162
  Extract Requirements from CRs
163
  </button>
164
  </div>
165
  <div class="tooltip" data-tip="Download all selected docs as text files">
166
+ <div class="dropdown">
167
+ <div tabindex="0" role="button" class="btn text-sm rounded px-3 py-1 shadow cursor-pointer">
168
+ 📦 Download </div>
169
+ <div tabindex="0" class="dropdown-content card card-sm bg-base-100 z-1 w-64 shadow-md">
170
+ <div class="card-body space-y-2">
171
+ <label class="label">
172
+ <input class="checkbox checkbox-primary" name="download-sorted-files"
173
+ type="checkbox" id="download-sorted-files">
174
+ <p class="text-m">Sort files by agenda</p>
175
+ </label>
176
+ <button id="download-tdocs-btn"
177
+ class="text-sm rounded px-3 py-1 shadow cursor-pointer">
178
+ 📦 Download docs
179
+ </button>
180
+ </div>
181
+ </div>
182
+ </div>
183
  </div>
184
  </div>
185
 
static/js/app.js CHANGED
@@ -236,6 +236,9 @@ async function downloadTDocs() {
236
  // Extraire les données du tableau avec le format suivant pour la requete backend
237
  // { document: "nom_doc", url: "url_doc", type: "type_de_doc"}
238
  const selectedData = extractTableData({ 'TDoc': 'document', 'URL': 'url', 'Type': "type", "Agenda": "agenda_item" });
 
 
 
239
 
240
  if (selectedData.length === 0) {
241
  alert('Please select at least one document');
@@ -248,7 +251,7 @@ async function downloadTDocs() {
248
  const response = await fetch('/docs/download_docs', {
249
  method: 'POST',
250
  headers: { 'Content-Type': 'application/json' },
251
- body: JSON.stringify({ documents: documents })
252
  });
253
 
254
  const blob = await response.blob();
 
236
  // Extraire les données du tableau avec le format suivant pour la requete backend
237
  // { document: "nom_doc", url: "url_doc", type: "type_de_doc"}
238
  const selectedData = extractTableData({ 'TDoc': 'document', 'URL': 'url', 'Type': "type", "Agenda": "agenda_item" });
239
+ const sortByAgendaItem = document.getElementById('download-sorted-files').checked;
240
+
241
+ console.log(sortByAgendaItem)
242
 
243
  if (selectedData.length === 0) {
244
  alert('Please select at least one document');
 
251
  const response = await fetch('/docs/download_docs', {
252
  method: 'POST',
253
  headers: { 'Content-Type': 'application/json' },
254
+ body: JSON.stringify({ documents: documents, sort_by_agenda_item: sortByAgendaItem })
255
  });
256
 
257
  const blob = await response.blob();