@sap-ux/preview-middleware 0.12.15 → 0.13.1
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.
- package/README.md +18 -10
- package/dist/base/flp.d.ts +10 -1
- package/dist/base/flp.js +77 -23
- package/dist/client/adp/api-handler.js +141 -141
- package/dist/client/adp/command-executor.js +54 -54
- package/dist/client/adp/control-utils.js +44 -44
- package/dist/client/adp/controllers/AddFragment.controller.js +206 -206
- package/dist/client/adp/controllers/BaseDialog.controller.js +57 -57
- package/dist/client/adp/controllers/ControllerExtension.controller.js +174 -174
- package/dist/client/adp/controllers/ExtensionPoint.controller.js +100 -100
- package/dist/client/adp/init-dialogs.js +74 -74
- package/dist/client/adp/ui5-version-utils.js +63 -63
- package/dist/client/adp/utils.js +33 -33
- package/dist/client/cpe/changes/flex-change.js +51 -51
- package/dist/client/cpe/changes/index.js +10 -10
- package/dist/client/cpe/changes/validator.js +35 -35
- package/dist/client/cpe/documentation.js +164 -164
- package/dist/client/cpe/logger.js +30 -30
- package/dist/client/cpe/outline/nodes.js +84 -84
- package/dist/client/cpe/outline/utils.js +37 -37
- package/dist/client/cpe/types.js +4 -4
- package/dist/client/cpe/ui5-utils.js +49 -49
- package/dist/client/cpe/utils.js +48 -48
- package/dist/client/flp/WorkspaceConnector.js +84 -84
- package/dist/client/flp/common.js +28 -28
- package/dist/client/flp/enableFakeConnector.js +77 -77
- package/dist/client/flp/init.js +220 -220
- package/dist/client/flp/initConnectors.js +33 -33
- package/dist/client/flp/initRta.js +178 -178
- package/dist/types/index.d.ts +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -34,13 +34,13 @@ When this middleware is used together with the `reload-middleware`, then the ord
|
|
|
34
34
|
|
|
35
35
|
### `flp.apps`
|
|
36
36
|
Array of additional application configurations:
|
|
37
|
-
| Option
|
|
38
|
-
|
|
|
39
|
-
| `target`
|
|
40
|
-
| `local`
|
|
41
|
-
| `intent`
|
|
42
|
-
| `intent.object`
|
|
43
|
-
| `intent.action`
|
|
37
|
+
| Option | Type | Default Value | Description |
|
|
38
|
+
| ------------------------ | -------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
39
|
+
| `target` | `string` | | Target path of the additional application |
|
|
40
|
+
| `local` or `componentId` | `string` | | Either a local path to a folder containing the application or the `componentId` of a remote app is required |
|
|
41
|
+
| `intent` | | | Optional intent to be used for the application |
|
|
42
|
+
| `intent.object` | `string` | `(calculated)` | Optional intent object, if it is not provided then it will be calculated based on the application id |
|
|
43
|
+
| `intent.action` | `string` | `preview` | Optional intent action |
|
|
44
44
|
|
|
45
45
|
### `adp.target`
|
|
46
46
|
| Option | Type | Description |
|
|
@@ -93,7 +93,7 @@ server:
|
|
|
93
93
|
|
|
94
94
|
### Additional Applications
|
|
95
95
|
If you want to test cross application navigation, then you can add additional applications into the local FLP.
|
|
96
|
-
With this configuration, an application that is locally available in `../local-folder` will be available at `/apps/other-app` and will also be added as tile to the local FLP
|
|
96
|
+
With this configuration, an application that is locally available in `../local-folder` will be available at `/apps/other-app` and will also be added as tile to the local FLP as well as one of the UI5 sample apps will be bound to the intent `TheOther-preview`.
|
|
97
97
|
```Yaml
|
|
98
98
|
server:
|
|
99
99
|
customMiddleware:
|
|
@@ -101,8 +101,16 @@ server:
|
|
|
101
101
|
afterMiddleware: compression
|
|
102
102
|
configuration:
|
|
103
103
|
apps:
|
|
104
|
-
-
|
|
105
|
-
|
|
104
|
+
- target: /apps/other-app
|
|
105
|
+
local: ../local-folder
|
|
106
|
+
intent:
|
|
107
|
+
object: TheLocal
|
|
108
|
+
action: preview
|
|
109
|
+
- target: /test-resources/sap/ushell/demoapps/AppNavSample
|
|
110
|
+
componentId: sap.ushell.demo.AppNavSample
|
|
111
|
+
intent:
|
|
112
|
+
object: TheOther
|
|
113
|
+
action: preview
|
|
106
114
|
```
|
|
107
115
|
|
|
108
116
|
### Runtime Adaptation Support
|
package/dist/base/flp.d.ts
CHANGED
|
@@ -134,7 +134,16 @@ export declare class FlpSandbox {
|
|
|
134
134
|
* @param manifest manifest of the additional target app
|
|
135
135
|
* @param app configuration for the preview
|
|
136
136
|
*/
|
|
137
|
-
addApp(manifest: Manifest, app: App): void
|
|
137
|
+
addApp(manifest: Manifest, app: App): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Get the i18n text of the given property.
|
|
140
|
+
*
|
|
141
|
+
* @param projectRoot absolute path to the project root
|
|
142
|
+
* @param propertyValue value of the property
|
|
143
|
+
* @returns i18n text of the property
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
private getI18nTextFromProperty;
|
|
138
147
|
/**
|
|
139
148
|
* Gets the UI5 libs dependencies from manifest.json.
|
|
140
149
|
*
|
package/dist/base/flp.js
CHANGED
|
@@ -15,6 +15,7 @@ const fs_1 = require("fs");
|
|
|
15
15
|
const path_1 = require("path");
|
|
16
16
|
const express_1 = require("express");
|
|
17
17
|
const flex_1 = require("./flex");
|
|
18
|
+
const project_access_1 = require("@sap-ux/project-access");
|
|
18
19
|
const adp_tooling_1 = require("@sap-ux/adp-tooling");
|
|
19
20
|
const test_1 = require("./test");
|
|
20
21
|
const DEVELOPER_MODE_CONFIG = new Map([
|
|
@@ -143,7 +144,7 @@ class FlpSandbox {
|
|
|
143
144
|
},
|
|
144
145
|
locateReuseLibsScript: (_e = this.config.libs) !== null && _e !== void 0 ? _e : (yield this.hasLocateReuseLibsScript())
|
|
145
146
|
};
|
|
146
|
-
this.addApp(manifest, {
|
|
147
|
+
yield this.addApp(manifest, {
|
|
147
148
|
componentId,
|
|
148
149
|
target: (_f = resources[componentId !== null && componentId !== void 0 ? componentId : id]) !== null && _f !== void 0 ? _f : this.templateConfig.basePath,
|
|
149
150
|
local: '.',
|
|
@@ -159,7 +160,7 @@ class FlpSandbox {
|
|
|
159
160
|
if (this.test) {
|
|
160
161
|
this.addTestRoutes(this.test, id);
|
|
161
162
|
}
|
|
162
|
-
this.addRoutesForAdditionalApps();
|
|
163
|
+
yield this.addRoutesForAdditionalApps();
|
|
163
164
|
this.logger.info(`Initialized for app ${id}`);
|
|
164
165
|
this.logger.debug(`Configured apps: ${JSON.stringify(this.templateConfig.apps)}`);
|
|
165
166
|
});
|
|
@@ -268,14 +269,32 @@ class FlpSandbox {
|
|
|
268
269
|
* Add additional routes for apps also to be shown in the local FLP.
|
|
269
270
|
*/
|
|
270
271
|
addRoutesForAdditionalApps() {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
272
|
+
var _a, _b;
|
|
273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
+
for (const app of this.config.apps) {
|
|
275
|
+
let manifest;
|
|
276
|
+
if (app.local) {
|
|
277
|
+
manifest = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(app.local, 'webapp/manifest.json'), 'utf-8'));
|
|
278
|
+
this.router.use(app.target, (0, express_1.static)((0, path_1.join)(app.local, 'webapp')));
|
|
279
|
+
this.logger.info(`Serving additional application at ${app.target} from ${app.local}`);
|
|
280
|
+
}
|
|
281
|
+
else if (app.componentId) {
|
|
282
|
+
manifest = {
|
|
283
|
+
'sap.app': {
|
|
284
|
+
id: app.componentId,
|
|
285
|
+
title: app.intent ? `${app.intent.object}-${app.intent.action}` : app.componentId
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (manifest) {
|
|
290
|
+
yield this.addApp(manifest, app);
|
|
291
|
+
this.logger.info(`Adding additional intent: ${(_a = app.intent) === null || _a === void 0 ? void 0 : _a.object}-${(_b = app.intent) === null || _b === void 0 ? void 0 : _b.action}`);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
this.logger.info(`Invalid application config for route ${app.target} because neither componentId nor local folder provided.`);
|
|
295
|
+
}
|
|
277
296
|
}
|
|
278
|
-
}
|
|
297
|
+
});
|
|
279
298
|
}
|
|
280
299
|
/**
|
|
281
300
|
* Retrieves the configuration settings for UI5 flexibility services.
|
|
@@ -400,21 +419,56 @@ class FlpSandbox {
|
|
|
400
419
|
* @param app configuration for the preview
|
|
401
420
|
*/
|
|
402
421
|
addApp(manifest, app) {
|
|
403
|
-
var _a, _b, _c, _d, _e, _f;
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
422
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
423
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
+
const id = manifest['sap.app'].id;
|
|
425
|
+
(_a = app.intent) !== null && _a !== void 0 ? _a : (app.intent = {
|
|
426
|
+
object: id.replace(/\./g, ''),
|
|
427
|
+
action: 'preview'
|
|
428
|
+
});
|
|
429
|
+
let title = (_b = manifest['sap.app'].title) !== null && _b !== void 0 ? _b : id;
|
|
430
|
+
let description = (_c = manifest['sap.app'].description) !== null && _c !== void 0 ? _c : '';
|
|
431
|
+
if (app.local) {
|
|
432
|
+
title = (_d = (yield this.getI18nTextFromProperty(app.local, manifest['sap.app'].title))) !== null && _d !== void 0 ? _d : id;
|
|
433
|
+
description = (_e = (yield this.getI18nTextFromProperty(app.local, manifest['sap.app'].description))) !== null && _e !== void 0 ? _e : '';
|
|
434
|
+
}
|
|
435
|
+
this.templateConfig.ui5.resources[id] = app.target;
|
|
436
|
+
this.templateConfig.apps[`${(_f = app.intent) === null || _f === void 0 ? void 0 : _f.object}-${(_g = app.intent) === null || _g === void 0 ? void 0 : _g.action}`] = {
|
|
437
|
+
title: title,
|
|
438
|
+
description: description,
|
|
439
|
+
additionalInformation: `SAPUI5.Component=${(_h = app.componentId) !== null && _h !== void 0 ? _h : id}`,
|
|
440
|
+
applicationType: 'URL',
|
|
441
|
+
url: app.target,
|
|
442
|
+
applicationDependencies: { manifest: true }
|
|
443
|
+
};
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Get the i18n text of the given property.
|
|
448
|
+
*
|
|
449
|
+
* @param projectRoot absolute path to the project root
|
|
450
|
+
* @param propertyValue value of the property
|
|
451
|
+
* @returns i18n text of the property
|
|
452
|
+
* @private
|
|
453
|
+
*/
|
|
454
|
+
getI18nTextFromProperty(projectRoot, propertyValue) {
|
|
455
|
+
var _a, _b, _c, _d;
|
|
456
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
457
|
+
//i18n model format could be {{key}} or {i18n>key}
|
|
458
|
+
if (!propertyValue || propertyValue.search(/{{\w+}}|{i18n>\w+}/g) === -1) {
|
|
459
|
+
return propertyValue;
|
|
460
|
+
}
|
|
461
|
+
const propertyI18nKey = propertyValue.replace(/i18n>|[{}]/g, '');
|
|
462
|
+
const projectAccess = yield (0, project_access_1.createProjectAccess)(projectRoot);
|
|
463
|
+
try {
|
|
464
|
+
const bundle = (yield projectAccess.getApplication('').getI18nBundles())['sap.app'];
|
|
465
|
+
return (_d = (_c = (_b = (_a = bundle[propertyI18nKey]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : propertyI18nKey;
|
|
466
|
+
}
|
|
467
|
+
catch (e) {
|
|
468
|
+
this.logger.warn('Failed to load i18n properties bundle');
|
|
469
|
+
}
|
|
470
|
+
return propertyI18nKey;
|
|
408
471
|
});
|
|
409
|
-
this.templateConfig.ui5.resources[id] = app.target;
|
|
410
|
-
this.templateConfig.apps[`${(_b = app.intent) === null || _b === void 0 ? void 0 : _b.object}-${(_c = app.intent) === null || _c === void 0 ? void 0 : _c.action}`] = {
|
|
411
|
-
title: (_d = manifest['sap.app'].title) !== null && _d !== void 0 ? _d : id,
|
|
412
|
-
description: (_e = manifest['sap.app'].description) !== null && _e !== void 0 ? _e : '',
|
|
413
|
-
additionalInformation: `SAPUI5.Component=${(_f = app.componentId) !== null && _f !== void 0 ? _f : id}`,
|
|
414
|
-
applicationType: 'URL',
|
|
415
|
-
url: app.target,
|
|
416
|
-
applicationDependencies: { manifest: true }
|
|
417
|
-
};
|
|
418
472
|
}
|
|
419
473
|
/**
|
|
420
474
|
* Gets the UI5 libs dependencies from manifest.json.
|
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define([], function () {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
var ApiEndpoints = /*#__PURE__*/function (ApiEndpoints) {
|
|
7
|
-
ApiEndpoints["CHANGES"] = "/preview/api/changes";
|
|
8
|
-
ApiEndpoints["FRAGMENT"] = "/adp/api/fragment";
|
|
9
|
-
ApiEndpoints["CONTROLLER"] = "/adp/api/controller";
|
|
10
|
-
ApiEndpoints["CODE_EXT"] = "/adp/api/code_ext";
|
|
11
|
-
ApiEndpoints["MANIFEST_APP_DESCRIPTOR"] = "/manifest.appdescr_variant";
|
|
12
|
-
return ApiEndpoints;
|
|
13
|
-
}(ApiEndpoints || {});
|
|
14
|
-
var RequestMethod = /*#__PURE__*/function (RequestMethod) {
|
|
15
|
-
RequestMethod["GET"] = "GET";
|
|
16
|
-
RequestMethod["PUT"] = "PUT";
|
|
17
|
-
RequestMethod["POST"] = "POST";
|
|
18
|
-
RequestMethod["PATCH"] = "PATCH";
|
|
19
|
-
RequestMethod["DELETE"] = "DELETE";
|
|
20
|
-
return RequestMethod;
|
|
21
|
-
}(RequestMethod || {});
|
|
22
|
-
/**
|
|
23
|
-
* Requests a given endpoint
|
|
24
|
-
*
|
|
25
|
-
* @param endpoint API Endpoint
|
|
26
|
-
* @param method RequestMethod
|
|
27
|
-
* @param data Data to be sent to the server
|
|
28
|
-
* @returns Data from the server request
|
|
29
|
-
*/
|
|
30
|
-
async function request(endpoint, method, data) {
|
|
31
|
-
const config = {
|
|
32
|
-
method,
|
|
33
|
-
body: JSON.stringify(data),
|
|
34
|
-
headers: {
|
|
35
|
-
'content-type': 'application/json'
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
try {
|
|
39
|
-
const response = await fetch(endpoint, config);
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
const errorData = await response.json();
|
|
42
|
-
const message = errorData?.message ?? '';
|
|
43
|
-
throw new Error(`Request failed, status: ${response.status}. ${message}`.trim());
|
|
44
|
-
}
|
|
45
|
-
switch (method) {
|
|
46
|
-
case RequestMethod.GET:
|
|
47
|
-
return response.json();
|
|
48
|
-
case RequestMethod.POST:
|
|
49
|
-
/**
|
|
50
|
-
* Since POST usually creates something
|
|
51
|
-
* and returns nothing (or a message) we just parse the text from res.send(msg)
|
|
52
|
-
*/
|
|
53
|
-
return response.text();
|
|
54
|
-
default:
|
|
55
|
-
return response.json();
|
|
56
|
-
}
|
|
57
|
-
} catch (e) {
|
|
58
|
-
throw new Error(e.message);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Retrieves all XML fragments from the project's workspace
|
|
64
|
-
*
|
|
65
|
-
* @returns Generic Promise<T>
|
|
66
|
-
*/
|
|
67
|
-
async function getFragments() {
|
|
68
|
-
return request(ApiEndpoints.FRAGMENT, RequestMethod.GET);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Writes an XML fragment to the project's workspace
|
|
73
|
-
*
|
|
74
|
-
* @param data Data to be send to the server
|
|
75
|
-
* @returns Generic Promise<T>
|
|
76
|
-
*/
|
|
77
|
-
async function writeFragment(data) {
|
|
78
|
-
return request(ApiEndpoints.FRAGMENT, RequestMethod.POST, data);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Retrieves manifest.appdescr_variant from the project's workspace
|
|
83
|
-
*
|
|
84
|
-
* @returns Generic Promise<T>
|
|
85
|
-
*/
|
|
86
|
-
async function getManifestAppdescr() {
|
|
87
|
-
return request(ApiEndpoints.MANIFEST_APP_DESCRIPTOR, RequestMethod.GET);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Retrieves all controller extensions from the project's workspace
|
|
92
|
-
*
|
|
93
|
-
* @returns Generic Promise<T>
|
|
94
|
-
*/
|
|
95
|
-
async function readControllers() {
|
|
96
|
-
return request(ApiEndpoints.CONTROLLER, RequestMethod.GET);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Writes a Controller to the project's workspace
|
|
101
|
-
*
|
|
102
|
-
* @param data Data to be send to the server
|
|
103
|
-
* @returns Generic Promise<T>
|
|
104
|
-
*/
|
|
105
|
-
async function writeController(data) {
|
|
106
|
-
return request(ApiEndpoints.CONTROLLER, RequestMethod.POST, data);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Checks for existing controller in the project's workspace
|
|
111
|
-
*
|
|
112
|
-
* @param controllerName Name of the controller
|
|
113
|
-
* @returns {CodeExtResponse} Returns path to existing controller if found
|
|
114
|
-
*/
|
|
115
|
-
async function getExistingController(controllerName) {
|
|
116
|
-
return request(`${ApiEndpoints.CODE_EXT}/${controllerName}`, RequestMethod.GET);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Writes a change object to the project's workspace
|
|
121
|
-
*
|
|
122
|
-
* @param data Data to be send to the server
|
|
123
|
-
* @returns Generic Promise<T>
|
|
124
|
-
*/
|
|
125
|
-
async function writeChange(data) {
|
|
126
|
-
return request(ApiEndpoints.CHANGES, RequestMethod.POST, data);
|
|
127
|
-
}
|
|
128
|
-
var __exports = {
|
|
129
|
-
__esModule: true
|
|
130
|
-
};
|
|
131
|
-
__exports.ApiEndpoints = ApiEndpoints;
|
|
132
|
-
__exports.RequestMethod = RequestMethod;
|
|
133
|
-
__exports.request = request;
|
|
134
|
-
__exports.getFragments = getFragments;
|
|
135
|
-
__exports.writeFragment = writeFragment;
|
|
136
|
-
__exports.getManifestAppdescr = getManifestAppdescr;
|
|
137
|
-
__exports.readControllers = readControllers;
|
|
138
|
-
__exports.writeController = writeController;
|
|
139
|
-
__exports.getExistingController = getExistingController;
|
|
140
|
-
__exports.writeChange = writeChange;
|
|
141
|
-
return __exports;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define([], function () {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
var ApiEndpoints = /*#__PURE__*/function (ApiEndpoints) {
|
|
7
|
+
ApiEndpoints["CHANGES"] = "/preview/api/changes";
|
|
8
|
+
ApiEndpoints["FRAGMENT"] = "/adp/api/fragment";
|
|
9
|
+
ApiEndpoints["CONTROLLER"] = "/adp/api/controller";
|
|
10
|
+
ApiEndpoints["CODE_EXT"] = "/adp/api/code_ext";
|
|
11
|
+
ApiEndpoints["MANIFEST_APP_DESCRIPTOR"] = "/manifest.appdescr_variant";
|
|
12
|
+
return ApiEndpoints;
|
|
13
|
+
}(ApiEndpoints || {});
|
|
14
|
+
var RequestMethod = /*#__PURE__*/function (RequestMethod) {
|
|
15
|
+
RequestMethod["GET"] = "GET";
|
|
16
|
+
RequestMethod["PUT"] = "PUT";
|
|
17
|
+
RequestMethod["POST"] = "POST";
|
|
18
|
+
RequestMethod["PATCH"] = "PATCH";
|
|
19
|
+
RequestMethod["DELETE"] = "DELETE";
|
|
20
|
+
return RequestMethod;
|
|
21
|
+
}(RequestMethod || {});
|
|
22
|
+
/**
|
|
23
|
+
* Requests a given endpoint
|
|
24
|
+
*
|
|
25
|
+
* @param endpoint API Endpoint
|
|
26
|
+
* @param method RequestMethod
|
|
27
|
+
* @param data Data to be sent to the server
|
|
28
|
+
* @returns Data from the server request
|
|
29
|
+
*/
|
|
30
|
+
async function request(endpoint, method, data) {
|
|
31
|
+
const config = {
|
|
32
|
+
method,
|
|
33
|
+
body: JSON.stringify(data),
|
|
34
|
+
headers: {
|
|
35
|
+
'content-type': 'application/json'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(endpoint, config);
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const errorData = await response.json();
|
|
42
|
+
const message = errorData?.message ?? '';
|
|
43
|
+
throw new Error(`Request failed, status: ${response.status}. ${message}`.trim());
|
|
44
|
+
}
|
|
45
|
+
switch (method) {
|
|
46
|
+
case RequestMethod.GET:
|
|
47
|
+
return response.json();
|
|
48
|
+
case RequestMethod.POST:
|
|
49
|
+
/**
|
|
50
|
+
* Since POST usually creates something
|
|
51
|
+
* and returns nothing (or a message) we just parse the text from res.send(msg)
|
|
52
|
+
*/
|
|
53
|
+
return response.text();
|
|
54
|
+
default:
|
|
55
|
+
return response.json();
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw new Error(e.message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves all XML fragments from the project's workspace
|
|
64
|
+
*
|
|
65
|
+
* @returns Generic Promise<T>
|
|
66
|
+
*/
|
|
67
|
+
async function getFragments() {
|
|
68
|
+
return request(ApiEndpoints.FRAGMENT, RequestMethod.GET);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Writes an XML fragment to the project's workspace
|
|
73
|
+
*
|
|
74
|
+
* @param data Data to be send to the server
|
|
75
|
+
* @returns Generic Promise<T>
|
|
76
|
+
*/
|
|
77
|
+
async function writeFragment(data) {
|
|
78
|
+
return request(ApiEndpoints.FRAGMENT, RequestMethod.POST, data);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves manifest.appdescr_variant from the project's workspace
|
|
83
|
+
*
|
|
84
|
+
* @returns Generic Promise<T>
|
|
85
|
+
*/
|
|
86
|
+
async function getManifestAppdescr() {
|
|
87
|
+
return request(ApiEndpoints.MANIFEST_APP_DESCRIPTOR, RequestMethod.GET);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Retrieves all controller extensions from the project's workspace
|
|
92
|
+
*
|
|
93
|
+
* @returns Generic Promise<T>
|
|
94
|
+
*/
|
|
95
|
+
async function readControllers() {
|
|
96
|
+
return request(ApiEndpoints.CONTROLLER, RequestMethod.GET);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Writes a Controller to the project's workspace
|
|
101
|
+
*
|
|
102
|
+
* @param data Data to be send to the server
|
|
103
|
+
* @returns Generic Promise<T>
|
|
104
|
+
*/
|
|
105
|
+
async function writeController(data) {
|
|
106
|
+
return request(ApiEndpoints.CONTROLLER, RequestMethod.POST, data);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Checks for existing controller in the project's workspace
|
|
111
|
+
*
|
|
112
|
+
* @param controllerName Name of the controller
|
|
113
|
+
* @returns {CodeExtResponse} Returns path to existing controller if found
|
|
114
|
+
*/
|
|
115
|
+
async function getExistingController(controllerName) {
|
|
116
|
+
return request(`${ApiEndpoints.CODE_EXT}/${controllerName}`, RequestMethod.GET);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Writes a change object to the project's workspace
|
|
121
|
+
*
|
|
122
|
+
* @param data Data to be send to the server
|
|
123
|
+
* @returns Generic Promise<T>
|
|
124
|
+
*/
|
|
125
|
+
async function writeChange(data) {
|
|
126
|
+
return request(ApiEndpoints.CHANGES, RequestMethod.POST, data);
|
|
127
|
+
}
|
|
128
|
+
var __exports = {
|
|
129
|
+
__esModule: true
|
|
130
|
+
};
|
|
131
|
+
__exports.ApiEndpoints = ApiEndpoints;
|
|
132
|
+
__exports.RequestMethod = RequestMethod;
|
|
133
|
+
__exports.request = request;
|
|
134
|
+
__exports.getFragments = getFragments;
|
|
135
|
+
__exports.writeFragment = writeFragment;
|
|
136
|
+
__exports.getManifestAppdescr = getManifestAppdescr;
|
|
137
|
+
__exports.readControllers = readControllers;
|
|
138
|
+
__exports.writeController = writeController;
|
|
139
|
+
__exports.getExistingController = getExistingController;
|
|
140
|
+
__exports.writeChange = writeChange;
|
|
141
|
+
return __exports;
|
|
142
142
|
});
|
|
143
143
|
//# sourceMappingURL=api-handler.js.map
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["sap/m/MessageToast", "sap/ui/rta/command/CommandFactory"], function (MessageToast, CommandFactory) {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Class responsible for handling rta calls
|
|
8
|
-
*/
|
|
9
|
-
class CommandExecutor {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @param rta Runtime Authoring
|
|
13
|
-
*/
|
|
14
|
-
constructor(rta) {
|
|
15
|
-
this.rta = rta;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Generates command based on given values
|
|
20
|
-
*
|
|
21
|
-
* @param runtimeControl Managed object
|
|
22
|
-
* @param commandName Command name
|
|
23
|
-
* @param modifiedValue Modified value/s
|
|
24
|
-
* @param designMetadata Design time metadata
|
|
25
|
-
* @param flexSettings Additional flex settings
|
|
26
|
-
*/
|
|
27
|
-
async getCommand(runtimeControl, commandName, modifiedValue, designMetadata, flexSettings) {
|
|
28
|
-
try {
|
|
29
|
-
return await CommandFactory.getCommandFor(runtimeControl, commandName, modifiedValue, designMetadata, flexSettings);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
const errorMsg = `Could not get command for '${commandName}'. ${e.message}`;
|
|
32
|
-
MessageToast.show(errorMsg);
|
|
33
|
-
throw new Error(errorMsg);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Pushed and executes the provided command
|
|
39
|
-
*
|
|
40
|
-
* @param command Command
|
|
41
|
-
*/
|
|
42
|
-
async pushAndExecuteCommand(command) {
|
|
43
|
-
try {
|
|
44
|
-
/**
|
|
45
|
-
* The change will have pending state and will only be saved to the workspace when the user clicks save icon
|
|
46
|
-
*/
|
|
47
|
-
await this.rta.getCommandStack().pushAndExecute(command);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
MessageToast.show(e.message);
|
|
50
|
-
throw new Error(e.message);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return CommandExecutor;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/m/MessageToast", "sap/ui/rta/command/CommandFactory"], function (MessageToast, CommandFactory) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Class responsible for handling rta calls
|
|
8
|
+
*/
|
|
9
|
+
class CommandExecutor {
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param rta Runtime Authoring
|
|
13
|
+
*/
|
|
14
|
+
constructor(rta) {
|
|
15
|
+
this.rta = rta;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates command based on given values
|
|
20
|
+
*
|
|
21
|
+
* @param runtimeControl Managed object
|
|
22
|
+
* @param commandName Command name
|
|
23
|
+
* @param modifiedValue Modified value/s
|
|
24
|
+
* @param designMetadata Design time metadata
|
|
25
|
+
* @param flexSettings Additional flex settings
|
|
26
|
+
*/
|
|
27
|
+
async getCommand(runtimeControl, commandName, modifiedValue, designMetadata, flexSettings) {
|
|
28
|
+
try {
|
|
29
|
+
return await CommandFactory.getCommandFor(runtimeControl, commandName, modifiedValue, designMetadata, flexSettings);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
const errorMsg = `Could not get command for '${commandName}'. ${e.message}`;
|
|
32
|
+
MessageToast.show(errorMsg);
|
|
33
|
+
throw new Error(errorMsg);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Pushed and executes the provided command
|
|
39
|
+
*
|
|
40
|
+
* @param command Command
|
|
41
|
+
*/
|
|
42
|
+
async pushAndExecuteCommand(command) {
|
|
43
|
+
try {
|
|
44
|
+
/**
|
|
45
|
+
* The change will have pending state and will only be saved to the workspace when the user clicks save icon
|
|
46
|
+
*/
|
|
47
|
+
await this.rta.getCommandStack().pushAndExecute(command);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
MessageToast.show(e.message);
|
|
50
|
+
throw new Error(e.message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return CommandExecutor;
|
|
55
55
|
});
|
|
56
56
|
//# sourceMappingURL=command-executor.js.map
|