This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Add competence profile Word version #107
Draft
kallepronk
wants to merge
7
commits into
develop
Choose a base branch
from
feature/word-competence-profile
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ab1029
CompetenceProfile table for word export
kallepronk 0ea8664
Fixed mastery level colors in competenceProfile wordexport
kallepronk 933c6d0
Added proffesional skills to word export competence profile
kallepronk 3bc5e10
Removed unnecessary variable
kallepronk e675c6f
Refactored file structure
kallepronk d6dcbdc
Bugfix for showing all architectures
NealGeilen f7799b8
Bugfix for showing all architectures
NealGeilen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using DocumentFormat.OpenXml; | ||
using DocumentFormat.OpenXml.Packaging; | ||
using DocumentFormat.OpenXml.Wordprocessing; | ||
using Epsilon.Abstractions.Model; | ||
|
@@ -12,17 +13,188 @@ IEnumerable<ProfessionalSkillResult> ProfessionalSkillOutcomes | |
{ | ||
public void AddToWordDocument(MainDocumentPart mainDocumentPart) | ||
{ | ||
// TODO: This is simply an example to show the capability of the component architecture | ||
var body = new Body(); | ||
|
||
body.AppendChild( | ||
new Paragraph( | ||
new Run( | ||
new Text("Competence profile comes here") | ||
) | ||
) | ||
); | ||
body.Append(new Paragraph(new Run(new Text("")))); | ||
body.AppendChild(GetTasks()); | ||
body.Append(new Paragraph(new Run(new Text("")))); | ||
body.AppendChild(GetSkills()); | ||
body.Append(new Paragraph(new Run(new Text("")))); | ||
body.AppendChild(GetLegend()); | ||
body.Append(new Paragraph(new Run(new Text("")))); | ||
|
||
|
||
mainDocumentPart.Document.AppendChild(body); | ||
} | ||
|
||
private OpenXmlElement GetTasks() | ||
{ | ||
// Create a table, with rows for the outcomes and columns for the assignments. | ||
var table = new Table(); | ||
|
||
var tasks = ProfessionalTaskOutcomes | ||
.GroupBy(static task => task.ArchitectureLayer) | ||
.Select(static group => new | ||
{ | ||
architectureId = group.Key, | ||
activities = group | ||
.GroupBy(static act => act.Activity) | ||
.Select(static group => new { activityId = group.Key, count = group.Count(), masteryLevel = group.Max(static m => m.MasteryLevel), }) | ||
.OrderBy(static i => i.activityId).ToList(), | ||
}).OrderBy(static i => i.architectureId).ToList(); | ||
|
||
// Set table properties for formatting. | ||
table.AppendChild(new TableProperties( | ||
new TableWidth { Width = "8", Type = TableWidthUnitValues.Auto, })); | ||
|
||
var headerRow = new TableRow(); | ||
|
||
// Empty top-left cell. | ||
headerRow.AppendChild(CreateTableCellWithBorders("2500", new Paragraph(new Run(new Text(""))))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you specify what these values are " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk what these values are, still need to figure out what they do |
||
|
||
foreach (var activity in HboIDomain.Activities) | ||
{ | ||
var cell = CreateTableCellWithBorders("500"); | ||
cell.FirstChild.Append(new TextDirection { Val = TextDirectionValues.LeftToRightTopToBottom2010, }); | ||
|
||
cell.Append(new Paragraph(new Run(new Text(activity.Name)))); | ||
headerRow.AppendChild(cell); | ||
} | ||
|
||
table.AppendChild(headerRow); | ||
|
||
foreach (var architectureLayer in HboIDomain.ArchitectureLayers) | ||
{ | ||
var row = new TableRow(); | ||
// Add the outcome title cell. | ||
row.AppendChild(CreateTableCellWithBorders("2500", | ||
new Paragraph(new Run(new | ||
Text(architectureLayer.Name))))); | ||
foreach (var architecture in tasks.Where(t => t.architectureId == architectureLayer.Id)) | ||
{ | ||
// Add the assignment cells. | ||
foreach (var activityValue in HboIDomain.Activities) | ||
{ | ||
var fillColor = "#fffff"; | ||
var kpiCount = 0; | ||
var cell = CreateTableCellWithBorders("500"); | ||
if (architecture.activities.Exists(x => x.activityId == activityValue.Id)) | ||
{ | ||
var activity = | ||
architecture | ||
.activities | ||
.First(x => x.activityId == activityValue.Id); | ||
// Set cell color based on GradeStatus. | ||
fillColor = HboIDomain.MasteryLevels.FirstOrDefault(x => x.Id == activity.masteryLevel).Color; | ||
kpiCount = activity.count; | ||
} | ||
|
||
cell.FirstChild?.Append(new Shading { Fill = fillColor, }); | ||
cell.Append(new Paragraph(new Run(new Text($"{kpiCount}")))); | ||
row.AppendChild(cell); | ||
} | ||
} | ||
table.AppendChild(row); | ||
} | ||
return table; | ||
} | ||
|
||
private OpenXmlElement GetSkills() | ||
{ | ||
var table = new Table(); | ||
|
||
var skills = ProfessionalSkillOutcomes | ||
.GroupBy(static x => x.Skill) | ||
.Select(group => new | ||
{ | ||
skillId = group.Key, | ||
count = group.Count(), | ||
maxMastery = HboIDomain | ||
.MasteryLevels | ||
.FirstOrDefault( | ||
x => x.Id == group.Max( | ||
static m => m.MasteryLevel)), | ||
}); | ||
|
||
// Set table properties for formatting. | ||
table.AppendChild(new TableProperties( | ||
new TableWidth { Width = "4", Type = TableWidthUnitValues.Auto, })); | ||
|
||
// Create the table header row. | ||
var headerRow = new TableRow(); | ||
|
||
|
||
foreach (var skill in HboIDomain.ProfessionalSkills) | ||
{ | ||
var cell = CreateTableCellWithBorders("500"); | ||
cell.FirstChild.Append(new TextDirection { Val = TextDirectionValues.LeftToRightTopToBottom2010, }); | ||
|
||
|
||
cell.Append(new Paragraph(new Run(new Text(skill.Name)))); | ||
headerRow.AppendChild(cell); | ||
} | ||
|
||
table.AppendChild(headerRow); | ||
var valueRow = new TableRow(); | ||
|
||
foreach (var skill in HboIDomain.ProfessionalSkills) | ||
{ | ||
var value = skills.First(x => x.skillId == skill.Id); | ||
var cell = CreateTableCellWithBorders("500"); | ||
cell.FirstChild?.Append(new Shading { Fill = value.maxMastery.Color, }); | ||
cell.Append(new Paragraph(new Run(new Text($"{value.count}")))); | ||
valueRow.AppendChild(cell); | ||
} | ||
|
||
table.AppendChild(valueRow); | ||
|
||
return table; | ||
} | ||
|
||
private OpenXmlElement GetLegend() | ||
{ | ||
var table = new Table(); | ||
|
||
foreach (var level in HboIDomain.MasteryLevels) | ||
{ | ||
var row = new TableRow(); | ||
var cellName = CreateTableCellWithBorders("200"); | ||
cellName.Append(new Paragraph(new Run(new Text($"Level: {level.Level}")))); | ||
|
||
var cellValue = CreateTableCellWithBorders("600"); | ||
cellValue.Append(new Paragraph(new Run(new Text("")))); | ||
cellValue.FirstChild?.Append(new Shading { Fill = level.Color, }); | ||
row.AppendChild(cellName); | ||
row.AppendChild(cellValue); | ||
table.AppendChild(row); | ||
} | ||
|
||
return table; | ||
} | ||
|
||
private static TableCell CreateTableCellWithBorders(string? width, params OpenXmlElement[] elements) | ||
{ | ||
var cell = new TableCell(); | ||
var cellProperties = new TableCellProperties(); | ||
var borders = new TableCellBorders( | ||
new LeftBorder { Val = BorderValues.Single, }, | ||
new RightBorder { Val = BorderValues.Single, }, | ||
new TopBorder { Val = BorderValues.Single, }, | ||
new BottomBorder { Val = BorderValues.Single, }); | ||
|
||
foreach (var element in elements) | ||
{ | ||
cell.Append(element); | ||
} | ||
|
||
if (width != null) | ||
{ | ||
cellProperties.Append(new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = width, }); | ||
} | ||
|
||
cellProperties.Append(borders); | ||
cell.PrependChild(cellProperties); | ||
|
||
return cell; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these
body.Append(new Paragraph(new Run(new Text(""))));
nessecary. It seems kind of bloated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these are not included, all the tables will merge together, will be automatically fixed with the refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you atleast replace it with something like a line break?