Skip to content

Commit

Permalink
Fixed tag adding, tags are now also saved as a set
Browse files Browse the repository at this point in the history
  • Loading branch information
gitjannes committed Dec 16, 2024
1 parent 3af2117 commit 4c7ad64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ui/runs/static/runs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function toggleFavouriteRun(runName, favouriteStatus){

function addTag(runName){
document.getElementById('add_tag_run_name_id').value = runName;
document.getElementById('add_tag_name_id').value = document.getElementById('tag_name_id').value;
console.log(runName);
document.getElementById('add_tag_name_id').value = document.getElementById('tag_name_id_' + runName).value;
document.getElementById('add_tag').submit();
};

Expand Down
2 changes: 1 addition & 1 deletion ui/runs/templates/runs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h3>Continue an existing run:
</svg>
</button>
{% endfor %}
<input type="text" name="tag_name" id="tag_name_id" placeholder="Tag name:" class="form-control" onclick="event.stopPropagation();">
<input type="text" name="tag_name" id="tag_name_id_{{run.run_name}}" placeholder="Tag name:" class="form-control" onclick="event.stopPropagation();">
<button type="button" class="btn btn-grey" onclick="addTag('{{run.run_name}}')"></button>
</div>
<p style="margin: 5px 0;">Description: </p>
Expand Down
11 changes: 8 additions & 3 deletions ui/runs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,23 +251,28 @@ def add_tag(request: HttpRequest):

run_tag = request.POST["add_tag_name"]
run_name = request.POST["add_tag_run_name"]
print(run_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()
tags = []
tags = set()
metadata = {}
if not os.path.exists(metadata_yaml_path):
with open(metadata_yaml_path, 'w') as file:
pass
else:
metadata = yaml_operator.read(metadata_yaml_path)
tags = metadata.get("tags")
tags.append(run_tag)
tags_from_metadata = metadata.get("tags")
tags.update(tags_from_metadata)
print(tags)
tags.add(run_tag)
print(tags)
metadata["tags"]= tags
print(metadata)
yaml_operator.write(Path(metadata_yaml_path), metadata)

return HttpResponseRedirect(reverse("runs:index"))
Expand Down

0 comments on commit 4c7ad64

Please sign in to comment.