@sapui5/sap.ui.export 1.94.0 → 1.97.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.
Files changed (64) hide show
  1. package/package.json +1 -1
  2. package/src/sap/ui/export/.library +45 -47
  3. package/src/sap/ui/export/ExportBase.js +197 -0
  4. package/src/sap/ui/export/ExportUtils.js +106 -23
  5. package/src/sap/ui/export/PortableDocument.js +371 -0
  6. package/src/sap/ui/export/Spreadsheet.js +36 -162
  7. package/src/sap/ui/export/SpreadsheetExport.js +136 -148
  8. package/src/sap/ui/export/js/SpreadsheetWorker.js +0 -1
  9. package/src/sap/ui/export/js/XLSXBuilder.js +1 -1
  10. package/src/sap/ui/export/js/XLSXBuilder.js.map +1 -1
  11. package/src/sap/ui/export/library.js +9 -2
  12. package/src/sap/ui/export/messagebundle.properties +3 -0
  13. package/src/sap/ui/export/messagebundle_ar.properties +2 -0
  14. package/src/sap/ui/export/messagebundle_bg.properties +2 -0
  15. package/src/sap/ui/export/messagebundle_ca.properties +2 -0
  16. package/src/sap/ui/export/messagebundle_cs.properties +2 -0
  17. package/src/sap/ui/export/messagebundle_cy.properties +2 -0
  18. package/src/sap/ui/export/messagebundle_da.properties +2 -0
  19. package/src/sap/ui/export/messagebundle_de.properties +2 -0
  20. package/src/sap/ui/export/messagebundle_el.properties +2 -0
  21. package/src/sap/ui/export/messagebundle_en.properties +2 -0
  22. package/src/sap/ui/export/messagebundle_en_GB.properties +2 -0
  23. package/src/sap/ui/export/messagebundle_en_US_sappsd.properties +2 -0
  24. package/src/sap/ui/export/messagebundle_en_US_saptrc.properties +2 -0
  25. package/src/sap/ui/export/messagebundle_es.properties +2 -0
  26. package/src/sap/ui/export/messagebundle_es_MX.properties +2 -0
  27. package/src/sap/ui/export/messagebundle_et.properties +2 -0
  28. package/src/sap/ui/export/messagebundle_fi.properties +2 -0
  29. package/src/sap/ui/export/messagebundle_fr.properties +2 -0
  30. package/src/sap/ui/export/messagebundle_fr_CA.properties +2 -0
  31. package/src/sap/ui/export/messagebundle_hi.properties +2 -0
  32. package/src/sap/ui/export/messagebundle_hr.properties +2 -0
  33. package/src/sap/ui/export/messagebundle_hu.properties +2 -0
  34. package/src/sap/ui/export/messagebundle_id.properties +2 -0
  35. package/src/sap/ui/export/messagebundle_it.properties +3 -1
  36. package/src/sap/ui/export/messagebundle_iw.properties +2 -0
  37. package/src/sap/ui/export/messagebundle_ja.properties +2 -0
  38. package/src/sap/ui/export/messagebundle_kk.properties +2 -0
  39. package/src/sap/ui/export/messagebundle_ko.properties +2 -0
  40. package/src/sap/ui/export/messagebundle_lt.properties +2 -0
  41. package/src/sap/ui/export/messagebundle_lv.properties +2 -0
  42. package/src/sap/ui/export/messagebundle_ms.properties +2 -0
  43. package/src/sap/ui/export/messagebundle_nl.properties +2 -0
  44. package/src/sap/ui/export/messagebundle_no.properties +2 -0
  45. package/src/sap/ui/export/messagebundle_pl.properties +2 -0
  46. package/src/sap/ui/export/messagebundle_pt.properties +2 -0
  47. package/src/sap/ui/export/messagebundle_pt_PT.properties +2 -0
  48. package/src/sap/ui/export/messagebundle_ro.properties +2 -0
  49. package/src/sap/ui/export/messagebundle_ru.properties +4 -2
  50. package/src/sap/ui/export/messagebundle_sh.properties +2 -0
  51. package/src/sap/ui/export/messagebundle_sk.properties +4 -2
  52. package/src/sap/ui/export/messagebundle_sl.properties +2 -0
  53. package/src/sap/ui/export/messagebundle_sv.properties +2 -0
  54. package/src/sap/ui/export/messagebundle_th.properties +2 -0
  55. package/src/sap/ui/export/messagebundle_tr.properties +2 -0
  56. package/src/sap/ui/export/messagebundle_uk.properties +2 -0
  57. package/src/sap/ui/export/messagebundle_vi.properties +2 -0
  58. package/src/sap/ui/export/messagebundle_zh_CN.properties +2 -0
  59. package/src/sap/ui/export/messagebundle_zh_TW.properties +2 -0
  60. package/src/sap/ui/export/provider/DataProviderBase.js +29 -30
  61. package/src/sap/ui/export/themes/sap_horizon/library.source.less +8 -0
  62. package/ui5.yaml +6 -4
  63. package/src/sap/ui/export/js/libs/uri.all.min.js +0 -3
  64. package/src/sap/ui/export/js/libs/uri.all.min.js.map +0 -1
@@ -0,0 +1,371 @@
1
+ /*!
2
+ * SAPUI5
3
+ * (c) Copyright 2009-2021 SAP SE. All rights reserved.
4
+ */
5
+
6
+ sap.ui.define([
7
+ 'sap/base/Log',
8
+ 'sap/ui/core/Core',
9
+ 'sap/ui/export/ExportBase',
10
+ 'sap/ui/export/ExportUtils',
11
+ 'sap/ui/model/odata/v4/ODataModel'
12
+ ], function(Log, Core, ExportBase, ExportUtils, ODataModel) {
13
+ 'use strict';
14
+
15
+ /**
16
+ * @constructor The <code>sap.ui.export.PortableDocument</code> class allows you to export table data from a UI5 application to a Portable Document Format (*.PDF) file.
17
+ *
18
+ * @author SAP SE
19
+ * @version 1.97.0
20
+ *
21
+ * @since 1.96
22
+ * @name sap.ui.export.PortableDocument
23
+ * @extends sap.ui.base.ExportBase
24
+ * @private
25
+ */
26
+ var PortableDocument = ExportBase.extend('sap.ui.export.PortableDocument', {
27
+
28
+ constructor: function(mSettings) {
29
+ ExportBase.call(this, mSettings);
30
+ }
31
+ });
32
+
33
+ /**
34
+ * Sets the data source configuration that will be used for exporting the data. If the passed parameter is null,
35
+ * the call will be ignored.
36
+ *
37
+ * @param {Object|sap.ui.model.ListBinding|sap.ui.model.TreeBinding} oDataSource Possible types are a data
38
+ * source configuration, a <code>sap.ui.model.ListBinding</code> or <code>sap.ui.model.TreeBinding</code>
39
+ * @returns {Object|null} - Valid dataSource object or null in case the dataSource configuration is not supported
40
+ *
41
+ * @since 1.96
42
+ * @public
43
+ */
44
+ PortableDocument.prototype.processDataSource = function(oDataSource) {
45
+ var mDataSource = null;
46
+ var sDataSourceType = typeof oDataSource;
47
+
48
+ if (!oDataSource) {
49
+ return null;
50
+ }
51
+
52
+ if (sDataSourceType != 'object') {
53
+ Log.error('Spreadsheet#processDataSource: Unable to apply data source of type ' + sDataSourceType);
54
+
55
+ return null;
56
+ }
57
+
58
+ if (oDataSource.dataUrl && oDataSource.serviceUrl) {
59
+ mDataSource = oDataSource;
60
+ }
61
+
62
+ if (oDataSource.isA && oDataSource.isA(['sap.ui.model.ListBinding', 'sap.ui.model.TreeBinding'])) {
63
+ mDataSource = this.createDataSourceFromBinding(oDataSource);
64
+ }
65
+
66
+ return mDataSource;
67
+ };
68
+
69
+ /**
70
+ * Creates a valid dataSource configuration
71
+ *
72
+ * @param {sap.ui.model.ListBinding|sap.ui.model.TreeBinding} oBinding - A subclass of <code>sap.ui.model.ListBinding</code> or <code>sap.ui.model.TreeBinding</code>
73
+ * @returns {Object} - Valid data source configuration built upon the ListBinding
74
+ */
75
+ PortableDocument.prototype.createDataSourceFromBinding = function(oBinding) {
76
+
77
+ /**
78
+ * Use empty array as default in case of <code>ListBinding</code> is not of type
79
+ * ClientListBinding and does not provide a getDownloadUrl function
80
+ */
81
+ var oDataSource = null;
82
+
83
+ /**
84
+ * If <code>ClientListBinding</code>, we use the binding path to receive the data from the underlying model
85
+ */
86
+ if (oBinding.isA('sap.ui.model.ClientListBinding')) {
87
+ Log.error('Unable to create dataSource configuration due to not supported Binding: ' + oBinding.getMetadata().getName());
88
+ }
89
+
90
+ if (oBinding.isA('sap.ui.model.ClientTreeBinding')) {
91
+ Log.error('Unable to create dataSource configuration due to not supported Binding: ' + oBinding.getMetadata().getName());
92
+ }
93
+
94
+ /**
95
+ * All other <code>Bindings</code> need to provide a downloadUrl
96
+ */
97
+ if (typeof oBinding.getDownloadUrl === 'function') {
98
+ var oModel = oBinding.getModel(),
99
+ sDataUrl = ExportUtils.interceptUrl(oBinding.getDownloadUrl('pdf')),
100
+ sServiceUrl = ExportUtils.interceptUrl(oModel.sServiceUrl),
101
+ bV4ODataModel = oModel.isA('sap.ui.model.odata.v4.ODataModel');
102
+
103
+ var oDataUrl = new URL(sDataUrl, document.baseURI);
104
+ oDataUrl.hash = '';
105
+
106
+ // Reference the Model for later use
107
+ this._oModel = oModel;
108
+ this._oModel.setUseBatch(false);
109
+
110
+ /* Remove $format system query option because it would overwrite the "Accept" header */
111
+ oDataUrl.search = oDataUrl.search.split('&').filter(function(val) {
112
+ return val.indexOf('$format') == -1;
113
+ }).join('&');
114
+
115
+ oDataSource = {
116
+ type: 'odata',
117
+ version: bV4ODataModel ? 4 : 2,
118
+ dataUrl: oDataUrl.toString(),
119
+ serviceUrl: sServiceUrl.split('/').slice(0, -5).join('/') + '/default/iwbep/common/0001/', // Requires the serviceUrl to end with a /
120
+ headers: bV4ODataModel ? oModel.getHttpHeaders(true) : oModel.getHeaders()
121
+ };
122
+ }
123
+
124
+ return oDataSource;
125
+ };
126
+
127
+ /**
128
+ * Creates the DocumentDescription based on the given export
129
+ * settings and assigns a unique Id to it.
130
+ *
131
+ * @param {Object} oWorkbook Workbook settings of the export configuration
132
+ * @returns {Object} DocumentDescription object that contains all relevant export settings
133
+ * @private
134
+ */
135
+ PortableDocument.prototype._createDocumentDescription = function(oWorkbook) {
136
+ var oDocumentDescription, oMetaInfo;
137
+
138
+ oDocumentDescription = {
139
+ "Title": oWorkbook.context.title,
140
+ "Format": {
141
+ "PaperSize": "DIN_A4",
142
+ "Orientation": "LANDSCAPE",
143
+ "FontSize": 12
144
+ },
145
+ "Signature": {
146
+ "DoSign": true,
147
+ "Reason": ""
148
+ },
149
+ "CoverPage": [],
150
+ "TableColumns": []
151
+ };
152
+
153
+ oMetaInfo = oWorkbook.context.metaInfo;
154
+
155
+ /* Add metaInfo to CoverPage */
156
+ if (oMetaInfo instanceof Array) {
157
+ oMetaInfo.forEach(function(oGroup) {
158
+ var oCoverPageGroup = {
159
+ "Title": oGroup.name,
160
+ "Content": []
161
+ };
162
+
163
+ oGroup.items.forEach(function(oItem) {
164
+ oCoverPageGroup["Content"].push({
165
+ "Name": oItem.key,
166
+ "Value": oItem.value
167
+ });
168
+ });
169
+ oDocumentDescription["CoverPage"].push(oCoverPageGroup);
170
+ });
171
+ }
172
+
173
+ /* Add columns */
174
+ oWorkbook.columns.forEach(function(oColumn){
175
+ oDocumentDescription["TableColumns"].push({
176
+ "Name": Array.isArray(oColumn.property) ? oColumn.property[0] : oColumn.property,
177
+ "Header": oColumn.label
178
+ });
179
+ });
180
+
181
+ return oDocumentDescription;
182
+ };
183
+
184
+ /**
185
+ * Returns the name of the EntitySet that is being used with the given OData version.
186
+ *
187
+ * @param {Object} mDataSource DataSource object containing information about OData version
188
+ * @returns {string} Name of the EntitySet according to the OData version
189
+ */
190
+ PortableDocument.prototype._getEntitySetName = function(mDataSource) {
191
+ var version = mDataSource && mDataSource.version || 2; // Use OData V2 by default
192
+
193
+ return version == 4 ? 'MyDocumentDescriptions' : 'SAP__MyDocumentDescriptions';
194
+ };
195
+
196
+ /**
197
+ * Returns the specific ODataModel that is being used for binding to the DocumentDescription EntitySet
198
+ *
199
+ * @param {Object} oDataSource DataSource settings of the export configuration
200
+ * @returns {ODataModel} ODataModel, either V2 or V4.
201
+ */
202
+ PortableDocument.prototype._getModel = function(oDataSource) {
203
+ var version = oDataSource.version || 2;
204
+
205
+ return version === 4 ? new ODataModel({
206
+ serviceUrl: oDataSource.serviceUrl,
207
+ synchronizationMode: 'None'
208
+ }) : this._oModel;
209
+ };
210
+
211
+ /**
212
+ * Applies default settings to the export configuration.
213
+ *
214
+ * @param {Object} mSettings Export configuration object
215
+ * @returns {Promise} Promise that gets resolved when the default settings have been applied
216
+ */
217
+ PortableDocument.prototype.setDefaultExportSettings = function(mSettings) {
218
+ var oContext = mSettings && mSettings.workbook && mSettings.workbook.context;
219
+
220
+ if (!(oContext instanceof Object)) {
221
+ oContext = mSettings.workbook.context = {};
222
+ }
223
+
224
+ if (typeof oContext.title === 'string') {
225
+ return Promise.resolve();
226
+ }
227
+
228
+ return Core.getLibraryResourceBundle('sap.ui.export', true).then(function(oResourceBundle) {
229
+ oContext.title = oResourceBundle.getText('XLSX_DEFAULT_TITLE');
230
+ });
231
+ };
232
+
233
+ /**
234
+ * Sends a POST request to the GW service which creates the
235
+ * DocumentDescription. The corresponding Id is assigned by
236
+ * the backend and passed to the event handler functions.
237
+ *
238
+ * @param {Object} oDocumentDescription DocumentDescription instance that is being created
239
+ * @param {Object} oDataSource DataSource settings of the export configuration
240
+ * @param {function} fnSuccess Success handler function
241
+ * @param {function} fnError Error handler function
242
+ */
243
+ PortableDocument.prototype.postDocumentDescription = function(oDocumentDescription, oDataSource, fnSuccess, fnError) {
244
+ var oBinding, oModel, sPath;
245
+
246
+ oModel = this._getModel(oDataSource);
247
+ sPath = '/' + this._getEntitySetName(oDataSource);
248
+
249
+ if (!oModel || !oModel.isA(['sap.ui.model.odata.v4.ODataModel', 'sap.ui.model.odata.v2.ODataModel'])) {
250
+ fnError('Unsupported Model');
251
+ }
252
+
253
+ if (oModel.isA('sap.ui.model.odata.v4.ODataModel')) {
254
+ oBinding = oModel.bindList(sPath);
255
+
256
+ oBinding.attachCreateCompleted(function(oEvent) {
257
+ var success = oEvent.getParameter('success');
258
+
259
+ if (success) {
260
+ fnSuccess(oEvent.getParameter('context').getObject()['Id']);
261
+ } else {
262
+ fnError();
263
+ }
264
+ });
265
+
266
+ oBinding.create(oDocumentDescription);
267
+ } else {
268
+ oModel.create(sPath, oDocumentDescription, {
269
+ success: function(oData) {
270
+ fnSuccess(oData['Id']);
271
+ },
272
+ error: fnError
273
+ });
274
+ }
275
+ };
276
+
277
+ /**
278
+ * Triggers the export process and returns a Promise the
279
+ * gets resolved as soon as the export is finished.
280
+ *
281
+ * @param {Object} mSettings Export settings
282
+ * @returns {Promise} Promise that is being resolved as soon as the PDF export is finished
283
+ */
284
+ PortableDocument.prototype.createBuildPromise = function(mSettings) {
285
+ var that = this;
286
+
287
+ return new Promise(function(fnResolve, fnReject) {
288
+ var oDocumentDescription;
289
+
290
+ oDocumentDescription = that._createDocumentDescription(mSettings.workbook);
291
+ that.postDocumentDescription(oDocumentDescription, mSettings.dataSource, fnResolve, fnReject);
292
+
293
+ }).then(function(sDocumentDescriptionId) {
294
+ return that.sendRequest(mSettings.dataSource.dataUrl, sDocumentDescriptionId).then(function(response) {
295
+ ExportUtils.saveAsFile(response, mSettings.fileName);
296
+ });
297
+ });
298
+ };
299
+
300
+ /**
301
+ * Requests the generated PDF via HTTP GET from the OData service.
302
+ *
303
+ * @param {string} sUrl Absolute data URL of the OData entity that should be exported as PDF
304
+ * @param {string} sDocumentDescriptionId GUID of the DocumentDescription that should be used for creating the PDF
305
+ * @returns {Promise} A Promise that gets resolved after the XHR request
306
+ */
307
+ PortableDocument.prototype.sendRequest = function(sUrl, sDocumentDescriptionId) {
308
+ return new Promise(function(fnResolve, fnReject) {
309
+ var oXHR = this.request = new XMLHttpRequest();
310
+
311
+ /* Send GET request to receive PDF file */
312
+ oXHR.open('GET', sUrl);
313
+ oXHR.responseType = 'blob';
314
+ oXHR.setRequestHeader("Accept", "application/pdf");
315
+ oXHR.setRequestHeader("SAP-Document-Description-Id", sDocumentDescriptionId);
316
+
317
+ oXHR.addEventListener('abort', function() {
318
+ fnReject('Request aborted');
319
+ });
320
+
321
+ oXHR.addEventListener('error', function() {
322
+ fnReject('Error occured while requesting data');
323
+ });
324
+
325
+ oXHR.addEventListener('load', function() {
326
+ var status = oXHR.status;
327
+
328
+ if (status >= 200 && status <= 400) {
329
+ fnResolve(oXHR.response);
330
+ } else {
331
+ fnReject(oXHR.response);
332
+ }
333
+ });
334
+
335
+ oXHR.send();
336
+ }.bind(this));
337
+ };
338
+
339
+ /**
340
+ * Cancels the active request. If the request has not been sent
341
+ * or the response has been received already, this function has
342
+ * no effect.
343
+ *
344
+ * @function
345
+ * @name sap.ui.export.PortableDocument#cancel
346
+ * @since 1.96
347
+ * @public
348
+ */
349
+ PortableDocument.prototype.cancel = function() {
350
+ if (this.request && this.request.readyState != XMLHttpRequest.DONE) {
351
+ this.request.abort();
352
+ this.request = null;
353
+ }
354
+ };
355
+
356
+ /**
357
+ * Cleans up the internal structures and removes all event handlers.
358
+ *
359
+ * The object must not be used anymore after destroy was called.
360
+ *
361
+ * @see sap.ui.export.ExportBase#destroy
362
+ * @public
363
+ */
364
+ PortableDocument.prototype.destroy = function() {
365
+ ExportBase.prototype.destroy.apply(this, arguments);
366
+
367
+ this._oModel = null;
368
+ };
369
+
370
+ return PortableDocument;
371
+ });