From 54d1c970ca0a7785a2d03ea2af7aa47db0d48967 Mon Sep 17 00:00:00 2001 From: juanpms2 Date: Fri, 7 Jul 2023 14:29:54 +0200 Subject: [PATCH 1/2] updated soft skills --- .../src/common-app/helpers/index.ts | 1 + .../helpers/render-elements.helpers.ts | 28 ++++++++ .../src/common-app/model/doc-parts.vm.ts | 24 +++++++ .../soft-skill-section.part.ts | 71 ++++++++++--------- .../soft-skill.constants.ts | 2 + 5 files changed, 94 insertions(+), 32 deletions(-) create mode 100644 packages/manfred2word/src/common-app/helpers/index.ts create mode 100644 packages/manfred2word/src/common-app/helpers/render-elements.helpers.ts create mode 100644 packages/manfred2word/src/common-app/model/doc-parts.vm.ts diff --git a/packages/manfred2word/src/common-app/helpers/index.ts b/packages/manfred2word/src/common-app/helpers/index.ts new file mode 100644 index 00000000..7e906df6 --- /dev/null +++ b/packages/manfred2word/src/common-app/helpers/index.ts @@ -0,0 +1 @@ +export * from './render-elements.helpers'; diff --git a/packages/manfred2word/src/common-app/helpers/render-elements.helpers.ts b/packages/manfred2word/src/common-app/helpers/render-elements.helpers.ts new file mode 100644 index 00000000..d4180342 --- /dev/null +++ b/packages/manfred2word/src/common-app/helpers/render-elements.helpers.ts @@ -0,0 +1,28 @@ +import { IParagraphOptions, IRunOptions, Paragraph, Table, TableCell, TableRow, TextRun, XmlComponent } from 'docx'; +import { TableStyles } from '../model/doc-parts.vm'; + +export const renderTable = (rows: TableRow[], styles?: TableStyles): XmlComponent => + new Table({ + ...styles, + rows: [...rows], + }); + +export const renderTableRow = (cells: TableCell[], styles?: TableStyles): TableRow => + new TableRow({ + ...styles, + children: [...cells], + }); + +export const renderTableCell = (children: XmlComponent[], styles?: TableStyles): TableCell => + new TableCell({ + ...styles, + children: [...children], + }); + +export const renderParagraph = (children: XmlComponent[], opcions?: IParagraphOptions): XmlComponent => + new Paragraph({ + ...opcions, + children: [...children], + }); + +export const renderTextRun = (text: string, options?: IRunOptions): XmlComponent => new TextRun({ ...options, text }); diff --git a/packages/manfred2word/src/common-app/model/doc-parts.vm.ts b/packages/manfred2word/src/common-app/model/doc-parts.vm.ts new file mode 100644 index 00000000..60e2f495 --- /dev/null +++ b/packages/manfred2word/src/common-app/model/doc-parts.vm.ts @@ -0,0 +1,24 @@ +import { + IImageOptions, + IParagraphPropertiesOptions, + IRunOptions, + ISectionOptions, + ITableCellOptions, + ITableOptions, + ITableRowOptions, +} from 'docx'; +import { IPropertiesOptions } from 'docx/build/file/core-properties'; + +export type SectionStyles = Omit; +export type DocumentStyle = Omit; +export type TableStyles = Omit; +export type TableCellStyles = Omit; +export type TableRowStyles = Omit; +export type TextRunStyles = Omit; +export type ParagraphStyles = IParagraphPropertiesOptions; +export type ImageStyles = Omit; + +export interface RowProperties { + rowStyles?: TableRowStyles; + cellStyles?: TableCellStyles; +} diff --git a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts index ab069197..2b5a68e7 100644 --- a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts +++ b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill-section.part.ts @@ -1,40 +1,47 @@ import { ManfredAwesomicCV } from '@/model'; -import { TableCell, TableRow, Table } from 'docx'; -import { titleSoftSkillSection, sectionSoftSkillSection } from './sections-soft-skill-section.parts'; +import { + renderParagraph, + renderTable, + renderTableCell, + renderTableRow, + renderTextRun, +} from '@/common-app/helpers/render-elements.helpers'; +import { TableRow, Table, XmlComponent } from 'docx'; import { SoftSkillVM } from './soft-skill-section.vm'; import { styles } from './soft-skill-section.styles'; import { mapFromCvToSoftSkillVm } from './soft-skill-section.mapper'; +import { sectionTitle } from './soft-skill.constants'; -export const generateSoftSkillSection = (cv: ManfredAwesomicCV): Table => { - const profileSectionVm = mapFromCvToSoftSkillVm(cv); +const getSkillNameList = (skillList: SoftSkillVM[]): string[] => + skillList.map(item => (item.skill?.name ? item.skill?.name : '')); + +const createSkillListWithSeparator = (skillList: string[]): XmlComponent[] => + skillList.map((item, index) => (index === skillList.length - 1 ? renderTextRun(item) : renderTextRun(`${item} / `))); + +const createSkillsTableRow = (skillList: SoftSkillVM[]): TableRow => { + const list = getSkillNameList(skillList); + const skillListWithSeparator = createSkillListWithSeparator(list); + const paragraph = renderParagraph(skillListWithSeparator, { spacing: { before: 200 } }); + const cell = renderTableCell([paragraph]); + const row = renderTableRow([cell]); - return generateSoftSkillSectionInner(profileSectionVm); + return row; }; -export const generateSoftSkillSectionInner = (softSkillSctionVm: SoftSkillVM[]): Table => - new Table({ - ...styles.table, - rows: [generateTitleSoftSkill(), ...generateSectionSoftSkillFromVmToRows(softSkillSctionVm)], - }); - -const generateTitleSoftSkill = (): TableRow => - new TableRow({ - children: [ - new TableCell({ - children: [titleSoftSkillSection()], - }), - ], - }); - -const generateSectionSoftSkillFromVmToRows = (softSkillSectionVm: SoftSkillVM[]): TableRow[] => - Boolean(softSkillSectionVm) ? softSkillSectionVm.map(softSkillVm => softSkillsSection(softSkillVm)) : []; - -const softSkillsSection = (sectionSoftSkillVm: SoftSkillVM): TableRow => - new TableRow({ - children: [ - new TableCell({ - ...styles.table, - children: sectionSoftSkillSection(sectionSoftSkillVm), - }), - ], - }); +const createTitleTableRow = (text: string): TableRow => { + const title = renderTextRun(text, { size: '18pt', bold: true }); + const paragraph = renderParagraph([title], { spacing: { before: 200 } }); + const cell = renderTableCell([paragraph]); + const row = renderTableRow([cell]); + + return row; +}; + +export const generateSoftSkillSection = (cv: ManfredAwesomicCV): Table => { + const hardSkillList = mapFromCvToSoftSkillVm(cv); + const title = createTitleTableRow(sectionTitle); + const hardSkillItems = createSkillsTableRow(hardSkillList); + const table = renderTable([title, hardSkillItems], styles.table); + + return table; +}; diff --git a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts index 0d9d54bc..e31259a4 100644 --- a/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts +++ b/packages/manfred2word/src/engine/doc-parts/soft-skill-section/soft-skill.constants.ts @@ -6,3 +6,5 @@ export const levelSkillList: SkillType[] = [ { level: 'high', spanish: 'Alto' }, { level: 'expert', spanish: 'Experto' }, ]; + +export const sectionTitle = 'Soft Skills'; From 13ac35470b2e5aec64967adbe27ef8157f2e40eb Mon Sep 17 00:00:00 2001 From: juanpms2 Date: Fri, 7 Jul 2023 14:39:49 +0200 Subject: [PATCH 2/2] refactor --- .../hard-skill-section.helpers.ts | 28 ------------------- .../hard-skill-section.part.ts | 6 ++-- 2 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts diff --git a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts deleted file mode 100644 index 64dd6b91..00000000 --- a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.helpers.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IParagraphOptions, IRunOptions, Paragraph, Table, TableCell, TableRow, TextRun, XmlComponent } from 'docx'; -import { TableStyles } from '../doc-parts.vm'; - -export const renderTable = (rows: TableRow[], styles?: TableStyles): XmlComponent => - new Table({ - ...styles, - rows: [...rows], - }); - -export const renderTableRow = (cells: TableCell[], styles?: TableStyles): TableRow => - new TableRow({ - ...styles, - children: [...cells], - }); - -export const renderTableCell = (children: XmlComponent[], styles?: TableStyles): TableCell => - new TableCell({ - ...styles, - children: [...children], - }); - -export const renderParagraph = (children: XmlComponent[], opcions?: IParagraphOptions): XmlComponent => - new Paragraph({ - ...opcions, - children: [...children], - }); - -export const renderTextRun = (text: string, options?: IRunOptions): XmlComponent => new TextRun({ ...options, text }); diff --git a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts index c13d84bd..5de05c7e 100644 --- a/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts +++ b/packages/manfred2word/src/engine/doc-parts/hard-skill-section/hard-skill-section.part.ts @@ -3,12 +3,12 @@ import { ManfredAwesomicCV } from '@/model'; import { HardSkillVM } from './hard-skill-section.vm'; import { mapFromCvToHardSkillVm } from './hard-skill-section.mapper'; import { + renderParagraph, renderTable, - renderTableRow, renderTableCell, - renderParagraph, + renderTableRow, renderTextRun, -} from './hard-skill-section.helpers'; +} from '@/common-app/helpers/render-elements.helpers'; import { sectionTitle } from './hard-skill-constants'; import { styles } from './hard-skill-section.styles';