full.py

mail@pastecode.io avatar
unknown
python
a month ago
4.0 kB
4
Indexable
Never
import theme
from utils.subquery_to_cte import subquery_to_cte

from nicegui import ui, app


def load_devices(device_container):
    device_container.clear()
    with device_container:
        if app.storage.user['input_type'] == 'Query Search with Sigma metadata':
            workbook_id = ui.input(label='Workbook ID', validation={
                                   'Input too long': lambda value: len(value) < 20})
            workbook_url = ui.input(label='Workbook URL', validation={
                                    'Input too long': lambda value: len(value) < 20})
            element_id = ui.input(label='Element ID', validation={
                                  'Input too long': lambda value: len(value) < 20})
            query_id = ui.input(label='Query ID', validation={
                                'Input too long': lambda value: len(value) < 20})
            ui.button('Execute')
        elif app.storage.user['input_type'] == 'Query Search with Query Text':
            query_text = ui.textarea(label='Query', placeholder='Put your query here').style(
                'width: 100%;')


def create():
    @ ui.page('/query_shifter_ui')
    def page_subquery_to_cte():
        with theme.frame():
            with ui.stepper().props('vertical').classes('w-full') as stepper:
                with ui.step('Query Search') as step:
                    input_type_container = ui.row().classes('w-full')
                    device_container = ui.row().classes('w-full')
                    with input_type_container:
                        ui.radio(['Query Search with Sigma metadata', 'Query Search with Query Text'], value=None, on_change=lambda: load_devices(device_container)).bind_value(
                            app.storage.user, 'input_type')
                    with ui.stepper_navigation():
                        ui.button('Next', on_click=stepper.next)
                    load_devices(device_container)
                with ui.step('Rewrite and Parse Query'):
                    query_cte = ui.textarea(label='Query', placeholder='Put your query here').style(
                        'width: 100%;')
                    ui.button('Replace Subquery to CTE',
                              on_click=lambda: replace_sub_to_cte())
                    mkd = ui.markdown('')

                    def replace_sub_to_cte():
                        result = subquery_to_cte(query_cte.value)
                        changing_text = result[0]
                        print(result[1])
                        mkd.content = '```sql \n' \
                            + changing_text \
                            + '\n```'

                    with ui.stepper_navigation():
                        ui.button('Next', on_click=stepper.next)
                        ui.button('Back', on_click=stepper.previous).props(
                            'flat')
                with ui.step('Transaxle'):
                    with ui.grid(columns=3).classes('w-full items-center justify-center'):
                        transaxle_query_source = ui.textarea(label='Query', placeholder='Put your query here').style(
                            'width: 100%;')
                        ui.button('Execute').classes('w-10 h-10 w-max justify-center mx-auto').on_click(
                            lambda: transaxle())

                        def transaxle():
                            changing_text = transaxle_query_source.value + 'transaxle'
                            transaxle_query_target.value = changing_text

                        transaxle_query_target = ui.textarea(label='Query', placeholder='Put your query here').style(
                            'width: 100%;')
                    with ui.stepper_navigation():
                        ui.button('Done', on_click=lambda: ui.notify(
                            'Yay!', type='positive'))
                        ui.button('Back', on_click=stepper.previous).props(
                            'flat')
Leave a Comment