Skip to content

Commit

Permalink
fix: jans-cli edit property (ref: #3058)
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar committed Nov 23, 2022
1 parent c67ab39 commit e2da3fd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 79 deletions.
31 changes: 11 additions & 20 deletions jans-cli-tui/cli_tui/plugins/010_oxauth/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def __init__(
self.pid = 'oxauth'
self.name = '[A]uth Server'
self.search_text= None

self.oauth_update_properties_start_index = 0
self.app_configuration = {}
self.oauth_containers = {}
self.oauth_prepare_navbar()
self.oauth_prepare_containers()
Expand All @@ -88,19 +89,9 @@ def init_plugin(self) -> None:

async def get_appconfiguration(self) -> None:
"""Coroutine for getting application configuration.
"""
try:
response = self.app.cli_object.process_command_by_id(
operation_id='get-properties',
url_suffix='',
endpoint_args='',
data_fn=None,
data={}
)

except Exception as e:
self.app.show_message(_("Error getting Jans configuration"), str(e))
return
"""
cli_args = {'operation_id': 'get-properties'}
response = await self.app.loop.run_in_executor(self.app.executor, self.app.cli_requests, cli_args)

if response.status_code not in (200, 201):
self.app.show_message(_("Error getting Jans configuration"), str(response.text))
Expand Down Expand Up @@ -449,7 +440,7 @@ def oauth_update_properties(
Args:
pattern (str, optional): endpoint arguments for the client data. Defaults to ''.
"""

self.oauth_update_properties_start_index = start_index
# ------------------------------------------------------------------------------- #
# ----------------------------------- Search ------------------------------------ #
# ------------------------------------------------------------------------------- #
Expand Down Expand Up @@ -479,7 +470,7 @@ def oauth_update_properties(

# ------------------------------------------------------------------------------- #
# --------------------------------- View Data ----------------------------------- #
# ------------------------------------------------------------------------------- #
# ------------------------------------------------------------------------------- #


if data:
Expand Down Expand Up @@ -549,14 +540,14 @@ def view_property(self, **params: Any) -> None:


selected_line_data = params['passed'] ##self.uma_result

title = _("Edit property")

dialog = ViewProperty(self.app, title=title, data=selected_line_data, get_properties= self.oauth_get_properties, search_properties=self.search_properties, search_text=self.search_text)
dialog = ViewProperty(app=self.app, parent=self, title=title, data=selected_line_data)

self.app.show_jans_dialog(dialog)

def search_properties(self, tbuffer:Buffer,) -> None:
def search_properties(self, tbuffer:Buffer) -> None:
self.app.logger.debug("tbuffer="+str(tbuffer))
self.app.logger.debug("type tbuffer="+str(type(tbuffer)))
self.search_text=tbuffer.text
Expand Down
104 changes: 45 additions & 59 deletions jans-cli-tui/cli_tui/plugins/010_oxauth/view_property.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from asyncio import Future
import asyncio

from prompt_toolkit.widgets import Button, TextArea
from prompt_toolkit.application.current import get_app
Expand All @@ -13,15 +13,15 @@
Button,
Label,
TextArea,

)
from asyncio import ensure_future


from prompt_toolkit.widgets import (
Button,
Dialog,
VerticalLine,
)

from cli import config_cli
from prompt_toolkit.layout.containers import (
ConditionalContainer,
Expand Down Expand Up @@ -63,26 +63,22 @@ class ViewProperty(JansGDialog, DialogUtils):
"""The Main UMA-resources Dialog to view UMA Resource Details
"""
def __init__(
self,
parent,
data:tuple,
title: AnyFormattedText= "",
search_text: AnyFormattedText= "",
buttons: Optional[Sequence[Button]]= [],
get_properties: Callable= None,
search_properties: Callable= None,
)-> Dialog:

super().__init__(parent, title, buttons)
self,
app,
parent,
data:tuple,
title: AnyFormattedText= "",
search_text: AnyFormattedText= "",
buttons: Optional[Sequence[Button]]= []
)-> None:
super().__init__(app, title, buttons)
self.property, self.value = data[0],data[1]
self.myparent= parent
self.get_properties = get_properties
self.search_properties= search_properties
self.search_text=search_text
self.app = app
self.myparent = parent
self.value_content = HSplit([],width=D())
self.tabs = {}
self.selected_tab = 'tab0'
self.schema = self.myparent.cli_object.get_schema_from_reference('', '#/components/schemas/AppConfiguration')
self.schema = self.app.cli_object.get_schema_from_reference('', '#/components/schemas/AppConfiguration')

self.prepare_properties()
self.create_window()
Expand Down Expand Up @@ -120,37 +116,27 @@ def save(self) -> None:
list_data.append(data_dict)
data = list_data
else :
self.myparent.logger.debug("self.value: "+str(self.value))
self.myparent.logger.debug("type self.value: "+str(type(self.value)))
self.app.logger.debug("self.value: "+str(self.value))
self.app.logger.debug("type self.value: "+str(type(self.value)))
data = []

# ------------------------------------------------------------#
# --------------------- Patch to server ----------------------#
# ------------------------------------------------------------#
if data :
response = self.myparent.cli_object.process_command_by_id(
operation_id='patch-properties' ,
url_suffix='',
endpoint_args='',
data_fn='',
data=[ {'op':'replace', 'path': self.property, 'value': data } ]
)
else:
return
# ------------------------------------------------------------#
# -- get_properties or serach again to see Momentary change --#
# ------------------------------------------------------------#
if response:
if self.search_text:
tbuff = Buffer(name='', )
tbuff.text=self.search_text
self.search_properties(tbuff)
else:
self.get_properties()
self.future.set_result(DialogResult.ACCEPT)
return True

self.myparent.show_message(_("Error!"), _("An error ocurred while saving property:\n") + str(response.text))

cli_args = {'operation_id': 'patch-properties', 'data': [ {'op':'replace', 'path': self.property, 'value': data } ]}

async def coroutine():
self.app.start_progressing()
response = await self.app.loop.run_in_executor(self.app.executor, self.app.cli_requests, cli_args)
self.app.stop_progressing()
self.myparent.app_configuration = response
self.future.set_result(DialogResult.ACCEPT)
self.myparent.oauth_update_properties(start_index=self.myparent.oauth_update_properties_start_index)
asyncio.ensure_future(coroutine())



def get_type(self,prop):
try :
Expand Down Expand Up @@ -192,7 +178,7 @@ def prepare_properties(self):
prop_type = self.get_type(self.property)

if prop_type == 'TitledText':
self.value_content= HSplit([self.myparent.getTitledText(
self.value_content= HSplit([self.app.getTitledText(
self.property,
name=self.property,
value=self.value,
Expand All @@ -201,7 +187,7 @@ def prepare_properties(self):
],width=D())

elif prop_type == 'int-TitledText':
self.value_content= HSplit([self.myparent.getTitledText(
self.value_content= HSplit([self.app.getTitledText(
self.property,
name=self.property,
value=self.value,
Expand All @@ -211,7 +197,7 @@ def prepare_properties(self):
],width=D())

elif prop_type == 'long-TitledText':
self.value_content= HSplit([self.myparent.getTitledText(
self.value_content= HSplit([self.app.getTitledText(
self.property,
name=self.property,
height=3,
Expand All @@ -222,7 +208,7 @@ def prepare_properties(self):

elif prop_type == 'checkboxlist':
self.value_content= HSplit([
self.myparent.getTitledCheckBoxList(
self.app.getTitledCheckBoxList(
self.property,
name=self.property,
values=self.get_listValues(self.property),
Expand All @@ -240,7 +226,7 @@ def prepare_properties(self):
tab_list=[]
for item in tab:
if type(tab[item]) == str:
tab_list.append(HSplit([self.myparent.getTitledText(
tab_list.append(HSplit([self.app.getTitledText(
item ,
name=item,
value=tab[item],
Expand All @@ -249,7 +235,7 @@ def prepare_properties(self):
],width=D()))

if type(tab[item]) == int :
tab_list.append(HSplit([self.myparent.getTitledText(
tab_list.append(HSplit([self.app.getTitledText(
item ,
name=item,
value=tab[item],
Expand All @@ -259,7 +245,7 @@ def prepare_properties(self):
],width=D()))

elif type(tab[item]) == list:
tab_list.append(HSplit([self.myparent.getTitledText(
tab_list.append(HSplit([self.app.getTitledText(
item,
name=item,
height=3,
Expand All @@ -270,7 +256,7 @@ def prepare_properties(self):

elif type(tab[item]) == bool:
tab_list.append(HSplit([
self.myparent.getTitledCheckBox(
self.app.getTitledCheckBox(
item,
name=item,
checked= tab[item],
Expand All @@ -280,7 +266,7 @@ def prepare_properties(self):
self.tabs['tab{}'.format(self.value.index(tab))] = HSplit(tab_list,width=D())

self.value_content=HSplit([
self.myparent.getTitledRadioButton(
self.app.getTitledRadioButton(
_("Tab Num"),
name='tabNum',
current_value=self.selected_tab,
Expand All @@ -294,7 +280,7 @@ def prepare_properties(self):

elif prop_type == 'TitledCheckBox':
self.value_content= HSplit([
self.myparent.getTitledCheckBox(
self.app.getTitledCheckBox(
self.property,
name=self.property,
checked= self.value,
Expand All @@ -305,7 +291,7 @@ def prepare_properties(self):
dict_list=[]
for item in self.value:
if type(self.value[item]) == str:
dict_list.append(HSplit([self.myparent.getTitledText(
dict_list.append(HSplit([self.app.getTitledText(
item ,
name=item,
value=self.value[item],
Expand All @@ -314,7 +300,7 @@ def prepare_properties(self):
],width=D()))

elif type(self.value[item]) == int :
dict_list.append(HSplit([self.myparent.getTitledText(
dict_list.append(HSplit([self.app.getTitledText(
item ,
name=item,
value=self.value[item],
Expand All @@ -324,7 +310,7 @@ def prepare_properties(self):
],width=D()))

elif type(self.value[item]) == list:
dict_list.append(HSplit([self.myparent.getTitledText(
dict_list.append(HSplit([self.app.getTitledText(
item,
name=item,
height=3,
Expand All @@ -335,15 +321,15 @@ def prepare_properties(self):

elif type(self.value[item]) == bool:
dict_list.append(HSplit([
self.myparent.getTitledCheckBox(
self.app.getTitledCheckBox(
item,
name=item,
checked= self.value[item],
style='class:outh-client-checkbox'),
],width=D()))

else :
dict_list.append(HSplit([self.myparent.getTitledText(
dict_list.append(HSplit([self.app.getTitledText(
item,
name=item,
value="No Items Here",
Expand Down

0 comments on commit e2da3fd

Please sign in to comment.