Skip to content

Commit

Permalink
fix: jans-cli DocString and removing unused imports (ref: #2572)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelwahabAdam committed Nov 29, 2022
1 parent b381ee5 commit 7caa495
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 131 deletions.
4 changes: 0 additions & 4 deletions jans-cli-tui/cli_tui/plugins/010_oxauth/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from typing import Any, Optional
from prompt_toolkit.application.current import get_app
from prompt_toolkit.eventloop import get_event_loop
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.layout.containers import (
HSplit,
VSplit,
Expand All @@ -24,7 +22,6 @@
)
from prompt_toolkit.lexers import PygmentsLexer, DynamicLexer
from utils.static import DialogResult
from cli import config_cli
from utils.utils import DialogUtils
from wui_components.jans_nav_bar import JansNavBar
from wui_components.jans_vetrical_nav import JansVerticalNav
Expand All @@ -36,7 +33,6 @@
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.application import Application
from utils.multi_lang import _
import cli_style

class Plugin(DialogUtils):
"""This is a general class for plugins
Expand Down
66 changes: 37 additions & 29 deletions jans-cli-tui/cli_tui/plugins/060_scripts/edit_script_dialog.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,34 @@
import re

from asyncio import ensure_future
from functools import partial

from prompt_toolkit.layout.dimension import D
from prompt_toolkit.layout.containers import (
HSplit,
VSplit,
DynamicContainer,
Window
)
from prompt_toolkit.widgets import (
Box,
Button,
Label,
TextArea,
RadioList,
Button,
Dialog,
)
from prompt_toolkit.application.current import get_app

from prompt_toolkit.lexers import PygmentsLexer
from pygments.lexers.python import PythonLexer
from pygments.lexers.jvm import JavaLexer

from cli import config_cli
from utils.static import DialogResult
from wui_components.jans_dialog_with_nav import JansDialogWithNav
from wui_components.jans_side_nav_bar import JansSideNavBar
from wui_components.jans_cli_dialog import JansGDialog
from wui_components.jans_drop_down import DropDownWidget
from wui_components.jans_data_picker import DateSelectWidget
from utils.utils import DialogUtils
from wui_components.jans_vetrical_nav import JansVerticalNav
from wui_components.jans_spinner import Spinner
from prompt_toolkit.layout.containers import (
AnyContainer,
)
from prompt_toolkit.formatted_text import AnyFormattedText
from prompt_toolkit.layout.dimension import AnyDimension
from typing import Optional, Sequence, Union
from typing import TypeVar, Callable

from typing import Optional, Sequence
from typing import Callable
from typing import Any, Optional


from view_uma_dialog import ViewUMADialog

from utils.multi_lang import _


class EditScriptDialog(JansGDialog, DialogUtils):
"""This Script editing dialog
"""
Expand All @@ -64,8 +42,9 @@ def __init__(
)-> Dialog:
"""init for `EditScriptDialog`, inherits from two diffrent classes `JansGDialog` and `DialogUtils`
JansGDialog (dialog): This is the main dialog Class Widget for all Jans-cli-tui dialogs except custom dialogs like dialogs with navbar
DialogUtils (methods): Responsable for all `make data from dialog` and `check required fields` in the form for any Edit or Add New
Args:
parent (widget): This is the parent widget for the dialog, to access `Pageup` and `Pagedown`
title (str): The Main dialog title
Expand All @@ -83,6 +62,8 @@ def __init__(
self.script = self.data.get('script','')

def save(self) -> None:
"""method to invoked when saving the dialog (Save button is pressed)
"""

data = {}

Expand Down Expand Up @@ -131,6 +112,9 @@ def save(self) -> None:
self.future.set_result(DialogResult.ACCEPT)

def cancel(self) -> None:
"""method to invoked when canceling changes in the dialog (Cancel button is pressed)
"""

self.future.set_result(DialogResult.CANCEL)

def create_window(self) -> None:
Expand Down Expand Up @@ -317,27 +301,35 @@ def create_window(self) -> None:
width=self.myparent.dialog_width,
)


def get_help(self, **kwargs: Any):
"""This method get focused field Description to display on statusbar
"""

# schema = self.app.cli_object.get_schema_from_reference('#/components/schemas/{}'.format(str(kwargs['scheme'])))

if kwargs['scheme'] == 'Properties':
self.myparent.status_bar_text= kwargs['data'][0]




def script_lang_changed(
self,
value: str,
) -> None:
"""Change the script lang
Args:
value (str): lang to change to (python, java)
"""
self.cur_lang = value

def set_location_widget_state(
self,
state: bool,
) -> None:
"""This method check the state of the location to save script
Args:
state (bool): state is changed or not
"""
self.location_widget.me.read_only = not state
self.location_widget.me.focusable = state
if not state:
Expand All @@ -347,10 +339,17 @@ def script_location_changed(
self,
redio_button: RadioList,
) -> None:
"""Location to save Script
Args:
redio_button (RadioList): Where to save the scripts (Database, Filesystem)
"""
state = redio_button.current_value == 'file'
self.set_location_widget_state(state)

def edit_property(self, **kwargs: Any) -> None:
"""This method for editing the properties
"""

if kwargs['jans_name'] == 'moduleProperties':
key, val = kwargs.get('data', ('',''))
Expand Down Expand Up @@ -389,12 +388,16 @@ def add_property(dialog: Dialog) -> None:
self.myparent.show_jans_dialog(dialog)

def delete_config_property(self, **kwargs: Any) -> None:
"""This method for deleting the coniguration of properties
"""
if kwargs['jans_name'] == 'configurationProperties':
self.config_properties_container.remove_item(kwargs['selected'])
else:
self.module_properties_container.remove_item(kwargs['selected'])

def edit_script_dialog(self) -> None:
"""This method shows the script itself and let the user view or edit it
"""

text_editor = TextArea(
text=self.script,
Expand All @@ -415,5 +418,10 @@ def modify_script(arg) -> None:
self.myparent.show_jans_dialog(dialog)

def __pt_container__(self)-> Dialog:
"""The container for the dialog itself
Returns:
Dialog: The Edit Script Dialog
"""
return self.dialog

52 changes: 19 additions & 33 deletions jans-cli-tui/cli_tui/plugins/060_scripts/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import os
import sys

from functools import partial
import asyncio

import prompt_toolkit
from prompt_toolkit.application.current import get_app
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.layout.containers import (
HSplit,
VSplit,
Expand All @@ -17,32 +10,16 @@
)
from prompt_toolkit.layout.dimension import D
from prompt_toolkit.widgets import (
Box,
Button,
Label,
Frame,
Dialog
)
from typing import Any, Optional
from prompt_toolkit.buffer import Buffer

from utils.static import DialogResult

from cli import config_cli
from wui_components.jans_nav_bar import JansNavBar
from wui_components.jans_side_nav_bar import JansSideNavBar
from wui_components.jans_vetrical_nav import JansVerticalNav
from wui_components.jans_dialog import JansDialog
from wui_components.jans_dialog_with_nav import JansDialogWithNav
from wui_components.jans_drop_down import DropDownWidget
from wui_components.jans_data_picker import DateSelectWidget

from edit_script_dialog import EditScriptDialog
from prompt_toolkit.application import Application

from utils.multi_lang import _
import cli_style


class Plugin():
"""This is a general class for plugins
Expand All @@ -51,10 +28,10 @@ def __init__(
self,
app: Application
) -> None:
"""init for Plugin class "oxauth"
"""init for Plugin class "scripts"
Args:
app (_type_): _description_
app (Generic): The main Application class
"""
self.app = app
self.pid = 'scripts'
Expand Down Expand Up @@ -87,12 +64,17 @@ def scripts_prepare_containers(self) -> None:
DynamicContainer(lambda: self.scripts_list_container)
],style='class:outh_containers_scopes')


