YchKhan commited on
Commit
953228e
·
verified ·
1 Parent(s): 4bf1cb4

hide previous analysis js

Browse files
Files changed (1) hide show
  1. templates/index.html +79 -14
templates/index.html CHANGED
@@ -23,8 +23,17 @@
23
 
24
  // Show loading indicator
25
  document.getElementById('loadingIndicator').style.display = 'block';
26
- // Hide results if they were previously shown
27
- document.getElementById('resultsContainer').style.display = 'none';
 
 
 
 
 
 
 
 
 
28
 
29
  // Send message to Flask backend
30
  fetch('/chat', {
@@ -49,15 +58,19 @@
49
  jsonData = JSON.parse(jsonString);
50
  }
51
 
52
- // Clear existing queries
53
- const queriesContainer = document.getElementById('queriesContainer');
54
- queriesContainer.innerHTML = '';
55
 
56
- // Add each query from the response
57
  Object.keys(jsonData).forEach(key => {
58
- addQueryField(jsonData[key]);
59
  });
60
 
 
 
 
 
61
  // Show results container
62
  document.getElementById('resultsContainer').style.display = 'block';
63
  } catch (error) {
@@ -73,9 +86,15 @@
73
  }
74
 
75
  // Add a new query field with the given text (or empty if not provided)
76
- function addQueryField(queryText = '') {
77
- const queriesContainer = document.getElementById('queriesContainer');
78
- const queryIndex = queriesContainer.children.length + 1;
 
 
 
 
 
 
79
 
80
  // Create main container for this query item
81
  const queryItem = document.createElement('div');
@@ -98,10 +117,17 @@
98
  deleteButton.className = 'action-button delete-button';
99
  deleteButton.textContent = 'Delete';
100
  deleteButton.onclick = function() {
101
- queriesContainer.removeChild(queryItem);
102
- // Update the placeholder numbers for remaining queries
103
- updateQueryIndices();
 
 
 
 
 
 
104
  };
 
105
  // Search button
106
  const searchButton = document.createElement('button');
107
  searchButton.type = 'button';
@@ -293,12 +319,12 @@
293
  }
294
 
295
  const documentType = row.cells[0].textContent.toLowerCase();
 
296
  // Check if there's already an insights row for this document
297
  let insightsRow = row.nextElementSibling;
298
  if (insightsRow && insightsRow.className === 'insights-row') {
299
  // Insights row already exists, get the container
300
  insightsContainer = insightsRow.querySelector('.insights-container');
301
-
302
  insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
303
  } else {
304
  // Create insights row that spans across all columns
@@ -907,6 +933,7 @@
907
  scoreCell.style.fontWeight = 'bold';
908
  scoreCell.style.textAlign = 'center';
909
  }
 
910
  // Add "Extract Insights" button to the justify cell - for Analyze All function
911
  const insightsButton = document.createElement('button');
912
  insightsButton.textContent = 'Extract Insights';
@@ -1137,6 +1164,44 @@
1137
  container.innerHTML = '';
1138
  container.appendChild(textarea);
1139
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1140
  </script>
1141
  </head>
1142
  <body>
 
23
 
24
  // Show loading indicator
25
  document.getElementById('loadingIndicator').style.display = 'block';
26
+
27
+ // Collapse all existing query sections
28
+ const existingAccordions = document.querySelectorAll('.accordion-section');
29
+ existingAccordions.forEach(accordion => {
30
+ const header = accordion.querySelector('.accordion-header');
31
+ const body = accordion.querySelector('.accordion-body');
32
+ if (header && body && !header.classList.contains('collapsed')) {
33
+ header.classList.add('collapsed');
34
+ body.classList.add('collapsed');
35
+ }
36
+ });
37
 
38
  // Send message to Flask backend
39
  fetch('/chat', {
 
58
  jsonData = JSON.parse(jsonString);
59
  }
60
 
61
+ // Create a new accordion section for these search results
62
+ const timestamp = new Date().toLocaleString();
63
+ const accordionSection = createAccordionSection(timestamp);
64
 
65
+ // Add each query from the response to this accordion
66
  Object.keys(jsonData).forEach(key => {
67
+ addQueryField(jsonData[key], accordionSection.querySelector('.accordion-content'));
68
  });
69
 
70
+ // Add the accordion to the container
71
+ const queriesContainer = document.getElementById('queriesContainer');
72
+ queriesContainer.insertBefore(accordionSection, queriesContainer.firstChild);
73
+
74
  // Show results container
75
  document.getElementById('resultsContainer').style.display = 'block';
76
  } catch (error) {
 
86
  }
