Skip to content

Commit b759278

Browse files
committed
For Act/Shielding fit, add the inja templates and options for showing for the calculation log.
This required re-factoring the <iframe> display stuff used to show summary results for batch analysis, into the InjaLogDialog class. Seems to work pretty decent. Left the old act/shield report logging in for the moment, but it will remove it at some point because it is a huge mess, and I think the new inja-template-based mecahnism covers everything (but this needs double checking) and more.
1 parent 35e486b commit b759278

27 files changed

+1087
-282
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ set(sources
266266
src/SpectrumChart.cpp
267267
src/SpectrumDataModel.cpp
268268
src/HelpSystem.cpp
269+
src/InjaLogDialog.cpp
269270
src/InterSpec.cpp
270271
src/InterSpecServer.cpp
271272
src/PopupDiv.cpp
@@ -379,6 +380,7 @@ set(headers
379380
InterSpec/SpectrumChart.h
380381
InterSpec/SpectrumDataModel.h
381382
InterSpec/HelpSystem.h
383+
InterSpec/InjaLogDialog.h
382384
InterSpec/InterSpec.h
383385
InterSpec/InterSpecServer.h
384386
InterSpec/PopupDiv.h

InterSpec/BatchInfoLog.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace BatchPeak
6363
namespace SpecUtils
6464
{
6565
class Measurement;
66+
class EnergyCalibration;
6667
}
6768

6869
namespace BatchActivity
@@ -83,8 +84,13 @@ namespace BatchInfoLog
8384
*/
8485
std::string template_include_dir( const BatchPeak::BatchPeakFitOptions &options );
8586

86-
/** Returns the default inja environment, with include directory, options, and callbacks set, as well as default templates loaded. */
87-
inja::Environment get_default_inja_env( const BatchPeak::BatchPeakFitOptions &options );
87+
/** Returns the default inja environment, with include directory, options, and callbacks set, as well as default templates loaded.
88+
89+
@param tmplt_dir The template include directory to use. Should include trailing path separator (as required by inja).
90+
If empty string, then no custom template directory will be used.
91+
To get the directory from options, use `template_include_dir(options)`.
92+
*/
93+
inja::Environment get_default_inja_env( const std::string &tmplt_dir );
8894

8995
/** Returns key-value pairs of of the file contents of the JS and CSS files needed for SpectrumChar. Specifically returns:
9096

InterSpec/InjaLogDialog.h

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#ifndef InjaLogDialog_h
2+
#define InjaLogDialog_h
3+
/* InterSpec: an application to analyze spectral gamma radiation data.
4+
5+
Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC
6+
(NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
7+
Government retains certain rights in this software.
8+
For questions contact William Johnson via email at [email protected], or
9+
alternative emails of [email protected].
10+
11+
This library is free software; you can redistribute it and/or
12+
modify it under the terms of the GNU Lesser General Public
13+
License as published by the Free Software Foundation; either
14+
version 2.1 of the License, or (at your option) any later version.
15+
16+
This library is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
Lesser General Public License for more details.
20+
21+
You should have received a copy of the GNU Lesser General Public
22+
License along with this library; if not, write to the Free Software
23+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24+
*/
25+
26+
#include "InterSpec_config.h"
27+
28+
#include <tuple>
29+
#include <vector>
30+
#include <string>
31+
#include <utility>
32+
#include <functional>
33+
34+
#include <Wt/WString>
35+
36+
#include <nlohmann/json.hpp>
37+
38+
#include "external_libs/SpecUtils/3rdparty/inja/inja.hpp"
39+
40+
#include "InterSpec/SimpleDialog.h"
41+
42+
43+
// Forward declarations
44+
namespace Wt
45+
{
46+
class WText;
47+
class WComboBox;
48+
class WResource;
49+
class WPushButton;
50+
class WContainerWidget;
51+
}// namespace Wt
52+
53+
54+
/** A reusable dialog for displaying content rendered from inja templates.
55+
56+
This dialog allows displaying HTML content generated from JSON data using inja templates.
57+
It supports multiple template options (selected via a combo box), displays the content in
58+
an iframe for isolation, and provides download functionality.
59+
60+
Originally extracted from BatchGuiAnaWidget to be reusable across the application.
61+
*/
62+
class InjaLogDialog : public SimpleDialog
63+
{
64+
public:
65+
/** Enum to specify the type of log content. */
66+
enum class LogType
67+
{
68+
Html, ///< HTML content that will be displayed directly in iframe
69+
Text ///< Plain text content that will be HTML-escaped and wrapped for display
70+
};
71+
72+
/** HTML wrapper tags for text log templates.
73+
Use these to wrap plain text content in HTML for display,
74+
so this way they can be stripped off when downloading the text version.
75+
*/
76+
static const char * const sm_txt_log_pre_wrapper;
77+
static const char * const sm_txt_log_post_wrapper;
78+
79+
/** Constructor for InjaLogDialog.
80+
81+
@param title The dialog title
82+
@param data The JSON data to be passed to inja templates
83+
@param template_options A vector of template options. Each entry contains a tuple:
84+
- get<0>: Display name for the template (shown in combo box)
85+
- get<1>: Filename suffix to append to spectrum filename for downloads (e.g., "_act_fit.html" or "_std_fit_log.txt")
86+
- get<2>: LogType enum indicating whether content is Html or Text
87+
- get<3>: Function that takes inja::Environment and JSON data,
88+
and returns rendered content string
89+
- For Html type: content must be a valid HTML page, as it will be displayed in an iframe
90+
- For Text type: content will be HTML-escaped and wrapped in <pre> tags for display
91+
92+
If template_options contains only one entry, no combo box is shown.
93+
If template_options is empty, an error is displayed.
94+
*/
95+
InjaLogDialog( const Wt::WString &title,
96+
const nlohmann::json &data,
97+
std::vector<std::tuple<Wt::WString, std::string, LogType, std::function<std::string(inja::Environment&, const nlohmann::json&)>>> template_options );
98+
99+
virtual ~InjaLogDialog();
100+
101+
const std::string &current_content() const;
102+
const std::string current_suggested_name() const;
103+
104+
/** Show or hide the toolbar containing the template selector and download button.
105+
@param show If true, toolbar is shown; if false, toolbar is hidden
106+
*/
107+
void setToolbarVisible( const bool show );
108+
109+
protected:
110+
/** Update the displayed content using the currently selected template. */
111+
void updateDisplay();
112+
113+
/** Handle template selection change from combo box. */
114+
void handleTemplateChange();
115+
116+
private:
117+
Wt::WResource *m_download_resource;
118+
119+
120+
// Member variables
121+
nlohmann::json m_data;
122+
std::vector<std::tuple<Wt::WString, std::string, LogType, std::function<std::string(inja::Environment&, const nlohmann::json&)>>> m_template_options;
123+
124+
Wt::WContainerWidget *m_toolbar;
125+
Wt::WComboBox *m_template_selector;
126+
Wt::WPushButton *m_download_button;
127+
Wt::WText *m_iframe_holder;
128+
Wt::WResource *m_current_resource;
129+
std::string m_current_content;
130+
};//class InjaLogDialog
131+
132+
133+
#endif // InjaLogDialog_h

InterSpec/ShieldingSourceDisplay.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class PeakDef;
5151
struct Material;
5252
class PeakModel;
5353
class AuxWindow;
54+
class InjaLogDialog;
5455
class MaterialDB;
5556
class ColorTheme;
5657
class PopupDivMenu;
@@ -707,10 +708,11 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
707708
bool m_multithread_computation;
708709

709710
PopupDivMenuItem *m_showLog;
710-
711-
AuxWindow *m_logDiv;
711+
712+
InjaLogDialog *m_logDiv;
712713
std::vector<std::string> m_calcLog;
713714
std::unique_ptr<const std::vector<GammaInteractionCalc::PeakDetail>> m_peakCalcLogInfo;
715+
std::shared_ptr<ShieldingSourceFitCalc::ModelFitResults> m_lastFitResults;
714716

715717
AuxWindow *m_modelUploadWindow;
716718
#if( USE_DB_TO_STORE_SPECTRA )

InterSpec_resources/BatchGuiAnaWidget.css

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -176,42 +176,10 @@
176176
align-items: center;
177177
}
178178

179-
/* Analysis result dialogs */
180-
.simple-dialog.BatchAnalysisResultDialog
181-
{
182-
max-width: 95vw;
183-
max-height: 95vh;
184-
width: 95vw;
185-
height: 95vw;
186-
}
187-
188-
.simple-dialog.BatchAnalysisResultDialog .body
189-
{
190-
/* The 95vh is from .simple-dialog, and the 90px is the header and footer height. */
191-
max-height: calc( 95vh - 90px );
192-
max-width: calc(95vw - 30px);
193-
overflow-y: hidden;
194-
padding-top: 16px;
195-
padding-bottom: 5px;
196-
}
197-
198-
.simple-dialog.BatchAnalysisResultDialog .body .BatchReportIFrameHolder
199-
{
200-
border: solid 1px #e1e1e1;
201-
border-radius: 5px;
202-
display: block;
203-
}
204-
205-
.simple-dialog.BatchAnalysisResultDialog .body .BatchReportJsonError,
206-
.simple-dialog.BatchAnalysisResultDialog .body .BatchReportInjaError,
207-
.simple-dialog.BatchAnalysisResultDialog .body .BatchReportMiscError
208-
{
209-
color: red;
210-
}
211-
179+
/* Warning dialog styles (analysis result dialog styles moved to InjaLogDialog.css) */
212180
.simple-dialog.BatchAnalysisWarningDialog
213181
{
214-
182+
215183
}
216184

217185
.simple-dialog.BatchAnalysisWarningDialog .body
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Analysis result dialogs */
2+
.simple-dialog.InjaLogDialog
3+
{
4+
}
5+
6+
.simple-dialog.InjaLogDialog .body
7+
{
8+
/* The 95vh is from .simple-dialog, and the 90px is the header and footer height. */
9+
max-height: calc( 95vh - 90px );
10+
max-width: calc(95vw - 30px);
11+
overflow-y: hidden;
12+
overflow-x: hidden;
13+
padding-top: 16px;
14+
padding-bottom: 5px;
15+
display: flex;
16+
flex-direction: column;
17+
gap: 10px;
18+
}
19+
20+
/* Toolbar containing template selector and download button */
21+
.simple-dialog.InjaLogDialog .InjaLogToolbar
22+
{
23+
display: flex;
24+
flex-direction: row;
25+
gap: 10px;
26+
align-items: center;
27+
justify-content: space-between;
28+
padding: 5px 10px;
29+
flex-shrink: 0;
30+
}
31+
32+
.simple-dialog.InjaLogDialog .InjaLogTemplateSelector
33+
{
34+
flex-grow: 1;
35+
max-width: 300px;
36+
}
37+
38+
.simple-dialog.InjaLogDialog .InjaLogDownloadBtn
39+
{
40+
flex-shrink: 0;
41+
}
42+
43+
44+
.RefGammaCsv
45+
{
46+
47+
}
48+
49+
.simple-dialog.InjaLogDialog .body .InjaLogDialogIFrameHolder
50+
{
51+
border: solid 1px #e1e1e1;
52+
border-radius: 5px;
53+
display: block;
54+
flex-grow: 1;
55+
overflow: hidden;
56+
}
57+
58+
.simple-dialog.InjaLogDialog .body .InjaLogDialogJsonError,
59+
.simple-dialog.InjaLogDialog .body .InjaLogDialogInjaError,
60+
.simple-dialog.InjaLogDialog .body .InjaLogDialogMiscError
61+
{
62+
color: red;
63+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<messages>
3+
<!-- This file applies to InjaLogDialog.cpp - a reusable dialog for displaying inja-rendered content -->
4+
<message id="ild-no-templates">No templates provided.</message>
5+
<message id="ild-json-parse-error">
6+
<p>Error parsing JSON data:</p>
7+
<code>{1}</code>
8+
</message>
9+
<message id="ild-inja-error">
10+
<p>Error rendering template:</p>
11+
<code>{1}</code>
12+
<br />
13+
at line {2}, column {3}
14+
</message>
15+
<message id="ild-misc-error">
16+
<p>Error displaying content:</p>
17+
<code>{1}</code>
18+
</message>
19+
</messages>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<messages>
3+
<!-- This file applies to InjaLogDialog.cpp - a reusable dialog for displaying inja-rendered content -->
4+
<message id="ild-no-templates">لم يتم توفير قوالب.</message>
5+
<message id="ild-json-parse-error">
6+
<p>خطأ في تحليل بيانات JSON:</p>
7+
<code>{1}</code>
8+
</message>
9+
<message id="ild-inja-error">
10+
<p>خطأ في عرض القالب:</p>
11+
<code>{1}</code>
12+
<br />
13+
في السطر {2}، العمود {3}
14+
</message>
15+
<message id="ild-misc-error">
16+
<p>خطأ في عرض المحتوى:</p>
17+
<code>{1}</code>
18+
</message>
19+
</messages>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<messages>
3+
<!-- This file applies to InjaLogDialog.cpp - a reusable dialog for displaying inja-rendered content -->
4+
<message id="ild-no-templates">কোনো টেমপ্লেট প্রদান করা হয়নি।</message>
5+
<message id="ild-json-parse-error">
6+
<p>JSON ডেটা পার্স করতে ত্রুটি:</p>
7+
<code>{1}</code>
8+
</message>
9+
<message id="ild-inja-error">
10+
<p>টেমপ্লেট রেন্ডার করতে ত্রুটি:</p>
11+
<code>{1}</code>
12+
<br />
13+
লাইন {2}, কলাম {3} এ
14+
</message>
15+
<message id="ild-misc-error">
16+
<p>কন্টেন্ট প্রদর্শন করতে ত্রুটি:</p>
17+
<code>{1}</code>
18+
</message>
19+
</messages>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<messages>
3+
<!-- This file applies to InjaLogDialog.cpp - a reusable dialog for displaying inja-rendered content -->
4+
<message id="ild-no-templates">No se proporcionaron plantillas.</message>
5+
<message id="ild-json-parse-error">
6+
<p>Error al analizar datos JSON:</p>
7+
<code>{1}</code>
8+
</message>
9+
<message id="ild-inja-error">
10+
<p>Error al renderizar la plantilla:</p>
11+
<code>{1}</code>
12+
<br />
13+
en la línea {2}, columna {3}
14+
</message>
15+
<message id="ild-misc-error">
16+
<p>Error al mostrar el contenido:</p>
17+
<code>{1}</code>
18+
</message>
19+
</messages>

0 commit comments

Comments
 (0)