From 4c6f9513fe92bd3e06f969ddd060414a1fa3524c Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Mon, 27 Jan 2025 16:11:42 +0100
Subject: [PATCH] =?UTF-8?q?refactor(graphs):=20=F0=9F=9A=9A=20rename=20plo?=
 =?UTF-8?q?t=20maker=20to=20explorer;=20move=20to=20/graphs/explorer=20url?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../graphs/templates/graphs/explorer.html     | 47 +++++++++++++++++++
 .../graphs/templates/graphs/graphs.html       | 33 -------------
 .../graphs/templates/graphs/plot.html         |  9 +++-
 scipost_django/graphs/urls.py                 |  8 ++--
 scipost_django/graphs/views.py                |  8 ++--
 .../commands/add_groups_and_permissions.py    | 10 ++++
 6 files changed, 73 insertions(+), 42 deletions(-)
 create mode 100644 scipost_django/graphs/templates/graphs/explorer.html
 delete mode 100644 scipost_django/graphs/templates/graphs/graphs.html

diff --git a/scipost_django/graphs/templates/graphs/explorer.html b/scipost_django/graphs/templates/graphs/explorer.html
new file mode 100644
index 000000000..fea72e51e
--- /dev/null
+++ b/scipost_django/graphs/templates/graphs/explorer.html
@@ -0,0 +1,47 @@
+{% extends "scipost/base.html" %}
+
+{% block pagetitle %}
+  : Graphs Explorer
+{% endblock pagetitle %}
+
+{% block content %}
+  <div class="d-flex justify-content-between mb-2">
+    <h1>Data Explorer</h1>
+    <span class="badge bg-warning bg-opacity-25 fs-6 d-flex align-items-center gap-2 text-body fw-normal">
+      {% include "bi/exclamation-triangle-fill.html" %}
+      Early preview
+    </span>
+  </div>
+  <p>
+    On this page you will find an interactive tool to explore SciPost data visually via plots.
+    The tool allows you to select a dataset, choose the columns to plot, and customize the plot's appearance.
+    The final plot may be exported as a vector or raster image, or as a CSV file containing the data used to generate the plot.
+  </p>
+  <p>
+    If you notice any issues, unexpected behavior, or have suggestions for improvements,
+    please let us know by sending an email to <a href="mailto:techsupport@{{ DOMAIN_HOST }}">tech support</a>,
+    or by <a href="https://git.{{ DOMAIN_HOST }}/scipost/SciPost/-/issues/new">creating an issue</a>
+    on our <a href="https://git.{{ DOMAIN_HOST }}/scipost/SciPost/">Gitlab</a> repository.
+  </p>
+
+  <div id="plot-container"
+       class="mt-4 row h-100"
+       hx-include="this"
+       hx-indicator="#plot-loading-indicator">
+    <div id="plot-options"
+         class="col-12 col-lg-3 d-flex flex-column"
+         hx-post="{% url "graphs:explorer_plot_options_form" %}"
+         hx-sync="this:replace"
+         hx-trigger="load, change from:#plot-container"></div>
+
+    <div class="col d-flex flex-column">
+      <div id="plot"
+           class="h-100 w-100"
+           hx-get="{% url "graphs:explorer_plot" %}"
+           hx-params="not csrfmiddlewaretoken"
+           hx-sync="this:replace"
+           hx-trigger="htmx:afterOnLoad from:#plot-container target:#plot-options">
+      </div>
+    </div>
+  </div>
+{% endblock content %}
diff --git a/scipost_django/graphs/templates/graphs/graphs.html b/scipost_django/graphs/templates/graphs/graphs.html
deleted file mode 100644
index b901d26eb..000000000
--- a/scipost_django/graphs/templates/graphs/graphs.html
+++ /dev/null
@@ -1,33 +0,0 @@
-{% extends "scipost/base.html" %}
-
-{% block content %}
-  <div class="d-flex justify-content-between align-items-center">
-    <h1>SciPost Graphs</h1>
-    <span id="plot-loading-indicator"
-          class="p-2 htmx-indicator justify-content-between bg-primary bg-opacity-25">
-      <strong>Loading</strong>
-      <div class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></div>
-    </span>
-  </div>
-
-  <div id="plot-container"
-       class="row h-100"
-       hx-include="this"
-       hx-indicator="#plot-loading-indicator">
-    <div id="plot-options"
-         class="col-12 col-lg-3 d-flex flex-column"
-         hx-post="{% url "graphs:plot_options_form" %}"
-         hx-sync="this:replace"
-         hx-trigger="load, change from:#plot-container"></div>
-
-    <div class="col d-flex flex-column">
-      <div id="plot"
-           class="h-100 w-100"
-           hx-get="{% url "graphs:plot" %}"
-           hx-params="not csrfmiddlewaretoken"
-           hx-sync="this:replace"
-           hx-trigger="htmx:afterOnLoad from:#plot-container target:#plot-options">
-      </div>
-    </div>
-  </div>
-{% endblock content %}
diff --git a/scipost_django/graphs/templates/graphs/plot.html b/scipost_django/graphs/templates/graphs/plot.html
index 4c8f1ddec..7f736c5ba 100644
--- a/scipost_django/graphs/templates/graphs/plot.html
+++ b/scipost_django/graphs/templates/graphs/plot.html
@@ -2,9 +2,16 @@
 
 {% if not request.GET.embed %}
   <div id="plot-controls" class="my-2 d-flex gap-2 justify-content-end">
