From ddfef394596f21c902bc394ee963e3f687d15886 Mon Sep 17 00:00:00 2001
From: Vanessa Stehr <vanessa.stehr@ptb.de>
Date: Tue, 19 Dec 2023 16:15:45 +0100
Subject: [PATCH] Add output elements

---
 main.py              | 52 +++++++++++++++++++++++++++++++++++++++++---
 requirements.txt     |  3 ++-
 templates/index.html |  2 +-
 3 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/main.py b/main.py
index b19f6d8..f0484e2 100644
--- a/main.py
+++ b/main.py
@@ -4,9 +4,10 @@ import json
 import tarfile
 import warnings
 import bokehCssPTB
-from bokeh.plotting import curdoc
+from dsiParser import dsiParser
+from bokeh.plotting import curdoc,figure
 from bokeh.layouts import column, row
-from bokeh.models import FileInput, Div, CustomJS, Button, TabPanel, Tabs, Dropdown, TextInput, Button
+from bokeh.models import FileInput, Div, CustomJS, Button, TabPanel, Tabs, Dropdown, TextInput, Button, MathText, Label
 from bokeh.events import ValueSubmit
 
 VERSION = "0.1.0"
@@ -26,7 +27,52 @@ class page():
 
         curdoc().add_root(self.inputRow)
 
+        self.results = column(children = [])
+        curdoc().add_root(self.results)
+
     def parseInput(self):
-        print(self.dsiInput.value)
+        self.results.children = []
+        input = self.dsiInput.value
+        p = dsiParser()
+        resultTree = p.parse(input)
+        parsingMessages = []
+        if resultTree.valid:
+            parsingMessages.append(
+                Div(
+                    text = "DSI string parsed without warnings",
+                    css_classes = ["msg-positive"],
+                )
+            )
+        else:
+            for message in resultTree.warnings:
+                parsingMessages.append(
+                    Div(
+                        text = message,
+                        css_classes = ["msg-negative"]
+                    )
+                )
+        self.resultErrors = column(children = parsingMessages)
+
+        # latexOutput = TextInput(value=resultTree.toLatex(), title="DSI unit string:")
+        # latexOutput.js_on_change()
+        latexOutput = row(children=[
+            Div(text = "$$\mathrm{\LaTeX{}}$$ code:"),
+            Div(text = "<pre><code>"+resultTree.toLatex()+"</code></pre>", disable_math=True)
+        ])
+
+        p = figure(width=500, height=100, x_range=(0, 1), y_range=(0, 1), tools="save")
+        p.xaxis.visible = False
+        p.yaxis.visible = False
+        p.grid.visible = False
+
+        p.add_layout(Label(
+            x=0.5, y=0.5, text=resultTree.toLatex(), text_font_size="12px", text_baseline="middle", text_align="center",
+        ))
+
+        imageOutput = row(children = [
+            Div(text = "$$\mathrm{\LaTeX{}}$$ output:"),
+            p
+        ])
+        self.results.children = [self.resultErrors, latexOutput, imageOutput]
 
 thisPage = page()
diff --git a/requirements.txt b/requirements.txt
index 8136874..068269f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
 bokeh~=3.3.2
--e git+https://dockerPull:-jVp9LBaxeKp9HKAe9dw@gitlab1.ptb.de/digitaldynamicmeasurement/bokehCssPtb.git#egg=bokehCssPTB
\ No newline at end of file
+-e git+https://dockerPull:-jVp9LBaxeKp9HKAe9dw@gitlab1.ptb.de/digitaldynamicmeasurement/bokehCssPtb.git#egg=bokehCssPTB
+-e git+https://dockerPull:x3S7APs-7WMgN6xiyM2T@gitlab1.ptb.de/Seeger/python_dsi_latex_converter.git@release#egg=dsiParser
\ No newline at end of file
diff --git a/templates/index.html b/templates/index.html
index 7727864..a02af2b 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -50,7 +50,7 @@
         <div class="container">
         <div>Contact: <a href="mailto:vanessa.stehr@ptb.de">vanessa.stehr@ptb.de</a></div>
         <div>Version: {{ VERSION }}</div>
-        <div><a href="">this project on Gitlab</a></div>
+        <div><a href="https://gitlab1.ptb.de/digitaldynamicmeasurement/dsi-parser-frontend">this project on Gitlab</a></div>
         <div><a href="https://gitlab1.ptb.de/digitaldynamicmeasurement/python_dsi_latex_converter">this functionality as a python library</a></div>
         </div>
     </footer>
-- 
GitLab