mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Adds async update from flask with other content
This commit is contained in:
parent
b50ef14dce
commit
f797519944
9 changed files with 49 additions and 61 deletions
|
@ -11,6 +11,5 @@ def post_search(request, search: SearchWithPlugins) -> None:
|
||||||
search_request = search.search_query
|
search_request = search.search_query
|
||||||
container = search.result_container
|
container = search.result_container
|
||||||
# container.infoboxes.append(container.infoboxes[0])
|
# container.infoboxes.append(container.infoboxes[0])
|
||||||
container.chat_box = {'chat_box': 'hello world'}
|
container.chat_box = [{'chat_box': 'hello world'}]
|
||||||
print(container.infoboxes)
|
container.chat_box[0]['content'] = 'some string that relates to your search query here' + f'\n{search_request.query}'
|
||||||
print("HELLO WORLD =====================================================================")
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -548,7 +548,8 @@ article[data-vim-selected].category-social {
|
||||||
}
|
}
|
||||||
|
|
||||||
#suggestions,
|
#suggestions,
|
||||||
#infoboxes {
|
#infoboxes,
|
||||||
|
#chat_box {
|
||||||
input {
|
input {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 3px;
|
margin: 3px;
|
||||||
|
@ -564,7 +565,8 @@ article[data-vim-selected].category-social {
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="submit"],
|
input[type="submit"],
|
||||||
.infobox .url a {
|
.infobox .url a,
|
||||||
|
.chat_box .url a {
|
||||||
color: var(--color-result-link-font);
|
color: var(--color-result-link-font);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
|
@ -595,6 +597,7 @@ article[data-vim-selected].category-social {
|
||||||
}
|
}
|
||||||
|
|
||||||
#infoboxes .title,
|
#infoboxes .title,
|
||||||
|
#chat_box .title,
|
||||||
#suggestions .title,
|
#suggestions .title,
|
||||||
#search_url .title,
|
#search_url .title,
|
||||||
#engines_msg .title,
|
#engines_msg .title,
|
||||||
|
@ -648,7 +651,8 @@ summary.title {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#infoboxes {
|
#infoboxes,
|
||||||
|
#chat_box {
|
||||||
form {
|
form {
|
||||||
min-width: 210px;
|
min-width: 210px;
|
||||||
}
|
}
|
||||||
|
@ -659,7 +663,8 @@ summary.title {
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
color: var(--color-sidebar-font);
|
color: var(--color-sidebar-font);
|
||||||
|
|
||||||
.infobox {
|
.infobox,
|
||||||
|
.chat_box {
|
||||||
margin: 10px 0 10px;
|
margin: 10px 0 10px;
|
||||||
border: 1px solid var(--color-sidebar-border);
|
border: 1px solid var(--color-sidebar-border);
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
@ -843,11 +848,13 @@ summary.title {
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#infoboxes {
|
#infoboxes,
|
||||||
|
#chat_box {
|
||||||
position: inherit;
|
position: inherit;
|
||||||
max-width: inherit;
|
max-width: inherit;
|
||||||
|
|
||||||
.infobox {
|
.infobox,
|
||||||
|
.chat_box {
|
||||||
clear: both;
|
clear: both;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
|
@ -1056,7 +1063,8 @@ summary.title {
|
||||||
background: var(--color-base-background-mobile);
|
background: var(--color-base-background-mobile);
|
||||||
}
|
}
|
||||||
|
|
||||||
.infobox {
|
.infobox,
|
||||||
|
.chat_box {
|
||||||
border: none !important;
|
border: none !important;
|
||||||
background-color: var(--color-sidebar-background);
|
background-color: var(--color-sidebar-background);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,23 @@
|
||||||
<aside class="chat_box" aria-label="{{ chat_box.chat_box }}">
|
<aside class="chat_box" aria-label="{{ chat_box.chat_box }}">
|
||||||
<h2 class="title"><bdi>{{ chat_box.chat_box }}</bdi></h2>
|
<h2 class="title"><bdi>{{ chat_box.chat_box }}</bdi></h2>
|
||||||
<!-- {%- if infobox.img_src -%}<img src="{{ image_proxify(infobox.img_src) }}" title="{{ infobox.infobox|striptags }}" alt="{{ infobox.infobox|striptags }}">{%- endif -%} -->
|
<p><bdi>{{ chat_box.content | safe }}</bdi></p>
|
||||||
<!-- <p><bdi>{{ infobox.content | safe }}</bdi></p> -->
|
</aside>
|
||||||
<!-- {%- if infobox.attributes -%}
|
<script>
|
||||||
<div class="attributes">
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
{%- for attribute in infobox.attributes -%}
|
function updateChatBox() {
|
||||||
<dl>
|
fetch('/get-chat-content')
|
||||||
<dt><bdi>{{ attribute.label }} :</bdi></dt>
|
.then(response => response.json())
|
||||||
{%- if attribute.image -%}
|
.then(data => {
|
||||||
<dd><img src="{{ image_proxify(attribute.image.src) }}" alt="{{ attribute.image.alt }}"></dd>
|
const chatBox = document.querySelector('.chat_box');
|
||||||
{%- else -%}
|
console.log('response from api', data);
|
||||||
<dd><bdi>{{ attribute.value }}</bdi></dd>
|
chatBox.querySelector('bdi').textContent = data.chat_box;
|
||||||
{%- endif -%}
|
chatBox.querySelector('p').textContent = data.content;
|
||||||
</dl>
|
})
|
||||||
{%- endfor -%}
|
.catch(error => console.error('Error:', error));
|
||||||
</div>
|
}
|
||||||
{%- endif -%} -->
|
|
||||||
<!-- {%- if infobox.urls -%}
|
// Call updateChatBox after search is completed
|
||||||
<div class="urls">
|
// This might be tied to an event, depending on how your search functionality is implemented
|
||||||
<ul>
|
updateChatBox();
|
||||||
{%- for url in infobox.urls -%}
|
});
|
||||||
<li class="url"><bdi><a href="{{ url.url }}" {%- if results_on_new_tab -%}target="_blank" rel="noopener noreferrer"{%- else -%}rel="noreferrer"{%- endif -%}>{{ url.title }}</a></bdi></li>
|
</script>
|
||||||
{%- endfor -%}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{%- endif -%} -->
|
|
||||||
<!-- {%- if infobox.relatedTopics -%}
|
|
||||||
<div class="relatedTopics">
|
|
||||||
{%- for topic in infobox.relatedTopics -%}
|
|
||||||
<div>
|
|
||||||
<h3><bdi>{{ topic.name }}</bdi></h3>
|
|
||||||
{%- for suggestion in topic.suggestions -%}
|
|
||||||
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
|
|
||||||
<input type="hidden" name="q" value="{{ suggestion }}">
|
|
||||||
<input type="hidden" name="time_range" value="{{ time_range }}">
|
|
||||||
<input type="hidden" name="language" value="{{ current_language }}">
|
|
||||||
<input type="hidden" name="safesearch" value="{{ safesearch }}">
|
|
||||||
<input type="hidden" name="theme" value="{{ theme }}">
|
|
||||||
{%- if timeout_limit -%}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}" >{%- endif -%}
|
|
||||||
<input type="submit" value="{{ suggestion }}" />
|
|
||||||
</form>
|
|
||||||
{%- endfor -%}
|
|
||||||
</div>
|
|
||||||
{%- endfor -%}
|
|
||||||
</div>
|
|
||||||
{%- endif -%} -->
|
|
||||||
</aside>
|
|
|
@ -47,7 +47,7 @@
|
||||||
<div id="chat_box">
|
<div id="chat_box">
|
||||||
<details open class="sidebar-collapsable">
|
<details open class="sidebar-collapsable">
|
||||||
<summary class="title">{{ _('Chat') }}</summary>
|
<summary class="title">{{ _('Chat') }}</summary>
|
||||||
{%- for infobox in chat_box -%}
|
{%- for chat_box in chat_box -%}
|
||||||
{%- include 'kvanDark/elements/chat_box.html' -%}
|
{%- include 'kvanDark/elements/chat_box.html' -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
</details>
|
</details>
|
||||||
|
|
|
@ -1300,6 +1300,12 @@ def config():
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@app.route('/get-chat-content')
|
||||||
|
def get_chat_content():
|
||||||
|
# Retrieve chat content from wherever it's stored
|
||||||
|
chat_content = {'chat_box': 'hello world', 'content': 'Response From Flask'}
|
||||||
|
return jsonify(chat_content)
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(_e):
|
def page_not_found(_e):
|
||||||
|
|
Loading…
Add table
Reference in a new issue