+    <div class="d-flex justify-content-between align-items-center">
+      <span id="plot-loading-indicator"
+            class="p-2 htmx-indicator justify-content-between bg-primary bg-opacity-25">
+        <strong>Loading</strong>
+        <div class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></div>
+      </span>
+    </div>
     <button id="plot-refresh"
             class="btn btn-primary"
-            hx-get="{% url "graphs:plot" %}"
+            hx-get="{% url "graphs:explorer_plot" %}"
             hx-params="not csrfmiddlewaretoken"
             hx-target="#plot"
             hx-vals='{"refresh": true}'
diff --git a/scipost_django/graphs/urls.py b/scipost_django/graphs/urls.py
index f83c66664..754be9463 100644
--- a/scipost_django/graphs/urls.py
+++ b/scipost_django/graphs/urls.py
@@ -10,11 +10,11 @@ from . import views
 app_name = "graphs"
 
 urlpatterns = [
-    path("", views.graphs, name="graphs"),
-    path("plot", views.PlotView.as_view(), name="plot"),
+    path("explorer", views.explorer, name="explorer"),
+    path("explorer/plot", views.PlotView.as_view(), name="explorer_plot"),
     path(
-        "plot/options_form",
+        "explorer/plot/options_form",
         views.PlotOptionsFormView.as_view(),
-        name="plot_options_form",
+        name="explorer_plot_options_form",
     ),
 ]
diff --git a/scipost_django/graphs/views.py b/scipost_django/graphs/views.py
index 33d714027..ff256bca9 100644
--- a/scipost_django/graphs/views.py
+++ b/scipost_django/graphs/views.py
@@ -19,19 +19,19 @@ from scipost.permissions import HTMXResponse
 
 
 @login_required
-@permission_required("scipost.can_preview_new_features", raise_exception=True)
-def graphs(request):
+@permission_required("scipost.can_explore_graphs", raise_exception=True)
+def explorer(request):
 
     form = PlotOptionsForm(request.POST or None)
     return render(
         request,
-        "graphs/graphs.html",
+        "graphs/explorer.html",
         {"form": form},
     )
 
 
 @method_decorator(
-    permission_required("scipost.can_preview_new_features", raise_exception=True),
+    permission_required("scipost.can_explore_graphs", raise_exception=True),
     name="dispatch",
 )
 @method_decorator(xframe_options_sameorigin, name="dispatch")
diff --git a/scipost_django/scipost/management/commands/add_groups_and_permissions.py b/scipost_django/scipost/management/commands/add_groups_and_permissions.py
index 0ddc54c1a..b9c976cc9 100644
--- a/scipost_django/scipost/management/commands/add_groups_and_permissions.py
+++ b/scipost_django/scipost/management/commands/add_groups_and_permissions.py
@@ -553,6 +553,13 @@ class Command(BaseCommand):
             content_type=content_type,
         )
 
+        # Graphs
+        can_explore_graphs, created = Permission.objects.get_or_create(
+            codename="can_explore_graphs",
+            name="Can access the Graphs Explorer",
+            content_type=content_type,
+        )
+
         # Assign permissions to groups
         SciPostAdmin.permissions.set(
             [
@@ -605,6 +612,7 @@ class Command(BaseCommand):
                 can_manage_mailing_lists,
                 can_create_affiliate_journals,
                 can_mark_submission_on_hold,
+                can_explore_graphs,
             ]
         )
 
@@ -694,6 +702,7 @@ class Command(BaseCommand):
                 can_view_internal_fellowship_notes,
                 can_view_mailing_lists,
                 can_create_affiliate_journals,
+                can_explore_graphs,
             ]
         )
 
@@ -751,6 +760,7 @@ class Command(BaseCommand):
         Previewers.permissions.set(
             [
                 can_preview_new_features,
+                can_explore_graphs,
             ]
         )
 
-- 
GitLab