Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI/logo+nav #126

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion web/admin_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import streamlit as st
from docq.config import LogType
from st_pages import add_page_title
from utils.layout import auth_required, list_logs_ui
from utils.layout import auth_required, list_logs_ui, run_page_scripts, setup_page_scripts

setup_page_scripts()

auth_required(requiring_admin=True)

Expand All @@ -15,3 +17,5 @@
with tab:
st.subheader(type_.value)
list_logs_ui(type_)

run_page_scripts()
6 changes: 4 additions & 2 deletions web/admin_orgs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Page: Admin / Manage Orgs."""

from st_pages import add_page_title
from utils.layout import auth_required, create_org_ui, list_orgs_ui
from utils.layout import auth_required, create_org_ui, list_orgs_ui, run_page_scripts, setup_page_scripts

setup_page_scripts()
auth_required(requiring_admin=True)

add_page_title()

create_org_ui()
list_orgs_ui()

run_page_scripts()
6 changes: 5 additions & 1 deletion web/admin_settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""Page: Admin / Manage Settings."""

from st_pages import add_page_title
from utils.layout import auth_required, system_settings_ui
from utils.layout import auth_required, run_page_scripts, setup_page_scripts, system_settings_ui

setup_page_scripts()

auth_required(requiring_admin=True)

add_page_title()

system_settings_ui()

run_page_scripts()
11 changes: 10 additions & 1 deletion web/admin_space_groups.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
"""Page: Admin / Manage Space Groups."""

from st_pages import add_page_title
from utils.layout import auth_required, create_space_group_ui, list_space_groups_ui
from utils.layout import (
auth_required,
create_space_group_ui,
list_space_groups_ui,
run_page_scripts,
setup_page_scripts,
)

setup_page_scripts()
auth_required(requiring_admin=True)

add_page_title()

create_space_group_ui()
list_space_groups_ui()

run_page_scripts()
5 changes: 4 additions & 1 deletion web/admin_spaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Page: Admin / Manage Documents."""
from st_pages import add_page_title
from utils.layout import admin_docs_ui, auth_required, create_space_ui
from utils.layout import admin_docs_ui, auth_required, create_space_ui, run_page_scripts, setup_page_scripts

setup_page_scripts()
auth_required(requiring_admin=True)

add_page_title()
Expand All @@ -12,3 +13,5 @@
create_space_ui()

admin_docs_ui(PARAM_NAME)

run_page_scripts()
6 changes: 4 additions & 2 deletions web/admin_user_groups.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Page: Admin / Manage User Groups."""

from st_pages import add_page_title
from utils.layout import auth_required, create_user_group_ui, list_user_groups_ui
from utils.layout import auth_required, create_user_group_ui, list_user_groups_ui, run_page_scripts, setup_page_scripts

setup_page_scripts()
auth_required(requiring_admin=True)

add_page_title()

create_user_group_ui()
list_user_groups_ui()

run_page_scripts()
11 changes: 4 additions & 7 deletions web/admin_users.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
"""Page: Admin / Manage Users."""

import logging
import streamlit as st
from st_pages import add_page_title
from utils.layout import auth_required, create_user_ui, list_users_ui, org_selection_ui
from utils.layout import auth_required, create_user_ui, list_users_ui, run_page_scripts, setup_page_scripts

setup_page_scripts()
auth_required(requiring_admin=True)

add_page_title()

with st.sidebar:
org_selection_ui()

create_user_ui()
list_users_ui()

run_page_scripts()
3 changes: 2 additions & 1 deletion web/embed.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Docq widget embed page."""
from docq.config import FeatureType
from docq.domain import FeatureKey
from utils.layout import chat_ui, public_session_setup, public_space_enabled
from utils.layout import chat_ui, public_session_setup, public_space_enabled, setup_page_scripts
from utils.sessions import get_public_session_id

setup_page_scripts()
public_session_setup()

public_space_enabled(FeatureType.ASK_PUBLIC)
Expand Down
16 changes: 12 additions & 4 deletions web/index.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"""Page: Home (no auth required)."""

import streamlit as st
from st_pages import Page, Section, add_page_title, show_pages
from utils.layout import init_with_pretty_error_ui, org_selection_ui, production_layout, public_access
from utils.layout import (
init_with_pretty_error_ui,
production_layout,
public_access,
setup_page_scripts,
)

init_with_pretty_error_ui()


production_layout()

with st.sidebar:
org_selection_ui()
# with st.sidebar:
# org_selection_ui()

show_pages(
[
Expand Down Expand Up @@ -59,4 +63,8 @@
"""
)


st.markdown("Enjoy [Docq](https://docq.ai)!")


