Skip to content

Commit

Permalink
fix: jans-cli-tui working branch 4 - many different improvements (#3504)
Browse files Browse the repository at this point in the history
* fix:jans-cli-tui change user password (ref: #3360)

* fix:jans-cli-tui show kid for each key (ref: #3405)

* fix:jans-cli-tui improve Scope Management for OpenID Client (ref: #3460)

* fix:jans-cli-tui remove repeated import

* fix:jans-cli-tui change the Quit key to  (ref: #3502)

* fix: jans-cli-tui ctrl+c and ctrl+q to exit

* feat: jans-cli-tui status bar message for listbox

* fix: jans-cli-tui code smells

* fix: jans-cli-tui sort properties for ease of navigation

* fix: enabled components are checked for porperties (ref: #3438)

* feat: jans-cli-tui add missing property

* fix:jans-cli-tui make list for scopes -baseDn and displayName- (ref: #3460)

* fix: jans-cli-tui Improve Scope Management for OpenID Client (ref: #3460)

* fix: jans-tui-client rewrite properties

* fix: jans-cli-tui remove debug line

* fix: jans-cli-tui code smells

* fix: jans-cli-tui typo

* fix: jans-cli-tui code smells

* fix: jans-cli-tui widget style for checkbox

* fix: jans-cli-tui remove unused imports

* fix: jans-cli-tui close dialog after updating client (ref: #3510)

* fix:jans-cli-tui add Scopes label and reverse Scopes columns

* fix: jans-cli-tui uppercase cli

* fix:jans-cli-tui Fixing Client dialog title

* fix:jans-cli-tui re-implementing Scopes

* fix:jans-cli-tui change background color and styling (ref: #3408)

* feat: jans-cli-tui label container widget (ref: #3631)

* fix: jans-cli-tui rewrite client scopes with lable container

* fix: jans-cli-tui save client scopes

* fix: jans-cli-tui only save client scopes no patch

* fix: jans-cli-tui client edit after save

* feat: jans-cli-tui check available plugins from config-api (ref: #3616)

* fix: jans-cli-tui code smells

* fix: jans-cli-tui on_display for label container

* fix: jans-cli-tui code smells

* fix: jans-cli-tui code smells

Co-authored-by: AbdelwahabAdam <abdelwahabosama.1@gmail.com>
  • Loading branch information
devrimyatar and AbdelwahabAdam committed Jan 19, 2023
1 parent 77412d5 commit e572552
Show file tree
Hide file tree
Showing 18 changed files with 1,035 additions and 524 deletions.
25 changes: 25 additions & 0 deletions jans-cli-tui/cli_tui/cli_style.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from prompt_toolkit.styles import Style
from types import SimpleNamespace

style = Style.from_dict(
{
Expand Down Expand Up @@ -76,6 +77,7 @@
"plugin-widget":"green",
"plugin-container":"",
"plugin-container.text":"green",
"plugin-black-bg": "bg: black",

## edit_client_dialog
"outh-client-navbar":"#2600ff",
Expand Down Expand Up @@ -130,9 +132,32 @@
"date-picker-time":"bg:#bab1b1",
"dialog-titled-widget":"bg:#ffffff fg:green",

####tab
"tab-nav-background": "fg:#b0e0e6 bg:#a9a9a9",
"tab-unselected": "fg:#b0e0e6 bg:#a9a9a9 underline",
"tab-selected": "fg:#000080 bg:#d3d3d3",

##scim
"scim-widget": "bg:black fg:white",

}
)


def get_color_for_style(style_name:str)->SimpleNamespace:
ret_val = SimpleNamespace()
ret_val.fg = '#000000'
ret_val.bg = '#ffffff'

for pstyle in style.class_names_and_attrs:
if pstyle[0].__contains__(style_name):
if pstyle[1].color:
ret_val.fg = '#'+pstyle[1].color
if pstyle[1].bgcolor:
ret_val.bg = '#'+pstyle[1].bgcolor

return ret_val

## jans nav bar
main_navbar_bgcolor = "DimGray"
outh_navbar_bgcolor = "#ADD8E6"
Expand Down
71 changes: 42 additions & 29 deletions jans-cli-tui/cli_tui/jans_cli_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self):
self.styles = dict(style.style_rules)
self._plugins = []
self._load_plugins()
self.available_plugins = []
self.cli_object_ok = False
self.pbar_text = ""
self.progressing_text = ""
Expand Down Expand Up @@ -217,9 +218,15 @@ def _load_plugins(self) -> None:
self._plugins.append(plugin_object)

def init_plugins(self) -> None:
"""Initilizse plugins
"""
for plugin in self._plugins:
if hasattr(plugin, 'init_plugin'):
if getattr(plugin, 'server_side_plugin', False) and plugin.pid not in self.available_plugins:
continue
self.logger.debug('Initializing plugin {}'.format(plugin.pid))
plugin.init_plugin()

self.plugins_initialised = True

def plugin_enabled(self, pid: str) -> bool:
Expand Down Expand Up @@ -317,27 +324,31 @@ async def coroutine():
self.stop_progressing()

self.cli_object_ok = True
if not self.plugins_initialised:
self.init_plugins()
self.runtime_plugins()
self.check_available_plugins()

asyncio.ensure_future(coroutine())

else:
self.cli_object_ok = True
if not self.plugins_initialised:
self.init_plugins()

self.runtime_plugins()
self.check_available_plugins()


def runtime_plugins(self) -> None:
def check_available_plugins(self) -> None:
"""Disables plugins when cli object is ready"""

if self.cli_object_ok:
response = self.cli_requests({'operation_id': 'is-license-active'})
if response.status_code == 404:
self.disable_plugin('config_api')
response = self.cli_requests({'operation_id': 'get-plugins'})
if response.ok:
plugins = response.json()
for plugin in plugins:
self.available_plugins.append(plugin['name'])

for pp in self._plugins:
if getattr(pp, 'server_side_plugin', False) and pp.pid not in self.available_plugins:
self.disable_plugin(pp.pid)

self.init_plugins()

def disable_plugin(self, pid) -> None:

Expand All @@ -355,9 +366,6 @@ async def check_jans_cli_ini(self) -> None:
else :
self.create_cli()

if self.cli_object_ok and not self.plugins_initialised:
self.init_plugins()


def jans_creds_dialog(self, *params: Any) -> None:
body=HSplit([
Expand Down Expand Up @@ -387,6 +395,7 @@ def set_keybindings(self) -> None:
self.bindings.add('tab')(self.focus_next)
self.bindings.add('s-tab')(self.focus_previous)
self.bindings.add('c-c')(do_exit)
self.bindings.add('c-q')(do_exit)
self.bindings.add('f1')(self.help)
self.bindings.add('escape')(self.escape)
self.bindings.add('s-up')(self.up)
Expand Down Expand Up @@ -569,6 +578,7 @@ def getTitledText(
focusable: Optional[bool] = None,
width: AnyDimension = None,
style: AnyFormattedText = '',
widget_style: AnyFormattedText = '',
scrollbar: Optional[bool] = False,
line_numbers: Optional[bool] = False,
lexer: PygmentsLexer = None,
Expand All @@ -583,7 +593,7 @@ def getTitledText(
height=height,
width=width,
read_only=read_only,
style=self.styles['textarea-readonly'] if read_only else self.styles['textarea'],
style=widget_style or (self.styles['textarea-readonly'] if read_only else self.styles['textarea']),
accept_handler=accept_handler,
focusable=not read_only if focusable is None else focusable,
scrollbar=scrollbar,
Expand All @@ -598,7 +608,7 @@ def getTitledText(
ta.window.jans_name = name
ta.window.jans_help = jans_help

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style, height=height), ta], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style, height=height), ta])
v.me = ta

return v
Expand All @@ -611,6 +621,7 @@ def getTitledCheckBoxList(
current_values: Optional[list] = [],
jans_help: AnyFormattedText= "",
style: AnyFormattedText= "",
widget_style: AnyFormattedText = '',
) -> AnyContainer:

title += ': '
Expand All @@ -620,9 +631,8 @@ def getTitledCheckBoxList(
cbl.current_values = current_values
cbl.window.jans_name = name
cbl.window.jans_help = jans_help
#li, cd, width = self.handle_long_string(title, values, cbl)

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cbl], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cbl], style=widget_style)
v.me = cbl

return v
Expand All @@ -636,10 +646,15 @@ def getTitledCheckBox(
on_selection_changed: Callable= None,
jans_help: AnyFormattedText= "",
style: AnyFormattedText= "",
widget_style: AnyFormattedText = '',
) -> AnyContainer:

title += ': '
cb = Checkbox(text)
if widget_style:
cb.default_style = widget_style
cb.checked_style = widget_style
cb.selected_style = widget_style
cb.checked = checked
cb.window.jans_name = name
cb.window.jans_help = jans_help
Expand All @@ -652,9 +667,7 @@ def custom_handler():
if on_selection_changed:
cb._handle_enter = custom_handler

#li, cd, width = self.handle_long_string(title, text, cb)

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cb], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), cb], style=widget_style)

v.me = cb

Expand All @@ -669,6 +682,7 @@ def getTitledRadioButton(
on_selection_changed: Callable= None,
jans_help: AnyFormattedText= "",
style: AnyFormattedText= "",
widget_style: AnyFormattedText = '',
) -> AnyContainer:

title += ': '
Expand All @@ -689,7 +703,7 @@ def custom_handler():
if on_selection_changed:
rl._handle_enter = custom_handler

v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), rl], padding=1)
v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style,), rl])

v.me = rl

Expand All @@ -715,9 +729,9 @@ def getTitledWidget(

def getButton(
self,
text: AnyFormattedText,
name: AnyFormattedText,
jans_help: AnyFormattedText,
text: AnyFormattedText,
name: AnyFormattedText,
jans_help: AnyFormattedText,
handler: Callable= None,
) -> Button:

Expand Down Expand Up @@ -845,15 +859,14 @@ def show_message(
self.layout.focus(dialog)
self.invalidate()

def show_again(self) -> None:
self.show_message(_("Again"), _("Nasted Dialogs"),)

def get_confirm_dialog(
self,
message: AnyFormattedText
self,
message: AnyFormattedText,
confirm_handler: Optional[Callable]=None
) -> Dialog:
body = VSplit([Label(message)], align=HorizontalAlign.CENTER)
buttons = [Button(_("No")), Button(_("Yes"))]
buttons = [Button(_("No")), Button(_("Yes"), handler=confirm_handler)]
dialog = JansGDialog(self, title=_("Confirmation"), body=body, buttons=buttons)
return dialog

Expand Down
Loading

0 comments on commit e572552

Please sign in to comment.