Skip to content

Commit

Permalink
fix:jans-cli view list of dicts--not saved yet
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelwahabAdam committed Oct 24, 2022
1 parent 84c7c7f commit 14434d2
Showing 1 changed file with 115 additions and 18 deletions.
133 changes: 115 additions & 18 deletions jans-cli-tui/plugins/010_oxauth/view_Property.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ def __init__(
self.search_properties= search_properties
self.search_text=search_text
self.UMA_containers = {}

# self.property_prepare_containers()

self.tabs = {}
self.selected_tab = 'tab0'

def cancel() -> None:
self.future.set_result(DialogResult.CANCEL)
Expand All @@ -107,13 +109,41 @@ def save() -> None:
data = item_data['value']

elif type(self.value) == list:
if type(self.value[0]) == str:
self.myparent.logger.debug("self.value: "+str(self.value))
if type(self.value[0]) in [str,int,bool] :

item_data = self.get_item_data(item)
self.myparent.logger.debug("item_data: "+str(item_data))
if item_data:
data[item_data['key']] = item_data['value'].split('\n')
data = item_data['value'].split('\n')
self.myparent.logger.debug("data[item_data['key']]: "+str(data))

else:
## TODO dict in list
pass
# pass
tab_num = len(self.value)
tabs = []
for i in range(tab_num) :
tabs.append(('tab{}'.format(i),'tab{}'.format(i)))
self.myparent.logger.debug("*******************************************")
data = []
self.myparent.logger.debug("itemitem: "+str(item))
self.myparent.logger.debug("wid: "+str(wid))
item_data = self.get_item_data(item)
self.myparent.logger.debug("item_data: "+str(item_data))
for tab in self.value:
data_tab={}
for i,field in enumerate(item.children) :
item_data = self.get_item_data(item)
self.myparent.logger.debug("item_data: "+str(item_data))

if item_data:
data_tab['tab{}'.format(self.value.index(tab))] = item_data['value']
self.myparent.logger.debug("data_tab: "+str(data_tab))
data.append(data_tab)
self.myparent.logger.debug("datadata: "+str(data))
self.myparent.logger.debug("*******************************************")


elif type(self.value) == dict:
data = {}
Expand All @@ -126,19 +156,22 @@ def save() -> None:
else:
item_data = self.get_item_data(item)
self.myparent.logger.debug("item_data,Else: "+str(item_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 } ]
)
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

if response:
tbuff = Buffer(name='', )
tbuff.text=self.search_text

if self.search_text:
tbuff = Buffer(name='', )
tbuff.text=self.search_text
self.search_properties(tbuff)
else:
self.get_properties()
Expand All @@ -157,7 +190,7 @@ def save() -> None:
],width=D())

elif type(self.value) == list:
try:
if type(self.value[0]) in [str,bool,int]:
value_content= HSplit([self.myparent.getTitledText(
self.property+'\n'*(len(self.value)-1),
name=self.property,
Expand All @@ -166,9 +199,63 @@ def save() -> None:
style='class:outh-scope-text'
),
],width=D())
except:
value_content=HSplit([],width=D())
pass
else: ### nasted dict
tab_num = len(self.value)
tabs = []
for i in range(tab_num) :
tabs.append(('tab{}'.format(i),'tab{}'.format(i)))
self.myparent.logger.debug("tabs: "+str(tabs))

self.myparent.logger.debug("self.value: "+str(self.value))
for tab in self.value:
tab_list=[]
self.myparent.logger.debug("tab: "+str(tab))
for item in tab:
self.myparent.logger.debug("item: "+str(item))
if type(tab[item]) == str or type(tab[item]) == int :
tab_list.append(HSplit([self.myparent.getTitledText(
item ,
name=item,
value=tab[item],
style='class:outh-scope-text'
),
],width=D()))

elif type(tab[item]) == list:
tab_list.append(HSplit([self.myparent.getTitledText(
item,
name=item,
height=3,
value='\n'.join(tab[item]),
style='class:outh-scope-text'
),
],width=D()))

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

self.tabs['tab{}'.format(self.value.index(tab))] = HSplit(tab_list,width=D())

self.myparent.logger.debug("self.tabs: "+str(self.tabs))
value_content=HSplit([
self.myparent.getTitledRadioButton(
_("Tab Num")+'\n'*(len(tabs)-1),
name='tabNum',
current_value=self.selected_tab,
values=tabs,
on_selection_changed=self.tab_selection_changed,
style='class:outh-scope-radiobutton'),

DynamicContainer(lambda: self.tabs[self.selected_tab]),

],width=D())


elif type(self.value) == bool:
value_content= HSplit([
Expand Down Expand Up @@ -231,6 +318,16 @@ def save() -> None:
with_background=False,
)




def tab_selection_changed(
self,
cb: RadioList,
) -> None:
self.selected_tab = cb.current_value


def __pt_container__(self)-> Dialog:
return self.dialog

0 comments on commit 14434d2

Please sign in to comment.