diff --git a/jans-cli-tui/plugins/010_oxauth/main.py b/jans-cli-tui/plugins/010_oxauth/main.py index 7a7eddea0d8..8354151239c 100755 --- a/jans-cli-tui/plugins/010_oxauth/main.py +++ b/jans-cli-tui/plugins/010_oxauth/main.py @@ -235,85 +235,89 @@ def get_next( ) -> None: self.oauth_update_clients(start_index, pattern='') - endpoint_args ='limit:{},startIndex:{}'.format(self.app.entries_per_page, start_index) - if pattern: - endpoint_args +=',pattern:'+pattern - try : - rsponse = self.app.cli_object.process_command_by_id( - operation_id='get-oauth-openid-clients', - url_suffix='', - endpoint_args=endpoint_args, - data_fn=None, - data={} - ) + async def coroutine(): + endpoint_args ='limit:{},startIndex:{}'.format(self.app.entries_per_page, start_index) + if pattern: + endpoint_args +=',pattern:'+pattern + try : + rsponse = self.app.cli_object.process_command_by_id( + operation_id='get-oauth-openid-clients', + url_suffix='', + endpoint_args=endpoint_args, + data_fn=None, + data={} + ) + + except Exception as e: + self.app.stop_progressing() + self.app.show_message(_("Error getting clients"), str(e)) + return - except Exception as e: self.app.stop_progressing() - self.app.show_message(_("Error getting clients"), str(e)) - return - self.app.stop_progressing() + if rsponse.status_code not in (200, 201): + self.app.show_message(_("Error getting clients"), str(rsponse.text)) + return - if rsponse.status_code not in (200, 201): - self.app.show_message(_("Error getting clients"), str(rsponse.text)) - return + try: + result = rsponse.json() + except Exception: + self.app.show_message(_("Error getting clients"), str(rsponse.text)) + return - try: - result = rsponse.json() - except Exception: - self.app.show_message(_("Error getting clients"), str(rsponse.text)) - return + data =[] - data =[] + for d in result.get('entries', []): + data.append( + [ + d['inum'], + d.get('clientName', {}).get('values', {}).get('', ''), + ','.join(d.get('grantTypes', [])), + d.get('subjectType', '') + ] + ) - for d in result.get('entries', []): - data.append( - [ - d['inum'], - d.get('clientName', {}).get('values', {}).get('', ''), - ','.join(d.get('grantTypes', [])), - d.get('subjectType', '') - ] - ) + if data: + clients = JansVerticalNav( + myparent=self.app, + headers=['Client ID', 'Client Name', 'Grant Types', 'Subject Type'], + preferred_size= [0,0,30,0], + data=data, + on_enter=self.edit_client_dialog, + on_display=self.app.data_display_dialog, + on_delete=self.delete_client, + get_help=(self.get_help,'Client'), + selectes=0, + headerColor='class:outh-verticalnav-headcolor', + entriesColor='class:outh-verticalnav-entriescolor', + all_data=result['entries'] + ) + buttons = [] + if start_index > 0: + handler_partial = partial(get_next, start_index-self.app.entries_per_page, pattern) + prev_button = Button(_("Prev"), handler=handler_partial) + prev_button.window.jans_help = _("Retreives previous %d entries") % self.app.entries_per_page + buttons.append(prev_button) + if result['start'] + self.app.entries_per_page < result['totalEntriesCount']: + handler_partial = partial(get_next, start_index+self.app.entries_per_page, pattern) + next_button = Button(_("Next"), handler=handler_partial) + next_button.window.jans_help = _("Retreives next %d entries") % self.app.entries_per_page + buttons.append(next_button) - if data: - clients = JansVerticalNav( - myparent=self.app, - headers=['Client ID', 'Client Name', 'Grant Types', 'Subject Type'], - preferred_size= [0,0,30,0], - data=data, - on_enter=self.edit_client_dialog, - on_display=self.app.data_display_dialog, - on_delete=self.delete_client, - get_help=(self.get_help,'Client'), - selectes=0, - headerColor='class:outh-verticalnav-headcolor', - entriesColor='class:outh-verticalnav-entriescolor', - all_data=result['entries'] - ) - buttons = [] - if start_index > 0: - handler_partial = partial(get_next, start_index-self.app.entries_per_page, pattern) - prev_button = Button(_("Prev"), handler=handler_partial) - prev_button.window.jans_help = _("Retreives previous %d entries") % self.app.entries_per_page - buttons.append(prev_button) - if result['start'] + self.app.entries_per_page < result['totalEntriesCount']: - handler_partial = partial(get_next, start_index+self.app.entries_per_page, pattern) - next_button = Button(_("Next"), handler=handler_partial) - next_button.window.jans_help = _("Retreives next %d entries") % self.app.entries_per_page - buttons.append(next_button) + self.app.layout.focus(clients) # clients.focuse..!? TODO >> DONE + self.oauth_data_container['clients'] = HSplit([ + clients, + VSplit(buttons, padding=5, align=HorizontalAlign.CENTER) + ]) - self.app.layout.focus(clients) # clients.focuse..!? TODO >> DONE - self.oauth_data_container['clients'] = HSplit([ - clients, - VSplit(buttons, padding=5, align=HorizontalAlign.CENTER) - ]) + get_app().invalidate() + self.app.layout.focus(clients) ### it fix focuse on the last item deletion >> try on UMA-res >> edit_client_dialog >> oauth_update_uma_resources - get_app().invalidate() - self.app.layout.focus(clients) ### it fix focuse on the last item deletion >> try on UMA-res >> edit_client_dialog >> oauth_update_uma_resources + else: + self.app.show_message(_("Oops"), _("No matching result"),tobefocused = self.oauth_containers['clients']) + + asyncio.ensure_future(coroutine()) - else: - self.app.show_message(_("Oops"), _("No matching result"),tobefocused = self.oauth_containers['clients']) def oauth_get_clients(self) -> None: """Method to get the clients data from server diff --git a/jans-cli-tui/plugins/060_scripts/main.py b/jans-cli-tui/plugins/060_scripts/main.py index 82050ac72c8..8aa014df652 100755 --- a/jans-cli-tui/plugins/060_scripts/main.py +++ b/jans-cli-tui/plugins/060_scripts/main.py @@ -4,6 +4,7 @@ import threading from asyncio import ensure_future from functools import partial +import asyncio import prompt_toolkit from prompt_toolkit.application.current import get_app @@ -108,84 +109,89 @@ def scripts_update_list( def get_next(start_index, pattern=''): self.scripts_update_list(start_index, pattern='') - endpoint_args ='limit:{},startIndex:{}'.format(self.app.entries_per_page, start_index) - #endpoint_args='' - if pattern: - endpoint_args +=',pattern:'+pattern - try : - rsponse = self.app.cli_object.process_command_by_id( - operation_id='get-config-scripts', - url_suffix='', - endpoint_args=endpoint_args, - data_fn=None, - data={} - ) - - except Exception as e: - self.app.show_message(_("Error getting scripts"), str(e)) - return - - if rsponse.status_code not in (200, 201): - self.app.show_message(_("Error getting scripts"), str(rsponse.text)) - return - - try: - result = rsponse.json() - except Exception: - self.app.show_message(_("Error getting scripts"), str(rsponse.text)) - return - - data =[] - - for d in result.get('entries', []): - data.append( - [ - d['inum'], - d.get('name', ''), - d.get('description',''), ## some scopes have no scopetypr - ] - ) - - if data: - - scripts = JansVerticalNav( - myparent=self.app, - headers=['inum', 'Name', 'Description'], - preferred_size= [12, 25, 0], - data=data, - on_enter=self.add_script_dialog, - on_display=self.app.data_display_dialog, - get_help=(self.get_help,'Scripts'), - #on_delete=self.delete_scope, - # selection_changed=self.data_selection_changed, - selectes=0, - headerColor='class:outh-verticalnav-headcolor', - entriesColor='class:outh-verticalnav-entriescolor', - all_data=result['entries'] + async def coroutine(): + + endpoint_args ='limit:{},startIndex:{}'.format(self.app.entries_per_page, start_index) + #endpoint_args='' + if pattern: + endpoint_args +=',pattern:'+pattern + try : + rsponse = self.app.cli_object.process_command_by_id( + operation_id='get-config-scripts', + url_suffix='', + endpoint_args=endpoint_args, + data_fn=None, + data={} + ) + + except Exception as e: + self.app.show_message(_("Error getting scripts"), str(e)) + return + + if rsponse.status_code not in (200, 201): + self.app.show_message(_("Error getting scripts"), str(rsponse.text)) + return + + try: + result = rsponse.json() + except Exception: + self.app.show_message(_("Error getting scripts"), str(rsponse.text)) + return + + data =[] + + for d in result.get('entries', []): + data.append( + [ + d['inum'], + d.get('name', ''), + d.get('description',''), ## some scopes have no scopetypr + ] ) - buttons = [] - if start_index > 1: - handler_partial = partial(get_next, start_index-self.app.entries_per_page, pattern) - prev_button = Button(_("Prev"), handler=handler_partial) - prev_button.window.jans_help = _("Retreives previous %d entries") % self.app.entries_per_page - buttons.append(prev_button) - if result['start'] + self.app.entries_per_page < result['totalEntriesCount']: - handler_partial = partial(get_next, start_index+self.app.entries_per_page, pattern) - next_button = Button(_("Next"), handler=handler_partial) - next_button.window.jans_help = _("Retreives next %d entries") % self.app.entries_per_page - buttons.append(next_button) - - self.scripts_list_container = HSplit([ - Window(height=1), - scripts, - VSplit(buttons, padding=5, align=HorizontalAlign.CENTER), - ], height=D()) - self.app.layout.focus(scripts) - get_app().invalidate() + if data: + + scripts = JansVerticalNav( + myparent=self.app, + headers=['inum', 'Name', 'Description'], + preferred_size= [12, 25, 0], + data=data, + on_enter=self.add_script_dialog, + on_display=self.app.data_display_dialog, + get_help=(self.get_help,'Scripts'), + #on_delete=self.delete_scope, + # selection_changed=self.data_selection_changed, + selectes=0, + headerColor='class:outh-verticalnav-headcolor', + entriesColor='class:outh-verticalnav-entriescolor', + all_data=result['entries'] + ) + + buttons = [] + if start_index > 1: + handler_partial = partial(get_next, start_index-self.app.entries_per_page, pattern) + prev_button = Button(_("Prev"), handler=handler_partial) + prev_button.window.jans_help = _("Retreives previous %d entries") % self.app.entries_per_page + buttons.append(prev_button) + if result['start'] + self.app.entries_per_page < result['totalEntriesCount']: + handler_partial = partial(get_next, start_index+self.app.entries_per_page, pattern) + next_button = Button(_("Next"), handler=handler_partial) + next_button.window.jans_help = _("Retreives next %d entries") % self.app.entries_per_page + buttons.append(next_button) + + self.scripts_list_container = HSplit([ + Window(height=1), + scripts, + VSplit(buttons, padding=5, align=HorizontalAlign.CENTER), + ], height=D()) + self.app.layout.focus(scripts) + get_app().invalidate() + + else: + self.app.show_message(_("Oops"), _("No matching result"),tobefocused = self.scripts_main_area) + + asyncio.ensure_future(coroutine()) - else: - self.app.show_message(_("Oops"), _("No matching result"),tobefocused = self.scripts_main_area) def get_help(self, **kwargs: Any):