@sap-ux/preview-middleware 0.16.69 → 0.16.71
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/controllers/AddFragment.controller.js +216 -234
- package/dist/client/adp/controllers/AddFragment.controller.ts +28 -7
- package/dist/client/adp/extension-point.js +5 -3
- package/dist/client/adp/extension-point.ts +3 -4
- package/dist/client/adp/init-dialogs.js +10 -4
- package/dist/client/adp/init-dialogs.ts +9 -9
- package/dist/client/adp/init.js +6 -20
- package/dist/client/adp/init.ts +7 -31
- package/dist/client/adp/quick-actions/common/op-add-custom-section.js +4 -1
- package/dist/client/adp/quick-actions/common/op-add-custom-section.ts +4 -1
- package/dist/client/adp/quick-actions/common/op-add-header-field.js +8 -2
- package/dist/client/adp/quick-actions/common/op-add-header-field.ts +8 -2
- package/dist/client/adp/ui/AddFragment.fragment.xml +7 -6
- package/dist/client/cpe/changes/service.js +4 -4
- package/dist/client/cpe/changes/service.ts +4 -4
- package/dist/client/cpe/communication-service.js +31 -0
- package/dist/client/cpe/communication-service.ts +40 -0
- package/dist/client/cpe/connector-service.js +6 -1
- package/dist/client/cpe/connector-service.ts +14 -1
- package/dist/client/cpe/init.js +8 -19
- package/dist/client/cpe/init.ts +6 -22
- package/dist/client/cpe/rta-service.js +2 -0
- package/dist/client/cpe/rta-service.ts +3 -1
- package/dist/client/flp/WorkspaceConnector.js +1 -1
- package/dist/client/flp/WorkspaceConnector.ts +1 -1
- package/dist/client/flp/enableFakeConnector.js +1 -1
- package/dist/client/flp/enableFakeConnector.ts +1 -1
- package/dist/client/i18n.js +16 -1
- package/dist/client/i18n.ts +15 -0
- package/dist/client/messagebundle.properties +7 -0
- package/dist/client/thirdparty/@sap-ux-private/control-property-editor-common.js +3 -2
- package/dist/client/tsconfig.tsbuildinfo +1 -0
- package/package.json +4 -4
|
@@ -1,235 +1,217 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
sap
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
const AddFragment = BaseDialog.extend("open.ux.preview.client.adp.controllers.AddFragment", {
|
|
19
|
-
constructor: function _constructor(name, overlays, rta, aggregation) {
|
|
20
|
-
BaseDialog.prototype.constructor.call(this, name);
|
|
21
|
-
this.aggregation = aggregation;
|
|
22
|
-
this.rta = rta;
|
|
23
|
-
this.overlays = overlays;
|
|
24
|
-
this.model = new JSONModel();
|
|
25
|
-
this.ui5Version = sap.ui.version;
|
|
26
|
-
this.commandExecutor = new CommandExecutor(this.rta);
|
|
27
|
-
},
|
|
28
|
-
/**
|
|
29
|
-
* Setups the Dialog and the JSON Model
|
|
30
|
-
*
|
|
31
|
-
* @param {Dialog} dialog - Dialog instance
|
|
32
|
-
*/
|
|
33
|
-
setup: async function _setup(dialog) {
|
|
34
|
-
this.dialog = dialog;
|
|
35
|
-
this.setEscapeHandler();
|
|
36
|
-
await this.buildDialogData();
|
|
37
|
-
this.dialog.setModel(this.model);
|
|
38
|
-
this.dialog.open();
|
|
39
|
-
},
|
|
40
|
-
/**
|
|
41
|
-
* Handles the index field whenever a specific aggregation is chosen
|
|
42
|
-
*
|
|
43
|
-
* @param specialIndexAggregation string | number
|
|
44
|
-
*/
|
|
45
|
-
specialIndexHandling: function _specialIndexHandling(specialIndexAggregation) {
|
|
46
|
-
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
47
|
-
const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
|
|
48
|
-
if (specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
|
|
49
|
-
const controlType = this.runtimeControl.getMetadata().getName();
|
|
50
|
-
this.model.setProperty('/indexHandlingFlag', false);
|
|
51
|
-
this.model.setProperty('/specialIndexHandlingIcon', true);
|
|
52
|
-
this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${controlType} and can't be set here`);
|
|
53
|
-
} else {
|
|
54
|
-
this.model.setProperty('/indexHandlingFlag', true);
|
|
55
|
-
this.model.setProperty('/specialIndexHandlingIcon', false);
|
|
56
|
-
this.model.setProperty('/specialIndexHandlingIconPressed', false);
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Handles the change in aggregations
|
|
61
|
-
*
|
|
62
|
-
* @param event Event
|
|
63
|
-
*/
|
|
64
|
-
onAggregationChanged: function _onAggregationChanged(event) {
|
|
65
|
-
const source = event.getSource();
|
|
66
|
-
const selectedKey = source.getSelectedKey();
|
|
67
|
-
const selectedItem = source.getSelectedItem();
|
|
68
|
-
let selectedItemText = '';
|
|
69
|
-
if (selectedItem) {
|
|
70
|
-
selectedItemText = selectedItem.getText();
|
|
71
|
-
}
|
|
72
|
-
this.model.setProperty('/selectedAggregation/key', selectedKey);
|
|
73
|
-
this.model.setProperty('/selectedAggregation/value', selectedItemText);
|
|
74
|
-
let newSelectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, selectedItemText));
|
|
75
|
-
newSelectedControlChildren = newSelectedControlChildren.map(key => {
|
|
76
|
-
return parseInt(key, radix);
|
|
77
|
-
});
|
|
78
|
-
this.specialIndexHandling(selectedItemText);
|
|
79
|
-
const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
|
|
80
|
-
this.model.setProperty('/index', updatedIndexArray);
|
|
81
|
-
this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
|
|
82
|
-
},
|
|
83
|
-
/**
|
|
84
|
-
* Handles create button press
|
|
85
|
-
*
|
|
86
|
-
* @param event Event
|
|
87
|
-
*/
|
|
88
|
-
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
89
|
-
const source = event.getSource();
|
|
90
|
-
source.setEnabled(false);
|
|
91
|
-
const fragmentName = this.model.getProperty('/newFragmentName');
|
|
92
|
-
const index = this.model.getProperty('/selectedIndex');
|
|
93
|
-
const targetAggregation = this.model.getProperty('/selectedAggregation/value');
|
|
94
|
-
const fragmentData = {
|
|
95
|
-
index,
|
|
96
|
-
fragmentName,
|
|
97
|
-
targetAggregation
|
|
98
|
-
};
|
|
99
|
-
await this.createFragmentChange(fragmentData);
|
|
100
|
-
notifyUser(`Note: The '${fragmentName}.fragment.xml' fragment will be created once you save the change.`, 8000);
|
|
101
|
-
this.handleDialogClose();
|
|
102
|
-
},
|
|
103
|
-
/**
|
|
104
|
-
* Builds data that is used in the dialog
|
|
105
|
-
*/
|
|
106
|
-
buildDialogData: async function _buildDialogData() {
|
|
107
|
-
const selectorId = this.overlays.getId();
|
|
108
|
-
let controlMetadata;
|
|
109
|
-
const overlayControl = sap.ui.getCore().byId(selectorId);
|
|
110
|
-
if (overlayControl) {
|
|
111
|
-
this.runtimeControl = ControlUtils.getRuntimeControl(overlayControl);
|
|
112
|
-
controlMetadata = this.runtimeControl.getMetadata();
|
|
113
|
-
} else {
|
|
114
|
-
throw new Error('Cannot get overlay control');
|
|
115
|
-
}
|
|
116
|
-
const allAggregations = Object.keys(controlMetadata.getAllAggregations());
|
|
117
|
-
const hiddenAggregations = ['customData', 'layoutData', 'dependents'];
|
|
118
|
-
const targetAggregation = allAggregations.filter(item => {
|
|
119
|
-
if (hiddenAggregations.indexOf(item) === -1) {
|
|
120
|
-
return item;
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
});
|
|
124
|
-
const defaultAggregation = this.aggregation ?? controlMetadata.getDefaultAggregationName();
|
|
125
|
-
const selectedControlName = controlMetadata.getName();
|
|
126
|
-
let selectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, defaultAggregation));
|
|
127
|
-
selectedControlChildren = selectedControlChildren.map(key => {
|
|
128
|
-
return parseInt(key, radix);
|
|
129
|
-
});
|
|
130
|
-
this.model.setProperty('/selectedControlName', selectedControlName);
|
|
131
|
-
this.model.setProperty('/selectedAggregation', {});
|
|
132
|
-
const indexArray = this.fillIndexArray(selectedControlChildren);
|
|
133
|
-
const controlAggregation = targetAggregation.map((elem, index) => {
|
|
134
|
-
return {
|
|
135
|
-
key: index,
|
|
136
|
-
value: elem
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
if (defaultAggregation !== null) {
|
|
140
|
-
controlAggregation.forEach(obj => {
|
|
141
|
-
if (obj.value === defaultAggregation) {
|
|
142
|
-
obj.key = 'default';
|
|
143
|
-
this.model.setProperty('/selectedAggregation/key', obj.key);
|
|
144
|
-
this.model.setProperty('/selectedAggregation/value', obj.value);
|
|
145
|
-
this.specialIndexHandling(obj.value);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
} else {
|
|
149
|
-
this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
|
|
150
|
-
this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
|
|
151
|
-
this.specialIndexHandling(controlAggregation[0].value);
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
const {
|
|
155
|
-
fragments
|
|
156
|
-
} = await getFragments();
|
|
157
|
-
this.model.setProperty('/fragmentList', fragments);
|
|
158
|
-
} catch (e) {
|
|
159
|
-
this.handleError(e);
|
|
160
|
-
}
|
|
161
|
-
this.model.setProperty('/selectedIndex', indexArray.length - 1);
|
|
162
|
-
this.model.setProperty('/targetAggregation', controlAggregation);
|
|
163
|
-
this.model.setProperty('/index', indexArray);
|
|
164
|
-
},
|
|
165
|
-
/**
|
|
166
|
-
* Fills indexArray from selected control children
|
|
167
|
-
*
|
|
168
|
-
* @param selectedControlChildren Array of numbers
|
|
169
|
-
* @returns Array of key value pairs
|
|
170
|
-
*/
|
|
171
|
-
fillIndexArray: function _fillIndexArray(selectedControlChildren) {
|
|
172
|
-
let indexArray = [];
|
|
173
|
-
if (selectedControlChildren.length === 0) {
|
|
174
|
-
indexArray.push({
|
|
175
|
-
key: 0,
|
|
176
|
-
value: 0
|
|
177
|
-
});
|
|
178
|
-
} else {
|
|
179
|
-
indexArray = selectedControlChildren.map((elem, index) => {
|
|
180
|
-
return {
|
|
181
|
-
key: index + 1,
|
|
182
|
-
value: elem + 1
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
indexArray.unshift({
|
|
186
|
-
key: 0,
|
|
187
|
-
value: 0
|
|
188
|
-
});
|
|
189
|
-
indexArray.push({
|
|
190
|
-
key: selectedControlChildren.length + 1,
|
|
191
|
-
value: selectedControlChildren.length + 1
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return indexArray;
|
|
195
|
-
},
|
|
196
|
-
/**
|
|
197
|
-
* Creates an addXML fragment command and pushes it to the command stack
|
|
198
|
-
*
|
|
199
|
-
* @param fragmentData Fragment Data
|
|
200
|
-
*/
|
|
201
|
-
createFragmentChange: async function _createFragmentChange(fragmentData) {
|
|
202
|
-
const {
|
|
203
|
-
fragmentName,
|
|
204
|
-
index,
|
|
205
|
-
targetAggregation
|
|
206
|
-
} = fragmentData;
|
|
207
|
-
const flexSettings = this.rta.getFlexSettings();
|
|
208
|
-
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
209
|
-
const designMetadata = overlay.getDesignTimeMetadata();
|
|
210
|
-
const modifiedValue = {
|
|
211
|
-
fragment: `<core:FragmentDefinition xmlns:core='sap.ui.core'></core:FragmentDefinition>`,
|
|
212
|
-
fragmentPath: `fragments/${fragmentName}.fragment.xml`,
|
|
213
|
-
index: index ?? 0,
|
|
214
|
-
targetAggregation: targetAggregation ?? 'content'
|
|
215
|
-
};
|
|
216
|
-
const command = await this.commandExecutor.getCommand(this.runtimeControl, 'addXML', modifiedValue, designMetadata, flexSettings);
|
|
217
|
-
const templateName = this.getFragmentTemplateName(modifiedValue.targetAggregation);
|
|
218
|
-
if (templateName) {
|
|
219
|
-
const preparedChange = command.getPreparedChange();
|
|
220
|
-
const content = preparedChange.getContent();
|
|
221
|
-
preparedChange.setContent({
|
|
222
|
-
...content,
|
|
223
|
-
templateName
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
await this.commandExecutor.pushAndExecuteCommand(command);
|
|
227
|
-
},
|
|
228
|
-
getFragmentTemplateName: function _getFragmentTemplateName(targetAggregation) {
|
|
229
|
-
const currentControlName = this.runtimeControl.getMetadata().getName();
|
|
230
|
-
return currentControlName === 'sap.uxap.ObjectPageLayout' && targetAggregation === 'sections' ? 'OBJECT_PAGE_CUSTOM_SECTION' : '';
|
|
1
|
+
'use strict';
|
|
2
|
+
sap.ui.define([
|
|
3
|
+
'sap/ui/model/json/JSONModel',
|
|
4
|
+
'sap/ui/dt/OverlayRegistry',
|
|
5
|
+
'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
|
|
6
|
+
'../../i18n',
|
|
7
|
+
'../../cpe/communication-service',
|
|
8
|
+
'../control-utils',
|
|
9
|
+
'../command-executor',
|
|
10
|
+
'../api-handler',
|
|
11
|
+
'./BaseDialog.controller',
|
|
12
|
+
'../utils'
|
|
13
|
+
], function (JSONModel, OverlayRegistry, ___sap_ux_private_control_property_editor_common, ____i18n, ____cpe_communication_service, __ControlUtils, __CommandExecutor, ___api_handler, __BaseDialog, ___utils) {
|
|
14
|
+
'use strict';
|
|
15
|
+
function _interopRequireDefault(obj) {
|
|
16
|
+
return obj && obj.__esModule && typeof obj.default !== 'undefined' ? obj.default : obj;
|
|
231
17
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
18
|
+
const setApplicationRequiresReload = ___sap_ux_private_control_property_editor_common['setApplicationRequiresReload'];
|
|
19
|
+
const getResourceModel = ____i18n['getResourceModel'];
|
|
20
|
+
const getTextBundle = ____i18n['getTextBundle'];
|
|
21
|
+
const CommunicationService = ____cpe_communication_service['CommunicationService'];
|
|
22
|
+
const ControlUtils = _interopRequireDefault(__ControlUtils);
|
|
23
|
+
const CommandExecutor = _interopRequireDefault(__CommandExecutor);
|
|
24
|
+
const getFragments = ___api_handler['getFragments'];
|
|
25
|
+
const BaseDialog = _interopRequireDefault(__BaseDialog);
|
|
26
|
+
const notifyUser = ___utils['notifyUser'];
|
|
27
|
+
const radix = 10;
|
|
28
|
+
const AddFragment = BaseDialog.extend('open.ux.preview.client.adp.controllers.AddFragment', {
|
|
29
|
+
constructor: function _constructor(name, overlays, rta, options) {
|
|
30
|
+
BaseDialog.prototype.constructor.call(this, name);
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.rta = rta;
|
|
33
|
+
this.overlays = overlays;
|
|
34
|
+
this.model = new JSONModel({
|
|
35
|
+
title: options.title,
|
|
36
|
+
completeView: options.aggregation === undefined
|
|
37
|
+
});
|
|
38
|
+
this.ui5Version = sap.ui.version;
|
|
39
|
+
this.commandExecutor = new CommandExecutor(this.rta);
|
|
40
|
+
},
|
|
41
|
+
setup: async function _setup(dialog) {
|
|
42
|
+
this.dialog = dialog;
|
|
43
|
+
this.setEscapeHandler();
|
|
44
|
+
await this.buildDialogData();
|
|
45
|
+
const resourceModel = await getResourceModel('open.ux.preview.client');
|
|
46
|
+
this.dialog.setModel(resourceModel, 'i18n');
|
|
47
|
+
this.dialog.setModel(this.model);
|
|
48
|
+
this.dialog.open();
|
|
49
|
+
},
|
|
50
|
+
specialIndexHandling: function _specialIndexHandling(specialIndexAggregation) {
|
|
51
|
+
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
52
|
+
const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
|
|
53
|
+
if (specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
|
|
54
|
+
const controlType = this.runtimeControl.getMetadata().getName();
|
|
55
|
+
this.model.setProperty('/indexHandlingFlag', false);
|
|
56
|
+
this.model.setProperty('/specialIndexHandlingIcon', true);
|
|
57
|
+
this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${ controlType } and can't be set here`);
|
|
58
|
+
} else {
|
|
59
|
+
this.model.setProperty('/indexHandlingFlag', true);
|
|
60
|
+
this.model.setProperty('/specialIndexHandlingIcon', false);
|
|
61
|
+
this.model.setProperty('/specialIndexHandlingIconPressed', false);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
onAggregationChanged: function _onAggregationChanged(event) {
|
|
65
|
+
const source = event.getSource();
|
|
66
|
+
const selectedKey = source.getSelectedKey();
|
|
67
|
+
const selectedItem = source.getSelectedItem();
|
|
68
|
+
let selectedItemText = '';
|
|
69
|
+
if (selectedItem) {
|
|
70
|
+
selectedItemText = selectedItem.getText();
|
|
71
|
+
}
|
|
72
|
+
this.model.setProperty('/selectedAggregation/key', selectedKey);
|
|
73
|
+
this.model.setProperty('/selectedAggregation/value', selectedItemText);
|
|
74
|
+
let newSelectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, selectedItemText));
|
|
75
|
+
newSelectedControlChildren = newSelectedControlChildren.map(key => {
|
|
76
|
+
return parseInt(key, radix);
|
|
77
|
+
});
|
|
78
|
+
this.specialIndexHandling(selectedItemText);
|
|
79
|
+
const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
|
|
80
|
+
this.model.setProperty('/index', updatedIndexArray);
|
|
81
|
+
this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
|
|
82
|
+
},
|
|
83
|
+
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
84
|
+
const source = event.getSource();
|
|
85
|
+
source.setEnabled(false);
|
|
86
|
+
const fragmentName = this.model.getProperty('/newFragmentName');
|
|
87
|
+
const index = this.model.getProperty('/selectedIndex');
|
|
88
|
+
const targetAggregation = this.model.getProperty('/selectedAggregation/value');
|
|
89
|
+
const fragmentData = {
|
|
90
|
+
index,
|
|
91
|
+
fragmentName,
|
|
92
|
+
targetAggregation
|
|
93
|
+
};
|
|
94
|
+
const templateName = await this.createFragmentChange(fragmentData);
|
|
95
|
+
const textKey = templateName ? 'ADP_ADD_FRAGMENT_WITH_TEMPLATE_NOTIFICATION' : 'ADP_ADD_FRAGMENT_NOTIFICATION';
|
|
96
|
+
const bundle = await getTextBundle();
|
|
97
|
+
notifyUser(bundle.getText(textKey, [fragmentName]), 8000);
|
|
98
|
+
this.handleDialogClose();
|
|
99
|
+
},
|
|
100
|
+
buildDialogData: async function _buildDialogData() {
|
|
101
|
+
const selectorId = this.overlays.getId();
|
|
102
|
+
let controlMetadata;
|
|
103
|
+
const overlayControl = sap.ui.getCore().byId(selectorId);
|
|
104
|
+
if (overlayControl) {
|
|
105
|
+
this.runtimeControl = ControlUtils.getRuntimeControl(overlayControl);
|
|
106
|
+
controlMetadata = this.runtimeControl.getMetadata();
|
|
107
|
+
} else {
|
|
108
|
+
throw new Error('Cannot get overlay control');
|
|
109
|
+
}
|
|
110
|
+
const allAggregations = Object.keys(controlMetadata.getAllAggregations());
|
|
111
|
+
const hiddenAggregations = [
|
|
112
|
+
'customData',
|
|
113
|
+
'layoutData',
|
|
114
|
+
'dependents'
|
|
115
|
+
];
|
|
116
|
+
const targetAggregation = allAggregations.filter(item => {
|
|
117
|
+
if (hiddenAggregations.indexOf(item) === -1) {
|
|
118
|
+
return item;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
});
|
|
122
|
+
const defaultAggregation = this.options.aggregation ?? controlMetadata.getDefaultAggregationName();
|
|
123
|
+
const selectedControlName = controlMetadata.getName();
|
|
124
|
+
let selectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, defaultAggregation));
|
|
125
|
+
selectedControlChildren = selectedControlChildren.map(key => {
|
|
126
|
+
return parseInt(key, radix);
|
|
127
|
+
});
|
|
128
|
+
this.model.setProperty('/selectedControlName', selectedControlName);
|
|
129
|
+
this.model.setProperty('/selectedAggregation', {});
|
|
130
|
+
const indexArray = this.fillIndexArray(selectedControlChildren);
|
|
131
|
+
const controlAggregation = targetAggregation.map((elem, index) => {
|
|
132
|
+
return {
|
|
133
|
+
key: index,
|
|
134
|
+
value: elem
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
if (defaultAggregation !== null) {
|
|
138
|
+
controlAggregation.forEach(obj => {
|
|
139
|
+
if (obj.value === defaultAggregation) {
|
|
140
|
+
obj.key = 'default';
|
|
141
|
+
this.model.setProperty('/selectedAggregation/key', obj.key);
|
|
142
|
+
this.model.setProperty('/selectedAggregation/value', obj.value);
|
|
143
|
+
this.specialIndexHandling(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
|
+
this.specialIndexHandling(controlAggregation[0].value);
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const {fragments} = await getFragments();
|
|
153
|
+
this.model.setProperty('/fragmentList', fragments);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
this.handleError(e);
|
|
156
|
+
}
|
|
157
|
+
this.model.setProperty('/selectedIndex', indexArray.length - 1);
|
|
158
|
+
this.model.setProperty('/targetAggregation', controlAggregation);
|
|
159
|
+
this.model.setProperty('/index', indexArray);
|
|
160
|
+
},
|
|
161
|
+
fillIndexArray: function _fillIndexArray(selectedControlChildren) {
|
|
162
|
+
let indexArray = [];
|
|
163
|
+
if (selectedControlChildren.length === 0) {
|
|
164
|
+
indexArray.push({
|
|
165
|
+
key: 0,
|
|
166
|
+
value: 0
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
indexArray = selectedControlChildren.map((elem, index) => {
|
|
170
|
+
return {
|
|
171
|
+
key: index + 1,
|
|
172
|
+
value: elem + 1
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
indexArray.unshift({
|
|
176
|
+
key: 0,
|
|
177
|
+
value: 0
|
|
178
|
+
});
|
|
179
|
+
indexArray.push({
|
|
180
|
+
key: selectedControlChildren.length + 1,
|
|
181
|
+
value: selectedControlChildren.length + 1
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return indexArray;
|
|
185
|
+
},
|
|
186
|
+
createFragmentChange: async function _createFragmentChange(fragmentData) {
|
|
187
|
+
const {fragmentName, index, targetAggregation} = fragmentData;
|
|
188
|
+
const flexSettings = this.rta.getFlexSettings();
|
|
189
|
+
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
190
|
+
const designMetadata = overlay.getDesignTimeMetadata();
|
|
191
|
+
const modifiedValue = {
|
|
192
|
+
fragment: `<core:FragmentDefinition xmlns:core='sap.ui.core'></core:FragmentDefinition>`,
|
|
193
|
+
fragmentPath: `fragments/${ fragmentName }.fragment.xml`,
|
|
194
|
+
index: index ?? 0,
|
|
195
|
+
targetAggregation: targetAggregation ?? 'content'
|
|
196
|
+
};
|
|
197
|
+
const command = await this.commandExecutor.getCommand(this.runtimeControl, 'addXML', modifiedValue, designMetadata, flexSettings);
|
|
198
|
+
const templateName = this.getFragmentTemplateName(modifiedValue.targetAggregation);
|
|
199
|
+
if (templateName) {
|
|
200
|
+
const preparedChange = command.getPreparedChange();
|
|
201
|
+
const content = preparedChange.getContent();
|
|
202
|
+
preparedChange.setContent({
|
|
203
|
+
...content,
|
|
204
|
+
templateName
|
|
205
|
+
});
|
|
206
|
+
CommunicationService.sendAction(setApplicationRequiresReload(true));
|
|
207
|
+
}
|
|
208
|
+
await this.commandExecutor.pushAndExecuteCommand(command);
|
|
209
|
+
return templateName;
|
|
210
|
+
},
|
|
211
|
+
getFragmentTemplateName: function _getFragmentTemplateName(targetAggregation) {
|
|
212
|
+
const currentControlName = this.runtimeControl.getMetadata().getName();
|
|
213
|
+
return currentControlName === 'sap.uxap.ObjectPageLayout' && targetAggregation === 'sections' ? 'OBJECT_PAGE_CUSTOM_SECTION' : '';
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
return AddFragment;
|
|
217
|
+
});
|
|
@@ -21,7 +21,12 @@ import OverlayRegistry from 'sap/ui/dt/OverlayRegistry';
|
|
|
21
21
|
import type ElementOverlay from 'sap/ui/dt/ElementOverlay';
|
|
22
22
|
|
|
23
23
|
/** sap.ui.fl */
|
|
24
|
-
import {type AddFragmentChangeContentType} from 'sap/ui/fl/Change';
|
|
24
|
+
import { type AddFragmentChangeContentType } from 'sap/ui/fl/Change';
|
|
25
|
+
|
|
26
|
+
import { setApplicationRequiresReload } from '@sap-ux-private/control-property-editor-common';
|
|
27
|
+
|
|
28
|
+
import { getResourceModel, getTextBundle } from '../../i18n';
|
|
29
|
+
import { CommunicationService } from '../../cpe/communication-service';
|
|
25
30
|
|
|
26
31
|
import ControlUtils from '../control-utils';
|
|
27
32
|
import CommandExecutor from '../command-executor';
|
|
@@ -38,20 +43,30 @@ interface CreateFragmentProps {
|
|
|
38
43
|
const radix = 10;
|
|
39
44
|
|
|
40
45
|
type AddFragmentModel = JSONModel & {
|
|
46
|
+
getProperty(sPath: '/title'): string;
|
|
47
|
+
getProperty(sPath: '/completeView'): boolean;
|
|
41
48
|
getProperty(sPath: '/newFragmentName'): string;
|
|
42
49
|
getProperty(sPath: '/selectedIndex'): number;
|
|
43
50
|
getProperty(sPath: '/selectedAggregation/value'): string;
|
|
44
51
|
};
|
|
45
52
|
|
|
53
|
+
export interface AddFragmentOptions {
|
|
54
|
+
title: string;
|
|
55
|
+
aggregation?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
/**
|
|
47
59
|
* @namespace open.ux.preview.client.adp.controllers
|
|
48
60
|
*/
|
|
49
61
|
export default class AddFragment extends BaseDialog<AddFragmentModel> {
|
|
50
|
-
constructor(name: string, overlays: UI5Element, rta: RuntimeAuthoring, private
|
|
62
|
+
constructor(name: string, overlays: UI5Element, rta: RuntimeAuthoring, private options: AddFragmentOptions) {
|
|
51
63
|
super(name);
|
|
52
64
|
this.rta = rta;
|
|
53
65
|
this.overlays = overlays;
|
|
54
|
-
this.model = new JSONModel(
|
|
66
|
+
this.model = new JSONModel({
|
|
67
|
+
title: options.title,
|
|
68
|
+
completeView: options.aggregation === undefined
|
|
69
|
+
});
|
|
55
70
|
this.ui5Version = sap.ui.version;
|
|
56
71
|
this.commandExecutor = new CommandExecutor(this.rta);
|
|
57
72
|
}
|
|
@@ -67,7 +82,9 @@ export default class AddFragment extends BaseDialog<AddFragmentModel> {
|
|
|
67
82
|
this.setEscapeHandler();
|
|
68
83
|
|
|
69
84
|
await this.buildDialogData();
|
|
85
|
+
const resourceModel = await getResourceModel('open.ux.preview.client');
|
|
70
86
|
|
|
87
|
+
this.dialog.setModel(resourceModel, 'i18n');
|
|
71
88
|
this.dialog.setModel(this.model);
|
|
72
89
|
|
|
73
90
|
this.dialog.open();
|
|
@@ -153,9 +170,11 @@ export default class AddFragment extends BaseDialog<AddFragmentModel> {
|
|
|
153
170
|
targetAggregation
|
|
154
171
|
};
|
|
155
172
|
|
|
156
|
-
await this.createFragmentChange(fragmentData);
|
|
173
|
+
const templateName = await this.createFragmentChange(fragmentData);
|
|
157
174
|
|
|
158
|
-
|
|
175
|
+
const textKey = templateName ? 'ADP_ADD_FRAGMENT_WITH_TEMPLATE_NOTIFICATION' : 'ADP_ADD_FRAGMENT_NOTIFICATION';
|
|
176
|
+
const bundle = await getTextBundle();
|
|
177
|
+
notifyUser(bundle.getText(textKey, [fragmentName]), 8000);
|
|
159
178
|
|
|
160
179
|
this.handleDialogClose();
|
|
161
180
|
}
|
|
@@ -184,7 +203,7 @@ export default class AddFragment extends BaseDialog<AddFragmentModel> {
|
|
|
184
203
|
}
|
|
185
204
|
return false;
|
|
186
205
|
});
|
|
187
|
-
const defaultAggregation = this.aggregation ?? controlMetadata.getDefaultAggregationName();
|
|
206
|
+
const defaultAggregation = this.options.aggregation ?? controlMetadata.getDefaultAggregationName();
|
|
188
207
|
const selectedControlName = controlMetadata.getName();
|
|
189
208
|
|
|
190
209
|
let selectedControlChildren: string[] | number[] = Object.keys(
|
|
@@ -262,7 +281,7 @@ export default class AddFragment extends BaseDialog<AddFragmentModel> {
|
|
|
262
281
|
*
|
|
263
282
|
* @param fragmentData Fragment Data
|
|
264
283
|
*/
|
|
265
|
-
private async createFragmentChange(fragmentData: CreateFragmentProps) {
|
|
284
|
+
private async createFragmentChange(fragmentData: CreateFragmentProps): Promise<string | undefined> {
|
|
266
285
|
const { fragmentName, index, targetAggregation } = fragmentData;
|
|
267
286
|
|
|
268
287
|
const flexSettings = this.rta.getFlexSettings();
|
|
@@ -290,8 +309,10 @@ export default class AddFragment extends BaseDialog<AddFragmentModel> {
|
|
|
290
309
|
const preparedChange = command.getPreparedChange();
|
|
291
310
|
const content = preparedChange.getContent();
|
|
292
311
|
preparedChange.setContent({ ...content, templateName });
|
|
312
|
+
CommunicationService.sendAction(setApplicationRequiresReload(true));
|
|
293
313
|
}
|
|
294
314
|
await this.commandExecutor.pushAndExecuteCommand(command);
|
|
315
|
+
return templateName;
|
|
295
316
|
}
|
|
296
317
|
|
|
297
318
|
private getFragmentTemplateName(targetAggregation: string): string {
|
|
@@ -4,11 +4,13 @@ sap.ui.define([
|
|
|
4
4
|
'sap/ui/rta/command/CommandFactory',
|
|
5
5
|
'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
|
|
6
6
|
'./utils',
|
|
7
|
+
'../cpe/communication-service',
|
|
7
8
|
'./init-dialogs'
|
|
8
|
-
], function (AddXMLAtExtensionPoint, CommandFactory, ___sap_ux_private_control_property_editor_common, ___utils, ___init_dialogs) {
|
|
9
|
+
], function (AddXMLAtExtensionPoint, CommandFactory, ___sap_ux_private_control_property_editor_common, ___utils, ___cpe_communication_service, ___init_dialogs) {
|
|
9
10
|
'use strict';
|
|
10
11
|
const addExtensionPoint = ___sap_ux_private_control_property_editor_common['addExtensionPoint'];
|
|
11
12
|
const createDeferred = ___utils['createDeferred'];
|
|
13
|
+
const CommunicationService = ___cpe_communication_service['CommunicationService'];
|
|
12
14
|
const DialogNames = ___init_dialogs['DialogNames'];
|
|
13
15
|
const handler = ___init_dialogs['handler'];
|
|
14
16
|
class ExtensionPointService {
|
|
@@ -16,9 +18,9 @@ sap.ui.define([
|
|
|
16
18
|
constructor(rta) {
|
|
17
19
|
this.rta = rta;
|
|
18
20
|
}
|
|
19
|
-
init(
|
|
21
|
+
init() {
|
|
20
22
|
this.initPlugin();
|
|
21
|
-
subscribe(async action => {
|
|
23
|
+
CommunicationService.subscribe(async action => {
|
|
22
24
|
if (addExtensionPoint.match(action)) {
|
|
23
25
|
try {
|
|
24
26
|
const {controlId, name} = action.payload;
|
|
@@ -8,7 +8,7 @@ import { ExternalAction, addExtensionPoint } from '@sap-ux-private/control-prope
|
|
|
8
8
|
|
|
9
9
|
import { Deferred, createDeferred } from './utils';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { CommunicationService } from '../cpe/communication-service';
|
|
12
12
|
import { DialogNames, handler } from './init-dialogs';
|
|
13
13
|
|
|
14
14
|
type ActionService = {
|
|
@@ -50,11 +50,10 @@ export default class ExtensionPointService {
|
|
|
50
50
|
/**
|
|
51
51
|
* Initializes communication with CPE, and the extension point plugin.
|
|
52
52
|
*
|
|
53
|
-
* @param subscribe Handles actions from CPE
|
|
54
53
|
*/
|
|
55
|
-
public init(
|
|
54
|
+
public init() {
|
|
56
55
|
this.initPlugin();
|
|
57
|
-
subscribe(async (action: ExternalAction): Promise<void> => {
|
|
56
|
+
CommunicationService.subscribe(async (action: ExternalAction): Promise<void> => {
|
|
58
57
|
if (addExtensionPoint.match(action)) {
|
|
59
58
|
try {
|
|
60
59
|
const { controlId, name } = action.payload;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFragment.controller", "./controllers/ControllerExtension.controller", "./controllers/ExtensionPoint.controller", "../cpe/utils"], function (Fragment, FlUtils, __AddFragment, __ControllerExtension, __ExtensionPoint, ___cpe_utils) {
|
|
3
|
+
sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFragment.controller", "./controllers/ControllerExtension.controller", "./controllers/ExtensionPoint.controller", "../cpe/utils", "../i18n"], function (Fragment, FlUtils, __AddFragment, __ControllerExtension, __ExtensionPoint, ___cpe_utils, ___i18n) {
|
|
4
4
|
"use strict";
|
|
5
5
|
|
|
6
6
|
function _interopRequireDefault(obj) {
|
|
@@ -10,6 +10,7 @@ sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFrag
|
|
|
10
10
|
const ControllerExtension = _interopRequireDefault(__ControllerExtension);
|
|
11
11
|
const ExtensionPoint = _interopRequireDefault(__ExtensionPoint);
|
|
12
12
|
const isReuseComponent = ___cpe_utils["isReuseComponent"];
|
|
13
|
+
const getTextBundle = ___i18n["getTextBundle"];
|
|
13
14
|
var DialogNames = /*#__PURE__*/function (DialogNames) {
|
|
14
15
|
DialogNames["ADD_FRAGMENT"] = "AddFragment";
|
|
15
16
|
DialogNames["CONTROLLER_EXTENSION"] = "ControllerExtension";
|
|
@@ -92,13 +93,18 @@ sap.ui.define(["sap/ui/core/Fragment", "sap/ui/fl/Utils", "./controllers/AddFrag
|
|
|
92
93
|
* @param rta Runtime Authoring
|
|
93
94
|
* @param dialogName Dialog name
|
|
94
95
|
* @param extensionPointData Control ID
|
|
95
|
-
* @param
|
|
96
|
+
* @param options Dialog options
|
|
96
97
|
*/
|
|
97
|
-
async function handler(overlay, rta, dialogName, extensionPointData
|
|
98
|
+
async function handler(overlay, rta, dialogName, extensionPointData) {
|
|
99
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
98
100
|
let controller;
|
|
101
|
+
const resources = await getTextBundle();
|
|
99
102
|
switch (dialogName) {
|
|
100
103
|
case DialogNames.ADD_FRAGMENT:
|
|
101
|
-
controller = new AddFragment(`open.ux.preview.client.adp.controllers.${dialogName}`, overlay, rta,
|
|
104
|
+
controller = new AddFragment(`open.ux.preview.client.adp.controllers.${dialogName}`, overlay, rta, {
|
|
105
|
+
aggregation: options.aggregation,
|
|
106
|
+
title: resources.getText(options.title ?? 'ADP_ADD_FRAGMENT_DIALOG_TITLE')
|
|
107
|
+
});
|
|
102
108
|
break;
|
|
103
109
|
case DialogNames.CONTROLLER_EXTENSION:
|
|
104
110
|
controller = new ControllerExtension(`open.ux.preview.client.adp.controllers.${dialogName}`, overlay, rta);
|