87
 
88
  // Add a new query field with the given text (or empty if not provided)
89
+ function addQueryField(queryText = '', container = null) {
90
+ const queriesContainer = container || document.getElementById('queriesContainer');
91
+
92
+ // Count existing query items in this container for indexing
93
+ const queryItems = container ?
94
+ container.querySelectorAll('.query-item') :
95
+ document.getElementById('queriesContainer').querySelectorAll('.query-item');
96
+
97
+ const queryIndex = queryItems.length + 1;
98
 
99
  // Create main container for this query item
100
  const queryItem = document.createElement('div');
 
117
  deleteButton.className = 'action-button delete-button';
118
  deleteButton.textContent = 'Delete';
119
  deleteButton.onclick = function() {
120
+ queryItem.parentNode.removeChild(queryItem);
121
+
122
+ // Update the placeholder numbers for remaining queries within this container
123
+ const parent = container || document.getElementById('queriesContainer');
124
+ const items = parent.querySelectorAll('.query-item');
125
+ items.forEach((item, idx) => {
126
+ const field = item.querySelector('.query-field');
127
+ if (field) field.placeholder = `Search Query ${idx + 1}`;
128
+ });
129
  };
130
+
131
  // Search button
132
  const searchButton = document.createElement('button');
133
  searchButton.type = 'button';
 
319
  }
320
 
321
  const documentType = row.cells[0].textContent.toLowerCase();
322
+
323
  // Check if there's already an insights row for this document
324
  let insightsRow = row.nextElementSibling;
325
  if (insightsRow && insightsRow.className === 'insights-row') {
326
  // Insights row already exists, get the container
327
  insightsContainer = insightsRow.querySelector('.insights-container');
 
328
  insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
329
  } else {
330
  // Create insights row that spans across all columns
 
933
  scoreCell.style.fontWeight = 'bold';
934
  scoreCell.style.textAlign = 'center';
935
  }
936
+
937
  // Add "Extract Insights" button to the justify cell - for Analyze All function
938
  const insightsButton = document.createElement('button');
939
  insightsButton.textContent = 'Extract Insights';
 
1164
  container.innerHTML = '';
1165
  container.appendChild(textarea);
1166
  }
1167
+
1168
+ // Create a new accordion section for search results
1169
+ function createAccordionSection(timestamp) {
1170
+ const accordionSection = document.createElement('div');
1171
+ accordionSection.className = 'accordion-section';
1172
+
1173
+ const accordionHeader = document.createElement('div');
1174
+ accordionHeader.className = 'accordion-header';
1175
+ accordionHeader.innerHTML = `
1176
+ <span>Search Results <span class="query-timestamp">${timestamp}</span></span>
1177
+ <span class="toggle-icon">▼</span>
1178
+ `;
1179
+ accordionHeader.onclick = function() {
1180
+ this.classList.toggle('collapsed');
1181
+ const body = this.nextElementSibling;
1182
+ body.classList.toggle('collapsed');
1183
+
1184
+ // Update the toggle icon
1185
+ const toggleIcon = this.querySelector('.toggle-icon');
1186
+ if (body.classList.contains('collapsed')) {
1187
+ toggleIcon.textContent = '►';
1188
+ } else {
1189
+ toggleIcon.textContent = '▼';
1190
+ }
1191
+ };
1192
+
1193
+ const accordionBody = document.createElement('div');
1194
+ accordionBody.className = 'accordion-body';
1195
+
1196
+ const accordionContent = document.createElement('div');
1197
+ accordionContent.className = 'accordion-content';
1198
+ accordionBody.appendChild(accordionContent);
1199
+
1200
+ accordionSection.appendChild(accordionHeader);
1201
+ accordionSection.appendChild(accordionBody);
1202
+
1203
+ return accordionSection;
1204
+ }
1205
  </script>
1206
  </head>
1207
  <body>