broadfield-dev commited on
Commit
37301ca
·
verified ·
1 Parent(s): 682ea6c

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +23 -17
templates/index.html CHANGED
@@ -31,6 +31,9 @@
31
  <input type="submit" value="Search">
32
  </form>
33
  <hr>
 
 
 
34
  <div class="admin-section">
35
  <h3>Admin Panel</h3>
36
  <form id="build-form">
@@ -39,6 +42,7 @@
39
  </form>
40
  <div id="build-status"></div>
41
  </div>
 
42
 
43
  {% if query %}
44
  <h2>Results for: "{{ query }}"</h2>
@@ -47,7 +51,6 @@
47
  {% if results %}
48
  {% for result in results %}
49
  <div class="result">
50
- <!-- *** CHANGE 1: MAKE THE REFERENCE A CLICKABLE LINK *** -->
51
  {% if result.book_name and result.chapter %}
52
  <p class="reference">
53
  <a href="{{ url_for('view_chapter', version=result.version, book_name=result.book_name, chapter_num=result.chapter) }}">
@@ -64,6 +67,7 @@
64
  {% endif %}
65
  </div>
66
 
 
67
  <script>
68
  const buildForm = document.getElementById('build-form');
69
  const buildButton = document.getElementById('build-button');
@@ -71,8 +75,9 @@
71
  let statusInterval;
72
 
73
  function updateStatusDisplay(status, message) {
 
74
  statusDiv.style.display = 'block';
75
- statusDiv.className = '';
76
 
77
  if (status.startsWith('IN_PROGRESS')) {
78
  statusDiv.classList.add('info');
@@ -84,8 +89,6 @@
84
  buildButton.disabled = false;
85
  buildButton.value = 'Build and Push Database to Hub';
86
  clearInterval(statusInterval);
87
- // *** CHANGE 2: REMOVE THE ANNOYING POPUP ***
88
- // Simply update the text to inform the user.
89
  statusDiv.textContent = message + " Refresh the page to use the new data.";
90
  } else if (status === 'FAILED') {
91
  statusDiv.classList.add('error');
@@ -110,20 +113,23 @@
110
  }
111
  }
112
 
113
- buildForm.addEventListener('submit', async function(event) {
114
- event.preventDefault();
115
- if (!confirm('This will rebuild the database, which can take a long time. Are you sure?')) return;
116
- buildButton.disabled = true;
117
- updateStatusDisplay('IN_PROGRESS', 'Initiating build process...');
118
- try {
119
- await fetch('/build-rag', { method: 'POST' });
120
- statusInterval = setInterval(checkStatus, 5000);
121
- } catch (error) {
122
- updateStatusDisplay('FAILED', 'Failed to send build request to the server.');
123
- }
124
- });
 
 
 
125
 
126
  document.addEventListener('DOMContentLoaded', checkStatus);
127
  </script>
128
  </body>
129
- </html>
 
31
  <input type="submit" value="Search">
32
  </form>
33
  <hr>
34
+
35
+ <!-- *** CHANGE 1: WRAP ADMIN PANEL IN A CONDITIONAL BLOCK *** -->
36
+ {% if show_admin %}
37
  <div class="admin-section">
38
  <h3>Admin Panel</h3>
39
  <form id="build-form">
 
42
  </form>
43
  <div id="build-status"></div>
44
  </div>
45
+ {% endif %}
46
 
47
  {% if query %}
48
  <h2>Results for: "{{ query }}"</h2>
 
51
  {% if results %}
52
  {% for result in results %}
53
  <div class="result">
 
54
  {% if result.book_name and result.chapter %}
55
  <p class="reference">
56
  <a href="{{ url_for('view_chapter', version=result.version, book_name=result.book_name, chapter_num=result.chapter) }}">
 
67
  {% endif %}
68
  </div>
69
 
70
+ <!-- The script can remain, it will just not find the elements if the admin panel is hidden, which is harmless. -->
71
  <script>
72
  const buildForm = document.getElementById('build-form');
73
  const buildButton = document.getElementById('build-button');
 
75
  let statusInterval;
76
 
77
  function updateStatusDisplay(status, message) {
78
+ if (!statusDiv) return; // Exit if admin panel is not shown
79
  statusDiv.style.display = 'block';
80
+ statusDiv.className = '';
81
 
82
  if (status.startsWith('IN_PROGRESS')) {
83
  statusDiv.classList.add('info');
 
89
  buildButton.disabled = false;
90
  buildButton.value = 'Build and Push Database to Hub';
91
  clearInterval(statusInterval);
 
 
92
  statusDiv.textContent = message + " Refresh the page to use the new data.";
93
  } else if (status === 'FAILED') {
94
  statusDiv.classList.add('error');
 
113
  }
114
  }
115
 
116
+ // Only add event listener if the form exists
117
+ if (buildForm) {
118
+ buildForm.addEventListener('submit', async function(event) {
119
+ event.preventDefault();
120
+ if (!confirm('This will rebuild the database, which can take a long time. Are you sure?')) return;
121
+ buildButton.disabled = true;
122
+ updateStatusDisplay('IN_PROGRESS', 'Initiating build process...');
123
+ try {
124
+ await fetch('/build-rag', { method: 'POST' });
125
+ statusInterval = setInterval(checkStatus, 5000);
126
+ } catch (error) {
127
+ updateStatusDisplay('FAILED', 'Failed to send build request to the server.');
128
+ }
129
+ });
130
+ }
131
 
132
  document.addEventListener('DOMContentLoaded', checkStatus);
133
  </script>
134
  </body>
135
+ </html>