CriterionTarget.cs 4.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using iText.Kernel.Colors;
using iText.Layout;
using iText.Layout.Element;
using PDFGenerator.Utilities;
using System.Collections.Generic;
using System.Linq;
using static PDFGenerator.Utilities.Globals;
using Target = PDFGenerator.Models.CriterionTarget;

namespace PDFGenerator.EvaluationReport
{
    public class CriterionTarget : BaseSection
    {
        private Target Target { get; }
        private int SectionIndent { get; }
        private Dictionary<string, byte[]> CustomUploads { get; set; }

        public CriterionTarget(Target target, int sectionDepth, Dictionary<string, byte[]> customUploads, Document document,
            Bookmarks bookmarks, TableOfContents tableOfContents) : base(document, bookmarks, tableOfContents)
        {
            Target = target;
            SectionIndent = sectionDepth;
            CustomUploads = customUploads;
        }

        /// <summary>
        /// Renders the content specific to the criterion target.
        /// </summary>
        public override void Render()
        {
            int count = 0;
            string section = Target.Paragraphs[count++];
            string description = Target.Paragraphs[count++];

            Bookmarks.AddOutline(section, OutlineLevel.Level2);

            TocItem tocItem = new TocItem
            {
                Title = section,
                Indent = SectionIndent,
                Page = GetCurrentPage()
            };
            TableOfContents.AddToTOC(tocItem);

            Style style = Styles.H3;
            style.SetFontColor(ColorConstants.WHITE);


            Paragraph paragraph = new Paragraph(new Text(section).AddStyle(style))
            .SetMultipliedLeading(0.85f)
            .SetDestination(section);

            style = Styles.Paragraph.SetItalic();
            style.SetFontColor(ColorConstants.WHITE);

            paragraph.Add(NewLine)
            .Add(new Text(description).AddStyle(style));

            DeviceRgb color = new DeviceRgb(142, 186, 229);

            if (!Target.Selected)
            {
                color = new DeviceRgb(156, 158, 159);
            }

            Document.Add(Panel.GetPanel(paragraph, color));


            style.SetFontColor(ColorConstants.BLACK);
70
            if (!Target.Selected && Target.EvaluatedCriterions == null && (count < Target.Paragraphs.Count))
71
72
73
74
75
76
77
78
79
80
            {
                Document.Add(new Paragraph(new Text(Target.Paragraphs[count++]).AddStyle(style))
                    .Add(NewLine)
                );
            }

            if (Target.EvaluatedCriterions != null)
            {
                if (Target.EvaluatedCriterions.Any(evaluatedCrit => !string.IsNullOrEmpty(evaluatedCrit.Description)))
                {
Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
81
82
                    // aimed target
                    Document.Add(ParagraphFactory.GetCustomParagraph(Target.Paragraphs[count++], Styles.H4, 5f, 2f, 1.15f));
83
84
85
86
87
88
89
90
91
92
93
                }

                Target.EvaluatedCriterions.ForEach(item =>
                {
                    if (!string.IsNullOrEmpty(item.Description))
                    {
                        if (!string.IsNullOrEmpty(item.CourseName))
                        {
                            Document.Add(ParagraphFactory.GetCustomParagraph(item.CourseName, Styles.H5, 5f, 5f, 1.15f));
                        }

Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
94
                        // avoid that existent multiple whitespaces after a line break are ignored by iText7
95
                        Document.Add(ParagraphFactory.GetStandardParagraph(PreserveLeadingSpaces(item.Description)));
96
97
98
99
100
                    }
                });

                if (Target.EvaluatedCriterions.Any(evaluatedCrit => !string.IsNullOrEmpty(evaluatedCrit.Comment)))
                {
Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
101
102
                    // actual state
                    Document.Add(ParagraphFactory.GetCustomParagraph(Target.Paragraphs[count++], Styles.H4, 5f, 2f, 1.15f));
103
104
105
106
107
108
109
110
111
112
113
                }

                Target.EvaluatedCriterions.ForEach(item =>
                {
                    if (!string.IsNullOrEmpty(item.Comment))
                    {
                        if (!string.IsNullOrEmpty(item.CourseName))
                        {
                            Document.Add(ParagraphFactory.GetCustomParagraph(item.CourseName, Styles.H5, 5f, 5f, 1.15f));
                        }

114
                        Document.Add(ParagraphFactory.GetStandardParagraph(PreserveLeadingSpaces(item.Comment)));
115
116
117
118
119
120
121
122
123
124
125
                    }
                });
            }

            if (Target.UploadedFilesForCriterion != null)
            {
                AddCustomUploads(Target.UploadedFilesForCriterion, CustomUploads);
            }
        }
    }
}