CriterionTarget.cs 4.67 KB
Newer Older
1
2
3
4
5
6
7
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;
8
9
using Styles = PDFGenerator.Utilities.Globals.Constants.EvaluationReport.Styles;
using Target = PDFGenerator.Models.EvaluationReport.CriterionTarget;
10

11
namespace PDFGenerator.DocumentStructures.EvaluationReport
12
{
13
    public class CriterionTarget : EvaluationReportBaseSection
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
70
    {
        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);
71
            if (!Target.Selected && Target.EvaluatedCriterions == null && (count < Target.Paragraphs.Count))
72
73
74
75
76
77
78
79
80
81
            {
                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
82
83
                    // aimed target
                    Document.Add(ParagraphFactory.GetCustomParagraph(Target.Paragraphs[count++], Styles.H4, 5f, 2f, 1.15f));
84
85
86
87
88
89
90
91
92
93
94
                }

                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
95
                        // avoid that existent multiple whitespaces after a line break are ignored by iText7
96
                        Document.Add(ParagraphFactory.GetStandardParagraph(PreserveLeadingSpaces(item.Description)));
97
98
99
100
101
                    }
                });

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

                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));
                        }

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

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