From e21250a8dcc61bc476945a2f13fe7e27cb69d17e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 23 Mar 2023 17:51:11 +0300 Subject: oauth2: data: Provide a UI for linking data, with search. Provide a UI for the phenotype datasets with a search interface (currently inactive) that is eventually going to allow for linking the traits to user groups. --- wqflask/wqflask/oauth2/data.py | 98 +++++------ .../templates/oauth2/data-list-phenotype.html | 124 ++++++++++++++ wqflask/wqflask/templates/oauth2/data-list.html | 188 +++++---------------- 3 files changed, 215 insertions(+), 195 deletions(-) create mode 100644 wqflask/wqflask/templates/oauth2/data-list-phenotype.html (limited to 'wqflask') diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py index 0cd110f6..432ca3b9 100644 --- a/wqflask/wqflask/oauth2/data.py +++ b/wqflask/wqflask/oauth2/data.py @@ -7,6 +7,39 @@ from .client import oauth2_get, oauth2_post data = Blueprint("data", __name__) +def __render_template__(templatepath, **kwargs): + roles = kwargs.get("roles", tuple()) + user_privileges = tuple( + privilege["privilege_id"] for role in roles + for privilege in role["privileges"]) + return render_template( + templatepath, **kwargs, user_privileges=user_privileges) + +@data.route("///list", + methods=["GET", "POST"]) +def list_data_by_species_and_dataset( + species_name: str, dataset_type: str) -> Response: + templates = { + "mrna": "oauth2/data-list-mrna.html", + "genotype": "oauth2/data-list-genotype.html", + "phenotype": "oauth2/data-list-phenotype.html"} + roles = oauth2_get("oauth2/user/roles").either( + lambda err: {"roles_error": process_error(err)}, + lambda roles: {"roles": roles}) + per_page = int(request.args.get("per_page", 500)) + traits = oauth2_get( + (f"search/?type={dataset_type}&per_page={per_page}&query=" + f"species:{species_name}")).either( + lambda err: {"traits_error": process_error(er)}, + lambda trts: {"traits": tuple({ + "index": idx, **trait + } for idx, trait in enumerate(trts, start=1))}) + + return __render_template__( + templates[dataset_type], **roles, **traits, species_name=species_name, + dataset_type=dataset_type, per_page=per_page, + query=request.args.get("query", "")) + @data.route("/list", methods=["GET", "POST"]) def list_data(): """List ungrouped data.""" @@ -23,65 +56,29 @@ 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)}) + species = oauth2_get("oauth2/data/species").either( + lambda err: {"species_error": process_error(err)}, + lambda species: {"species": species}) if request.method == "GET": - return __render__(**{**groups, **roles, **menus}) + return __render__(**{**groups, **roles, **species}) + species_name = request.form["species_name"] dataset_type = request.form["dataset_type"] - offset = int(request.form.get("offset", 0)) + ( - 0 if request.form.get("offset_submit") is None else( - 100 if request.form["offset_submit"] == "Next" else -100)) if dataset_type not in ("mrna", "genotype", "phenotype"): flash("InvalidDatasetType: An invalid dataset type was provided", "alert-danger") - return __render__(**{**groups, **roles}) + return __render__(**{**groups, **roles, **species}) - data_items = oauth2_get( - f"oauth2/group/{dataset_type}/ungrouped-data?offset={offset}").either( - lambda err: {"data_items_error": process_error(err)}, - lambda data: {"data_items": data}) - return __render__(**{ - **groups, **roles, **menus, **data_items, "dataset_type": dataset_type, - "offset": offset - }) + return redirect(url_for( + "oauth2.data.list_data_by_species_and_dataset", + species_name=species_name, dataset_type=dataset_type)) @data.route("/link", methods=["POST"]) def link_data(): @@ -96,20 +93,25 @@ def link_data(): form = request.form try: - keys = ("dataset_id", "dataset_type", "group_id") + keys = ("dataset_type", "group_id") assert all(item in form for item in keys) assert all(bool(form[item]) for item in keys) state_data = { "dataset_type": form["dataset_type"], "offset": form.get("offset", 0)} + dataset_ids = form.getlist("dataset_ids") + if len(dataset_ids) == 0: + flash("You must select at least one item to link", "alert-danger") + return redirect(url_for( + "oauth2.data.list_data", **state_data)) return oauth2_post( "oauth2/group/data/link", data={ "dataset_type": form["dataset_type"], - "dataset_id": form["dataset_id"], + "dataset_ids": dataset_ids, "group_id": form["group_id"] }).either(lambda err: __error__(err, state_data), lambda success: __success__(success, state_data)) except AssertionError as aserr: - flash("You must provide all the expected data.", "alert-error") + flash("You must provide all the expected data.", "alert-danger") return redirect(url_for("oauth2.data.list_data")) diff --git a/wqflask/wqflask/templates/oauth2/data-list-phenotype.html b/wqflask/wqflask/templates/oauth2/data-list-phenotype.html new file mode 100644 index 00000000..3c58f275 --- /dev/null +++ b/wqflask/wqflask/templates/oauth2/data-list-phenotype.html @@ -0,0 +1,124 @@ +{%extends "base.html"%} +{%from "oauth2/profile_nav.html" import profile_nav%} +{%from "oauth2/display_error.html" import display_error%} + +{%block title%}View User{%endblock%} + +{%block css%} + + + +{%endblock%} + +{%block content%} + +
+ {{profile_nav("data", user_privileges)}} + + {{flash_me()}} + +
+ +
+ +
+
+ {%if dataset_type == "mrna"%} + mRNA: Search + {%else%} + + {{dataset_type}}: Search + + {%endif%} + + + + +
+ +
+ species:{{species_name}} + +
+
+
+
+ +
+ + + + + +
+
Loading...
+
+
+ +
+ +{%endblock%} + +{%block js%} + + + + + + + + + + + +{%endblock%} diff --git a/wqflask/wqflask/templates/oauth2/data-list.html b/wqflask/wqflask/templates/oauth2/data-list.html index 019e2346..4e0cf5ae 100644 --- a/wqflask/wqflask/templates/oauth2/data-list.html +++ b/wqflask/wqflask/templates/oauth2/data-list.html @@ -3,156 +3,50 @@ {%from "oauth2/display_error.html" import display_error%} {%block title%}View User{%endblock%} {%block content%} -
- {{profile_nav("data", user_privileges)}} - - {{flash_me()}} - -
-
-
- Dataset Type - - -
- - -
-
- - -
- -
+
+ {{profile_nav("data", user_privileges)}} + + {{flash_me()}} + +
+
+ Search + {%if species_error is defined%} + {{display_error("Species", species_error)}} + {%elif species | length == 0%} + + +   + No list of species to select from + {%else%} +
+ +
- {%if dataset_type is defined%} - {%if data_items_error is defined%} - {{display_error("Data Error", data_items_error)}} - {%else%} -
- - Link Data to Group - - - -
- - -
- - - - - - - - {%if dataset_type == "phenotype"%} - - - {%endif%} - - - - - - - - {%for data_item in data_items%} - - - {%if dataset_type == "phenotype"%} - - - {%endif%} - - - - - {%else%} - - - - {%endfor%} - -
Link Data to Group
SelectTrait IDData GroupDataset NameDataset Full NameLink
- - - - {{data_item.Id}} - - {{data_item.InbredSetName}} - - {{data_item.dataset_name}} - - {{data_item.dataset_fullname}} - -
- - -   - No available data to link -
- - -
- - -
- {%if offset != 0%} - - {%endif%} - {%if data_items | length == 100:%} - - {%endif%} -
-
+
+ +
- {%endif%} - {%endif%} - -
+ + {%endif%} +
+
{%endblock%} -- cgit v1.2.3