From c4e102e3c5fb7a18b5dd4cc4c5fed7b9939a9974 Mon Sep 17 00:00:00 2001 From: ronjakrg Date: Sun, 24 Nov 2024 19:40:13 +0100 Subject: [PATCH 01/15] added basic construct of settings page --- protzilla/constants/paths.py | 1 + ui/main/urls.py | 1 + ui/main/views.py | 16 +++++++- ui/static/templates/navbar.html | 5 +++ ui/static/templates/settings.html | 58 +++++++++++++++++++++++++++ user_data/settings/user_settings.yaml | 9 +++++ 6 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 ui/static/templates/settings.html create mode 100644 user_data/settings/user_settings.yaml diff --git a/protzilla/constants/paths.py b/protzilla/constants/paths.py index 6802d5033..a192cc7dc 100644 --- a/protzilla/constants/paths.py +++ b/protzilla/constants/paths.py @@ -3,6 +3,7 @@ PROJECT_PATH = Path(__file__).resolve().parent.parent.parent RUNS_PATH = Path(PROJECT_PATH, "user_data/runs") WORKFLOWS_PATH = Path(PROJECT_PATH, "user_data/workflows") +SETTINGS_PATH = Path(PROJECT_PATH, "user_data/settings") EXTERNAL_DATA_PATH = Path(PROJECT_PATH, "user_data/external_data") WORKFLOW_META_PATH = Path(PROJECT_PATH, "protzilla/constants/workflow_meta.json") UI_PATH = Path(PROJECT_PATH, "ui") diff --git a/ui/main/urls.py b/ui/main/urls.py index 54726696c..c0bbff70c 100644 --- a/ui/main/urls.py +++ b/ui/main/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ path("", views.index), + path("settings", views.settings, name="settings"), path("runs/", include("runs.urls")), path("databases", views.databases, name="databases"), path("databases/upload", views.database_upload, name="database_upload"), diff --git a/ui/main/views.py b/ui/main/views.py index 14e36465d..a9c2a5d55 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -8,16 +8,30 @@ from django.shortcuts import redirect, render from django.urls import reverse -from protzilla.constants.paths import EXTERNAL_DATA_PATH +from protzilla.constants.paths import EXTERNAL_DATA_PATH, SETTINGS_PATH from protzilla.data_integration.database_query import uniprot_columns, uniprot_databases +from protzilla.disk_operator import YamlOperator database_metadata_path = EXTERNAL_DATA_PATH / "internal" / "metadata" / "uniprot.json" +user_settings_path = SETTINGS_PATH / "user_settings.yaml" def index(request): return redirect("/runs/") +def settings(request): + op = YamlOperator() + sections = op.read(user_settings_path) + return render( + request, + "settings.html", + context=dict( + sections=sections + ) + ) + + def databases(request): databases = uniprot_databases() df_infos = {} diff --git a/ui/static/templates/navbar.html b/ui/static/templates/navbar.html index e85afdff8..ab1c41a30 100644 --- a/ui/static/templates/navbar.html +++ b/ui/static/templates/navbar.html @@ -16,6 +16,11 @@ Logo + + + + + \ No newline at end of file diff --git a/ui/static/templates/settings.html b/ui/static/templates/settings.html new file mode 100644 index 000000000..7803f7731 --- /dev/null +++ b/ui/static/templates/settings.html @@ -0,0 +1,58 @@ +{% extends 'base.html' %} +{% load static %} +{# params: sections #} + +{% block css %} + +{% endblock %} + +{% block js %} +{% endblock %} + +{% block content %} +
+ + + + +
+
+

All settings of a section will appear here.

+
+
+
+{% endblock %} + diff --git a/user_data/settings/user_settings.yaml b/user_data/settings/user_settings.yaml new file mode 100644 index 000000000..6caf6cacd --- /dev/null +++ b/user_data/settings/user_settings.yaml @@ -0,0 +1,9 @@ +- id: general + name: General +- file_format: svg + font: Sans Serif + font_size: 11 + height: 80 + id: exporting_plots + name: Exporting plots + width: 100 From 8d764178867750f521e01829f39390b30bc76476 Mon Sep 17 00:00:00 2001 From: ronjakrg Date: Mon, 25 Nov 2024 19:15:48 +0100 Subject: [PATCH 02/15] added selection of sections and forms for plot settings --- ui/main/user_settings_forms.py | 44 +++++++++++++++++++++++++++ ui/main/views.py | 19 +++++++++++- ui/static/templates/settings.html | 27 ++++++++++++---- user_data/settings/user_settings.yaml | 2 ++ 4 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 ui/main/user_settings_forms.py diff --git a/ui/main/user_settings_forms.py b/ui/main/user_settings_forms.py new file mode 100644 index 000000000..bfa7850f3 --- /dev/null +++ b/ui/main/user_settings_forms.py @@ -0,0 +1,44 @@ +from enum import Enum +from django.forms import Form +from ui.runs.forms.custom_fields import CustomChoiceField, CustomNumberField + +class FileFormat(Enum): + png = "png" + tiff = "tiff" + svg = "svg" + pdf = "pdf" + eps = "eps" + jpg = "jpg" + +class Font(Enum): + arial = "Arial" + +class ExportingPlotsSettingsForm(Form): + file_format = CustomChoiceField( + label="File format", + choices=FileFormat, + initial=FileFormat.svg + ) + width = CustomNumberField( + label="Width (in mm)", + min_value=10, + max_value=1000, + initial=100 + ) + height = CustomNumberField( + label="Height (in mm)", + min_value=10, + max_value=1000, + initial=80 + ) + font = CustomChoiceField( + label="Font", + choices=Font, + initial=Font.arial + ) + font_size = CustomNumberField( + label="Font size", + min_value=1, + max_value=100, + initial=11 + ) \ No newline at end of file diff --git a/ui/main/views.py b/ui/main/views.py index a9c2a5d55..859fb4703 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -11,6 +11,7 @@ from protzilla.constants.paths import EXTERNAL_DATA_PATH, SETTINGS_PATH from protzilla.data_integration.database_query import uniprot_columns, uniprot_databases from protzilla.disk_operator import YamlOperator +from ui.main.user_settings_forms import ExportingPlotsSettingsForm database_metadata_path = EXTERNAL_DATA_PATH / "internal" / "metadata" / "uniprot.json" user_settings_path = SETTINGS_PATH / "user_settings.yaml" @@ -23,11 +24,27 @@ def index(request): def settings(request): op = YamlOperator() sections = op.read(user_settings_path) + for item in sections: + if isinstance(item, dict) and item.get("selected") is True: + selected_section=item.get("id") + + if selected_section == "general": + title="General Settings" + description="General settings relating to the PROTzilla application can be adjusted here." + settings_form="" + elif selected_section == "exporting_plots": + title="Configurations for Exporting Plots" + description="Configurations for plots and diagrams can be stored here. This information is automatically applied to all plot downloads." + settings_form=ExportingPlotsSettingsForm + return render( request, "settings.html", context=dict( - sections=sections + sections=sections, + title=title, + description=description, + settings_form=settings_form ) ) diff --git a/ui/static/templates/settings.html b/ui/static/templates/settings.html index 7803f7731..e1d3ea685 100644 --- a/ui/static/templates/settings.html +++ b/ui/static/templates/settings.html @@ -1,6 +1,6 @@ {% extends 'base.html' %} {% load static %} -{# params: sections #} +{# params: sections, title, description, settings_form #} {% block css %} -{% endblock %} - -{% block js %} -{% endblock %} - -{% block title %} - PROTzilla - Settings -{% endblock %} - -{% block content %} -
- - - - -
-
-

{{ title }}

-
{{ description }}
-
- {% for field in settings_form %} -
- {% if field.field.label %}{{ field.label_tag }}{% endif %} - {{ field }} -
- {% endfor %} -
-
-
-
-{% endblock %} \ No newline at end of file diff --git a/user_data/settings/user_settings.yaml b/user_data/settings/user_settings.yaml index 3e6727585..ce5f448e4 100644 --- a/user_data/settings/user_settings.yaml +++ b/user_data/settings/user_settings.yaml @@ -1,11 +1,9 @@ - id: general name: General - selected: false - file_format: svg font: Sans Serif font_size: 11 height: 80 - id: exporting_plots + id: plots name: Exporting plots - selected: true width: 100 From 701b0a7dea1b6b64b70c6005ccc5f70787e80cdb Mon Sep 17 00:00:00 2001 From: ronjakrg Date: Tue, 10 Dec 2024 17:02:07 +0100 Subject: [PATCH 04/15] Added footer and returning to last view after saving or canceling --- ui/main/views.py | 1 + ui/runs/views.py | 6 ++++ ui/settings/templates/settings_footer.html | 37 +++++++++++++++++++++ ui/settings/templates/settings_general.html | 33 +++++++++--------- ui/settings/templates/settings_plots.html | 5 ++- ui/settings/urls.py | 2 ++ ui/settings/views.py | 28 +++++++++++----- 7 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 ui/settings/templates/settings_footer.html diff --git a/ui/main/views.py b/ui/main/views.py index d3e45e499..4ae5852f1 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -18,6 +18,7 @@ def index(request): def databases(request): + request.session['last_view'] = "databases" databases = uniprot_databases() df_infos = {} if database_metadata_path.exists(): diff --git a/ui/runs/views.py b/ui/runs/views.py index 56d0d264e..b7b25f521 100644 --- a/ui/runs/views.py +++ b/ui/runs/views.py @@ -68,6 +68,9 @@ def detail(request: HttpRequest, run_name: str): active_runs[run_name] = Run(run_name) run: Run = active_runs[run_name] + request.session['last_view'] = "runs:detail" + request.session['run_name'] = run_name + # section, step, method = run.current_run_location() # end_of_run = not step @@ -173,6 +176,9 @@ def index(request: HttpRequest, index_error: bool = False): :return: the rendered index page :rtype: HttpResponse """ + + request.session['last_view'] = "runs:index" + return render( request, "runs/index.html", diff --git a/ui/settings/templates/settings_footer.html b/ui/settings/templates/settings_footer.html new file mode 100644 index 000000000..216e9b562 --- /dev/null +++ b/ui/settings/templates/settings_footer.html @@ -0,0 +1,37 @@ +{% load static %} + +{% block css %} + +{% endblock %} + +{% block content %} + +{% endblock %} \ No newline at end of file diff --git a/ui/settings/templates/settings_general.html b/ui/settings/templates/settings_general.html index b3d10659f..25cc79f20 100644 --- a/ui/settings/templates/settings_general.html +++ b/ui/settings/templates/settings_general.html @@ -14,21 +14,24 @@ {% endblock %} {% block content %} -
- {{ sidebar|safe }} -
-
-

General Settings

-
General settings relating to the PROTzilla application can be adjusted here.
-
- {% for field in settings_form %} -
- {% if field.field.label %}{{ field.label_tag }}{% endif %} - {{ field }} -
- {% endfor %} +
+ {{ sidebar|safe }} +
+
+

General Settings

+
General settings relating to the PROTzilla application can be adjusted here.
+
+ {% for field in settings_form %} +
+ {% if field.field.label %}{{ field.label_tag }}{% endif %} + {{ field }} +
+ {% endfor %} +
+ {% block footer %} + {% include "settings_footer.html" %} + {% endblock %}
-
-{% endblock %} \ No newline at end of file +{% endblock %} \ No newline at end of file diff --git a/ui/settings/templates/settings_plots.html b/ui/settings/templates/settings_plots.html index d0bdb43e4..e3e8616af 100644 --- a/ui/settings/templates/settings_plots.html +++ b/ui/settings/templates/settings_plots.html @@ -32,4 +32,7 @@

Configurations for Exporting Plots

-{% endblock %} \ No newline at end of file + {% block footer %} + {% include "settings_footer.html" %} + {% endblock %} +{% endblock %} \ No newline at end of file diff --git a/ui/settings/urls.py b/ui/settings/urls.py index 2c2c91232..4f6eec7df 100644 --- a/ui/settings/urls.py +++ b/ui/settings/urls.py @@ -5,6 +5,8 @@ app_name = "settings" urlpatterns = [ + path("runs/", include("runs.urls")), path("general", views.settings_general, name="settings_general"), path("plots", views.settings_plots, name="settings_plots"), + path("last_view", views.last_view, name="last_view") ] \ No newline at end of file diff --git a/ui/settings/views.py b/ui/settings/views.py index 2eec7958e..3bf8e3f58 100644 --- a/ui/settings/views.py +++ b/ui/settings/views.py @@ -2,7 +2,7 @@ from django.contrib import messages from django.http import HttpResponseRedirect from django.shortcuts import redirect, render -from django.urls import reverse +from django.urls import reverse, NoReverseMatch from django.template.loader import render_to_string from protzilla.constants.paths import EXTERNAL_DATA_PATH, SETTINGS_PATH @@ -30,9 +30,9 @@ def get_user_settings(): def settings_general(request): - settings_form="" - sections=get_user_settings() - sidebar=make_sidebar(request, sections, "general") + settings_form = "" + sections = get_user_settings() + sidebar = make_sidebar(request, sections, "general") return render( request, "settings_general.html", @@ -44,9 +44,9 @@ def settings_general(request): def settings_plots(request): - settings_form=ExportingPlotsSettingsForm - sections=get_user_settings() - sidebar=make_sidebar(request, sections, "plots") + settings_form = ExportingPlotsSettingsForm + sections = get_user_settings() + sidebar = make_sidebar(request, sections, "plots") return render( request, "settings_plots.html", @@ -54,4 +54,16 @@ def settings_plots(request): sidebar=sidebar, settings_form=settings_form ) - ) \ No newline at end of file + ) + + +def last_view(request): + view_name = request.session['last_view'] + run_name = request.session['run_name'] + try: + if view_name=="runs:detail": + return HttpResponseRedirect(reverse(view_name, args=(run_name,))) + else: + return HttpResponseRedirect(reverse(view_name)) + except NoReverseMatch: + return HttpResponseRedirect(reverse("runs:index")) \ No newline at end of file From 7e4aedca1439d25988e9d9ef9b7746ba7f115a27 Mon Sep 17 00:00:00 2001 From: ronjakrg Date: Tue, 10 Dec 2024 19:23:24 +0100 Subject: [PATCH 05/15] small bugfix and refactoring --- ui/runs/templates/runs/details.html | 4 ++-- ui/settings/views.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/runs/templates/runs/details.html b/ui/runs/templates/runs/details.html index e60a42d64..fd7e0a924 100644 --- a/ui/runs/templates/runs/details.html +++ b/ui/runs/templates/runs/details.html @@ -278,11 +278,11 @@