From 52c3e22f0dec34788b9507ac1be898c9b6cf5ba6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Sat, 25 Jun 2022 22:16:40 +0200
Subject: [PATCH 1/2] backoffice: add fullscreen workflow schema page (#66624)

---
 tests/admin_pages/test_workflow.py            |  6 +++++
 wcs/admin/workflows.py                        | 26 +++++++++++++++++++
 wcs/qommon/static/css/dc2/admin.scss          |  5 ++++
 .../workflow-fullscreen-schema.html           | 19 ++++++++++++++
 .../wcs/backoffice/workflow-status.html       |  3 ++-
 wcs/templates/wcs/backoffice/workflow.html    |  3 ++-
 6 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 wcs/templates/wcs/backoffice/workflow-fullscreen-schema.html

diff --git a/tests/admin_pages/test_workflow.py b/tests/admin_pages/test_workflow.py
index e916ba84a..ddf678218 100644
--- a/tests/admin_pages/test_workflow.py
+++ b/tests/admin_pages/test_workflow.py
@@ -93,6 +93,9 @@ def test_workflows_new(pub):
     resp = resp.follow()
     assert '<svg ' in resp.text
     assert '@import ' not in resp.text
+    assert resp.click('Download').content_type == 'image/svg+xml'
+    resp_fullscreen = resp.click('Full Screen')
+    assert 'data-gadjo="true"' not in resp_fullscreen.text
 
     # create a new action
     resp = resp.click('new status')
@@ -101,6 +104,9 @@ def test_workflows_new(pub):
     assert resp.location == 'http://example.net/backoffice/workflows/1/status/1/'
     resp = resp.follow()
     assert 'Use drag and drop' in resp.text
+    assert resp.click('Download').content_type == 'image/svg+xml'
+    resp_fullscreen = resp.click('Full Screen')
+    assert 'data-gadjo="true"' not in resp_fullscreen.text
 
     # fill action
     resp = resp.click('Alert')
diff --git a/wcs/admin/workflows.py b/wcs/admin/workflows.py
index a5f674764..358a44983 100644
--- a/wcs/admin/workflows.py
+++ b/wcs/admin/workflows.py
@@ -614,6 +614,7 @@ class WorkflowStatusPage(Directory):
         'endpoint',
         'display',
         ('backoffice-info-text', 'backoffice_info_text'),
+        'fullscreen',
         ('schema.svg', 'svg'),
         'svg',
     ]
@@ -663,6 +664,18 @@ class WorkflowStatusPage(Directory):
     def graphviz(self):
         return graphviz(self.workflow, url_prefix='../../', include=True, select='%s' % self.status.id)
 
+    def fullscreen(self):
+        get_response().add_javascript(['jquery.js', 'svg-pan-zoom.js', 'qommon.admin.js'])
+        context = {
+            'view': self,
+            'workflow': self.workflow,
+        }
+        return template.QommonTemplateResponse(
+            templates=['wcs/backoffice/workflow-fullscreen-schema.html'],
+            context=context,
+            is_django_native=True,
+        )
+
     def svg(self):
         response = get_response()
         response.set_content_type('image/svg+xml')
@@ -1564,6 +1577,7 @@ class WorkflowPage(Directory):
         ('criticality-levels', 'criticality_levels_dir'),
         ('logged-errors', 'logged_errors_dir'),
         ('history', 'snapshots_dir'),
+        ('fullscreen'),
     ]
     do_not_call_in_templates = True
 
@@ -1633,6 +1647,18 @@ class WorkflowPage(Directory):
     def graphviz(self):
         return graphviz(self.workflow, include=True)
 
+    def fullscreen(self):
+        get_response().add_javascript(['jquery.js', 'svg-pan-zoom.js', 'qommon.admin.js'])
+        context = {
+            'view': self,
+            'workflow': self.workflow,
+        }
+        return template.QommonTemplateResponse(
+            templates=['wcs/backoffice/workflow-fullscreen-schema.html'],
+            context=context,
+            is_django_native=True,
+        )
+
     def _q_index(self):
         self.html_top(title=_('Workflow - %s') % self.workflow.name)
         get_response().filter['sidebar'] = self.get_sidebar()
diff --git a/wcs/qommon/static/css/dc2/admin.scss b/wcs/qommon/static/css/dc2/admin.scss
index 6359084a5..2d0a5474f 100644
--- a/wcs/qommon/static/css/dc2/admin.scss
+++ b/wcs/qommon/static/css/dc2/admin.scss
@@ -2455,3 +2455,8 @@ a.button.button--go-to-option {
 	padding-left: 10px;
 	padding-right: 10px;
 }
+
+#workflow-fullscreen-schema {
+	height: 95vh;
+	width: 100%;
+}
diff --git a/wcs/templates/wcs/backoffice/workflow-fullscreen-schema.html b/wcs/templates/wcs/backoffice/workflow-fullscreen-schema.html
new file mode 100644
index 000000000..69fceadb5
--- /dev/null
+++ b/wcs/templates/wcs/backoffice/workflow-fullscreen-schema.html
@@ -0,0 +1,19 @@
+{% load i18n gadjo static %}<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8"/>
+    <title>{{ workflow.name }}</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
+    <link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/qommon.css?{% version_hash %}"/>
+    <link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/dc2/admin.css?{% version_hash %}"/>
+    {{script|safe}}
+  </html>
+  <body>
+<div id="workflow-fullscreen-schema">
+{{ view.graphviz|safe }}
+<div class="full-screen-link"><a download href="schema.svg">{% trans "Download" %}</a></div>
+</div>
+  </body>
+</html>
diff --git a/wcs/templates/wcs/backoffice/workflow-status.html b/wcs/templates/wcs/backoffice/workflow-status.html
index f119fb44f..588c95b96 100644
--- a/wcs/templates/wcs/backoffice/workflow-status.html
+++ b/wcs/templates/wcs/backoffice/workflow-status.html
@@ -65,7 +65,8 @@
 
 <div class="bo-block">
 {{ view.graphviz|safe }}
-<div class="full-screen-link"><a href="schema.svg">{% trans "Full Screen" %}</a></div>
+<div class="full-screen-link"><a download href="schema.svg">{% trans "Download" %}</a> -
+        <a href="fullscreen">{% trans "Full Screen" %}</a></div>
 </div>
 
 {% endblock %}
diff --git a/wcs/templates/wcs/backoffice/workflow.html b/wcs/templates/wcs/backoffice/workflow.html
index e4e3b0b3e..2700ba044 100644
--- a/wcs/templates/wcs/backoffice/workflow.html
+++ b/wcs/templates/wcs/backoffice/workflow.html
@@ -145,7 +145,8 @@
 {% if workflow.possible_status %}
 <div class="bo-block">
 {{ view.graphviz|safe }}
-<div class="full-screen-link"><a href="schema.svg">{% trans "Full Screen" %}</a></div>
+<div class="full-screen-link"><a download href="schema.svg">{% trans "Download" %}</a> -
+        <a href="fullscreen">{% trans "Full Screen" %}</a></div>
 </div>
 {% endif %}
 
-- 
2.36.1