setup_page_scripts()
6 changes: 4 additions & 2 deletions web/personal_ask.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Page: Personal / Ask Your Documents."""

from docq.config import FeatureType
from docq.domain import FeatureKey
from st_pages import add_page_title
from utils.layout import auth_required, chat_ui, feature_enabled
from utils.layout import auth_required, chat_ui, feature_enabled, run_page_scripts, setup_page_scripts
from utils.sessions import get_authenticated_user_id

setup_page_scripts()
auth_required()

feature_enabled(FeatureType.ASK_PERSONAL)
Expand All @@ -15,3 +15,5 @@
feature = FeatureKey(FeatureType.ASK_PERSONAL, get_authenticated_user_id())

chat_ui(feature)

run_page_scripts()
7 changes: 5 additions & 2 deletions web/personal_chat.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Page: Personal / General Chat."""

from docq.config import FeatureType
from docq.domain import FeatureKey
from st_pages import add_page_title
from utils.layout import auth_required, chat_ui, feature_enabled
from utils.layout import auth_required, chat_ui, feature_enabled, run_page_scripts, setup_page_scripts
from utils.sessions import get_authenticated_user_id

setup_page_scripts()
auth_required()

feature_enabled(FeatureType.CHAT_PRIVATE)
Expand All @@ -15,3 +15,6 @@
feature = FeatureKey(FeatureType.CHAT_PRIVATE, get_authenticated_user_id())

chat_ui(feature)


run_page_scripts()
6 changes: 4 additions & 2 deletions web/personal_docs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Page: Personal / Manage Your Documents."""

from docq.config import FeatureType, SpaceType
from docq.domain import SpaceKey
from st_pages import add_page_title
from utils.layout import auth_required, documents_ui, feature_enabled
from utils.layout import auth_required, documents_ui, feature_enabled, run_page_scripts, setup_page_scripts
from utils.sessions import get_authenticated_user_id, get_selected_org_id

setup_page_scripts()
auth_required()

feature_enabled(FeatureType.ASK_PERSONAL)
Expand All @@ -15,3 +15,5 @@
space = SpaceKey(SpaceType.PERSONAL, get_authenticated_user_id(), get_selected_org_id())

documents_ui(space)

run_page_scripts()
6 changes: 4 additions & 2 deletions web/shared_ask.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Page: Shared / Ask Shared Documents."""

from docq.config import FeatureType
from docq.domain import FeatureKey
from st_pages import add_page_title
from utils.layout import auth_required, chat_ui, feature_enabled
from utils.layout import auth_required, chat_ui, feature_enabled, run_page_scripts, setup_page_scripts
from utils.sessions import get_authenticated_user_id

setup_page_scripts()
auth_required()

feature_enabled(FeatureType.ASK_SHARED)
Expand All @@ -15,3 +15,5 @@
feature = FeatureKey(FeatureType.ASK_SHARED, get_authenticated_user_id())

chat_ui(feature)

run_page_scripts()
5 changes: 4 additions & 1 deletion web/shared_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from docq.config import FeatureType
from docq.domain import FeatureKey
from st_pages import add_page_title
from utils.layout import auth_required, feature_enabled, list_spaces_ui
from utils.layout import auth_required, feature_enabled, list_spaces_ui, run_page_scripts, setup_page_scripts
from utils.sessions import get_authenticated_user_id

setup_page_scripts()
auth_required()

feature_enabled(FeatureType.ASK_SHARED)
Expand All @@ -15,3 +16,5 @@
feature = FeatureKey(FeatureType.ASK_SHARED, get_authenticated_user_id())

list_spaces_ui()

run_page_scripts()
42 changes: 42 additions & 0 deletions web/st_components/page_header/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Header bar."""
import os

from streamlit.components.v1 import html

from ..static_utils import load_file_variables

parent_dir = os.path.dirname(os.path.abspath(__file__))
script_path = os.path.join(parent_dir, "static", "header.js")
css_path = os.path.join(parent_dir, "static", "header.css")

# Run this at the start of each page
def _setup_page_script(auth_state: bool) -> None:
"""Setup page script."""
auth_ = "true" if auth_state else "false"
html(
f"""
<script>
if (!{auth_}) {{
const __parent = window.parent.document || window.document;
const docqHeader = __parent.getElementById("docq-header-container");
if (docqHeader) {{
docqHeader.remove();
}}
}}
</script>
""",
height=0
)


def run_script(auth_state: bool, username: str, avatar_src: str, selected_org: str) -> None:
"""Render the header bar."""
style = load_file_variables(css_path, {})
script_args = {
"username": username,
"avatar_src": avatar_src,
"style_doc": style,
"auth_state": "authenticated" if auth_state else "unauthenticated",
"selected_org": selected_org,
}
html(f"<script>{load_file_variables(script_path, script_args)}</script>", height=0)
Loading