Skip to content

Commit 8eeabb4

Browse files
authored
MMI-3341 Fix front page images (#2490)
DB Migration 1.3.33
1 parent 8e79e5e commit 8eeabb4

File tree

14 files changed

+8866
-16
lines changed

14 files changed

+8866
-16
lines changed

app/editor/src/features/admin/report-templates/templates/body/CustomReport.cshtml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
var pageBreak = Settings.Sections.UsePageBreaks ? "page-break-after: always;" : "";
88
var utcOffset = ReportExtensions.GetUtcOffset(System.DateTime.Now, "Pacific Standard Time");
99
var hasImages = Sections.Any(section => section.Value.SectionType == TNO.Entities.ReportSectionType.Image);
10+
var subscriberAppUrl = @SubscriberAppUrl?.ToString();
1011
}
1112

1213
<style>
@@ -18,7 +19,7 @@
1819
1920
</style>
2021

21-
<center><div style="margin-bottom: 25px; color:#FFFFF6;"><img src="@($"{SubscriberAppUrl}assets/reports/MMI_logo_white.png")" width="600"></div></center>
22+
<center><div style="margin-bottom: 25px; color:#FFFFF6;"><img src="@($"{subscriberAppUrl}assets/reports/MMI_logo_white.png")" width="600"></div></center>
2223

2324
@* This is the Do Not Forward disclaimer *@
2425
<div><p style="background-color: #FFF7E1; color: #876503; text-align: center; font-size: 1em; font-weight: 700; line-height: 1.1em; letter-spacing: 0.08px; padding: 10px 0px; margin: 6px 0px 20px 0px;">DO NOT FORWARD THIS REPORT IN FULL &mdash; OR IN PART &mdash; TO ANYONE</p></div>
@@ -190,7 +191,8 @@
190191
}
191192

192193
var containImage = body.Contains("<img");
193-
var hasImageToDisplay = (!string.IsNullOrEmpty(content.ImageContent) && section.Value.Settings.ShowImage) || containImage;
194+
var filePath = content.FileReferences.FirstOrDefault()?.Path;
195+
var hasImageToDisplay = ((!string.IsNullOrEmpty(content.ImageContent) || !string.IsNullOrEmpty(filePath)) && section.Value.Settings.ShowImage) || containImage;
194196

