From 8534382e9479e34d8d05ec0d0bd0d0642d35a3eb Mon Sep 17 00:00:00 2001 From: Mutugi <48474421+Mutugiii@users.noreply.github.com> Date: Thu, 25 Apr 2024 21:53:51 +0300 Subject: [PATCH] myLife: print achievements (fixes #7436) (#7438) Co-authored-by: dogi --- package.json | 4 +- .../users-achievements.component.html | 5 +- .../users-achievements.component.ts | 82 +++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0038a75746..f3df97516e 100755 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "planet", "license": "AGPL-3.0", - "version": "0.14.25", + "version": "0.14.26", "myplanet": { - "latest": "v0.14.92", + "latest": "v0.14.97", "min": "v0.14.0" }, "scripts": { diff --git a/src/app/users/users-achievements/users-achievements.component.html b/src/app/users/users-achievements/users-achievements.component.html index 98e1ef1882..3614aa9ae0 100644 --- a/src/app/users/users-achievements/users-achievements.component.html +++ b/src/app/users/users-achievements/users-achievements.component.html @@ -9,7 +9,10 @@ {{ user.firstName}} {{user.middleName}} {{user.lastName }} {{ user.name }} - mode_edit + + Print Achievements +
+ Add Achievements Edit Achievements diff --git a/src/app/users/users-achievements/users-achievements.component.ts b/src/app/users/users-achievements/users-achievements.component.ts index 8a496aeb91..1f37347fce 100644 --- a/src/app/users/users-achievements/users-achievements.component.ts +++ b/src/app/users/users-achievements/users-achievements.component.ts @@ -1,3 +1,4 @@ +import { format } from 'date-fns'; import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { Router, ActivatedRoute, ParamMap } from '@angular/router'; import { CouchService } from '../../shared/couchdb.service'; @@ -10,6 +11,10 @@ import { StateService } from '../../shared/state.service'; import { CoursesService } from '../../courses/courses.service'; import { CertificationsService } from '../../manager-dashboard/certifications/certifications.service'; +const pdfMake = require('pdfmake/build/pdfmake'); +const pdfFonts = require('pdfmake/build/vfs_fonts'); +pdfMake.vfs = pdfFonts.pdfMake.vfs; + @Component({ templateUrl: './users-achievements.component.html', styleUrls: [ './users-achievements.scss' ], @@ -107,4 +112,81 @@ export class UsersAchievementsComponent implements OnInit { }); } + generatePDF() { + const formattedBirthDate = format(new Date(this.user.birthDate), 'MMM d, y, h:mm:ss a'); + let contentArray = [ + { + text: `${`${this.user.firstName}'s achievements`}`, + style: 'header', + alignment: 'center', + }, + { + text: ` + ${this.user.firstName} ${this.user.middleName ? this.user.middleName : ''} ${this.user.lastName} + ${this.user.birthDate ? `Birthdate: ${this.user.birthDate}` : ''} + ${formattedBirthDate ? `Birthplace: ${formattedBirthDate}` : ''} + `, + alignment: 'center', + }, + ]; + + const optionals = []; + if (this.achievements.purpose) { + optionals.push( + { text: 'My Purpose', style: 'subHeader', alignment: 'center' }, + { text: this.achievements.purpose, alignment: 'left', margin: [ 20, 5 ] } + ); + } + + if (this.achievements.goals) { + optionals.push( + { text: 'My Goals', style: 'subHeader', alignment: 'center' }, + { text: this.achievements.goals, alignment: 'left', margin: [ 20, 5 ] } + ); + } + + if (this.achievements.achievements && this.achievements.achievements.length > 0) { + optionals.push( + { text: 'My Achievements', style: 'subHeader', alignment: 'center' }, + ...this.achievements.achievements.map((achievement) => { + return [ + { text: achievement.title, bold: true, margin: [ 20, 5 ] }, + { text: achievement.description, marginLeft: 40 }, + ]; + }) + ); + } + + if (this.certifications && this.certifications.length > 0) { + optionals.push( + { text: 'My Certifications', style: 'subHeader', alignment: 'center' }, + ...this.certifications.map((certification) => { + return [ + { text: certification.title, bold: true, margin: [ 20, 5 ] }, + { text: certification.description, marginLeft: 40 }, + ]; + }) + ); + } + + contentArray = contentArray.concat(optionals); + + const documentDefinition = { + content: contentArray, + styles: { + header: { + fontSize: 18, + bold: true, + }, + subHeader: { + fontSize: 16, + bold: true + } + }, + }; + + pdfMake + .createPdf(documentDefinition) + .download(`${this.user.name} achievements.pdf`); + } }