Skip to content

Commit

Permalink
fix(jans-cli-tui): asset management: Jans Service and asset types (#8658
Browse files Browse the repository at this point in the history
)

fix(jans-cli-tui): asset management changes:  Jans Service and asset types

Signed-off-by: Mustafa Baser <mbaser@mail.com>
Signed-off-by: Devrim <devrimyatar@gluu.org>
  • Loading branch information
devrimyatar committed Jun 5, 2024
1 parent e695937 commit 61ea9ac
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
2 changes: 1 addition & 1 deletion jans-cli-tui/cli_tui/plugins/020_fido/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def coroutine():
if result.lower() == 'yes':
self.requested_parties_container.remove_item(kwargs['selected'])
self.app.stop_progressing()

return result

asyncio.ensure_future(coroutine())
Expand Down
58 changes: 43 additions & 15 deletions jans-cli-tui/cli_tui/plugins/130_assets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from wui_components.jans_vetrical_nav import JansVerticalNav
from wui_components.jans_cli_dialog import JansGDialog
from wui_components.jans_spinner import Spinner
from wui_components.jans_drop_down import DropDownWidget
from wui_components.jans_path_browser import jans_file_browser_dialog, BrowseType



class Plugin(DialogUtils):
"""This is a general class for plugins
"""
Expand Down Expand Up @@ -62,8 +62,10 @@ def init_plugin(self) -> None:
"""The initialization for this plugin
"""

self.app.create_background_task(self.get_initial_data())
self.app.create_background_task(self.get_assets())


def set_center_frame(self) -> None:
"""center frame content
"""
Expand Down Expand Up @@ -113,9 +115,7 @@ def save_asset(dialog: Dialog) -> None:
self.app.show_message(common_strings.error, HTML(_("Please fill <b>Description</b> and <b>Display Name</b>")), tobefocused=dialog)
return

for prop in data['jansModuleProperty'][:]:
if not prop:
data['jansModuleProperty'].remove(prop)
data['jansService'] = [data.pop('jansService')]

data.pop('document', None)
form_data = {'assetFile': self.asset_file_path, 'document': data}
Expand Down Expand Up @@ -144,7 +144,15 @@ async def coroutine():


def display_file_browser_dialog():
file_browser_dialog.future = asyncio.futures.Future()

file_browser_dialog = jans_file_browser_dialog(
common_data.app,
path=common_data.app.browse_path,
browse_type=BrowseType.file,
ok_handler=read_asset,
extensions=[f'.{e}' for e in common_data.asset_types]
)

common_data.app.show_jans_dialog(file_browser_dialog)


Expand All @@ -166,9 +174,18 @@ def read_asset(path):
)
enabled_widget = common_data.app.getTitledCheckBox(_("Enabled"), name='jansEnabled', checked=data.get('jansEnabled'), style=cli_style.check_box)
description_widget = common_data.app.getTitledText(_("Description"), name='description', value=data.get('description', ''), style=cli_style.edit_text_required)
#selected_widget = common_data.app.getTitledCheckBox(_("Selected"), name='selected', checked=data.get('selected'), style=cli_style.check_box)
jans_module_widget = common_data.app.getTitledText(_("Jans Module Properties"), name='jansModuleProperty', value='\n'.join(data.get('jansModuleProperty', [])), height=3, jans_list_type=True, style=cli_style.edit_text, jans_help=_("Enter property each line"))
#document_widget = common_data.app.getTitledText(_("Document"), name='document', height=3, value=data.get('document', ''), style=cli_style.edit_text)

jans_serice_widget = self.app.getTitledWidget(
_("Jans Service"),
name='jansService',
widget=DropDownWidget(
values=[(s,s) for s in common_data.asset_services],
value=data.get('jansService', common_data.asset_services)[0],
select_one_option=False
),
jans_help=_("Select Jans Service"),
style=cli_style.edit_text
)