195197
/**
196198
* Checks if there is no image to display and the section settings do not allow showing the full story.
@@ -254,23 +256,31 @@
254256
}
255257
@if (hasImageToDisplay)
256258
{
257-
var src = $"data:{content.ContentType};base64," + content.ImageContent;
258-
<div><img src="@src" alt="@content.FileReferences.FirstOrDefault()?.FileName" /></div>
259+
if (!string.IsNullOrEmpty(content.ImageContent) && section.Value.Settings.ShowImage)
260+
{
261+
var src = $"data:{content.ContentType};base64," + content.ImageContent;
262+
<div><img src="@src" alt="@content.FileReferences.FirstOrDefault()?.FileName" /></div>
263+
}
264+
else if (!string.IsNullOrEmpty(filePath) && section.Value.Settings.ShowImage)
265+
{
266+
var apiFileUrl = subscriberAppUrl + "api/subscriber/contents/download?path=" + filePath;
267+
<div><img src="@(apiFileUrl)" alt="@content.Headline" /></div>
268+
}
259269
}
260270
@if (Settings.Content.ShowLinkToStory && !isPrivate)
261271
{
262272
@* LINK TO STORY ON WEBSITE *@
263273
<div>
264274
<span style="font-size: .85em; text-transform:uppercase; vertical-align: middle; background-color:#FFF; border:#ccc 1px solid; margin:20 auto; padding:6px 10px;">
265-
<a href="@($"{ViewContentUrl}{content.Id}")" target="_blank" style="color: #6750a4; text-decoration: none;">View Article <img height="14" style="max-width: 14px; height: 14px;" valign="absmiddle" src="@($"{SubscriberAppUrl}assets/reports/follow_link.png")"></a>
275+
<a href="@($"{ViewContentUrl}{content.Id}")" target="_blank" style="color: #6750a4; text-decoration: none;">View Article <img height="14" style="max-width: 14px; height: 14px;" valign="absmiddle" src="@($"{subscriberAppUrl}assets/reports/follow_link.png")"></a>
266276
</span>
267277
</div>
268278
}
269279
else if (Settings.Content.ShowLinkToStory)
270280
{
271281
<div>
272282
<span style="font-size: .85em; text-transform:uppercase; vertical-align: middle; background-color:#FFF; border:#ccc 1px solid; margin:20 auto; padding:6px 10px;">
273-
<a rel="noreferrer" href="@($"{sourceUrl}")" target="_blank" style="color: #6750a4; text-decoration: none;">View Article (external site)<img height="14" style="max-width: 14px; height: 14px;" valign="absmiddle" src="@($"{SubscriberAppUrl}assets/reports/follow_link.png")"></a>
283+
<a rel="noreferrer" href="@($"{sourceUrl}")" target="_blank" style="color: #6750a4; text-decoration: none;">View Article (external site)<img height="14" style="max-width: 14px; height: 14px;" valign="absmiddle" src="@($"{subscriberAppUrl}assets/reports/follow_link.png")"></a>
274284
</span>
275285
</div>
276286
}
@@ -298,10 +308,19 @@
298308
@for (var i = 0; i < sectionContent.Length; i++)
299309
{
300310
var content = sectionContent[i];
301-
var fileName = content.FileReferences.FirstOrDefault()?.FileName ?? content.Id.ToString();
302-
var src = $"data:{content.ContentType};base64," + content.ImageContent;
311+
var filePath = content.FileReferences.FirstOrDefault()?.Path;
303312

304-
<img style="height:min-content" src="@src" alt="@fileName" />
313+
if (!string.IsNullOrEmpty(content.ImageContent))
314+
{
315+
var src = $"data:{content.ContentType};base64," + content.ImageContent;
316+
var fileName = content.FileReferences.FirstOrDefault()?.FileName ?? content.Id.ToString();
317+
<img style="height:min-content" src="@src" alt="@fileName" />
318+
}
319+
else if (!string.IsNullOrEmpty(filePath))
320+
{
321+
var apiFileUrl = subscriberAppUrl + "api/subscriber/contents/download?path=" + filePath;
322+
<img style="height:min-content" src="@(apiFileUrl)" alt="@content.Headline" />
323+
}
305324
}
306325
</div>
307326
}
@@ -310,13 +329,18 @@
310329
for (var i = 0; i < sectionContent.Length; i++)
311330
{
312331
var content = sectionContent[i];
313-
var fileName = content.FileReferences.FirstOrDefault()?.FileName ?? content.Id.ToString();
314-
var src = $"data:{content.ContentType};base64," + content.ImageContent;
332+
var filePath = content.FileReferences.FirstOrDefault()?.Path;
333+
315334
if (!string.IsNullOrEmpty(content.ImageContent))
316335
{
317-
<div>
318-
<img style="height:min-content" src="@src" alt="@fileName" />
319-
</div>
336+
var src = $"data:{content.ContentType};base64," + content.ImageContent;
337+
var fileName = content.FileReferences.FirstOrDefault()?.FileName ?? content.Id.ToString();
338+
<div><img style="height:min-content" src="@src" alt="@fileName" /></div>
339+
}
340+
else if (!string.IsNullOrEmpty(filePath))
341+
{
342+
var apiFileUrl = subscriberAppUrl + "api/subscriber/contents/download?path=" + filePath;
343+
<div><img style="height:min-content" src="@(apiFileUrl)" alt="@content.Headline" /></div>
320344
}
321345
}
322346
}
@@ -357,7 +381,7 @@
357381
@* FOOTER *@
358382
<div style="width:100%">
359383
<hr style="background-color:#646293; border-width:0;height:1px;line-height:0;width:100%; margin-top:20px; margin-bottom:10px;"/>
360-
<a style="text-transform:uppercase; color:#fff;" href="@($"{SubscriberAppUrl}{(ReportInstanceId.HasValue ? $"report/instances/{ReportInstanceId }" : $"reports/{ReportId}")}/view")" target="_blank">
384+
<a style="text-transform:uppercase; color:#fff;" href="@($"{subscriberAppUrl}{(ReportInstanceId.HasValue ? $"report/instances/{ReportInstanceId }" : $"reports/{ReportId}")}/view")" target="_blank">
361385
<div style="vertical-align:middle; text-align: center; background-color:#6750A4; border:#ccc 1px solid; margin:20px 20px; padding:6px 10px;">
362386
View this report as a web page
363387
</div>

app/editor/src/features/admin/report-templates/templates/body/FrontPagesReport.cshtml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@{
77
var pageBreak = Settings.Sections.UsePageBreaks ? "page-break-after: always;" : "";
88
var utcOffset = ReportExtensions.GetUtcOffset(System.DateTime.Now, "Pacific Standard Time");
9+
var subscriberAppUrl = @SubscriberAppUrl?.ToString();
910
}
1011
<h1 id="top" style="margin: 0; padding: 0;">@Settings.Subject.Text</h1>
1112
<a name="top"></a>
@@ -38,6 +39,8 @@ else
3839
for (var i = 0; i < sectionContent.Length; i++)
3940
{
4041
var content = sectionContent[i];
42+
var filePath = content.FileReferences.FirstOrDefault()?.Path;
43+
var apiFileUrl = subscriberAppUrl + "api/subscriber/contents/download?path=" + filePath;
4144
<div style="width:20rem;padding:0.5rem;">
4245
<h3>@content.Source?.Name</h3>
4346
<p>@content.PublishedOn?.AddHours(utcOffset).ToString("dddd, MMMM d, yyyy")</p>
@@ -46,6 +49,10 @@ else
4649
var src = $"data:{content.ContentType};base64," + content.ImageContent;
4750
<p><img src="@src" alt="@content.FileReferences.FirstOrDefault()?.FileName" /></p>
4851
}
52+
else if (!string.IsNullOrEmpty(filePath))
53+
{
54+
<p><img src="@(apiFileUrl)" alt="@(content.Headline)" /></p>
55+
}
4956
</div>
5057
}
5158
}
@@ -59,4 +66,4 @@ else
5966
intended for original addressee. All content is the copyrighted property of a third party creator of the material.
6067
Copying, retransmitting, archiving, redistributing, selling, licensing, or emailing the material to any third party
6168
or any employee of the Province who is not authorized to access the material is prohibited.
62-
</p>
69+
</p>

app/editor/src/features/admin/reports/components/ReportSectionContent.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export const ReportSectionContent = ({ index }: IReportSectionContentProps) => {
9797
label="Show Image"
9898
tooltip="Display the image for each content item in this section (if there is an image)"
9999
/>
100+
<FormikCheckbox
101+
name={`sections.${index}.settings.convertToBase64Image`}
102+
label="Convert Images to Base64"
103+
tooltip="This format is not well supported by all email clients and can significantly increase the size of the report. Use with caution."
104+
/>
100105
<Checkbox
101106
name={`sections.${index}.settings.inTableOfContents`}
102107
label="Include in Table of Contents"

app/editor/src/features/admin/reports/components/ReportSectionGallery.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export const ReportSectionGallery = ({ index }: IReportSectionGalleryProps) => {
8686
label="Show Image"
8787
tooltip="Display the image for each content item in this section (if there is an image)"
8888
/>
89+
<FormikCheckbox
90+
name={`sections.${index}.settings.convertToBase64Image`}
91+
label="Convert Images to Base64"
92+
tooltip="This format is not well supported by all email clients and can significantly increase the size of the report. Use with caution."
93+
/>
8994
<Checkbox
9095
name={`sections.${index}.settings.inTableOfContents`}
9196
label="Include in Table of Contents"

app/editor/src/features/admin/reports/components/ReportSectionImage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export const ReportSectionImage = ({ index }: IReportSectionImageProps) => {
4242
label="Cache Image"
4343
tooltip="Save a copy in MMI"
4444
/>
45+
<FormikCheckbox
46+
name={`sections.${index}.settings.convertToBase64Image`}
47+
label="Convert Images to Base64"
48+
tooltip="This format is not well supported by all email clients and can significantly increase the size of the report. Use with caution."
49+
/>
4550
</Col>
4651
);
4752
};

app/subscriber/src/features/my-reports/edit/settings/template/ReportSectionContent.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export const ReportSectionContent = React.forwardRef<HTMLDivElement, IReportSect
6767
label="Show Image"
6868
tooltip="Display the image for each content item in this section (if there is an image)"
6969
/>
70+
<FormikCheckbox
71+
name={`sections.${index}.settings.convertToBase64Image`}
72+
label="Convert Images to Base64"
73+
tooltip="This format is not well supported by all email clients and can significantly increase the size of the report. Use with caution."
74+
/>
7075
<FormikCheckbox
7176
name={`sections.${index}.settings.showHeadlines`}
7277
label="Show additional Table of Content for this section"

app/subscriber/src/features/my-reports/edit/settings/template/ReportSectionGallery.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export const ReportSectionGallery = React.forwardRef<HTMLDivElement, IReportSect
6262
label="Show Image"
6363
tooltip="Display the image for each content item in this section (if there is an image)"
6464
/>
65+
<FormikCheckbox
66+
name={`sections.${index}.settings.convertToBase64Image`}
67+
label="Convert Images to Base64"
68+
tooltip="This format is not well supported by all email clients and can significantly increase the size of the report. Use with caution."
69+
/>
6570
<Checkbox
6671
name={`sections.${index}.settings.inTableOfContents`}
6772
label="Include in Table of Contents"

app/subscriber/src/features/my-reports/edit/settings/template/ReportSectionImage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export const ReportSectionImage = React.forwardRef<HTMLDivElement, IReportSectio
3535
label="Cache Image"
3636
tooltip="This will cache the image in MMI"
3737
/>
38+
<FormikCheckbox
39+
name={`sections.${index}.settings.convertToBase64Image`}
40+
label="Convert Images to Base64"
41+
tooltip="This format is not well supported by all email clients and can significantly increase the size of the report. Use with caution."
42+
/>
3843
<Col>
3944
<FormikText name={`sections.${index}.settings.url`} label="URL" required />
4045
</Col>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
DO $$
2+
BEGIN
3+
4+
-- Update custom report with latest template.
5+
UPDATE public."report_template" SET
6+
"body" = '@inherits RazorEngineCore.RazorEngineTemplateBase<TNO.TemplateEngine.Models.Reports.ReportEngineContentModel>
7+
@using System
8+
@using System.Linq
9+
@using TNO.Entities
10+
@using TNO.TemplateEngine
11+
@{
12+
var pageBreak = Settings.Sections.UsePageBreaks ? "page-break-after: always;" : "";
13+
var utcOffset = ReportExtensions.GetUtcOffset(System.DateTime.Now, "Pacific Standard Time");
14+
}
15+
<h1 id="top" style="margin: 0; padding: 0;">@Settings.Subject.Text</h1>
16+
<a name="top"></a>
17+
<div style="color:red;">DO NOT FORWARD THIS EMAIL TO ANYONE</div>
18+
<br />
19+
20+
@if (Content.Count() == 0)
21+
{
22+
<p>There is no content in this report.</p>
23+
}
24+
@if (ViewOnWebOnly)
25+
{
26+
<a href="@($"{SubscriberAppUrl}landing/todaysfrontpages")" target="_blank">Click to view this report online</a>
27+
}
28+
else
29+
{
30+
foreach (var section in Sections)
31+
{
32+
var sectionContent = section.Value.Content.ToArray();
33+
if (section.Value.IsEnabled &&
34+
(sectionContent.Length > 0 ||
35+
!section.Value.Settings.HideEmpty ||
36+
(section.Value.SectionType == ReportSectionType.TableOfContents)
37+
&& Content.Any()))
38+
{
39+
<div style="@pageBreak;display:flex; flex-flow:row wrap;">
40+
@* Full Stories *@
41+
@if (section.Value.Settings.ShowFullStory)
42+
{
43+
for (var i = 0; i < sectionContent.Length; i++)
44+
{
45+
var content = sectionContent[i];
46+
<div style="width:20rem;padding:0.5rem;">
47+
<h3>@content.Source?.Name</h3>
48+
<p>@content.PublishedOn?.AddHours(utcOffset).ToString("dddd, MMMM d, yyyy")</p>
49+
@if (!string.IsNullOrEmpty(content.ImageContent))
50+
{
51+
var src = $"data:{content.ContentType};base64," + content.ImageContent;
52+
<p><img src="@src" alt="@content.FileReferences.FirstOrDefault()?.FileName" /></p>
53+
}
54+
</div>
55+
}
56+
}
57+
</div>
58+
}
59+
}
60+
}
61+
62+
<p style="font-size: 9pt; margin-top: 0.5rem;">
63+
Terms of Use - This summary is a service provided by Government Communications and Public Engagement and is only
64+
intended for original addressee. All content is the copyrighted property of a third party creator of the material.
65+
Copying, retransmitting, archiving, redistributing, selling, licensing, or emailing the material to any third party
66+
or any employee of the Province who is not authorized to access the material is prohibited.
67+
</p>
68+
'
69+
WHERE "name" = 'Frontpages Report';
70+
71+
END $$;

0 commit comments

Comments
 (0)