From 6e45510c3ee685a960db594aef70661220bebe60 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 20 Mar 2023 16:01:45 +0300 Subject: oauth2: Load menu and populate dropdown In order to enable searching through the existing datasets for linking with the auth system, we need a way to filter the data. In this commit, I load the menu and load it onto a dropdown box as a proof of concept to give an idea of some of the filters I can use down the road to fetch the data. This commit breaks the data-linking code. I will need to rework the data-linking code entirely to get it working again. --- wqflask/wqflask/oauth2/data.py | 36 ++++- wqflask/wqflask/templates/oauth2/data-list.html | 200 ++++++++++++++---------- 2 files changed, 149 insertions(+), 87 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py index 8005a2a0..0cd110f6 100644 --- a/wqflask/wqflask/oauth2/data.py +++ b/wqflask/wqflask/oauth2/data.py @@ -23,15 +23,47 @@ def list_data(): **{key:val for key,val in kwargs.items() if key not in ("groups", "data_items", "user_privileges")}) + def __process_menus__(mns): + return { + species_id: { + "display_name": display_name, + "family": family, + "groups": { + group_id: { + "group_name": group_name, + "family": family, + "types": { + type_id: { + "menu_value": type_menu_value, + "menu_heading": type_menu_heading, + "datasets": tuple( + dict(zip(("accession_id", "dataset_id", + "dataset_fullname"), + dataset_row)) + for dataset_row in mns["datasets"][ + species_id][group_id][type_id]) + } + for type_id, type_menu_value, type_menu_heading + in mns["types"][species_id][group_id] + } + } + for group_id, group_name, family in mns["groups"][species_id] + } + } + for species_id, display_name, family in mns["species"]} + groups = oauth2_get("oauth2/group/list").either( lambda err: {"groups_error": process_error(err)}, lambda grp: {"groups": grp}) roles = oauth2_get("oauth2/user/roles").either( lambda err: {"roles_error": process_error(err)}, lambda roles: {"roles": roles}) + menus = oauth2_get("menu/generate/json").either( + lambda err: {"menus_error": process_error(err)}, + lambda mns: {"menus": __process_menus__(mns)}) if request.method == "GET": - return __render__(**{**groups, **roles}) + return __render__(**{**groups, **roles, **menus}) dataset_type = request.form["dataset_type"] offset = int(request.form.get("offset", 0)) + ( @@ -47,7 +79,7 @@ def list_data(): lambda err: {"data_items_error": process_error(err)}, lambda data: {"data_items": data}) return __render__(**{ - **groups, **roles, **data_items, "dataset_type": dataset_type, + **groups, **roles, **menus, **data_items, "dataset_type": dataset_type, "offset": offset }) diff --git a/wqflask/wqflask/templates/oauth2/data-list.html b/wqflask/wqflask/templates/oauth2/data-list.html index 6d0ae427..019e2346 100644 --- a/wqflask/wqflask/templates/oauth2/data-list.html +++ b/wqflask/wqflask/templates/oauth2/data-list.html @@ -12,23 +12,46 @@