1313 margin : 0 auto;
1414 }
1515
16+ .section {
17+ max-width : 800px ;
18+ margin : 0 auto;
19+ }
20+
1621 # messages {
1722 height : 400px ;
1823 border : 1px solid # ccc ;
129134 min-width : 100px ;
130135 flex-shrink : 0 ;
131136 }
137+
138+ .control-section {
139+ margin : 10px 0 ;
140+ }
141+
142+ .control-section button {
143+ margin-right : 10px ;
144+ padding : 8px 16px ;
145+ }
146+
147+ # statusResult {
148+ margin-top : 10px ;
149+ padding : 10px ;
150+ border-radius : 4px ;
151+ }
152+
153+ .search-index-btn {
154+ background : # 2196F3 ;
155+ padding : 8px 16px ;
156+ }
157+
158+ .search-index-btn : hover {
159+ background : # 1976D2 ;
160+ }
161+
162+ .links-section {
163+ margin : 20px 0 ;
164+ padding : 15px ;
165+ background : # f9f9f9 ;
166+ border-radius : 4px ;
167+ }
168+
169+ .links-section h3 {
170+ margin-top : 0 ;
171+ }
132172 </ style >
133173</ head >
134174< body >
135175< div id ="chat-container ">
136- < h1 > Chat with currently edited Wikipedia pages</ h1 >
176+ < h3 > Chat with currently edited Wikipedia pages</ h3 >
137177 < div id ="messages "> </ div >
138178 < div id ="input-container ">
139179 < div id ="persons-container ">
@@ -149,13 +189,30 @@ <h1>Chat with currently edited Wikipedia pages</h1>
149189 </ div >
150190 </ div >
151191</ div >
192+ < div class ="section ">
193+ < h3 > Processing Control</ h3 >
194+ < div class ="control-section ">
195+ < button id ="statusBtn " onclick ="getProcessingStatus() "> Get Status</ button >
196+ < button id ="startBtn " onclick ="startProcessing() "> Enable Processing</ button >
197+ < button id ="stopBtn " onclick ="stopProcessing() "> Disable Processing</ button >
198+ < button id ="countBtn " onclick ="getIndexCount() "> Get Index Count</ button >
199+ < div id ="statusResult "> </ div >
200+ < div id ="countResult "> </ div >
201+ </ div >
202+ </ div >
203+ < div class ="section ">
204+ < div class ="links-section ">
205+ < h3 > External Links</ h3 >
206+ < button class ="search-index-btn " onclick ="openSearchIndex() "> Search Index</ button >
207+ < p > < small > Opens the Elasticsearch/OpenSearch index in a new tab to browse raw data</ small > </ p >
208+ </ div >
209+ </ div >
152210
153211< script >
154212 let selectedPerson = null ;
155213 let autocompleteData = [ ] ;
156214 let currentSelection = - 1 ;
157215
158- // Initialize autocomplete functionality
159216 document . addEventListener ( 'DOMContentLoaded' , function ( ) {
160217 const personsInput = document . getElementById ( 'persons-input' ) ;
161218 const autocompleteList = document . getElementById ( 'autocomplete-list' ) ;
@@ -190,7 +247,6 @@ <h1>Chat with currently edited Wikipedia pages</h1>
190247 }
191248 } ) ;
192249
193- // Hide autocomplete when clicking outside
194250 document . addEventListener ( 'click' , function ( event ) {
195251 if ( ! personsInput . contains ( event . target ) && ! autocompleteList . contains ( event . target ) ) {
196252 hideAutocomplete ( ) ;
@@ -320,27 +376,7 @@ <h1>Chat with currently edited Wikipedia pages</h1>
320376 const messagesDiv = document . getElementById ( 'messages' ) ;
321377 const messageElement = document . createElement ( 'div' ) ;
322378 messageElement . className = className ;
323-
324- // Format code blocks if present
325- if ( message . includes ( '```' ) ) {
326- const parts = message . split ( / ( ` ` ` [ \s \S ] * ?` ` ` ) / ) ;
327- let formattedMessage = '' ;
328-
329- for ( let i = 0 ; i < parts . length ; i ++ ) {
330- if ( parts [ i ] . startsWith ( '```' ) && parts [ i ] . endsWith ( '```' ) ) {
331- // Extract the code content (remove the backticks)
332- const code = parts [ i ] . substring ( 3 , parts [ i ] . length - 3 ) ;
333- formattedMessage += '<pre>' + code + '</pre>' ;
334- } else {
335- formattedMessage += parts [ i ] ;
336- }
337- }
338-
339- messageElement . innerHTML = formattedMessage ;
340- } else {
341- messageElement . textContent = message ;
342- }
343-
379+ messageElement . textContent = message ;
344380 messagesDiv . appendChild ( messageElement ) ;
345381 messagesDiv . scrollTop = messagesDiv . scrollHeight ;
346382 }
@@ -350,6 +386,78 @@ <h1>Chat with currently edited Wikipedia pages</h1>
350386 sendQuery ( ) ;
351387 }
352388 } ) ;
389+
390+ async function getIndexCount ( ) {
391+ try {
392+ const response = await fetch ( '/assistant/indexCount' ) ;
393+ const result = await response . json ( ) ;
394+ displayIndexCount ( result . count ) ;
395+ } catch ( error ) {
396+ document . getElementById ( 'countResult' ) . innerHTML = `<p style="color: red;">Error fetching index count: ${ error . message } </p>` ;
397+ }
398+ }
399+
400+ function displayIndexCount ( count ) {
401+ const countDiv = document . getElementById ( 'countResult' ) ;
402+ countDiv . innerHTML = `<p style="color: blue;">Index contains: ${ count } documents</p>` ;
403+ countDiv . style . backgroundColor = '#e6f3ff' ;
404+ countDiv . style . padding = '10px' ;
405+ countDiv . style . borderRadius = '4px' ;
406+ countDiv . style . marginTop = '10px' ;
407+ }
408+
409+ async function getProcessingStatus ( ) {
410+ try {
411+ const response = await fetch ( '/assistant/control' ) ;
412+ const result = await response . json ( ) ;
413+ displayStatus ( result ) ;
414+ await getIndexCount ( ) ;
415+ } catch ( error ) {
416+ document . getElementById ( 'statusResult' ) . innerHTML = `<p style="color: red;">Error: ${ error . message } </p>` ;
417+ }
418+ }
419+
420+ async function startProcessing ( ) {
421+ await controlProcessing ( true ) ;
422+ }
423+
424+ async function stopProcessing ( ) {
425+ await controlProcessing ( false ) ;
426+ }
427+
428+ async function controlProcessing ( enabled ) {
429+ try {
430+ const response = await fetch ( '/assistant/control' , {
431+ method : 'POST' ,
432+ headers : { 'Content-Type' : 'application/json' } ,
433+ body : JSON . stringify ( { enabled : enabled } )
434+ } ) ;
435+ const result = await response . json ( ) ;
436+ displayStatus ( result ) ;
437+ } catch ( error ) {
438+ document . getElementById ( 'statusResult' ) . innerHTML = `<p style="color: red;">Error: ${ error . message } </p>` ;
439+ }
440+ }
441+
442+ function displayStatus ( result ) {
443+ const statusDiv = document . getElementById ( 'statusResult' ) ;
444+ const color = result . enabled ? 'green' : 'orange' ;
445+ statusDiv . innerHTML = `<p style="color: ${ color } ;">Status: ${ result . message } </p>` ;
446+ statusDiv . style . backgroundColor = result . enabled ? '#e8f5e8' : '#fff3cd' ;
447+ }
448+
449+ function openSearchIndex ( ) {
450+ fetch ( '/assistant/searchIndexUrl' )
451+ . then ( response => response . json ( ) )
452+ . then ( data => {
453+ window . open ( data . url , '_blank' ) ;
454+ } )
455+ . catch ( error => {
456+ console . error ( 'Error getting search index URL:' , error ) ;
457+ const fallbackUrl = `http://localhost:9200/wikipediaedits/_search?q=personsFoundLocal:*&size=100` ;
458+ window . open ( fallbackUrl , '_blank' ) ;
459+ } ) ;
460+ }
353461</ script >
354462</ body >
355463</ html >
0 commit comments