mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Only show search in web app nav pane if user has documents indexed
This commit is contained in:
parent
c0789dc57b
commit
6eb7df717c
7 changed files with 26 additions and 9 deletions
|
@ -371,8 +371,8 @@ class EntryAdapters:
|
|||
)
|
||||
|
||||
@staticmethod
|
||||
async def user_has_entries(user: KhojUser):
|
||||
return await Entry.objects.filter(user=user).aexists()
|
||||
def user_has_entries(user: KhojUser):
|
||||
return Entry.objects.filter(user=user).exists()
|
||||
|
||||
@staticmethod
|
||||
async def adelete_entry_by_file(user: KhojUser, file_path: str):
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
<!--Add Header Logo and Nav Pane-->
|
||||
{% import 'utils.html' as utils %}
|
||||
{{ utils.heading_pane(user_photo, username, is_active) }}
|
||||
{{ utils.heading_pane(user_photo, username, is_active, has_documents) }}
|
||||
|
||||
<div class="filler"></div>
|
||||
</div>
|
||||
|
|
|
@ -363,7 +363,7 @@
|
|||
|
||||
<!--Add Header Logo and Nav Pane-->
|
||||
{% import 'utils.html' as utils %}
|
||||
{{ utils.heading_pane(user_photo, username, is_active) }}
|
||||
{{ utils.heading_pane(user_photo, username, is_active, has_documents) }}
|
||||
|
||||
<!-- Chat Body -->
|
||||
<div id="chat-body"></div>
|
||||
|
|
|
@ -272,7 +272,7 @@
|
|||
<body>
|
||||
<!--Add Header Logo and Nav Pane-->
|
||||
{% import 'utils.html' as utils %}
|
||||
{{ utils.heading_pane(user_photo, username, is_active) }}
|
||||
{{ utils.heading_pane(user_photo, username, is_active, has_documents) }}
|
||||
|
||||
<!--Add Text Box To Enter Query, Trigger Incremental Search OnChange -->
|
||||
<input type="text" id="query" class="option" onkeyup=incrementalSearch(event) autofocus="autofocus" placeholder="Search your knowledge base using natural language">
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
{% macro heading_pane(user_photo, username, is_active) -%}
|
||||
{% macro heading_pane(user_photo, username, is_active, has_documents) -%}
|
||||
<div class="khoj-header">
|
||||
<a class="khoj-logo" href="/" target="_blank">
|
||||
<img class="khoj-logo" src="/static/assets/icons/khoj-logo-sideways-500.png" alt="Khoj"></img>
|
||||
</a>
|
||||
<nav class="khoj-nav">
|
||||
<a id="chat-nav" class="khoj-nav" href="/chat">💬 Chat</a>
|
||||
{% if has_documents %}
|
||||
<a id="search-nav" class="khoj-nav" href="/search">🔎 Search</a>
|
||||
{% endif %}
|
||||
<!-- Dropdown Menu -->
|
||||
<div id="khoj-nav-menu-container" class="khoj-nav dropdown">
|
||||
{% if user_photo and user_photo != "None" %}
|
||||
|
|
|
@ -326,9 +326,7 @@ def get_config_types(
|
|||
request: Request,
|
||||
):
|
||||
user = request.user.object
|
||||
|
||||
enabled_file_types = EntryAdapters.get_unique_file_types(user)
|
||||
|
||||
configured_content_types = list(enabled_file_types)
|
||||
|
||||
if state.config and state.config.content_type:
|
||||
|
@ -665,7 +663,7 @@ async def extract_references_and_questions(
|
|||
if conversation_type == ConversationCommand.General:
|
||||
return compiled_references, inferred_queries, q
|
||||
|
||||
if not await EntryAdapters.user_has_entries(user=user):
|
||||
if not sync_to_async(EntryAdapters.user_has_entries)(user=user):
|
||||
logger.warning(
|
||||
"No content index loaded, so cannot extract references from knowledge base. Please configure your data sources and update the index to chat with your notes."
|
||||
)
|
||||
|
|
|
@ -38,6 +38,7 @@ def index(request: Request):
|
|||
user = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
user_subscription_state = get_user_subscription_state(user.email)
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"chat.html",
|
||||
|
@ -46,6 +47,7 @@ def index(request: Request):
|
|||
"username": user.username,
|
||||
"user_photo": user_picture,
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -56,6 +58,7 @@ def index_post(request: Request):
|
|||
user = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
user_subscription_state = get_user_subscription_state(user.email)
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"chat.html",
|
||||
|
@ -64,6 +67,7 @@ def index_post(request: Request):
|
|||
"username": user.username,
|
||||
"user_photo": user_picture,
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -74,6 +78,7 @@ def search_page(request: Request):
|
|||
user = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
user_subscription_state = get_user_subscription_state(user.email)
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"search.html",
|
||||
|
@ -82,6 +87,7 @@ def search_page(request: Request):
|
|||
"username": user.username,
|
||||
"user_photo": user_picture,
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -92,6 +98,7 @@ def chat_page(request: Request):
|
|||
user = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
user_subscription_state = get_user_subscription_state(user.email)
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"chat.html",
|
||||
|
@ -100,6 +107,7 @@ def chat_page(request: Request):
|
|||
"username": user.username,
|
||||
"user_photo": user_picture,
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -126,6 +134,8 @@ def login_page(request: Request):
|
|||
def config_page(request: Request):
|
||||
user: KhojUser = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
|
||||
user_subscription_state = get_user_subscription_state(user.email)
|
||||
user_subscription = adapters.get_user_subscription(user.email)
|
||||
subscription_renewal_date = (
|
||||
|
@ -162,6 +172,7 @@ def config_page(request: Request):
|
|||
"subscription_renewal_date": subscription_renewal_date,
|
||||
"khoj_cloud_subscription_url": os.getenv("KHOJ_CLOUD_SUBSCRIPTION_URL"),
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -172,6 +183,7 @@ def github_config_page(request: Request):
|
|||
user = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
user_subscription_state = get_user_subscription_state(user.email)
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
current_github_config = get_user_github_config(user)
|
||||
|
||||
if current_github_config:
|
||||
|
@ -201,6 +213,7 @@ def github_config_page(request: Request):
|
|||
"username": user.username,
|
||||
"user_photo": user_picture,
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -211,6 +224,7 @@ def notion_config_page(request: Request):
|
|||
user = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
user_subscription_state = adapters.get_user_subscription(user.email)
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
current_notion_config = get_user_notion_config(user)
|
||||
|
||||
current_config = NotionContentConfig(
|
||||
|
@ -227,6 +241,7 @@ def notion_config_page(request: Request):
|
|||
"username": user.username,
|
||||
"user_photo": user_picture,
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -237,6 +252,7 @@ def computer_config_page(request: Request):
|
|||
user = request.user.object
|
||||
user_picture = request.session.get("user", {}).get("picture")
|
||||
user_subscription_state = get_user_subscription_state(user.email)
|
||||
has_documents = EntryAdapters.user_has_entries(user=user)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"content_source_computer_input.html",
|
||||
|
@ -245,5 +261,6 @@ def computer_config_page(request: Request):
|
|||
"username": user.username,
|
||||
"user_photo": user_picture,
|
||||
"is_active": user_subscription_state == "subscribed" or user_subscription_state == "unsubscribed",
|
||||
"has_documents": has_documents,
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue