identity-admin 1.26.23 → 1.27.0

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.
@@ -124,7 +124,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
124
124
  return (_b = this.modelConfigurations) === null || _b === void 0 ? void 0 : _b.get(modelName);
125
125
  }
126
126
  const collection = mongoose_1.default.connection.db.collection('modelconfigurations');
127
- return yield collection.findOne({ modelName: modelName });
127
+ return (yield collection.findOne({ modelName: modelName }));
128
128
  });
129
129
  }
130
130
  index(req, res) {
@@ -396,6 +396,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
396
396
  const scope = req.query.scope;
397
397
  const currentUser = req.user;
398
398
  const modelName = req.params.resource;
399
+ const language = req.headers.language ? req.headers.language : 'en';
399
400
  const filtersQuery = req.query.filters;
400
401
  const filters = filtersQuery ? filtersQuery.split('^^') : undefined;
401
402
  const resource = (_a = this.resource) !== null && _a !== void 0 ? _a : (0, ResourceUtils_1.getResource)(modelName, (_b = this.resources) !== null && _b !== void 0 ? _b : []);
@@ -460,7 +461,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
460
461
  const fields = req.query.fields.map((v) => JSON.parse(v));
461
462
  const fileType = req.query.fileType;
462
463
  if (fileType === 'xlsx') {
463
- const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName);
464
+ const buffer = ReportsGenerator_1.default.CreateXlsxFile(fields, documents, modelName, language);
464
465
  res.writeHead(200, {
465
466
  'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
466
467
  'Content-disposition': 'attachment;filename=' + `${modelName}.xlsx`,
@@ -469,7 +470,7 @@ let DashboardController = DashboardController_1 = class DashboardController {
469
470
  res.end(buffer);
470
471
  }
471
472
  if (fileType === 'pdf') {
472
- const buffer = yield ReportsGenerator_1.default.CreatePdfFile(fields, documents, modelName);
473
+ const buffer = yield ReportsGenerator_1.default.CreatePdfFile(fields, documents, modelName, language);
473
474
  res.writeHead(200, {
474
475
  'Content-Type': 'application/pdf',
475
476
  'Content-disposition': 'attachment;filename=' + `${modelName}.pdf`,
@@ -692,7 +693,7 @@ __decorate([
692
693
  __param(1, (0, inversify_express_utils_1.response)())
693
694
  ], DashboardController.prototype, "validateRequest", null);
694
695
  __decorate([
695
- (0, inversify_express_utils_1.httpGet)("/"),
696
+ (0, inversify_express_utils_1.httpGet)('/'),
696
697
  __param(0, (0, inversify_express_utils_1.request)()),
697
698
  __param(1, (0, inversify_express_utils_1.response)())
698
699
  ], DashboardController.prototype, "index", null);
@@ -1,4 +1,5 @@
1
1
  import { IResourceFile } from '../types/IResourceFile';
2
+ import { Languages } from './ReportsGenerator';
2
3
  export default class LocalizedStringHelper {
3
4
  static mapLocalizableString(recordParams: any, resource: IResourceFile): any;
4
5
  private static getArrayOfLanguages;
@@ -6,4 +7,5 @@ export default class LocalizedStringHelper {
6
7
  static getFilterObject(searchBy: string, index: string, value: any): {
7
8
  [key: string]: any;
8
9
  };
10
+ static getLocalizedValue(document: any, field: string, language?: Languages): any;
9
11
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const helpers_1 = require("../types/helpers");
4
+ const ReportsGenerator_1 = require("./ReportsGenerator");
4
5
  class LocalizedStringHelper {
5
6
  static mapLocalizableString(recordParams, resource) {
6
7
  const modelObject = resource.properties.model;
@@ -53,5 +54,21 @@ class LocalizedStringHelper {
53
54
  filterObject[`${searchBy}.${index}.value`] = value;
54
55
  return filterObject;
55
56
  }
57
+ static getLocalizedValue(document, field, language) {
58
+ if (!language) {
59
+ language = ReportsGenerator_1.Languages.ENGLISH;
60
+ }
61
+ if (!document[field] || document[field].length === 0) {
62
+ return '';
63
+ }
64
+ switch (language) {
65
+ case ReportsGenerator_1.Languages.ENGLISH:
66
+ return document[field][0].value;
67
+ case ReportsGenerator_1.Languages.ARABIC:
68
+ return document[field].length >= 2 && document[field][1].value ? document[field][1].value : document[field][0].value;
69
+ default:
70
+ return document[field][0].value;
71
+ }
72
+ }
56
73
  }
57
74
  exports.default = LocalizedStringHelper;
@@ -14,9 +14,9 @@ export interface ILanguage {
14
14
  value?: string;
15
15
  }
16
16
  export default class ReportsGenerator {
17
- static CreateXlsxFile(columns: Columns[], data: any[], name: string): Buffer;
18
- static CreatePdfFile(columns: Columns[], data: any[], name: string): Promise<Buffer>;
19
- static getRows(columns: Columns[], data: any[]): any[][];
20
- static getFieldValue(field: Columns, row: any): any;
17
+ static CreateXlsxFile(columns: Columns[], data: any[], name: string, language: Languages): Buffer;
18
+ static CreatePdfFile(columns: Columns[], data: any[], name: string, language: Languages): Promise<Buffer>;
19
+ static getRows(columns: Columns[], data: any[], language: Languages): any[][];
20
+ static getFieldValue(field: Columns, row: any, language: Languages): any;
21
21
  static checkLocalizedStringExistence(columns: Columns[]): boolean;
22
22
  }
@@ -41,15 +41,16 @@ const lodash_1 = require("lodash");
41
41
  const helpers_1 = require("../types/helpers");
42
42
  const pdfjs_1 = __importDefault(require("pdfjs"));
43
43
  const fs = __importStar(require("fs"));
44
+ const LocalizedStringHelper_1 = __importDefault(require("./LocalizedStringHelper"));
44
45
  var Languages;
45
46
  (function (Languages) {
46
47
  Languages["ARABIC"] = "ar";
47
48
  Languages["ENGLISH"] = "en";
48
49
  })(Languages = exports.Languages || (exports.Languages = {}));
49
50
  class ReportsGenerator {
50
- static CreateXlsxFile(columns, data, name) {
51
+ static CreateXlsxFile(columns, data, name, language) {
51
52
  const header = columns.map((field) => field.label);
52
- const rows = this.getRows(columns, data);
53
+ const rows = this.getRows(columns, data, language);
53
54
  const sheets = [
54
55
  {
55
56
  name,
@@ -60,9 +61,9 @@ class ReportsGenerator {
60
61
  const buffer = node_xlsx_1.default.build(sheets);
61
62
  return buffer;
62
63
  }
63
- static CreatePdfFile(columns, data, name) {
64
+ static CreatePdfFile(columns, data, name, language) {
64
65
  return __awaiter(this, void 0, void 0, function* () {
65
- const rows = this.getRows(columns, data);
66
+ const rows = this.getRows(columns, data, language);
66
67
  const ArabicFont = new pdfjs_1.default.Font(fs.readFileSync(__dirname + '/../assets/Amiri-Regular.ttf'));
67
68
  const localizedStringIsExisted = this.checkLocalizedStringExistence(columns);
68
69
  const doc = new pdfjs_1.default.Document({
@@ -85,22 +86,17 @@ class ReportsGenerator {
85
86
  return yield doc.asBuffer();
86
87
  });
87
88
  }
88
- static getRows(columns, data) {
89
- const rows = data.map((row) => columns.map((field) => this.getFieldValue(field, row)));
89
+ static getRows(columns, data, language) {
90
+ const rows = data.map((row) => columns.map((field) => this.getFieldValue(field, row, language)));
90
91
  return rows;
91
92
  }
92
- static getFieldValue(field, row) {
93
+ static getFieldValue(field, row, language) {
93
94
  var _a, _b;
94
95
  switch (field.type) {
95
96
  case helpers_1.FieldTypes.OBJECTID:
96
97
  return (_b = (_a = (0, lodash_1.get)(row, field.value)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
97
98
  case helpers_1.FieldTypes.LOCALIZEDSTRING:
98
- const items = (0, lodash_1.get)(row, field.value);
99
- var formattedString = ``;
100
- items.forEach((item) => {
101
- formattedString += `${item.key} --> ${item.value}\n`;
102
- });
103
- return formattedString;
99
+ return LocalizedStringHelper_1.default.getLocalizedValue(row, field.value, language);
104
100
  default:
105
101
  return (0, lodash_1.get)(row, field.value);
106
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-admin",
3
- "version": "1.26.23",
3
+ "version": "1.27.0",
4
4
  "description": "",
5
5
  "main": "lib/Dashboard.js",
6
6
  "types": "lib/Dashbord.d.ts",