2021-01-16 01:31:39 +01:00
|
|
|
using QuestPDF.Fluent;
|
2021-04-16 01:19:34 +02:00
|
|
|
using QuestPDF.Helpers;
|
2021-01-16 01:31:39 +01:00
|
|
|
using QuestPDF.Infrastructure;
|
|
|
|
|
|
|
|
|
|
namespace QuestPDF.ReportSample.Layouts
|
|
|
|
|
{
|
|
|
|
|
public class SectionTemplate : IComponent
|
|
|
|
|
{
|
|
|
|
|
public ReportSection Model { get; set; }
|
|
|
|
|
|
|
|
|
|
public SectionTemplate(ReportSection model)
|
|
|
|
|
{
|
|
|
|
|
Model = model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Compose(IContainer container)
|
|
|
|
|
{
|
|
|
|
|
container
|
2021-04-16 01:19:34 +02:00
|
|
|
.EnsureSpace()
|
2021-05-02 21:11:08 +02:00
|
|
|
.Decoration(decoration =>
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
2021-05-02 21:11:08 +02:00
|
|
|
decoration
|
2021-01-16 01:31:39 +01:00
|
|
|
.Header()
|
|
|
|
|
.PaddingBottom(5)
|
|
|
|
|
.Text(Model.Title, Typography.Headline);
|
|
|
|
|
|
2021-05-02 21:11:08 +02:00
|
|
|
decoration.Content().Border(0.75f).BorderColor(Colors.Grey.Medium).Stack(stack =>
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
|
|
|
|
foreach (var part in Model.Parts)
|
|
|
|
|
{
|
2021-05-01 22:46:37 +02:00
|
|
|
stack.Item().Row(row =>
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
2021-04-16 01:19:34 +02:00
|
|
|
row.ConstantColumn(150).LabelCell().Text(part.Label, Typography.Normal);
|
|
|
|
|
var frame = row.RelativeColumn().ValueCell();
|
2021-01-16 01:31:39 +01:00
|
|
|
|
|
|
|
|
if (part is ReportSectionText text)
|
|
|
|
|
frame.Text(text.Text, Typography.Normal);
|
|
|
|
|
|
|
|
|
|
if (part is ReportSectionMap map)
|
2021-03-22 11:49:27 +01:00
|
|
|
frame.Element(x => MapElement(x, map));
|
2021-01-16 01:31:39 +01:00
|
|
|
|
|
|
|
|
if (part is ReportSectionPhotos photos)
|
2021-03-22 11:49:27 +01:00
|
|
|
frame.Element(x => PhotosElement(x, photos));
|
2021-01-16 01:31:39 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MapElement(IContainer container, ReportSectionMap model)
|
|
|
|
|
{
|
|
|
|
|
if (model.ImageSource == null || model.Location == null)
|
|
|
|
|
{
|
|
|
|
|
container.Text("No location provided", Typography.Normal);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 17:49:19 +02:00
|
|
|
container.ShowEntire().Stack(stack =>
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
|
|
|
|
stack.Spacing(5);
|
|
|
|
|
|
2021-05-01 22:46:37 +02:00
|
|
|
stack.Item().MaxWidth(250).AspectRatio(4 / 3f).Image(Placeholders.Image);
|
|
|
|
|
stack.Item().Text(model.Location.Format(), Typography.Normal);
|
2021-01-16 01:31:39 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhotosElement(IContainer container, ReportSectionPhotos model)
|
|
|
|
|
{
|
|
|
|
|
if (model.Photos.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
container.Text("No photos", Typography.Normal);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 23:11:29 +02:00
|
|
|
container.Debug("Photo gallery").Grid(grid =>
|
2021-01-16 01:31:39 +01:00
|
|
|
{
|
2021-03-28 17:49:19 +02:00
|
|
|
grid.Spacing(5);
|
|
|
|
|
grid.Columns(3);
|
|
|
|
|
|
2021-05-02 21:11:08 +02:00
|
|
|
model.Photos.ForEach(x => grid.Item().AspectRatio(4 / 3f).Image(Placeholders.Image));
|
2021-01-16 01:31:39 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|