save_button = Button(_("Save"), handler=save_asset)
save_button.keep_dialog = True
Expand All @@ -187,17 +204,12 @@ def read_asset(path):
description_widget,
jans_level_widget,
enabled_widget,
#selected_widget,
jans_module_widget,
#document_widget,
jans_serice_widget,
],
width=D())

edit_asset_dialog = JansGDialog(common_data.app, title=title, body=body, buttons=buttons, width=common_data.app.dialog_width)

file_browser_dialog = jans_file_browser_dialog(common_data.app, path=common_data.app.browse_path, browse_type=BrowseType.file, ok_handler=read_asset)


common_data.app.show_jans_dialog(edit_asset_dialog)

def delete_asset(self, **kwargs: Any) -> None:
Expand Down Expand Up @@ -242,7 +254,7 @@ async def get_assets(self, pattern='') -> None:
self.app.start_progressing(_("Retreiving assets from server..."))
response = await get_event_loop().run_in_executor(self.app.executor, self.app.cli_requests, cli_args)
self.app.stop_progressing()

try:
result = response.json()
except Exception as e:
Expand All @@ -267,3 +279,19 @@ async def get_assets(self, pattern='') -> None:
self.assets_list_box.add_item((asset_info['inum'], asset_info['displayName'], asset_info['jansEnabled'], asset_info['creationDate']))

self.assets_container = self.assets_list_box


async def get_initial_data(self) -> None:
if not hasattr(common_data, 'asset_services'):
response = await get_event_loop().run_in_executor(common_data.app.executor, common_data.app.cli_requests, {'operation_id': 'get-asset-services'})
try:
common_data.asset_services = response.json()
except Exception as e:
self.app.logger.error(f"Fail to get asset services: {e}")

if not hasattr(common_data, 'asset_types'):
response = await get_event_loop().run_in_executor(common_data.app.executor, common_data.app.cli_requests, {'operation_id': 'get-asset-types'})
try:
common_data.asset_types = response.json()
except Exception as e:
self.app.logger.error(f"Fail to get asset types: {e}")
12 changes: 8 additions & 4 deletions jans-cli-tui/cli_tui/wui_components/jans_path_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __init__(self,
path: str,
browse_type: BrowseType,
height: int = 10,
hide_hidden_files: Optional[bool] = True
hide_hidden_files: Optional[bool] = True,
extensions: Optional[list] = []
) -> None:
"""init for JansPathBrowserWidget"""

Expand All @@ -44,7 +45,7 @@ def __init__(self,
self.browse_type = browse_type
self.height = height
self.hide_hidden_files = hide_hidden_files

self.extensions = extensions
self.selected_line = 0
browsed_dir = Window(FormattedTextControl(lambda: self.path.as_posix()))
path_selection_window = Window(
Expand Down Expand Up @@ -108,6 +109,8 @@ def _update_path_content(self) -> None:
dirs = []

for path_ in self.path.glob('*'):
if self.extensions and path_.is_file() and path_.suffix not in self.extensions:
continue
if self.hide_hidden_files and path_.name.startswith('.'):
continue
if path_.is_dir():
Expand Down Expand Up @@ -171,7 +174,8 @@ def jans_file_browser_dialog(
path: str = '/',
browse_type: Optional[BrowseType] = BrowseType.save_as,
ok_handler: Optional[Callable] = None,
hide_hidden_files: Optional[bool] = True
hide_hidden_files: Optional[bool] = True,
extensions: Optional[list] = []
) -> JansGDialog:
"""Functo to create a Jans File Browser Dialog
Expand All @@ -181,7 +185,7 @@ def jans_file_browser_dialog(
ok_handler (collable, optional): Callable when OK button is pressed
"""

browse_widget = JansPathBrowserWidget(path, browse_type, hide_hidden_files=hide_hidden_files)
browse_widget = JansPathBrowserWidget(path, browse_type, hide_hidden_files=hide_hidden_files, extensions=extensions)


def call_ok_handler(dialog):
Expand Down

0 comments on commit 61ea9ac

Please sign in to comment.