@sap-ux/preview-middleware 0.12.11 → 0.12.12
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 +22 -0
- package/dist/base/flp.d.ts +10 -1
- package/dist/base/flp.js +67 -4
- package/dist/base/test.d.ts +24 -0
- package/dist/base/test.js +59 -0
- 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 +69 -69
- package/dist/client/flp/common.js +28 -28
- package/dist/client/flp/enableFakeConnector.js +77 -77
- package/dist/client/flp/init.js +220 -212
- package/dist/client/flp/init.ts +17 -2
- package/dist/client/flp/initConnectors.js +33 -33
- package/dist/client/flp/initRta.js +178 -178
- package/dist/index.d.ts +1 -1
- package/dist/types/index.d.ts +23 -0
- package/package.json +3 -3
- package/templates/flp/sandbox.html +5 -4
- package/templates/test/qunit.html +25 -0
- package/templates/test/qunit.js +6 -0
|
@@ -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
|
|
@@ -1,46 +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;
|
|
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
45
|
});
|
|
46
46
|
//# sourceMappingURL=control-utils.js.map
|
|
@@ -1,208 +1,208 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["sap/m/MessageToast", "sap/ui/model/json/JSONModel", "sap/ui/dt/OverlayRegistry", "../control-utils", "../command-executor", "../api-handler", "./BaseDialog.controller"], function (MessageToast, JSONModel, OverlayRegistry, __ControlUtils, __CommandExecutor, ___api_handler, __BaseDialog) {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
function _interopRequireDefault(obj) {
|
|
7
|
-
return obj && obj.__esModule && typeof obj.default !== "undefined" ? obj.default : obj;
|
|
8
|
-
}
|
|
9
|
-
const ControlUtils = _interopRequireDefault(__ControlUtils);
|
|
10
|
-
const CommandExecutor = _interopRequireDefault(__CommandExecutor);
|
|
11
|
-
const getFragments = ___api_handler["getFragments"];
|
|
12
|
-
const writeFragment = ___api_handler["writeFragment"];
|
|
13
|
-
const BaseDialog = _interopRequireDefault(__BaseDialog);
|
|
14
|
-
/**
|
|
15
|
-
* @namespace open.ux.preview.client.adp.controllers
|
|
16
|
-
*/
|
|
17
|
-
const AddFragment = BaseDialog.extend("open.ux.preview.client.adp.controllers.AddFragment", {
|
|
18
|
-
constructor: function _constructor(name, overlays, rta) {
|
|
19
|
-
BaseDialog.prototype.constructor.call(this, name);
|
|
20
|
-
this.rta = rta;
|
|
21
|
-
this.overlays = overlays;
|
|
22
|
-
this.model = new JSONModel();
|
|
23
|
-
this.ui5Version = sap.ui.version;
|
|
24
|
-
this.commandExecutor = new CommandExecutor(this.rta);
|
|
25
|
-
},
|
|
26
|
-
setup: async function _setup(dialog) {
|
|
27
|
-
this.dialog = dialog;
|
|
28
|
-
this.setEscapeHandler();
|
|
29
|
-
await this.buildDialogData();
|
|
30
|
-
this.dialog.setModel(this.model);
|
|
31
|
-
this.dialog.open();
|
|
32
|
-
},
|
|
33
|
-
specialIndexHandling: function _specialIndexHandling(specialIndexAggregation) {
|
|
34
|
-
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
35
|
-
const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
|
|
36
|
-
if (specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
|
|
37
|
-
const controlType = this.runtimeControl.getMetadata().getName();
|
|
38
|
-
this.model.setProperty('/indexHandlingFlag', false);
|
|
39
|
-
this.model.setProperty('/specialIndexHandlingIcon', true);
|
|
40
|
-
this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${controlType} and can't be set here`);
|
|
41
|
-
} else {
|
|
42
|
-
this.model.setProperty('/indexHandlingFlag', true);
|
|
43
|
-
this.model.setProperty('/specialIndexHandlingIcon', false);
|
|
44
|
-
this.model.setProperty('/specialIndexHandlingIconPressed', false);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
onAggregationChanged: function _onAggregationChanged(event) {
|
|
48
|
-
const source = event.getSource();
|
|
49
|
-
const selectedKey = source.getSelectedKey();
|
|
50
|
-
const selectedItem = source.getSelectedItem();
|
|
51
|
-
let selectedItemText = '';
|
|
52
|
-
if (selectedItem) {
|
|
53
|
-
selectedItemText = selectedItem.getText();
|
|
54
|
-
}
|
|
55
|
-
this.model.setProperty('/selectedAggregation/key', selectedKey);
|
|
56
|
-
this.model.setProperty('/selectedAggregation/value', selectedItemText);
|
|
57
|
-
let newSelectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, selectedItemText));
|
|
58
|
-
newSelectedControlChildren = newSelectedControlChildren.map(key => {
|
|
59
|
-
return parseInt(key);
|
|
60
|
-
});
|
|
61
|
-
this.specialIndexHandling(selectedItemText);
|
|
62
|
-
const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
|
|
63
|
-
this.model.setProperty('/index', updatedIndexArray);
|
|
64
|
-
this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
|
|
65
|
-
},
|
|
66
|
-
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
67
|
-
const source = event.getSource();
|
|
68
|
-
source.setEnabled(false);
|
|
69
|
-
const fragmentName = this.model.getProperty('/newFragmentName');
|
|
70
|
-
const index = parseInt(this.model.getProperty('/selectedIndex'));
|
|
71
|
-
const targetAggregation = this.model.getProperty('/selectedAggregation/value');
|
|
72
|
-
const fragmentData = {
|
|
73
|
-
index,
|
|
74
|
-
fragmentName,
|
|
75
|
-
targetAggregation
|
|
76
|
-
};
|
|
77
|
-
await this.createNewFragment(fragmentData);
|
|
78
|
-
this.handleDialogClose();
|
|
79
|
-
},
|
|
80
|
-
buildDialogData: async function _buildDialogData() {
|
|
81
|
-
const selectorId = this.overlays.getId();
|
|
82
|
-
let controlMetadata;
|
|
83
|
-
const overlayControl = sap.ui.getCore().byId(selectorId);
|
|
84
|
-
if (overlayControl) {
|
|
85
|
-
this.runtimeControl = ControlUtils.getRuntimeControl(overlayControl);
|
|
86
|
-
controlMetadata = this.runtimeControl.getMetadata();
|
|
87
|
-
} else {
|
|
88
|
-
throw new Error('Cannot get overlay control');
|
|
89
|
-
}
|
|
90
|
-
const allAggregations = Object.keys(controlMetadata.getAllAggregations());
|
|
91
|
-
const hiddenAggregations = ['customData', 'layoutData', 'dependents'];
|
|
92
|
-
const targetAggregation = allAggregations.filter(item => {
|
|
93
|
-
if (hiddenAggregations.indexOf(item) === -1) {
|
|
94
|
-
return item;
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
97
|
-
});
|
|
98
|
-
const defaultAggregation = controlMetadata.getDefaultAggregationName();
|
|
99
|
-
const selectedControlName = controlMetadata.getName();
|
|
100
|
-
let selectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, defaultAggregation));
|
|
101
|
-
selectedControlChildren = selectedControlChildren.map(key => {
|
|
102
|
-
return parseInt(key);
|
|
103
|
-
});
|
|
104
|
-
this.model.setProperty('/selectedControlName', selectedControlName);
|
|
105
|
-
this.model.setProperty('/selectedAggregation', {});
|
|
106
|
-
const indexArray = this.fillIndexArray(selectedControlChildren);
|
|
107
|
-
const controlAggregation = targetAggregation.map((elem, index) => {
|
|
108
|
-
return {
|
|
109
|
-
key: index,
|
|
110
|
-
value: elem
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
if (defaultAggregation !== null) {
|
|
114
|
-
controlAggregation.forEach(obj => {
|
|
115
|
-
if (obj.value === defaultAggregation) {
|
|
116
|
-
obj.key = 'default';
|
|
117
|
-
this.model.setProperty('/selectedAggregation/key', obj.key);
|
|
118
|
-
this.model.setProperty('/selectedAggregation/value', obj.value);
|
|
119
|
-
this.specialIndexHandling(obj.value);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
|
|
124
|
-
this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
|
|
125
|
-
this.specialIndexHandling(controlAggregation[0].value);
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
const {
|
|
129
|
-
fragments
|
|
130
|
-
} = await getFragments();
|
|
131
|
-
this.model.setProperty('/fragmentList', fragments);
|
|
132
|
-
} catch (e) {
|
|
133
|
-
MessageToast.show(e.message);
|
|
134
|
-
throw new Error(e.message);
|
|
135
|
-
}
|
|
136
|
-
this.model.setProperty('/selectedIndex', indexArray.length - 1);
|
|
137
|
-
this.model.setProperty('/targetAggregation', controlAggregation);
|
|
138
|
-
this.model.setProperty('/index', indexArray);
|
|
139
|
-
},
|
|
140
|
-
fillIndexArray: function _fillIndexArray(selectedControlChildren) {
|
|
141
|
-
let indexArray = [];
|
|
142
|
-
if (selectedControlChildren.length === 0) {
|
|
143
|
-
indexArray.push({
|
|
144
|
-
key: 0,
|
|
145
|
-
value: 0
|
|
146
|
-
});
|
|
147
|
-
} else {
|
|
148
|
-
indexArray = selectedControlChildren.map((elem, index) => {
|
|
149
|
-
return {
|
|
150
|
-
key: index + 1,
|
|
151
|
-
value: elem + 1
|
|
152
|
-
};
|
|
153
|
-
});
|
|
154
|
-
indexArray.unshift({
|
|
155
|
-
key: 0,
|
|
156
|
-
value: 0
|
|
157
|
-
});
|
|
158
|
-
indexArray.push({
|
|
159
|
-
key: selectedControlChildren.length + 1,
|
|
160
|
-
value: selectedControlChildren.length + 1
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
return indexArray;
|
|
164
|
-
},
|
|
165
|
-
createNewFragment: async function _createNewFragment(fragmentData) {
|
|
166
|
-
const {
|
|
167
|
-
fragmentName,
|
|
168
|
-
index,
|
|
169
|
-
targetAggregation
|
|
170
|
-
} = fragmentData;
|
|
171
|
-
try {
|
|
172
|
-
await writeFragment({
|
|
173
|
-
fragmentName
|
|
174
|
-
});
|
|
175
|
-
MessageToast.show(`Fragment with name '${fragmentName}' was created.`);
|
|
176
|
-
} catch (e) {
|
|
177
|
-
// In case of error when creating a new fragment, we should not create a change file
|
|
178
|
-
MessageToast.show(e.message);
|
|
179
|
-
throw new Error(e.message);
|
|
180
|
-
}
|
|
181
|
-
await this.createFragmentChange({
|
|
182
|
-
fragmentName,
|
|
183
|
-
index,
|
|
184
|
-
targetAggregation
|
|
185
|
-
});
|
|
186
|
-
},
|
|
187
|
-
createFragmentChange: async function _createFragmentChange(fragmentData) {
|
|
188
|
-
const {
|
|
189
|
-
fragmentName,
|
|
190
|
-
index,
|
|
191
|
-
targetAggregation
|
|
192
|
-
} = fragmentData;
|
|
193
|
-
const flexSettings = this.rta.getFlexSettings();
|
|
194
|
-
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
195
|
-
const designMetadata = overlay.getDesignTimeMetadata();
|
|
196
|
-
const modifiedValue = {
|
|
197
|
-
fragment: `<core:FragmentDefinition xmlns:core='sap.ui.core'></core:FragmentDefinition>`,
|
|
198
|
-
fragmentPath: `fragments/${fragmentName}.fragment.xml`,
|
|
199
|
-
index: index ?? 0,
|
|
200
|
-
targetAggregation: targetAggregation ?? 'content'
|
|
201
|
-
};
|
|
202
|
-
const command = await this.commandExecutor.getCommand(this.runtimeControl, 'addXML', modifiedValue, designMetadata, flexSettings);
|
|
203
|
-
await this.commandExecutor.pushAndExecuteCommand(command);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
return AddFragment;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/m/MessageToast", "sap/ui/model/json/JSONModel", "sap/ui/dt/OverlayRegistry", "../control-utils", "../command-executor", "../api-handler", "./BaseDialog.controller"], function (MessageToast, JSONModel, OverlayRegistry, __ControlUtils, __CommandExecutor, ___api_handler, __BaseDialog) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
function _interopRequireDefault(obj) {
|
|
7
|
+
return obj && obj.__esModule && typeof obj.default !== "undefined" ? obj.default : obj;
|
|
8
|
+
}
|
|
9
|
+
const ControlUtils = _interopRequireDefault(__ControlUtils);
|
|
10
|
+
const CommandExecutor = _interopRequireDefault(__CommandExecutor);
|
|
11
|
+
const getFragments = ___api_handler["getFragments"];
|
|
12
|
+
const writeFragment = ___api_handler["writeFragment"];
|
|
13
|
+
const BaseDialog = _interopRequireDefault(__BaseDialog);
|
|
14
|
+
/**
|
|
15
|
+
* @namespace open.ux.preview.client.adp.controllers
|
|
16
|
+
*/
|
|
17
|
+
const AddFragment = BaseDialog.extend("open.ux.preview.client.adp.controllers.AddFragment", {
|
|
18
|
+
constructor: function _constructor(name, overlays, rta) {
|
|
19
|
+
BaseDialog.prototype.constructor.call(this, name);
|
|
20
|
+
this.rta = rta;
|
|
21
|
+
this.overlays = overlays;
|
|
22
|
+
this.model = new JSONModel();
|
|
23
|
+
this.ui5Version = sap.ui.version;
|
|
24
|
+
this.commandExecutor = new CommandExecutor(this.rta);
|
|
25
|
+
},
|
|
26
|
+
setup: async function _setup(dialog) {
|
|
27
|
+
this.dialog = dialog;
|
|
28
|
+
this.setEscapeHandler();
|
|
29
|
+
await this.buildDialogData();
|
|
30
|
+
this.dialog.setModel(this.model);
|
|
31
|
+
this.dialog.open();
|
|
32
|
+
},
|
|
33
|
+
specialIndexHandling: function _specialIndexHandling(specialIndexAggregation) {
|
|
34
|
+
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
35
|
+
const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
|
|
36
|
+
if (specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
|
|
37
|
+
const controlType = this.runtimeControl.getMetadata().getName();
|
|
38
|
+
this.model.setProperty('/indexHandlingFlag', false);
|
|
39
|
+
this.model.setProperty('/specialIndexHandlingIcon', true);
|
|
40
|
+
this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${controlType} and can't be set here`);
|
|
41
|
+
} else {
|
|
42
|
+
this.model.setProperty('/indexHandlingFlag', true);
|
|
43
|
+
this.model.setProperty('/specialIndexHandlingIcon', false);
|
|
44
|
+
this.model.setProperty('/specialIndexHandlingIconPressed', false);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
onAggregationChanged: function _onAggregationChanged(event) {
|
|
48
|
+
const source = event.getSource();
|
|
49
|
+
const selectedKey = source.getSelectedKey();
|
|
50
|
+
const selectedItem = source.getSelectedItem();
|
|
51
|
+
let selectedItemText = '';
|
|
52
|
+
if (selectedItem) {
|
|
53
|
+
selectedItemText = selectedItem.getText();
|
|
54
|
+
}
|
|
55
|
+
this.model.setProperty('/selectedAggregation/key', selectedKey);
|
|
56
|
+
this.model.setProperty('/selectedAggregation/value', selectedItemText);
|
|
57
|
+
let newSelectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, selectedItemText));
|
|
58
|
+
newSelectedControlChildren = newSelectedControlChildren.map(key => {
|
|
59
|
+
return parseInt(key);
|
|
60
|
+
});
|
|
61
|
+
this.specialIndexHandling(selectedItemText);
|
|
62
|
+
const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
|
|
63
|
+
this.model.setProperty('/index', updatedIndexArray);
|
|
64
|
+
this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
|
|
65
|
+
},
|
|
66
|
+
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
67
|
+
const source = event.getSource();
|
|
68
|
+
source.setEnabled(false);
|
|
69
|
+
const fragmentName = this.model.getProperty('/newFragmentName');
|
|
70
|
+
const index = parseInt(this.model.getProperty('/selectedIndex'));
|
|
71
|
+
const targetAggregation = this.model.getProperty('/selectedAggregation/value');
|
|
72
|
+
const fragmentData = {
|
|
73
|
+
index,
|
|
74
|
+
fragmentName,
|
|
75
|
+
targetAggregation
|
|
76
|
+
};
|
|
77
|
+
await this.createNewFragment(fragmentData);
|
|
78
|
+
this.handleDialogClose();
|
|
79
|
+
},
|
|
80
|
+
buildDialogData: async function _buildDialogData() {
|
|
81
|
+
const selectorId = this.overlays.getId();
|
|
82
|
+
let controlMetadata;
|
|
83
|
+
const overlayControl = sap.ui.getCore().byId(selectorId);
|
|
84
|
+
if (overlayControl) {
|
|
85
|
+
this.runtimeControl = ControlUtils.getRuntimeControl(overlayControl);
|
|
86
|
+
controlMetadata = this.runtimeControl.getMetadata();
|
|
87
|
+
} else {
|
|
88
|
+
throw new Error('Cannot get overlay control');
|
|
89
|
+
}
|
|
90
|
+
const allAggregations = Object.keys(controlMetadata.getAllAggregations());
|
|
91
|
+
const hiddenAggregations = ['customData', 'layoutData', 'dependents'];
|
|
92
|
+
const targetAggregation = allAggregations.filter(item => {
|
|
93
|
+
if (hiddenAggregations.indexOf(item) === -1) {
|
|
94
|
+
return item;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
});
|
|
98
|
+
const defaultAggregation = controlMetadata.getDefaultAggregationName();
|
|
99
|
+
const selectedControlName = controlMetadata.getName();
|
|
100
|
+
let selectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, defaultAggregation));
|
|
101
|
+
selectedControlChildren = selectedControlChildren.map(key => {
|
|
102
|
+
return parseInt(key);
|
|
103
|
+
});
|
|
104
|
+
this.model.setProperty('/selectedControlName', selectedControlName);
|
|
105
|
+
this.model.setProperty('/selectedAggregation', {});
|
|
106
|
+
const indexArray = this.fillIndexArray(selectedControlChildren);
|
|
107
|
+
const controlAggregation = targetAggregation.map((elem, index) => {
|
|
108
|
+
return {
|
|
109
|
+
key: index,
|
|
110
|
+
value: elem
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
if (defaultAggregation !== null) {
|
|
114
|
+
controlAggregation.forEach(obj => {
|
|
115
|
+
if (obj.value === defaultAggregation) {
|
|
116
|
+
obj.key = 'default';
|
|
117
|
+
this.model.setProperty('/selectedAggregation/key', obj.key);
|
|
118
|
+
this.model.setProperty('/selectedAggregation/value', obj.value);
|
|
119
|
+
this.specialIndexHandling(obj.value);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
|
|
124
|
+
this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
|
|
125
|
+
this.specialIndexHandling(controlAggregation[0].value);
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const {
|
|
129
|
+
fragments
|
|
130
|
+
} = await getFragments();
|
|
131
|
+
this.model.setProperty('/fragmentList', fragments);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
MessageToast.show(e.message);
|
|
134
|
+
throw new Error(e.message);
|
|
135
|
+
}
|
|
136
|
+
this.model.setProperty('/selectedIndex', indexArray.length - 1);
|
|
137
|
+
this.model.setProperty('/targetAggregation', controlAggregation);
|
|
138
|
+
this.model.setProperty('/index', indexArray);
|
|
139
|
+
},
|
|
140
|
+
fillIndexArray: function _fillIndexArray(selectedControlChildren) {
|
|
141
|
+
let indexArray = [];
|
|
142
|
+
if (selectedControlChildren.length === 0) {
|
|
143
|
+
indexArray.push({
|
|
144
|
+
key: 0,
|
|
145
|
+
value: 0
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
indexArray = selectedControlChildren.map((elem, index) => {
|
|
149
|
+
return {
|
|
150
|
+
key: index + 1,
|
|
151
|
+
value: elem + 1
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
indexArray.unshift({
|
|
155
|
+
key: 0,
|
|
156
|
+
value: 0
|
|
157
|
+
});
|
|
158
|
+
indexArray.push({
|
|
159
|
+
key: selectedControlChildren.length + 1,
|
|
160
|
+
value: selectedControlChildren.length + 1
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return indexArray;
|
|
164
|
+
},
|
|
165
|
+
createNewFragment: async function _createNewFragment(fragmentData) {
|
|
166
|
+
const {
|
|
167
|
+
fragmentName,
|
|
168
|
+
index,
|
|
169
|
+
targetAggregation
|
|
170
|
+
} = fragmentData;
|
|
171
|
+
try {
|
|
172
|
+
await writeFragment({
|
|
173
|
+
fragmentName
|
|
174
|
+
});
|
|
175
|
+
MessageToast.show(`Fragment with name '${fragmentName}' was created.`);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
// In case of error when creating a new fragment, we should not create a change file
|
|
178
|
+
MessageToast.show(e.message);
|
|
179
|
+
throw new Error(e.message);
|
|
180
|
+
}
|
|
181
|
+
await this.createFragmentChange({
|
|
182
|
+
fragmentName,
|
|
183
|
+
index,
|
|
184
|
+
targetAggregation
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
createFragmentChange: async function _createFragmentChange(fragmentData) {
|
|
188
|
+
const {
|
|
189
|
+
fragmentName,
|
|
190
|
+
index,
|
|
191
|
+
targetAggregation
|
|
192
|
+
} = fragmentData;
|
|
193
|
+
const flexSettings = this.rta.getFlexSettings();
|
|
194
|
+
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
195
|
+
const designMetadata = overlay.getDesignTimeMetadata();
|
|
196
|
+
const modifiedValue = {
|
|
197
|
+
fragment: `<core:FragmentDefinition xmlns:core='sap.ui.core'></core:FragmentDefinition>`,
|
|
198
|
+
fragmentPath: `fragments/${fragmentName}.fragment.xml`,
|
|
199
|
+
index: index ?? 0,
|
|
200
|
+
targetAggregation: targetAggregation ?? 'content'
|
|
201
|
+
};
|
|
202
|
+
const command = await this.commandExecutor.getCommand(this.runtimeControl, 'addXML', modifiedValue, designMetadata, flexSettings);
|
|
203
|
+
await this.commandExecutor.pushAndExecuteCommand(command);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
return AddFragment;
|
|
207
207
|
});
|
|
208
208
|
//# sourceMappingURL=AddFragment.controller.js.map
|