@sap-ux/preview-middleware 0.5.7 → 0.6.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.
- package/dist/client/adp/api-handler.js +96 -0
- package/dist/client/adp/api-handler.ts +102 -0
- package/dist/client/adp/command-executor.js +43 -0
- package/dist/client/adp/command-executor.ts +52 -0
- package/dist/client/adp/control-utils.js +46 -0
- package/dist/client/adp/control-utils.ts +48 -0
- package/dist/client/adp/controllers/AddFragment.controller.js +253 -0
- package/dist/client/adp/controllers/AddFragment.controller.ts +377 -0
- package/dist/client/adp/init-dialogs.js +51 -0
- package/dist/client/adp/init-dialogs.ts +43 -0
- package/dist/client/adp/init.js +5 -3
- package/dist/client/adp/init.ts +7 -5
- package/dist/client/adp/ui/AddFragment.view.xml +59 -0
- package/dist/client/flp/init.js +54 -73
- package/dist/ui5/middleware.js +5 -4
- package/package.json +4 -4
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define([], function () {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
var ApiEndpoints = /*#__PURE__*/function (ApiEndpoints) {
|
|
7
|
+
ApiEndpoints["FRAGMENT"] = "/adp/api/fragment";
|
|
8
|
+
ApiEndpoints["CONTROLLER"] = "/adp/api/controller";
|
|
9
|
+
ApiEndpoints["MANIFEST_APP_DESCRIPTOR"] = "/manifest.appdescr_variant";
|
|
10
|
+
return ApiEndpoints;
|
|
11
|
+
}(ApiEndpoints || {});
|
|
12
|
+
var RequestMethod = /*#__PURE__*/function (RequestMethod) {
|
|
13
|
+
RequestMethod["GET"] = "GET";
|
|
14
|
+
RequestMethod["PUT"] = "PUT";
|
|
15
|
+
RequestMethod["POST"] = "POST";
|
|
16
|
+
RequestMethod["PATCH"] = "PATCH";
|
|
17
|
+
RequestMethod["DELETE"] = "DELETE";
|
|
18
|
+
return RequestMethod;
|
|
19
|
+
}(RequestMethod || {});
|
|
20
|
+
/**
|
|
21
|
+
* Requests a given endpoint
|
|
22
|
+
*
|
|
23
|
+
* @param endpoint API Endpoint
|
|
24
|
+
* @param method RequestMethod
|
|
25
|
+
* @param data Data to be sent to the server
|
|
26
|
+
* @returns Data from the server request
|
|
27
|
+
*/
|
|
28
|
+
async function request(endpoint, method, data) {
|
|
29
|
+
const config = {
|
|
30
|
+
method,
|
|
31
|
+
body: JSON.stringify(data),
|
|
32
|
+
headers: {
|
|
33
|
+
'content-type': 'application/json'
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(endpoint, config);
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(`Request failed, status: ${response.status}.`);
|
|
40
|
+
}
|
|
41
|
+
switch (method) {
|
|
42
|
+
case RequestMethod.GET:
|
|
43
|
+
return response.json();
|
|
44
|
+
case RequestMethod.POST:
|
|
45
|
+
/**
|
|
46
|
+
* Since POST usually creates something
|
|
47
|
+
* and returns nothing (or a message) we just parse the text from res.send(msg)
|
|
48
|
+
*/
|
|
49
|
+
return response.text();
|
|
50
|
+
default:
|
|
51
|
+
return response.json();
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
throw new Error(e.message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves all XML fragments from the project's workspace
|
|
60
|
+
*
|
|
61
|
+
* @returns Generic Promise<T>
|
|
62
|
+
*/
|
|
63
|
+
async function getFragments() {
|
|
64
|
+
return request(ApiEndpoints.FRAGMENT, RequestMethod.GET);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Writes an XML fragment to the project's workspace
|
|
69
|
+
*
|
|
70
|
+
* @param data Data to be send to the server
|
|
71
|
+
* @returns Generic Promise<T>
|
|
72
|
+
*/
|
|
73
|
+
async function writeFragment(data) {
|
|
74
|
+
return request(ApiEndpoints.FRAGMENT, RequestMethod.POST, data);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves manifest.appdescr_variant from the project's workspace
|
|
79
|
+
*
|
|
80
|
+
* @returns Generic Promise<T>
|
|
81
|
+
*/
|
|
82
|
+
async function getManifestAppdescr() {
|
|
83
|
+
return request(ApiEndpoints.MANIFEST_APP_DESCRIPTOR, RequestMethod.GET);
|
|
84
|
+
}
|
|
85
|
+
var __exports = {
|
|
86
|
+
__esModule: true
|
|
87
|
+
};
|
|
88
|
+
__exports.ApiEndpoints = ApiEndpoints;
|
|
89
|
+
__exports.RequestMethod = RequestMethod;
|
|
90
|
+
__exports.request = request;
|
|
91
|
+
__exports.getFragments = getFragments;
|
|
92
|
+
__exports.writeFragment = writeFragment;
|
|
93
|
+
__exports.getManifestAppdescr = getManifestAppdescr;
|
|
94
|
+
return __exports;
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=api-handler.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Layer } from 'sap/ui/fl';
|
|
2
|
+
|
|
3
|
+
export const enum ApiEndpoints {
|
|
4
|
+
FRAGMENT = '/adp/api/fragment',
|
|
5
|
+
CONTROLLER = '/adp/api/controller',
|
|
6
|
+
MANIFEST_APP_DESCRIPTOR = '/manifest.appdescr_variant'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const enum RequestMethod {
|
|
10
|
+
GET = 'GET',
|
|
11
|
+
PUT = 'PUT',
|
|
12
|
+
POST = 'POST',
|
|
13
|
+
PATCH = 'PATCH',
|
|
14
|
+
DELETE = 'DELETE'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Fragments = { fragmentName: string }[];
|
|
18
|
+
|
|
19
|
+
export interface FragmentsResponse {
|
|
20
|
+
fragments: Fragments;
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ManifestAppdescr {
|
|
25
|
+
fileName: string;
|
|
26
|
+
layer: Layer;
|
|
27
|
+
fileType: string;
|
|
28
|
+
reference: string;
|
|
29
|
+
id: string;
|
|
30
|
+
namespace: string;
|
|
31
|
+
version: string;
|
|
32
|
+
content: object[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Requests a given endpoint
|
|
37
|
+
*
|
|
38
|
+
* @param endpoint API Endpoint
|
|
39
|
+
* @param method RequestMethod
|
|
40
|
+
* @param data Data to be sent to the server
|
|
41
|
+
* @returns Data from the server request
|
|
42
|
+
*/
|
|
43
|
+
export async function request<T>(endpoint: ApiEndpoints, method: RequestMethod, data?: unknown): Promise<T> {
|
|
44
|
+
const config: RequestInit = {
|
|
45
|
+
method,
|
|
46
|
+
body: JSON.stringify(data),
|
|
47
|
+
headers: {
|
|
48
|
+
'content-type': 'application/json'
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const response: Response = await fetch(endpoint, config);
|
|
54
|
+
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new Error(`Request failed, status: ${response.status}.`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
switch (method) {
|
|
60
|
+
case RequestMethod.GET:
|
|
61
|
+
return response.json();
|
|
62
|
+
case RequestMethod.POST:
|
|
63
|
+
/**
|
|
64
|
+
* Since POST usually creates something
|
|
65
|
+
* and returns nothing (or a message) we just parse the text from res.send(msg)
|
|
66
|
+
*/
|
|
67
|
+
return response.text() as T;
|
|
68
|
+
default:
|
|
69
|
+
return response.json();
|
|
70
|
+
}
|
|
71
|
+
} catch (e) {
|
|
72
|
+
throw new Error(e.message);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves all XML fragments from the project's workspace
|
|
78
|
+
*
|
|
79
|
+
* @returns Generic Promise<T>
|
|
80
|
+
*/
|
|
81
|
+
export async function getFragments(): Promise<FragmentsResponse> {
|
|
82
|
+
return request<FragmentsResponse>(ApiEndpoints.FRAGMENT, RequestMethod.GET);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Writes an XML fragment to the project's workspace
|
|
87
|
+
*
|
|
88
|
+
* @param data Data to be send to the server
|
|
89
|
+
* @returns Generic Promise<T>
|
|
90
|
+
*/
|
|
91
|
+
export async function writeFragment<T>(data: T): Promise<T> {
|
|
92
|
+
return request<T>(ApiEndpoints.FRAGMENT, RequestMethod.POST, data);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves manifest.appdescr_variant from the project's workspace
|
|
97
|
+
*
|
|
98
|
+
* @returns Generic Promise<T>
|
|
99
|
+
*/
|
|
100
|
+
export async function getManifestAppdescr(): Promise<ManifestAppdescr> {
|
|
101
|
+
return request<ManifestAppdescr>(ApiEndpoints.MANIFEST_APP_DESCRIPTOR, RequestMethod.GET);
|
|
102
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 and executes it
|
|
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 generateAndExecuteCommand(runtimeControl, commandName, modifiedValue, designMetadata, flexSettings) {
|
|
28
|
+
try {
|
|
29
|
+
const command = await CommandFactory.getCommandFor(runtimeControl, commandName, modifiedValue, designMetadata, flexSettings);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The change will have pending state and will only be saved to the workspace when the user clicks save icon
|
|
33
|
+
*/
|
|
34
|
+
await this.rta.getCommandStack().pushAndExecute(command);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
MessageToast.show(e.message);
|
|
37
|
+
throw new Error(e.message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return CommandExecutor;
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=command-executor.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import MessageToast from 'sap/m/MessageToast';
|
|
2
|
+
import type ManagedObject from 'sap/ui/base/ManagedObject';
|
|
3
|
+
import CommandFactory from 'sap/ui/rta/command/CommandFactory';
|
|
4
|
+
import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
|
|
5
|
+
import type { FlexSettings } from 'sap/ui/rta/RuntimeAuthoring';
|
|
6
|
+
import type DesignTimeMetadata from 'sap/ui/dt/DesignTimeMetadata';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Class responsible for handling rta calls
|
|
10
|
+
*/
|
|
11
|
+
export default class CommandExecutor {
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param rta Runtime Authoring
|
|
15
|
+
*/
|
|
16
|
+
constructor(private readonly rta: RuntimeAuthoring) {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates command based on given values and executes it
|
|
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
|
+
public async generateAndExecuteCommand(
|
|
28
|
+
runtimeControl: ManagedObject,
|
|
29
|
+
commandName: 'addXML',
|
|
30
|
+
modifiedValue: object,
|
|
31
|
+
designMetadata: DesignTimeMetadata,
|
|
32
|
+
flexSettings: FlexSettings
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
try {
|
|
35
|
+
const command = await CommandFactory.getCommandFor(
|
|
36
|
+
runtimeControl,
|
|
37
|
+
commandName,
|
|
38
|
+
modifiedValue,
|
|
39
|
+
designMetadata,
|
|
40
|
+
flexSettings
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The change will have pending state and will only be saved to the workspace when the user clicks save icon
|
|
45
|
+
*/
|
|
46
|
+
await this.rta.getCommandStack().pushAndExecute(command);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
MessageToast.show(e.message);
|
|
49
|
+
throw new Error(e.message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define([], function () {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Handles calling control specific functions for retrieving control data
|
|
8
|
+
*/
|
|
9
|
+
class ControlUtils {
|
|
10
|
+
/**
|
|
11
|
+
* Returns ManagedObject runtime control
|
|
12
|
+
*
|
|
13
|
+
* @param overlayControl Overlay
|
|
14
|
+
* @returns {ManagedObject} Managed Object instance
|
|
15
|
+
*/
|
|
16
|
+
static getRuntimeControl(overlayControl) {
|
|
17
|
+
let runtimeControl;
|
|
18
|
+
if (overlayControl.getElementInstance) {
|
|
19
|
+
runtimeControl = overlayControl.getElementInstance();
|
|
20
|
+
} else {
|
|
21
|
+
runtimeControl = overlayControl.getElement();
|
|
22
|
+
}
|
|
23
|
+
return runtimeControl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns control aggregation names in an array
|
|
28
|
+
*
|
|
29
|
+
* @param control Managed Object runtime control
|
|
30
|
+
* @param name Aggregation name
|
|
31
|
+
* @returns Array of control aggregations
|
|
32
|
+
*/
|
|
33
|
+
static getControlAggregationByName(control, name) {
|
|
34
|
+
let result = [];
|
|
35
|
+
const aggregation = (control ? control.getMetadata().getAllAggregations() : {})[name];
|
|
36
|
+
if (aggregation) {
|
|
37
|
+
// This executes a _sGetter function that can vary from control to control (_sGetter can be: getContent, getItems, etc)
|
|
38
|
+
const names = aggregation._sGetter && control[aggregation._sGetter]() || [];
|
|
39
|
+
result = Array.isArray(names) ? names : [names];
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return ControlUtils;
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=control-utils.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type ElementOverlay from 'sap/ui/dt/ElementOverlay';
|
|
2
|
+
import type ManagedObject from 'sap/ui/base/ManagedObject';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles calling control specific functions for retrieving control data
|
|
6
|
+
*/
|
|
7
|
+
export default class ControlUtils {
|
|
8
|
+
/**
|
|
9
|
+
* Returns ManagedObject runtime control
|
|
10
|
+
*
|
|
11
|
+
* @param overlayControl Overlay
|
|
12
|
+
* @returns {ManagedObject} Managed Object instance
|
|
13
|
+
*/
|
|
14
|
+
public static getRuntimeControl(overlayControl: ElementOverlay): ManagedObject {
|
|
15
|
+
let runtimeControl;
|
|
16
|
+
if (overlayControl.getElementInstance) {
|
|
17
|
+
runtimeControl = overlayControl.getElementInstance();
|
|
18
|
+
} else {
|
|
19
|
+
runtimeControl = overlayControl.getElement();
|
|
20
|
+
}
|
|
21
|
+
return runtimeControl;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns control aggregation names in an array
|
|
26
|
+
*
|
|
27
|
+
* @param control Managed Object runtime control
|
|
28
|
+
* @param name Aggregation name
|
|
29
|
+
* @returns Array of control aggregations
|
|
30
|
+
*/
|
|
31
|
+
public static getControlAggregationByName(control: ManagedObject, name: string): unknown[] {
|
|
32
|
+
let result: unknown[] = [];
|
|
33
|
+
const aggregation = (control ? control.getMetadata().getAllAggregations() : {})[name] as unknown as object & {
|
|
34
|
+
_sGetter: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (aggregation) {
|
|
38
|
+
// This executes a _sGetter function that can vary from control to control (_sGetter can be: getContent, getItems, etc)
|
|
39
|
+
const names =
|
|
40
|
+
(aggregation._sGetter &&
|
|
41
|
+
(control as ManagedObject & { [key: string]: () => unknown })[aggregation._sGetter]()) ||
|
|
42
|
+
[];
|
|
43
|
+
|
|
44
|
+
result = Array.isArray(names) ? names : [names];
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel", "sap/ui/dt/OverlayRegistry", "../control-utils", "../command-executor", "../api-handler"], function (MessageToast, sap_ui_core_library, Controller, JSONModel, OverlayRegistry, __ControlUtils, __CommandExecutor, ___api_handler) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
function _interopRequireDefault(obj) {
|
|
7
|
+
return obj && obj.__esModule && typeof obj.default !== "undefined" ? obj.default : obj;
|
|
8
|
+
}
|
|
9
|
+
/** sap.ui.core */
|
|
10
|
+
const ValueState = sap_ui_core_library["ValueState"];
|
|
11
|
+
const ControlUtils = _interopRequireDefault(__ControlUtils);
|
|
12
|
+
const CommandExecutor = _interopRequireDefault(__CommandExecutor);
|
|
13
|
+
const getFragments = ___api_handler["getFragments"];
|
|
14
|
+
const getManifestAppdescr = ___api_handler["getManifestAppdescr"];
|
|
15
|
+
const writeFragment = ___api_handler["writeFragment"];
|
|
16
|
+
/**
|
|
17
|
+
* @namespace open.ux.preview.client.adp.controllers
|
|
18
|
+
*/
|
|
19
|
+
const AddFragment = Controller.extend("open.ux.preview.client.adp.controllers.AddFragment", {
|
|
20
|
+
constructor: function _constructor(name, overlays, rta) {
|
|
21
|
+
Controller.prototype.constructor.call(this, name);
|
|
22
|
+
this.rta = rta;
|
|
23
|
+
this.overlays = overlays;
|
|
24
|
+
this.commandExecutor = new CommandExecutor(this.rta);
|
|
25
|
+
},
|
|
26
|
+
onInit: async function _onInit() {
|
|
27
|
+
this.model = new JSONModel();
|
|
28
|
+
this.dialog = this.byId('addNewFragmentDialog');
|
|
29
|
+
await this.buildDialogData();
|
|
30
|
+
this.getView()?.setModel(this.model);
|
|
31
|
+
this.dialog.open();
|
|
32
|
+
},
|
|
33
|
+
onAggregationChanged: function _onAggregationChanged(event) {
|
|
34
|
+
const source = event.getSource();
|
|
35
|
+
const selectedKey = source.getSelectedKey();
|
|
36
|
+
const selectedItem = source.getSelectedItem();
|
|
37
|
+
let selectedItemText = '';
|
|
38
|
+
if (selectedItem) {
|
|
39
|
+
selectedItemText = selectedItem.getText();
|
|
40
|
+
}
|
|
41
|
+
this.model.setProperty('/selectedAggregation/key', selectedKey);
|
|
42
|
+
this.model.setProperty('/selectedAggregation/value', selectedItemText);
|
|
43
|
+
let newSelectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, selectedItemText));
|
|
44
|
+
newSelectedControlChildren = newSelectedControlChildren.map(key => {
|
|
45
|
+
return parseInt(key);
|
|
46
|
+
});
|
|
47
|
+
const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
|
|
48
|
+
this.model.setProperty('/index', updatedIndexArray);
|
|
49
|
+
this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
|
|
50
|
+
},
|
|
51
|
+
onIndexChanged: function _onIndexChanged(event) {
|
|
52
|
+
const source = event.getSource();
|
|
53
|
+
const selectedIndex = source.getSelectedItem()?.getText();
|
|
54
|
+
this.model.setProperty('/selectedIndex', selectedIndex);
|
|
55
|
+
},
|
|
56
|
+
onFragmentNameInputChange: function _onFragmentNameInputChange(event) {
|
|
57
|
+
const source = event.getSource();
|
|
58
|
+
const fragmentName = source.getValue().trim();
|
|
59
|
+
const fragmentList = this.model.getProperty('/fragmentList');
|
|
60
|
+
if (fragmentName.length <= 0) {
|
|
61
|
+
this.dialog.getBeginButton().setEnabled(false);
|
|
62
|
+
source.setValueState(ValueState.None);
|
|
63
|
+
this.model.setProperty('/newFragmentName', null);
|
|
64
|
+
} else {
|
|
65
|
+
const fileExists = fragmentList.find(f => {
|
|
66
|
+
return f.fragmentName === `${fragmentName}.fragment.xml`;
|
|
67
|
+
});
|
|
68
|
+
const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
|
|
69
|
+
if (fileExists) {
|
|
70
|
+
source.setValueState(ValueState.Error);
|
|
71
|
+
source.setValueStateText('Enter a different name. The fragment name that you entered already exists in your project.');
|
|
72
|
+
this.dialog.getBeginButton().setEnabled(false);
|
|
73
|
+
} else if (!isValidName) {
|
|
74
|
+
source.setValueState(ValueState.Error);
|
|
75
|
+
source.setValueStateText('A Fragment Name cannot contain white spaces or special characters.');
|
|
76
|
+
this.dialog.getBeginButton().setEnabled(false);
|
|
77
|
+
} else {
|
|
78
|
+
this.dialog.getBeginButton().setEnabled(true);
|
|
79
|
+
source.setValueState(ValueState.None);
|
|
80
|
+
this.model.setProperty('/newFragmentName', fragmentName);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
85
|
+
const source = event.getSource();
|
|
86
|
+
source.setEnabled(false);
|
|
87
|
+
const fragmentName = this.model.getProperty('/newFragmentName');
|
|
88
|
+
const index = parseInt(this.model.getProperty('/selectedIndex'));
|
|
89
|
+
const targetAggregation = this.model.getProperty('/selectedAggregation/value');
|
|
90
|
+
const fragmentData = {
|
|
91
|
+
index,
|
|
92
|
+
fragmentName,
|
|
93
|
+
targetAggregation
|
|
94
|
+
};
|
|
95
|
+
await this.createNewFragment(fragmentData);
|
|
96
|
+
this.handleDialogClose();
|
|
97
|
+
},
|
|
98
|
+
closeDialog: function _closeDialog() {
|
|
99
|
+
this.handleDialogClose();
|
|
100
|
+
},
|
|
101
|
+
handleDialogClose: function _handleDialogClose() {
|
|
102
|
+
this.dialog.close();
|
|
103
|
+
this.getView()?.destroy();
|
|
104
|
+
},
|
|
105
|
+
buildDialogData: async function _buildDialogData() {
|
|
106
|
+
const selectorId = this.overlays.getId();
|
|
107
|
+
let controlMetadata;
|
|
108
|
+
const overlayControl = sap.ui.getCore().byId(selectorId);
|
|
109
|
+
if (overlayControl) {
|
|
110
|
+
this.runtimeControl = ControlUtils.getRuntimeControl(overlayControl);
|
|
111
|
+
controlMetadata = this.runtimeControl.getMetadata();
|
|
112
|
+
} else {
|
|
113
|
+
throw new Error('Cannot get overlay control');
|
|
114
|
+
}
|
|
115
|
+
const allAggregations = Object.keys(controlMetadata.getAllAggregations());
|
|
116
|
+
const hiddenAggregations = ['customData', 'layoutData', 'dependents'];
|
|
117
|
+
const targetAggregation = allAggregations.filter(item => {
|
|
118
|
+
if (hiddenAggregations.indexOf(item) === -1) {
|
|
119
|
+
return item;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
});
|
|
123
|
+
const defaultAggregation = controlMetadata.getDefaultAggregationName();
|
|
124
|
+
const selectedControlName = controlMetadata.getName();
|
|
125
|
+
let selectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, defaultAggregation));
|
|
126
|
+
selectedControlChildren = selectedControlChildren.map(key => {
|
|
127
|
+
return parseInt(key);
|
|
128
|
+
});
|
|
129
|
+
this.model.setProperty('/selectedControlName', selectedControlName);
|
|
130
|
+
this.model.setProperty('/selectedAggregation', {});
|
|
131
|
+
const indexArray = this.fillIndexArray(selectedControlChildren);
|
|
132
|
+
const controlAggregation = targetAggregation.map((elem, index) => {
|
|
133
|
+
return {
|
|
134
|
+
key: index,
|
|
135
|
+
value: elem
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
if (defaultAggregation !== null) {
|
|
139
|
+
controlAggregation.forEach(obj => {
|
|
140
|
+
if (obj.value === defaultAggregation) {
|
|
141
|
+
obj.key = 'default';
|
|
142
|
+
this.model.setProperty('/selectedAggregation/key', obj.key);
|
|
143
|
+
this.model.setProperty('/selectedAggregation/value', obj.value);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
|
|
148
|
+
this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const {
|
|
152
|
+
fragments
|
|
153
|
+
} = await getFragments();
|
|
154
|
+
this.model.setProperty('/fragmentList', fragments);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
throw new Error(e.message);
|
|
157
|
+
}
|
|
158
|
+
this.model.setProperty('/selectedIndex', indexArray.length - 1);
|
|
159
|
+
this.model.setProperty('/targetAggregation', controlAggregation);
|
|
160
|
+
this.model.setProperty('/index', indexArray);
|
|
161
|
+
},
|
|
162
|
+
fillIndexArray: function _fillIndexArray(selectedControlChildren) {
|
|
163
|
+
let indexArray = [];
|
|
164
|
+
if (selectedControlChildren.length === 0) {
|
|
165
|
+
indexArray.push({
|
|
166
|
+
key: 0,
|
|
167
|
+
value: 0
|
|
168
|
+
});
|
|
169
|
+
} else {
|
|
170
|
+
indexArray = selectedControlChildren.map((elem, index) => {
|
|
171
|
+
return {
|
|
172
|
+
key: index + 1,
|
|
173
|
+
value: elem + 1
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
indexArray.unshift({
|
|
177
|
+
key: 0,
|
|
178
|
+
value: 0
|
|
179
|
+
});
|
|
180
|
+
indexArray.push({
|
|
181
|
+
key: selectedControlChildren.length + 1,
|
|
182
|
+
value: selectedControlChildren.length + 1
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return indexArray;
|
|
186
|
+
},
|
|
187
|
+
createNewFragment: async function _createNewFragment(fragmentData) {
|
|
188
|
+
const {
|
|
189
|
+
fragmentName,
|
|
190
|
+
index,
|
|
191
|
+
targetAggregation
|
|
192
|
+
} = fragmentData;
|
|
193
|
+
try {
|
|
194
|
+
await writeFragment({
|
|
195
|
+
fragmentName
|
|
196
|
+
});
|
|
197
|
+
MessageToast.show(`Fragment with name '${fragmentName}' was created.`);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
// In case of error when creating a new fragment, we should not create a change file
|
|
200
|
+
MessageToast.show(e.message);
|
|
201
|
+
throw new Error(e.message);
|
|
202
|
+
}
|
|
203
|
+
await this.createFragmentChange({
|
|
204
|
+
fragmentName,
|
|
205
|
+
index,
|
|
206
|
+
targetAggregation
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
createFragmentChange: async function _createFragmentChange(fragmentData) {
|
|
210
|
+
const {
|
|
211
|
+
fragmentName,
|
|
212
|
+
index,
|
|
213
|
+
targetAggregation
|
|
214
|
+
} = fragmentData;
|
|
215
|
+
let manifest;
|
|
216
|
+
try {
|
|
217
|
+
manifest = await getManifestAppdescr();
|
|
218
|
+
if (!manifest) {
|
|
219
|
+
// Highly unlikely since adaptation projects are required to have manifest.appdescr_variant
|
|
220
|
+
throw new Error('Could not retrieve manifest');
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
MessageToast.show(e.message);
|
|
224
|
+
throw new Error(e.message);
|
|
225
|
+
}
|
|
226
|
+
const {
|
|
227
|
+
id,
|
|
228
|
+
reference,
|
|
229
|
+
namespace,
|
|
230
|
+
layer
|
|
231
|
+
} = manifest;
|
|
232
|
+
const flexSettings = {
|
|
233
|
+
baseId: reference,
|
|
234
|
+
developerMode: true,
|
|
235
|
+
layer: layer,
|
|
236
|
+
namespace: namespace,
|
|
237
|
+
projectId: id,
|
|
238
|
+
rootNamespace: namespace.split('/').slice(0, 2).join('/'),
|
|
239
|
+
scenario: undefined
|
|
240
|
+
};
|
|
241
|
+
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
242
|
+
const designMetadata = overlay.getDesignTimeMetadata();
|
|
243
|
+
const modifiedValue = {
|
|
244
|
+
fragmentPath: `fragments/${fragmentName}.fragment.xml`,
|
|
245
|
+
index: index ?? 0,
|
|
246
|
+
targetAggregation: targetAggregation ?? 'content'
|
|
247
|
+
};
|
|
248
|
+
await this.commandExecutor.generateAndExecuteCommand(this.runtimeControl, 'addXML', modifiedValue, designMetadata, flexSettings);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
return AddFragment;
|
|
252
|
+
});
|
|
253
|
+
//# sourceMappingURL=AddFragment.controller.js.map
|