identity-admin 1.27.2 → 1.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -451,19 +451,23 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
451
451
|
populate: modifiedPopulatedObject,
|
|
452
452
|
});
|
|
453
453
|
var documents = [];
|
|
454
|
-
var documents = [];
|
|
455
454
|
for (var i = 0; i < records.length; i++) {
|
|
456
455
|
const record = records[i];
|
|
457
456
|
const recordFlatten = record.toObject();
|
|
458
457
|
documents.push(recordFlatten);
|
|
459
458
|
}
|
|
460
459
|
if (crudOperations && crudOperations.index && crudOperations.index.after) {
|
|
461
|
-
|
|
460
|
+
try {
|
|
461
|
+
documents = yield crudOperations.index.after(req, documents, currentUser);
|
|
462
|
+
}
|
|
463
|
+
catch (e) {
|
|
464
|
+
documents = yield crudOperations.index.after(req, records, currentUser);
|
|
465
|
+
}
|
|
462
466
|
}
|
|
463
467
|
const fields = req.query.fields.map((v) => JSON.parse(v));
|
|
464
468
|
const fileType = req.query.fileType;
|
|
465
469
|
if (fileType === 'xlsx') {
|
|
466
|
-
const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName, language);
|
|
470
|
+
const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName, language, resource);
|
|
467
471
|
res.writeHead(200, {
|
|
468
472
|
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
469
473
|
'Content-disposition': 'attachment;filename=' + `${modelName}.xlsx`,
|
|
@@ -472,7 +476,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
|
|
|
472
476
|
res.end(buffer);
|
|
473
477
|
}
|
|
474
478
|
if (fileType === 'pdf') {
|
|
475
|
-
const buffer = yield ReportsGenerator_1.default.CreatePdfFile(fields, documents, modelName, language);
|
|
479
|
+
const buffer = yield ReportsGenerator_1.default.CreatePdfFile(fields, documents, modelName, language, resource);
|
|
476
480
|
res.writeHead(200, {
|
|
477
481
|
'Content-Type': 'application/pdf',
|
|
478
482
|
'Content-disposition': 'attachment;filename=' + `${modelName}.pdf`,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { FieldTypes } from '../types/helpers';
|
|
3
|
+
import { IResourceFile } from '../types/IResourceFile';
|
|
3
4
|
export interface Columns {
|
|
4
5
|
label: string;
|
|
5
6
|
value: string;
|
|
@@ -16,10 +17,10 @@ export interface ILanguage {
|
|
|
16
17
|
value?: string;
|
|
17
18
|
}
|
|
18
19
|
export default class ReportsGenerator {
|
|
19
|
-
static CreateXlsxFile(columns: Columns[], data: any[], name: string, language: Languages): Buffer;
|
|
20
|
-
static CreatePdfFile(columns: Columns[], data: any[], name: string, language: Languages): Promise<Buffer>;
|
|
21
|
-
static getRows(columns: Columns[], data: any[], language: Languages): any[][];
|
|
22
|
-
static getFieldValue(field: Columns, row: any, language: Languages): any;
|
|
20
|
+
static CreateXlsxFile(columns: Columns[], data: any[], name: string, language: Languages, resource: IResourceFile): Buffer;
|
|
21
|
+
static CreatePdfFile(columns: Columns[], data: any[], name: string, language: Languages, resource: IResourceFile): Promise<Buffer>;
|
|
22
|
+
static getRows(columns: Columns[], data: any[], language: Languages, resource: IResourceFile): any[][];
|
|
23
|
+
static getFieldValue(field: Columns, row: any, language: Languages, resource: IResourceFile): any;
|
|
23
24
|
static checkLocalizedStringExistence(columns: Columns[]): boolean;
|
|
24
25
|
static getReferenceValueByTitleType(rowValue: any, language: Languages, titleType?: FieldTypes): any;
|
|
25
26
|
}
|
|
@@ -42,15 +42,16 @@ const helpers_1 = require("../types/helpers");
|
|
|
42
42
|
const pdfjs_1 = __importDefault(require("pdfjs"));
|
|
43
43
|
const fs = __importStar(require("fs"));
|
|
44
44
|
const LocalizedStringHelper_1 = __importDefault(require("./LocalizedStringHelper"));
|
|
45
|
+
const DateUtils_1 = require("../utils/DateUtils");
|
|
45
46
|
var Languages;
|
|
46
47
|
(function (Languages) {
|
|
47
48
|
Languages["ARABIC"] = "ar";
|
|
48
49
|
Languages["ENGLISH"] = "en";
|
|
49
50
|
})(Languages = exports.Languages || (exports.Languages = {}));
|
|
50
51
|
class ReportsGenerator {
|
|
51
|
-
static CreateXlsxFile(columns, data, name, language) {
|
|
52
|
+
static CreateXlsxFile(columns, data, name, language, resource) {
|
|
52
53
|
const header = columns.map((field) => field.label);
|
|
53
|
-
const rows = this.getRows(columns, data, language);
|
|
54
|
+
const rows = this.getRows(columns, data, language, resource);
|
|
54
55
|
const sheets = [
|
|
55
56
|
{
|
|
56
57
|
name,
|
|
@@ -61,9 +62,9 @@ class ReportsGenerator {
|
|
|
61
62
|
const buffer = node_xlsx_1.default.build(sheets);
|
|
62
63
|
return buffer;
|
|
63
64
|
}
|
|
64
|
-
static CreatePdfFile(columns, data, name, language) {
|
|
65
|
+
static CreatePdfFile(columns, data, name, language, resource) {
|
|
65
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const rows = this.getRows(columns, data, language);
|
|
67
|
+
const rows = this.getRows(columns, data, language, resource);
|
|
67
68
|
const ArabicFont = new pdfjs_1.default.Font(fs.readFileSync(__dirname + '/../assets/Amiri-Regular.ttf'));
|
|
68
69
|
const localizedStringIsExisted = this.checkLocalizedStringExistence(columns);
|
|
69
70
|
const doc = new pdfjs_1.default.Document({
|
|
@@ -75,28 +76,43 @@ class ReportsGenerator {
|
|
|
75
76
|
borderWidth: 1,
|
|
76
77
|
});
|
|
77
78
|
const header = table.header({
|
|
78
|
-
backgroundColor:
|
|
79
|
-
color:
|
|
79
|
+
backgroundColor: 0xdddddd,
|
|
80
|
+
color: 0x333333,
|
|
81
|
+
paddingBottom: 5,
|
|
82
|
+
paddingTop: 5,
|
|
80
83
|
});
|
|
81
|
-
columns.map((field) => header.cell(field.label
|
|
84
|
+
columns.map((field) => header.cell(field.label, {
|
|
85
|
+
textAlign: 'center',
|
|
86
|
+
alignment: 'center',
|
|
87
|
+
}));
|
|
82
88
|
rows.forEach((row) => {
|
|
83
89
|
const tableRow = table.row();
|
|
84
|
-
row.map((cell) => tableRow.cell(`${cell !== null && cell !== void 0 ? cell : '---'}
|
|
90
|
+
row.map((cell) => tableRow.cell(`${cell !== null && cell !== void 0 ? cell : '---'}`, {
|
|
91
|
+
textAlign: 'center',
|
|
92
|
+
alignment: 'center',
|
|
93
|
+
paddingBottom: 5,
|
|
94
|
+
paddingTop: 5,
|
|
95
|
+
}));
|
|
85
96
|
});
|
|
86
97
|
return yield doc.asBuffer();
|
|
87
98
|
});
|
|
88
99
|
}
|
|
89
|
-
static getRows(columns, data, language) {
|
|
90
|
-
const rows = data.map((row) => columns.map((field) => this.getFieldValue(field, row, language)));
|
|
100
|
+
static getRows(columns, data, language, resource) {
|
|
101
|
+
const rows = data.map((row) => columns.map((field) => this.getFieldValue(field, row, language, resource)));
|
|
91
102
|
return rows;
|
|
92
103
|
}
|
|
93
|
-
static getFieldValue(field, row, language) {
|
|
104
|
+
static getFieldValue(field, row, language, resource) {
|
|
94
105
|
var _a, _b, _c;
|
|
106
|
+
const schema = resource.properties.model;
|
|
107
|
+
const fieldProps = schema ? schema[field.value] : undefined;
|
|
95
108
|
switch (field.type) {
|
|
96
109
|
case helpers_1.FieldTypes.OBJECTID:
|
|
97
110
|
return (_b = (_a = (0, lodash_1.get)(row, field.value)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
|
|
98
111
|
case helpers_1.FieldTypes.LOCALIZEDSTRING:
|
|
99
112
|
return LocalizedStringHelper_1.default.getLocalizedValue(row, field.value, language);
|
|
113
|
+
case helpers_1.FieldTypes.DATE:
|
|
114
|
+
const withTime = fieldProps && fieldProps.withTime ? true : false;
|
|
115
|
+
return DateUtils_1.DateUtils.getIsoDate((0, lodash_1.get)(row, field.value), withTime);
|
|
100
116
|
case helpers_1.FieldTypes.REFERENCE:
|
|
101
117
|
const valuePath = (_c = field.titlePath) !== null && _c !== void 0 ? _c : field.value;
|
|
102
118
|
const rowValue = (0, lodash_1.get)(row, valuePath);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Languages } from '../helpers/ReportsGenerator';
|
|
2
|
+
export declare class DateUtils {
|
|
3
|
+
static addBegginingZero(value: number): string;
|
|
4
|
+
static localizingToArabicAMPM(amOrPm: string): "صباحاً" | "مساءاً";
|
|
5
|
+
static formatAMPM(date: Date, language: Languages): string;
|
|
6
|
+
static getIsoDate(date: Date | string, withTime: boolean): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateUtils = void 0;
|
|
4
|
+
const ReportsGenerator_1 = require("../helpers/ReportsGenerator");
|
|
5
|
+
class DateUtils {
|
|
6
|
+
static addBegginingZero(value) {
|
|
7
|
+
return value % 10 === value ? `0${value.toString()}` : value.toString();
|
|
8
|
+
}
|
|
9
|
+
static localizingToArabicAMPM(amOrPm) {
|
|
10
|
+
switch (amOrPm) {
|
|
11
|
+
case 'am':
|
|
12
|
+
return 'صباحاً';
|
|
13
|
+
case 'pm':
|
|
14
|
+
return 'مساءاً';
|
|
15
|
+
default:
|
|
16
|
+
return 'صباحاً';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static formatAMPM(date, language) {
|
|
20
|
+
var hours = date.getHours();
|
|
21
|
+
var minutes = date.getMinutes();
|
|
22
|
+
var ampm = hours >= 12 ? 'pm' : 'am';
|
|
23
|
+
if (language === ReportsGenerator_1.Languages.ARABIC) {
|
|
24
|
+
ampm = this.localizingToArabicAMPM(ampm);
|
|
25
|
+
}
|
|
26
|
+
hours = hours % 12;
|
|
27
|
+
hours = hours ? hours : 12;
|
|
28
|
+
minutes = minutes < 10 ? '0' + minutes : minutes;
|
|
29
|
+
var strTime = hours + ':' + minutes + ' ' + ampm;
|
|
30
|
+
return strTime;
|
|
31
|
+
}
|
|
32
|
+
static getIsoDate(date, withTime) {
|
|
33
|
+
date = new Date(date);
|
|
34
|
+
const month = date.getMonth() + 1;
|
|
35
|
+
const day = date.getDate();
|
|
36
|
+
const mappedMonth = this.addBegginingZero(month);
|
|
37
|
+
const mappedDay = this.addBegginingZero(day);
|
|
38
|
+
var isoDate = date.getFullYear() + '-' + mappedMonth + '-' + mappedDay;
|
|
39
|
+
if (withTime) {
|
|
40
|
+
isoDate = isoDate + ' ' + this.formatAMPM(date, ReportsGenerator_1.Languages.ENGLISH);
|
|
41
|
+
}
|
|
42
|
+
return isoDate;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.DateUtils = DateUtils;
|