From 6267ff50715aa76d7379b97466f65f89d5afaae6 Mon Sep 17 00:00:00 2001 From: Pablo Bonilla Date: Tue, 10 Aug 2021 18:07:25 -0600 Subject: [PATCH] Add jsPDF export as PDF --- package-lock.json | 289 +++++++++++++++++- package.json | 1 + .../dashboard-admin.component.html | 3 +- .../dashboard-admin.component.ts | 58 ++-- .../dashboard/export/export_common.ts | 10 + .../entities/dashboard/export/export_excel.ts | 26 ++ .../entities/dashboard/export/export_pdf.ts | 35 +++ 7 files changed, 380 insertions(+), 42 deletions(-) create mode 100644 src/main/webapp/app/entities/dashboard/export/export_common.ts create mode 100644 src/main/webapp/app/entities/dashboard/export/export_excel.ts create mode 100644 src/main/webapp/app/entities/dashboard/export/export_pdf.ts diff --git a/package-lock.json b/package-lock.json index d63d325..ca1294a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "dayjs": "1.10.5", "file-saver": "^2.0.5", "jquery": "^3.6.0", + "jspdf": "^2.3.1", "ngx-infinite-scroll": "10.0.1", "ngx-webstorage": "8.0.0", "rxjs": "6.6.7", @@ -2573,6 +2574,19 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/runtime-corejs3": { + "version": "7.14.9", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.14.9.tgz", + "integrity": "sha512-64RiH2ON4/y8qYtoa8rUiyam/tUVyGqRyNYhe+vCRGmjnV4bUlZvY+mwd0RrmLoCpJpdq3RsrNqKb7SJdw/4kw==", + "optional": true, + "dependencies": { + "core-js-pure": "^3.16.0", + "regenerator-runtime": "^0.13.4" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/template": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.14.5.tgz", @@ -4384,6 +4398,12 @@ "integrity": "sha512-0/HnwIfW4ki2D8L8c9GVcG5I72s9jP5GSLVF0VIXDW00kmIpA6O33G7a8n59Tmh7Nz0WUC3rSb7PTY/sdW2JzA==", "dev": true }, + "node_modules/@types/raf": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@types/raf/-/raf-3.4.0.tgz", + "integrity": "sha512-taW5/WYqo36N7V39oYyHP9Ipfd5pNFvGTIQsNGj86xV88YQ7GnI30/yMfKDF7Zgin0m3e+ikX88FvImnK4RjGw==", + "optional": true + }, "node_modules/@types/sizzle": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.3.tgz", @@ -5478,7 +5498,6 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", - "dev": true, "bin": { "atob": "bin/atob.js" }, @@ -6538,6 +6557,17 @@ "node-int64": "^0.4.0" } }, + "node_modules/btoa": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", + "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==", + "bin": { + "btoa": "bin/btoa.js" + }, + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/buffer": { "version": "4.9.2", "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz", @@ -6683,6 +6713,23 @@ "integrity": "sha512-feylzsbDxi1gPZ1IjystzIQZagYYLvfKrSuygUCgf7z6x790VEzze5QEkdSV1U58RA7Hi0+v6fv4K54atOzATg==", "dev": true }, + "node_modules/canvg": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/canvg/-/canvg-3.0.7.tgz", + "integrity": "sha512-4sq6iL5Q4VOXS3PL1BapiXIZItpxYyANVzsAKpTPS5oq4u3SKbGfUcbZh2gdLCQ3jWpG/y5wRkMlBBAJhXeiZA==", + "optional": true, + "dependencies": { + "@babel/runtime-corejs3": "^7.9.6", + "@types/raf": "^3.4.0", + "raf": "^3.4.1", + "rgbcolor": "^1.0.1", + "stackblur-canvas": "^2.0.0", + "svg-pathdata": "^5.0.5" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -7673,7 +7720,7 @@ "version": "3.15.1", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.15.1.tgz", "integrity": "sha512-h8VbZYnc9pDzueiS2610IULDkpFFPunHwIpl8yRwFahAEEdSpHlTy3h3z3rKq5h11CaUdBEeRViu9AYvbxiMeg==", - "dev": true, + "devOptional": true, "hasInstallScript": true, "funding": { "type": "opencollective", @@ -7703,6 +7750,17 @@ "semver": "bin/semver.js" } }, + "node_modules/core-js-pure": { + "version": "3.16.1", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.16.1.tgz", + "integrity": "sha512-TyofCdMzx0KMhi84mVRS8rL1XsRk2SPUNz2azmth53iRN0/08Uim9fdhQTaZTG1LqaXHYVci4RDHka6WrXfnvg==", + "hasInstallScript": true, + "optional": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -8013,6 +8071,24 @@ "node": ">=6" } }, + "node_modules/css-line-break": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.0.1.tgz", + "integrity": "sha512-gwKYIMUn7xodIcb346wgUhE2Dt5O1Kmrc16PWi8sL4FTfyDj8P5095rzH7+O8CTZudJr+uw2GCI/hwEkDJFI2w==", + "optional": true, + "dependencies": { + "base64-arraybuffer": "^0.2.0" + } + }, + "node_modules/css-line-break/node_modules/base64-arraybuffer": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.2.0.tgz", + "integrity": "sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ==", + "optional": true, + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/css-loader": { "version": "5.2.6", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-5.2.6.tgz", @@ -9121,6 +9197,12 @@ "url": "https://github.com/fb55/domhandler?sponsor=1" } }, + "node_modules/dompurify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.3.0.tgz", + "integrity": "sha512-VV5C6Kr53YVHGOBKO/F86OYX6/iLTw2yVSI721gKetxpHCK/V5TaLEf9ODjRgl1KLSWRMY6cUhAbv/c+IUnwQw==", + "optional": true + }, "node_modules/domutils": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.7.0.tgz", @@ -11729,6 +11811,18 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "node_modules/html2canvas": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.2.2.tgz", + "integrity": "sha512-cxZR1bGxtmhxeoCxM+s1WfRzDtpKPuHHZ7ExX01EdhgdEQCvMDZLDj3aknE8ywSoed8JM8AXhQiuD1KFwMm3Gw==", + "optional": true, + "dependencies": { + "css-line-break": "2.0.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/http-basic": { "version": "8.1.3", "resolved": "https://registry.npmjs.org/http-basic/-/http-basic-8.1.3.tgz", @@ -15833,6 +15927,27 @@ "node >= 0.2.0" ] }, + "node_modules/jspdf": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/jspdf/-/jspdf-2.3.1.tgz", + "integrity": "sha512-1vp0USP1mQi1h7NKpwxjFgQkJ5ncZvtH858aLpycUc/M+r/RpWJT8PixAU7Cw/3fPd4fpC8eB/Bj42LnsR21YQ==", + "dependencies": { + "atob": "^2.1.2", + "btoa": "^1.2.1", + "fflate": "^0.4.8" + }, + "optionalDependencies": { + "canvg": "^3.0.6", + "core-js": "^3.6.0", + "dompurify": "^2.2.0", + "html2canvas": "^1.0.0-rc.5" + } + }, + "node_modules/jspdf/node_modules/fflate": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz", + "integrity": "sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==" + }, "node_modules/jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -18469,7 +18584,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", - "dev": true + "devOptional": true }, "node_modules/picomatch": { "version": "2.3.0", @@ -21339,6 +21454,15 @@ } ] }, + "node_modules/raf": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", + "integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==", + "optional": true, + "dependencies": { + "performance-now": "^2.1.0" + } + }, "node_modules/randexp": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.5.3.tgz", @@ -21659,7 +21783,7 @@ "version": "0.13.7", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz", "integrity": "sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==", - "dev": true + "devOptional": true }, "node_modules/regenerator-transform": { "version": "0.14.5", @@ -22103,6 +22227,15 @@ "integrity": "sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=", "dev": true }, + "node_modules/rgbcolor": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/rgbcolor/-/rgbcolor-1.0.1.tgz", + "integrity": "sha1-1lBezbMEplldom+ktDMHMGd1lF0=", + "optional": true, + "engines": { + "node": ">= 0.8.15" + } + }, "node_modules/rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -23503,6 +23636,15 @@ "node": ">=8" } }, + "node_modules/stackblur-canvas": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/stackblur-canvas/-/stackblur-canvas-2.5.0.tgz", + "integrity": "sha512-EeNzTVfj+1In7aSLPKDD03F/ly4RxEuF/EX0YcOG0cKoPXs+SLZxDawQbexQDBzwROs4VKLWTOaZQlZkGBFEIQ==", + "optional": true, + "engines": { + "node": ">=0.1.14" + } + }, "node_modules/static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -24011,6 +24153,15 @@ "node": ">=8" } }, + "node_modules/svg-pathdata": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/svg-pathdata/-/svg-pathdata-5.0.5.tgz", + "integrity": "sha512-TAAvLNSE3fEhyl/Da19JWfMAdhSXTYeviXsLSoDT1UM76ADj5ndwAPX1FKQEgB/gFMPavOy6tOqfalXKUiXrow==", + "optional": true, + "engines": { + "node": ">=6.9.5" + } + }, "node_modules/svgo": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/svgo/-/svgo-2.3.1.tgz", @@ -29215,6 +29366,16 @@ "regenerator-runtime": "^0.13.4" } }, + "@babel/runtime-corejs3": { + "version": "7.14.9", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.14.9.tgz", + "integrity": "sha512-64RiH2ON4/y8qYtoa8rUiyam/tUVyGqRyNYhe+vCRGmjnV4bUlZvY+mwd0RrmLoCpJpdq3RsrNqKb7SJdw/4kw==", + "optional": true, + "requires": { + "core-js-pure": "^3.16.0", + "regenerator-runtime": "^0.13.4" + } + }, "@babel/template": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.14.5.tgz", @@ -30699,6 +30860,12 @@ "integrity": "sha512-0/HnwIfW4ki2D8L8c9GVcG5I72s9jP5GSLVF0VIXDW00kmIpA6O33G7a8n59Tmh7Nz0WUC3rSb7PTY/sdW2JzA==", "dev": true }, + "@types/raf": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@types/raf/-/raf-3.4.0.tgz", + "integrity": "sha512-taW5/WYqo36N7V39oYyHP9Ipfd5pNFvGTIQsNGj86xV88YQ7GnI30/yMfKDF7Zgin0m3e+ikX88FvImnK4RjGw==", + "optional": true + }, "@types/sizzle": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.3.tgz", @@ -31521,8 +31688,7 @@ "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", - "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", - "dev": true + "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" }, "atomically": { "version": "1.7.0", @@ -32349,6 +32515,11 @@ "node-int64": "^0.4.0" } }, + "btoa": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", + "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==" + }, "buffer": { "version": "4.9.2", "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz", @@ -32472,6 +32643,20 @@ "integrity": "sha512-feylzsbDxi1gPZ1IjystzIQZagYYLvfKrSuygUCgf7z6x790VEzze5QEkdSV1U58RA7Hi0+v6fv4K54atOzATg==", "dev": true }, + "canvg": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/canvg/-/canvg-3.0.7.tgz", + "integrity": "sha512-4sq6iL5Q4VOXS3PL1BapiXIZItpxYyANVzsAKpTPS5oq4u3SKbGfUcbZh2gdLCQ3jWpG/y5wRkMlBBAJhXeiZA==", + "optional": true, + "requires": { + "@babel/runtime-corejs3": "^7.9.6", + "@types/raf": "^3.4.0", + "raf": "^3.4.1", + "rgbcolor": "^1.0.1", + "stackblur-canvas": "^2.0.0", + "svg-pathdata": "^5.0.5" + } + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -33279,7 +33464,7 @@ "version": "3.15.1", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.15.1.tgz", "integrity": "sha512-h8VbZYnc9pDzueiS2610IULDkpFFPunHwIpl8yRwFahAEEdSpHlTy3h3z3rKq5h11CaUdBEeRViu9AYvbxiMeg==", - "dev": true + "devOptional": true }, "core-js-compat": { "version": "3.15.2", @@ -33299,6 +33484,12 @@ } } }, + "core-js-pure": { + "version": "3.16.1", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.16.1.tgz", + "integrity": "sha512-TyofCdMzx0KMhi84mVRS8rL1XsRk2SPUNz2azmth53iRN0/08Uim9fdhQTaZTG1LqaXHYVci4RDHka6WrXfnvg==", + "optional": true + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -33534,6 +33725,23 @@ } } }, + "css-line-break": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.0.1.tgz", + "integrity": "sha512-gwKYIMUn7xodIcb346wgUhE2Dt5O1Kmrc16PWi8sL4FTfyDj8P5095rzH7+O8CTZudJr+uw2GCI/hwEkDJFI2w==", + "optional": true, + "requires": { + "base64-arraybuffer": "^0.2.0" + }, + "dependencies": { + "base64-arraybuffer": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.2.0.tgz", + "integrity": "sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ==", + "optional": true + } + } + }, "css-loader": { "version": "5.2.6", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-5.2.6.tgz", @@ -34361,6 +34569,12 @@ "domelementtype": "^2.2.0" } }, + "dompurify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.3.0.tgz", + "integrity": "sha512-VV5C6Kr53YVHGOBKO/F86OYX6/iLTw2yVSI721gKetxpHCK/V5TaLEf9ODjRgl1KLSWRMY6cUhAbv/c+IUnwQw==", + "optional": true + }, "domutils": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.7.0.tgz", @@ -36406,6 +36620,15 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "html2canvas": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.2.2.tgz", + "integrity": "sha512-cxZR1bGxtmhxeoCxM+s1WfRzDtpKPuHHZ7ExX01EdhgdEQCvMDZLDj3aknE8ywSoed8JM8AXhQiuD1KFwMm3Gw==", + "optional": true, + "requires": { + "css-line-break": "2.0.1" + } + }, "http-basic": { "version": "8.1.3", "resolved": "https://registry.npmjs.org/http-basic/-/http-basic-8.1.3.tgz", @@ -39529,6 +39752,27 @@ "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", "dev": true }, + "jspdf": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/jspdf/-/jspdf-2.3.1.tgz", + "integrity": "sha512-1vp0USP1mQi1h7NKpwxjFgQkJ5ncZvtH858aLpycUc/M+r/RpWJT8PixAU7Cw/3fPd4fpC8eB/Bj42LnsR21YQ==", + "requires": { + "atob": "^2.1.2", + "btoa": "^1.2.1", + "canvg": "^3.0.6", + "core-js": "^3.6.0", + "dompurify": "^2.2.0", + "fflate": "^0.4.8", + "html2canvas": "^1.0.0-rc.5" + }, + "dependencies": { + "fflate": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz", + "integrity": "sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==" + } + } + }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -41563,7 +41807,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", - "dev": true + "devOptional": true }, "picomatch": { "version": "2.3.0", @@ -43631,6 +43875,15 @@ "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", "dev": true }, + "raf": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", + "integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==", + "optional": true, + "requires": { + "performance-now": "^2.1.0" + } + }, "randexp": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.5.3.tgz", @@ -43882,7 +44135,7 @@ "version": "0.13.7", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz", "integrity": "sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==", - "dev": true + "devOptional": true }, "regenerator-transform": { "version": "0.14.5", @@ -44223,6 +44476,12 @@ "integrity": "sha1-QzdOLiyglosO8VI0YLfXMP8i7rM=", "dev": true }, + "rgbcolor": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/rgbcolor/-/rgbcolor-1.0.1.tgz", + "integrity": "sha1-1lBezbMEplldom+ktDMHMGd1lF0=", + "optional": true + }, "rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -45384,6 +45643,12 @@ } } }, + "stackblur-canvas": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/stackblur-canvas/-/stackblur-canvas-2.5.0.tgz", + "integrity": "sha512-EeNzTVfj+1In7aSLPKDD03F/ly4RxEuF/EX0YcOG0cKoPXs+SLZxDawQbexQDBzwROs4VKLWTOaZQlZkGBFEIQ==", + "optional": true + }, "static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -45761,6 +46026,12 @@ } } }, + "svg-pathdata": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/svg-pathdata/-/svg-pathdata-5.0.5.tgz", + "integrity": "sha512-TAAvLNSE3fEhyl/Da19JWfMAdhSXTYeviXsLSoDT1UM76ADj5ndwAPX1FKQEgB/gFMPavOy6tOqfalXKUiXrow==", + "optional": true + }, "svgo": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/svgo/-/svgo-2.3.1.tgz", diff --git a/package.json b/package.json index 9ff8336..d25a4a9 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "dayjs": "1.10.5", "file-saver": "^2.0.5", "jquery": "^3.6.0", + "jspdf": "^2.3.1", "ngx-infinite-scroll": "10.0.1", "ngx-webstorage": "8.0.0", "rxjs": "6.6.7", diff --git a/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.html b/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.html index b1ed5e0..ae29458 100644 --- a/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.html +++ b/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.html @@ -1,2 +1,3 @@

