Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: arranges the screenorder based on CanvasManifest file and adds e… #23

Merged
merged 1 commit into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ RelevantObjects:
screen: [OnVisible]
text: [OnSelect]
#typedDataCard: [DataField, Default, Update]

ScreenFlow:
# By default all screens from CanvasManifest.json will be used in same sequence.
# If screens shall be excluded from the graph, list them here.
ExcludeScreens: []
70 changes: 38 additions & 32 deletions powerapps_docstring/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ def __init__(self, source, output, config) -> None:
self.output_path = output
self.parser = Parser(self.source_path)
self.config = config
self.manifest_file = self.parser.get_canvas_manifest()
self.relevant_objects = self.config["RelevantObjects"]
self.relevant_object_keys = [f" As {x}" for x in self.relevant_objects.keys()]

def _get_screen_files(self):
screen_files = []
screens_path = self.source_path + "/Src/"
for file in os.listdir(screens_path):
if os.path.isfile(screens_path + file) & file.endswith(".yaml"):
if file != "App.fx.yaml":
screen_files.append(file)

# read screen order from manifest and check if files exists
screen_order = self.manifest_file["ScreenOrder"]
for screen in screen_order:
screen_file_name = screen + ".fx.yaml"
if screen_file_name in os.listdir(screens_path):
if screen_file_name != "App.fx.yaml":
screen_files.append(screen_file_name)

return screen_files

Expand Down Expand Up @@ -119,29 +124,32 @@ def get_recursively(search_dict, field):

screen_files = self._get_screen_files()
screens_path = self.source_path + "/Src/"

for screen in screen_files:
screen_obj = self.parser.get_screen_objects(screen)
from_screen = screen_obj[0]
list_of_onselects = get_recursively(screen_obj[1], "OnSelect")

for item in list_of_onselects:
if "Navigate(" in item:

item = item.strip().replace("\n", "").replace("\t", "").replace(" ", "")
navigate_occurences = [m.start() for m in re.finditer('Navigate\(', item)]

for occurence in navigate_occurences:
#print(occurence)
start = occurence + len("Navigate(")
#print(start)
end = item[start:].find(",")
if end == -1:
end = item[start:].find(")")
end = end + start
to_screen = item[start:end]
if to_screen != None and to_screen != "" and not to_screen.startswith("[@"):
to_screen = to_screen.replace("\n", "").replace("\t", "").replace(" ", "").replace(")", "")
screenflow_list.append(from_screen + " ==> " + to_screen.replace("\n", "").replace("\t", "").replace(" ", ""))
# check if screen has been excluded
if screen.replace(".fx.yaml", "") not in self.config["ScreenFlow"]["ExcludeScreens"]:
screen_obj = self.parser.get_screen_objects(screen)
from_screen = screen_obj[0]
list_of_onselects = get_recursively(screen_obj[1], "OnSelect")

for item in list_of_onselects:
if "Navigate(" in item:

item = item.strip().replace("\n", "").replace("\t", "").replace(" ", "")
navigate_occurences = [m.start() for m in re.finditer('Navigate\(', item)]

for occurence in navigate_occurences:
#print(occurence)
start = occurence + len("Navigate(")
#print(start)
end = item[start:].find(",")
if end == -1:
end = item[start:].find(")")
end = end + start
to_screen = item[start:end]
if to_screen != None and to_screen != "" and not to_screen.startswith("[@") and to_screen not in self.config["ScreenFlow"]["ExcludeScreens"]:
to_screen = to_screen.replace("\n", "").replace("\t", "").replace(" ", "").replace(")", "")
screenflow_list.append(from_screen + " ==> " + to_screen.replace("\n", "").replace("\t", "").replace(" ", ""))


#print(screenflow_list)
Expand All @@ -158,7 +166,7 @@ def create_documentation(self, format=None):

# instantiate the md file
# TODO: get title from docstring variable
app_name = self.parser.get_app_name()
app_name = self.manifest_file["PublishInfo"]["AppName"]
self.md_file = MdUtils(file_name=self.output_path +
f'/{app_name}-doc', title='Power App Documentation')

Expand Down Expand Up @@ -215,11 +223,9 @@ def create_documentation(self, format=None):

# loop thru all screens and create markdown
screens_path = self.source_path + "/Src/"
for file in os.listdir(screens_path):
if os.path.isfile(screens_path + file) & file.endswith(".yaml"):
if file != "App.fx.yaml":
screen_objects = self.parser.get_screen_objects(file)
self._extract_screen_content_to_markdown(screen_objects)
for file in self._get_screen_files():
screen_objects = self.parser.get_screen_objects(file)
self._extract_screen_content_to_markdown(screen_objects)

# write toc + file
self.md_file.new_table_of_contents(table_title='Contents', depth=2)
Expand Down
5 changes: 2 additions & 3 deletions powerapps_docstring/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ def get_screen_objects(self, screen_name) -> tuple:
screen_name = list(screen_content.keys())[0].split(" ")[0]
return screen_name, screen_content

def get_app_name(self):
def get_canvas_manifest(self):
app_name = "PowerApp_Documentation"
# get name from CanvasManifest.json
if os.path.isfile(self.source_path + "CanvasManifest.json"):
with open(self.source_path + "CanvasManifest.json", "r", encoding="utf-8") as file:
canvas_manifest = json.load(file)
app_name = canvas_manifest["PublishInfo"]["AppName"]

return app_name
return canvas_manifest