From ff4fa08a7d4e1c12c65c94f6715f01990af7a1ab Mon Sep 17 00:00:00 2001 From: gitjannes Date: Thu, 12 Dec 2024 14:40:14 +0100 Subject: [PATCH] Added added html forms and js functions to add/delete tags. added set of all tags, will be displayed in the filters now. --- protzilla/run_v2.py | 9 ++++--- ui/runs/static/runs/index.js | 14 +++++++++++ ui/runs/templates/runs/index.html | 16 +++++++++---- ui/runs/urls.py | 4 +++- ui/runs/views.py | 39 ++++++++++++++++++++++++++----- 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/protzilla/run_v2.py b/protzilla/run_v2.py index e010a47c..b8b4da79 100644 --- a/protzilla/run_v2.py +++ b/protzilla/run_v2.py @@ -22,12 +22,12 @@ def get_available_run_names() -> list[str]: if not directory.name.startswith(".") ] -def get_available_runs() -> list[dict[str, str | list[str]]]: +def get_available_runinfo() -> tuple[list[dict[str, str | list[str]]], list[dict[str, str | list[str]]], set[str]]: if not paths.RUNS_PATH.exists(): return [] runs = [] runs_favourited = [] - + all_tags = {} for directory in paths.RUNS_PATH.iterdir(): if directory.name.startswith("."): continue @@ -52,6 +52,9 @@ def get_available_runs() -> list[dict[str, str | list[str]]]: yaml_operator = YamlOperator() metadata = yaml_operator.read(metadata_yaml_path) tags = metadata.get("tags") + + for tag in tags: + all_tags.add(tag) run = { "run_name": name, @@ -67,7 +70,7 @@ def get_available_runs() -> list[dict[str, str | list[str]]]: runs_favourited.append(run) else: runs.append(run) - return runs, runs_favourited + return (runs, runs_favourited, all_tags) def delete_run_folder(run_name) -> None: path = os.path.join(paths.RUNS_PATH, run_name) diff --git a/ui/runs/static/runs/index.js b/ui/runs/static/runs/index.js index 3a8450bf..d520a8fe 100644 --- a/ui/runs/static/runs/index.js +++ b/ui/runs/static/runs/index.js @@ -57,6 +57,20 @@ function toggleFavouriteRun(runName, favouriteStatus){ document.getElementById('change_favourite').submit(); }; +function addTag(runName, tagName){ + + document.getElementById('run_name_id').value = runName; + document.getElementById('tag_name_id').value = tagName; + document.getElementById('add_tag').submit(); +}; + +function deleteTag(runName, tagName){ + + document.getElementById('run_name_id').value = runName; + document.getElementById('tag_name_id').value = tagName; + document.getElementById('delete_tag').submit(); +}; + function toggleDetails(element) { document.querySelectorAll('.list-item.expanded').forEach(item => { if (item !== element) { diff --git a/ui/runs/templates/runs/index.html b/ui/runs/templates/runs/index.html index 72b851ce..9a2bac3b 100644 --- a/ui/runs/templates/runs/index.html +++ b/ui/runs/templates/runs/index.html @@ -122,6 +122,16 @@

Continue an existing run: +
+ {% csrf_token %} + + +
+
+ {% csrf_token %} + + +
@@ -131,24 +141,20 @@

Select filters:

- -
-
- + -
diff --git a/ui/runs/urls.py b/ui/runs/urls.py index 4d073f8f..a96e82da 100644 --- a/ui/runs/urls.py +++ b/ui/runs/urls.py @@ -7,9 +7,11 @@ path("", views.index, name="index"), # path("filter", views.filtered_index, name="filter"), path("create_run_menu", views.create_run_menu, name="create_run_menu"), - path("create", views.create, name="create"), #create, continue and delete paths should be in main/urls.py, also change index.html accordingly + path("create", views.create, name="create"), #create, continue and delete paths should be in main/urls.py, also change index.html accordingly probalby not actually path("continue", views.continue_, name="continue"), path("delete", views.delete_, name="delete"), + path("add_tag", views.add_tag, name="add_tag"), + path("delete_tag", views.delete_tag, name="delete_tag"), path("toggle_favourite", views.favourite, name="toggle_favourite"), path("detail/", views.detail, name="detail"), path("/plot", views.plot, name="plot"), diff --git a/ui/runs/views.py b/ui/runs/views.py index 08a1d7c6..f62de868 100644 --- a/ui/runs/views.py +++ b/ui/runs/views.py @@ -24,7 +24,7 @@ from ui.runs.filter import filter_runs #prob should put this file somewhere else. import protzilla.constants.paths as paths from protzilla.run import Run, get_available_run_names -from protzilla.run_v2 import delete_run_folder, get_available_runs +from protzilla.run_v2 import delete_run_folder, get_available_runinfo from protzilla.run_helper import log_messages from protzilla.stepfactory import StepFactory from protzilla.steps import Step @@ -202,7 +202,7 @@ def index(request: HttpRequest, index_error: bool = False): #should replace inde print(get_all_possible_step_names()) #print(filter["name"]) #filter = {"name":"d", "steps":["MaxQuant Protein Groups Import", "kNN"], "memory_mode":"disk_memory"} #dummy filter for testing -> might need to be adapted for your workflows to actually show something - runs, runs_favourite = get_available_runs() + runs, runs_favourite, all_tags = get_available_runinfo() filtered_runs = filter_runs(runs, filter) filtered_runs_favourite = filter_runs(runs_favourite, filter) all_available_runs = filtered_runs_favourite + filtered_runs @@ -216,7 +216,7 @@ def index(request: HttpRequest, index_error: bool = False): #should replace inde "available_runs_favourite": filtered_runs_favourite, "all_available_runs": all_available_runs, "all_possible_step_names": get_all_possible_step_names(), - "all_tags": [], + "all_tags": all_tags, }, ) @@ -242,9 +242,9 @@ def favourite(request: HttpRequest): return HttpResponseRedirect(reverse("runs:index")) -def tag(request: HttpRequest): +def add_tag(request: HttpRequest): - run_name = request.POST["favourite_run_name"] + run_name = request.POST["run_name"] run_tag = request.POST["tag"] from protzilla.disk_operator import YamlOperator # to avoid a circular import (geht das cleaner? habs einfach kopiert von unten?) @@ -256,7 +256,34 @@ def tag(request: HttpRequest): metadata = yaml_operator.read(metadata_yaml_path) tags = metadata.get("tags") tags.append(run_tag) - yaml_operator.read(metadata_yaml_path, tags) + yaml_operator.write(metadata_yaml_path, tags) + + return HttpResponseRedirect(reverse("runs:index")) + +def delete_tag(request: HttpRequest): + """ + Deletes a specific tag from a run + + :param request: the request object + :type request: HttpRequest + + :return: the rendered index page + :rtype: HttpResponse + """ + + run_name = request.POST["run_name"] + run_tag = request.POST["tag"] + + from protzilla.disk_operator import YamlOperator # to avoid a circular import (geht das cleaner? habs einfach kopiert von unten?) + + directory_path = os.path.join(paths.RUNS_PATH, run_name) + metadata_yaml_path = os.path.join(directory_path, "metadata.yaml") + + yaml_operator = YamlOperator() + metadata = yaml_operator.read(metadata_yaml_path) + tags = metadata.get("tags") + tags.remove(run_tag) + yaml_operator.write(metadata_yaml_path, tags) return HttpResponseRedirect(reverse("runs:index"))