dashboard-admin works!

- + + diff --git a/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.ts b/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.ts index dd2de7a..721f6a7 100644 --- a/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.ts +++ b/src/main/webapp/app/entities/dashboard/dashboard-admin/dashboard-admin.component.ts @@ -1,6 +1,9 @@ import { Component, OnInit } from '@angular/core'; -import * as FileSaver from 'file-saver'; import * as XLSX from 'xlsx'; +import * as FileSaver from 'file-saver'; +import { jsPDF } from 'jspdf'; +import { exportAsExcelFile } from '../export/export_excel'; +import { generatePDFTableData, createPDFTableHeaders, generatePDFTable } from '../export/export_pdf'; @Component({ selector: 'jhi-dashboard-admin', @@ -10,38 +13,9 @@ import * as XLSX from 'xlsx'; export class DashboardAdminComponent implements OnInit { constructor() {} - EXCEL_TYPE: string = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'; - EXCEL_EXTENSION: string = '.xlsx'; - ngOnInit(): void {} - exportAsExcelFile = (sheetNames: string[], arrayOfData: any[], excelFileName: any) => { - const workbook = XLSX.utils.book_new(); - - arrayOfData.forEach((data, index) => { - let sheetName = sheetNames[index]; - let worksheet = XLSX.utils.json_to_sheet([data]); - XLSX.utils.book_append_sheet(workbook, worksheet, sheetName); - }); - - const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' }); - this.saveAsExcelFile(excelBuffer, excelFileName); - }; - - saveAsExcelFile = (buffer: any, fileName: any) => { - const data = new Blob([buffer], { type: this.EXCEL_TYPE }); - FileSaver.saveAs( - data, - fileName + - '_' + - new Date().toLocaleDateString().substr(0, 10).split('/').join('-') + - '_' + - Math.random().toString().substring(2) + - this.EXCEL_EXTENSION - ); - }; - - exportReportesGeneralesAdministrador(): void { + exportReportesGeneralesAdministradorExcel(): void { /* Cantidad de usuarios activos Cantidad de usuarios bloqueados @@ -54,6 +28,26 @@ export class DashboardAdminComponent implements OnInit { const _reporteUsuarios = { usuarios_activos: 100, usuarios_bloqueados: 50 }; const _excelFinalData = [_reporteUsuarios]; - this.exportAsExcelFile(_sheets, _excelFinalData, 'reporte_general'); + exportAsExcelFile(_sheets, _excelFinalData, 'reporte_general'); + } + + exportReportesGeneralesAdministradorPDF(): void { + /* + Cantidad de usuarios activos + Cantidad de usuarios bloqueados + Cantidad de encuestas publicadas por categoría + Cantidad de encuestas finalizadas por categoría + Cantidad de encuestas publicadas por mes y año + */ + + const doc = new jsPDF(); + + const _reporteUsuarios = [{ usuarios_activos: '100', usuarios_bloqueados: '50' }]; + const _docData = generatePDFTableData(_reporteUsuarios); + + const _headers = ['usuarios_activos', 'usuarios_bloqueados']; + const _docHeaders = createPDFTableHeaders(_headers); + + generatePDFTable(doc, _docData, _docHeaders); } } diff --git a/src/main/webapp/app/entities/dashboard/export/export_common.ts b/src/main/webapp/app/entities/dashboard/export/export_common.ts new file mode 100644 index 0000000..d3a083e --- /dev/null +++ b/src/main/webapp/app/entities/dashboard/export/export_common.ts @@ -0,0 +1,10 @@ +export const generateFileName = (fileName: string, extension: string): string => { + return ( + fileName + + '_' + + new Date().toLocaleDateString().substr(0, 10).split('/').join('-') + + '_' + + Math.random().toString().substring(2) + + extension + ); +}; diff --git a/src/main/webapp/app/entities/dashboard/export/export_excel.ts b/src/main/webapp/app/entities/dashboard/export/export_excel.ts new file mode 100644 index 0000000..8f549af --- /dev/null +++ b/src/main/webapp/app/entities/dashboard/export/export_excel.ts @@ -0,0 +1,26 @@ +import * as XLSX from 'xlsx'; +import * as FileSaver from 'file-saver'; +import { generateFileName } from './export_common'; + +const EXCEL_TYPE: string = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'; +const EXCEL_EXTENSION: string = '.xlsx'; + +export const exportAsExcelFile = (sheetNames: string[], arrayOfData: any[], excelFileName: any) => { + const workbook = XLSX.utils.book_new(); + + arrayOfData.forEach((data, index) => { + let sheetName = sheetNames[index]; + let worksheet = XLSX.utils.json_to_sheet([data]); + XLSX.utils.book_append_sheet(workbook, worksheet, sheetName); + }); + + const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' }); + saveAsExcelFile(excelBuffer, excelFileName); +}; + +const saveAsExcelFile = (buffer: any, fileName: any) => { + const data = new Blob([buffer], { type: EXCEL_EXTENSION }); + const generatedFileName = generateFileName(fileName, EXCEL_EXTENSION); + + FileSaver.saveAs(data, generatedFileName); +}; diff --git a/src/main/webapp/app/entities/dashboard/export/export_pdf.ts b/src/main/webapp/app/entities/dashboard/export/export_pdf.ts new file mode 100644 index 0000000..1f5132f --- /dev/null +++ b/src/main/webapp/app/entities/dashboard/export/export_pdf.ts @@ -0,0 +1,35 @@ +import { jsPDF } from 'jspdf'; +import { generateFileName } from './export_common'; + +const PDF_EXTENSION: string = '.pdf'; + +export const generatePDFTableData = (data: any): any => { + const result: any = []; + + data.forEach((item: any) => { + result.push(Object.assign({}, item)); + }); + + return result; +}; + +export const createPDFTableHeaders = (keys: any): any[] => { + let result = []; + for (let i = 0; i < keys.length; i += 1) { + result.push({ + id: keys[i], + name: keys[i], + prompt: keys[i], + width: 65, + align: 'center', + padding: 0, + }); + } + return result; +}; + +export const generatePDFTable = (doc: jsPDF, _docData: any, _docHeaders: string[]): void => { + doc.table(1, 1, _docData, _docHeaders, { autoSize: true }); + const generatedFileName = generateFileName('reporte_general', PDF_EXTENSION); + doc.save(generatedFileName); +};