-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/edit queue #133
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
Open
bakspace-itk
wants to merge
14
commits into
develop
Choose a base branch
from
feature/edit_queue
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/edit queue #133
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ea346df
deleting queue element
bakspace-itk 74ec5c7
refactored delete to use generic popup
bakspace-itk 0baba6b
refactored in attempt to use prepopulate and proper input types
bakspace-itk 0bf4146
Fixed datetimes and changed json_editor to textarea, reordered some e…
bakspace-itk d359e28
Added tests for new ui stuff, not all are passing
bakspace-itk 337c630
tests passing
bakspace-itk 3b0feb1
updated changelog, changed icons and colors, removed styling constant…
bakspace-itk 2ea8540
Changed queue element popup to use queue element, hide delete button …
bakspace-itk bb01804
layout and hide created by label when no value is found
bakspace-itk d2af382
le linting
bakspace-itk 096123b
removed unused datetime conversion
bakspace-itk e7aeb6a
removed redundant test and added debug for github actions
bakspace-itk 2095e1b
fixed id being a string
bakspace-itk 9c95058
Removed prints, changed select to get and expanded doc string to expl…
bakspace-itk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 96 additions & 49 deletions
145
OpenOrchestrator/orchestrator/popups/queue_element_popup.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,74 +1,121 @@ | ||
| """Class for queue element popups.""" | ||
| import json | ||
| from typing import Callable | ||
|
|
||
| from nicegui import ui | ||
|
|
||
| from OpenOrchestrator.orchestrator import test_helper | ||
|
|
||
| # Styling constants | ||
| LABEL = 'text-subtitle2 text-grey-7' | ||
| VALUE = 'text-body1 gap-0' | ||
| SECTION = 'gap-0' | ||
| from OpenOrchestrator.database import db_util | ||
| from OpenOrchestrator.orchestrator.popups import generic_popups | ||
| from OpenOrchestrator.orchestrator.datetime_input import DatetimeInput | ||
| from OpenOrchestrator.database.queues import QueueStatus, QueueElement | ||
|
|
||
|
|
||
| # pylint: disable-next=too-few-public-methods, too-many-instance-attributes | ||
| class QueueElementPopup(): | ||
| """A popup to display queue element data. | ||
| """ | ||
| def __init__(self, row_data: ui.row): | ||
| def __init__(self, queue_element: QueueElement | None, on_dialog_close_callback: Callable, queue_name: str): | ||
| """Show a dialogue with details of the row selected. | ||
|
|
||
| Args: | ||
| row_data: Data from the row selected. | ||
| """ | ||
| with ui.dialog() as dialog: | ||
| with ui.card().style('min-width: 37.5rem; max-width: 50rem'): | ||
|
|
||
| with ui.row().classes('w-full justify-between items-start mb-4'): | ||
| with ui.column().classes(SECTION + ' mb-4'): | ||
| ui.label("Reference:").classes(LABEL) | ||
| self.reference_text = ui.label(row_data.get('Reference', 'N/A')).classes('text-h5') | ||
| with ui.column().classes(SECTION + ' items-end'): | ||
| ui.label('Status').classes(LABEL) | ||
| self.status_text = ui.label(row_data.get('Status', 'N/A')).classes('text-h5') | ||
| ui.separator() | ||
|
|
||
| with ui.column().classes('gap-1'): | ||
| self.on_dialog_close_callback = on_dialog_close_callback | ||
| self.queue_element = queue_element | ||
| self.queue_name = queue_name | ||
| with ui.dialog() as self.dialog: | ||
| with ui.card().style('min-width: 37.5rem; max-width: 50rem').classes('gap-0'): | ||
|
|
||
| data_text = row_data.get('Data', None) | ||
| if data_text and len(data_text) > 0: | ||
| with ui.row().classes('w-full'): | ||
| ui.label('Data').classes(LABEL) | ||
| try: | ||
| data = json.loads(data_text) | ||
| formatted_data = json.dumps(data, indent=2, ensure_ascii=False) | ||
| self.data_text = ui.code(formatted_data).classes('h-12.5rem w-full').style('max-width: 37.5rem;') | ||
| except (json.JSONDecodeError, TypeError): | ||
| self.data_text = ui.code(data_text).classes('h-12.5rem w-full').style('max-width: 37.5rem;') | ||
|
|
||
| message_text = row_data.get('Message') | ||
| if message_text and len(message_text) > 0: | ||
| with ui.row().classes('w-full mt-4'): | ||
| ui.label('Message').classes(LABEL) | ||
| self.message_text = ui.label(message_text).classes(VALUE) | ||
| with ui.row().classes('w-full justify-between items-start'): | ||
| with ui.column().classes('gap-0'): | ||
| ui.label("ID:").classes('text-subtitle2 text-grey-7') | ||
| self.id_text = ui.label() | ||
| self.reference = ui.input("Reference") | ||
| with ui.column().classes('gap-0 items-end'): | ||
| self.created_by_label = ui.label("Created by:").classes('text-subtitle2 text-grey-7') | ||
| self.created_by = ui.label() | ||
| self.status = ui.select(options={status.name: status.value for status in QueueStatus}, label="Status").classes("w-32") | ||
|
|
||
| with ui.column().classes('gap-0'): | ||
| with ui.row().classes('w-full'): | ||
| self.data_field = ui.textarea("Data").classes('w-full') | ||
| with ui.row().classes('w-full mt-4'): | ||
| self.message = ui.input('Message').classes('w-full') | ||
| with ui.row().classes('w-full mt-4'): | ||
| with ui.column().classes('flex-1'): | ||
| ui.label("Created Date:").classes(LABEL) | ||
| self.created_date = ui.label(row_data.get('Created Date', 'N/A')).classes(VALUE) | ||
| self.created_date = DatetimeInput("Created Date", allow_empty=True) | ||
| with ui.column().classes('flex-1'): | ||
| ui.label("Start Date:").classes(LABEL) | ||
| self.start_date = ui.label(row_data.get('Start Date', 'N/A')).classes(VALUE) | ||
| self.start_date = DatetimeInput("Start Date", allow_empty=True) | ||
| with ui.column().classes('flex-1'): | ||
| ui.label("End Date:").classes(LABEL) | ||
| self.end_date = ui.label(row_data.get('End Date', 'N/A')).classes(VALUE) | ||
| self.end_date = DatetimeInput("End Date", allow_empty=True) | ||
|
|
||
| with ui.row().classes('w-full mt-4'): | ||
| ui.label("Created By:").classes(LABEL) | ||
| self.created_by = ui.label(row_data.get('Created By', 'N/A')).classes(VALUE) | ||
| with ui.row().classes('w-full'): | ||
| ui.label("ID:").classes(LABEL) | ||
| self.id_text = ui.label(row_data.get('ID', 'N/A')).classes(VALUE) | ||
| with ui.row().classes('w-full mt-4'): | ||
| self.save_button = ui.button(text='Save', on_click=self._save_and_close).classes('mt-4') | ||
| self.close_button = ui.button('Close', on_click=self._close_dialog).classes('mt-4') | ||
| self.delete_button = ui.button(text='Delete', on_click=self._delete_element, color="negative").classes('mt-4') | ||
|
|
||
| ui.button('Close', on_click=dialog.close).classes('mt-4') | ||
| test_helper.set_automation_ids(self, "queue_element_popup") | ||
| dialog.open() | ||
| self.dialog.open() | ||
| self._pre_populate() | ||
|
|
||
| def _pre_populate(self): | ||
| """Pre populate the inputs with an existing credential.""" | ||
| if self.queue_element: | ||
| if not self.queue_element.created_by: | ||
| self.created_by_label.visible = False | ||
| else: | ||
| self.created_by.text = self.queue_element.created_by | ||
| self.id_text.text = self.queue_element.id | ||
| self.reference.value = self.queue_element.reference | ||
| self.status.value = self.queue_element.status.name | ||
| self.message.value = self.queue_element.message | ||
| self.data_field.value = self._prettify_json(self.queue_element.data) | ||
| self.created_date.set_datetime(self.queue_element.created_date) | ||
| self.start_date.set_datetime(self.queue_element.start_date) | ||
| self.end_date.set_datetime(self.queue_element.end_date) | ||
| else: | ||
| self.id_text.text = "NOT SAVED" | ||
| self.created_by.text = "Orchestrator UI" | ||
| self.status.value = "NEW" | ||
| self.delete_button.visible = False | ||
|
|
||
| def _prettify_json(self, json_string: str) -> str: | ||
| if not json_string: | ||
| return None | ||
| try: | ||
| data = json.loads(json_string) | ||
| return json.dumps(data, indent=2, ensure_ascii=False) | ||
| except ValueError: | ||
| return json_string | ||
|
|
||
| def _close_dialog(self): | ||
| self.on_dialog_close_callback() | ||
| self.dialog.close() | ||
|
|
||
| async def _delete_element(self): | ||
| if not self.queue_element: | ||
| return | ||
| if await generic_popups.question_popup(f"Delete element '{self.queue_element.id}'?", "Delete", "Cancel", color1='negative'): | ||
| db_util.delete_queue_element(self.queue_element.id) | ||
| ui.notify("Queue element deleted", type='positive') | ||
| self._close_dialog() | ||
|
|
||
| def _save_element(self): | ||
| if not self.queue_element: | ||
| self.queue_element = db_util.create_queue_element(self.queue_name) | ||
| self.id_text.text = self.queue_element.id | ||
| ui.notify("New queue element created", type="positive") | ||
| db_util.update_queue_element(self.queue_element.id, | ||
| reference=self.reference.value, | ||
| status=self.status.value, | ||
| data=self.data_field.value, | ||
| message=self.message.value, | ||
| created_by=self.created_by.text, | ||
| created_date=self.created_date.get_datetime(), | ||
| start_date=self.start_date.get_datetime(), | ||
| end_date=self.end_date.get_datetime()) | ||
|
|
||
| def _save_and_close(self): | ||
| self._save_element() | ||
| self._close_dialog() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.