Skip to content

Commit

Permalink
Added added html forms and js functions to add/delete tags. added set…
Browse files Browse the repository at this point in the history
… of all tags, will be displayed in the filters now.
  • Loading branch information
gitjannes committed Dec 12, 2024
1 parent e6db66d commit ff4fa08
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
9 changes: 6 additions & 3 deletions protzilla/run_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions ui/runs/static/runs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 11 additions & 5 deletions ui/runs/templates/runs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ <h3>Continue an existing run:
<input type="hidden" name="favourite_run_name" id="favourites_run_name_id" value="{{available_runs.0.run_name}}">
<input type="hidden" name="favourite_run_status" id="favourites_run_status_id" value="{{available_runs.0.favourite_status}}">
</form>
<form id="add_tag" class="mb-5" action="{% url 'runs:add_tag' %}" method="post">
{% csrf_token %}
<input type="hidden" name="tag_name" id="tag_name_id" value="">
<input type="hidden" name="run_name" id="run_name_id" value="">
</form>
<form id="delete_tag" class="mb-5" action="{% url 'runs:delete_tag' %}" method="post">
{% csrf_token %}
<input type="hidden" name="tag_name" id="tag_name_id" value="">
<input type="hidden" name="run_name" id="run_name_id" value="">
</form>
</div>
<div class="col-2">
<form id="filtertest" class="mb-5" action="{% url 'runs:index' %}" method="post">
Expand All @@ -131,24 +141,20 @@ <h3>Select filters:</h3>
<input name="run_name" id="run_name" placeholder="Name contains:" class="form-control">
</div>
<div class="mb-2">
<form>
<label for="steps">With steps:</label>
<select id="steps" name="steps" data-placeholder="Select step(s)" multiple data-multi-select>
{% for step in all_possible_step_names %}
<option value="{{ step }}">{{ step }}</option>
{% endfor %}
</select>
</form>
</div>
<div class="mb-2">
<form>
<label for="tags">With steps:</label>
<label for="tags">With tags:</label>
<select id="tags" name="tags" data-placeholder="Select tag(s)" multiple data-multi-select>
{% for tag in all_tags %}
<option value="{{ tag }}">{{ tag }}</option>
{% endfor %}
</select>
</form>
</div>
<div class="mb-2">
<label for="df_mode">Memory mode:</label>
Expand Down
4 changes: 3 additions & 1 deletion ui/runs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<str:run_name>", views.detail, name="detail"),
path("<str:run_name>/plot", views.plot, name="plot"),
Expand Down
39 changes: 33 additions & 6 deletions ui/runs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
)

Expand All @@ -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?)
Expand All @@ -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"))

Expand Down

0 comments on commit ff4fa08

Please sign in to comment.