def get_scripts(
self,
start_index: Optional[int]= 1,
pattern: Optional[str]= '',
) -> None:
"""Get the current Scripts from server
Args:
start_index (Optional[int], optional): This is flag for the Scripts pages. Defaults to 0.
pattern (Optional[str], optional):endpoint arguments for the Scripts. Defaults to ''.
"""

endpoint_args ='limit:{},startIndex:{}'.format(self.app.entries_per_page, start_index)
if pattern:
Expand All @@ -116,15 +98,14 @@ async def coroutine():

asyncio.ensure_future(coroutine())


def scripts_update_list(
self,
pattern: Optional[str]= '',
) -> None:
"""Updates Scripts data from server
Args:
start_index (int, optional): add Button("Prev") to the layout. Defaults to 0.
pattern (Optional[str], optional):endpoint arguments for the Scripts. Defaults to ''.
"""

data =[]
Expand Down Expand Up @@ -175,17 +156,20 @@ def scripts_update_list(
self.app.layout.focus(self.scripts_listbox)
get_app().invalidate()


def get_help(self, **kwargs: Any):
"""This method get focused field Description to display on statusbar
"""

# schema = self.app.cli_object.get_schema_from_reference('#/components/schemas/{}'.format(str(kwargs['scheme'])))

if kwargs['scheme'] == 'Scripts':
self.app.status_bar_text= kwargs['data'][2]



def search_scripts(self, tbuffer:Buffer) -> None:
"""This method handel the search for scripts
Args:
tbuffer (Buffer): Buffer returned from the TextArea widget > GetTitleText
"""
if not len(tbuffer.text) > 2:
self.app.show_message(_("Error!"), _("Search string should be at least three characters"), tobefocused=self.scripts_main_area)
return
Expand All @@ -212,7 +196,7 @@ def save_script(self, dialog: Dialog) -> None:
dialog (_type_): the main dialog to save data in
Returns:
_type_: bool value to check the status code response
bool : value to check the status code response
"""

async def coroutine():
Expand All @@ -231,6 +215,8 @@ async def coroutine():
asyncio.ensure_future(coroutine())

def delete_script(self, **kwargs: Any) -> None:
"""This method for the deletion of the Scripts
"""

def do_delete_script():

Expand Down
Loading

0 comments on commit 7caa495

Please sign in to comment.