@sap-ux/preview-middleware 0.16.11 → 0.16.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/dist/client/adp/api-handler.js +142 -142
- package/dist/client/adp/command-executor.js +58 -58
- package/dist/client/adp/control-utils.js +44 -44
- package/dist/client/adp/controllers/AddFragment.controller.js +219 -219
- package/dist/client/adp/controllers/BaseDialog.controller.js +105 -105
- package/dist/client/adp/controllers/ControllerExtension.controller.js +228 -228
- package/dist/client/adp/controllers/ExtensionPoint.controller.js +138 -138
- package/dist/client/adp/init-dialogs.js +138 -138
- package/dist/client/adp/ui5-version-utils.js +63 -63
- package/dist/client/adp/utils.js +61 -61
- 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 +34 -34
- package/dist/client/cpe/documentation.js +164 -164
- package/dist/client/cpe/error-utils.js +19 -19
- package/dist/client/cpe/logger.js +30 -30
- package/dist/client/cpe/outline/nodes.js +172 -172
- package/dist/client/cpe/outline/utils.js +60 -60
- 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 +84 -84
- package/dist/client/flp/initConnectors.js +33 -33
- package/dist/client/flp/initRta.js +178 -178
- package/package.json +3 -3
|
@@ -1,221 +1,221 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["sap/ui/model/json/JSONModel", "sap/ui/dt/OverlayRegistry", "../control-utils", "../command-executor", "../api-handler", "./BaseDialog.controller", "../utils"], function (JSONModel, OverlayRegistry, __ControlUtils, __CommandExecutor, ___api_handler, __BaseDialog, ___utils) {
|
|
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 BaseDialog = _interopRequireDefault(__BaseDialog);
|
|
13
|
-
const notifyUser = ___utils["notifyUser"];
|
|
14
|
-
const radix = 10;
|
|
15
|
-
/**
|
|
16
|
-
* @namespace open.ux.preview.client.adp.controllers
|
|
17
|
-
*/
|
|
18
|
-
const AddFragment = BaseDialog.extend("open.ux.preview.client.adp.controllers.AddFragment", {
|
|
19
|
-
constructor: function _constructor(name, overlays, rta) {
|
|
20
|
-
BaseDialog.prototype.constructor.call(this, name);
|
|
21
|
-
this.rta = rta;
|
|
22
|
-
this.overlays = overlays;
|
|
23
|
-
this.model = new JSONModel();
|
|
24
|
-
this.ui5Version = sap.ui.version;
|
|
25
|
-
this.commandExecutor = new CommandExecutor(this.rta);
|
|
26
|
-
},
|
|
27
|
-
/**
|
|
28
|
-
* Setups the Dialog and the JSON Model
|
|
29
|
-
*
|
|
30
|
-
* @param {Dialog} dialog - Dialog instance
|
|
31
|
-
*/
|
|
32
|
-
setup: async function _setup(dialog) {
|
|
33
|
-
this.dialog = dialog;
|
|
34
|
-
this.setEscapeHandler();
|
|
35
|
-
await this.buildDialogData();
|
|
36
|
-
this.dialog.setModel(this.model);
|
|
37
|
-
this.dialog.open();
|
|
38
|
-
},
|
|
39
|
-
/**
|
|
40
|
-
* Handles the index field whenever a specific aggregation is chosen
|
|
41
|
-
*
|
|
42
|
-
* @param specialIndexAggregation string | number
|
|
43
|
-
*/
|
|
44
|
-
specialIndexHandling: function _specialIndexHandling(specialIndexAggregation) {
|
|
45
|
-
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
46
|
-
const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
|
|
47
|
-
if (specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
|
|
48
|
-
const controlType = this.runtimeControl.getMetadata().getName();
|
|
49
|
-
this.model.setProperty('/indexHandlingFlag', false);
|
|
50
|
-
this.model.setProperty('/specialIndexHandlingIcon', true);
|
|
51
|
-
this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${controlType} and can't be set here`);
|
|
52
|
-
} else {
|
|
53
|
-
this.model.setProperty('/indexHandlingFlag', true);
|
|
54
|
-
this.model.setProperty('/specialIndexHandlingIcon', false);
|
|
55
|
-
this.model.setProperty('/specialIndexHandlingIconPressed', false);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
/**
|
|
59
|
-
* Handles the change in aggregations
|
|
60
|
-
*
|
|
61
|
-
* @param event Event
|
|
62
|
-
*/
|
|
63
|
-
onAggregationChanged: function _onAggregationChanged(event) {
|
|
64
|
-
const source = event.getSource();
|
|
65
|
-
const selectedKey = source.getSelectedKey();
|
|
66
|
-
const selectedItem = source.getSelectedItem();
|
|
67
|
-
let selectedItemText = '';
|
|
68
|
-
if (selectedItem) {
|
|
69
|
-
selectedItemText = selectedItem.getText();
|
|
70
|
-
}
|
|
71
|
-
this.model.setProperty('/selectedAggregation/key', selectedKey);
|
|
72
|
-
this.model.setProperty('/selectedAggregation/value', selectedItemText);
|
|
73
|
-
let newSelectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, selectedItemText));
|
|
74
|
-
newSelectedControlChildren = newSelectedControlChildren.map(key => {
|
|
75
|
-
return parseInt(key, radix);
|
|
76
|
-
});
|
|
77
|
-
this.specialIndexHandling(selectedItemText);
|
|
78
|
-
const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
|
|
79
|
-
this.model.setProperty('/index', updatedIndexArray);
|
|
80
|
-
this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* Handles create button press
|
|
84
|
-
*
|
|
85
|
-
* @param event Event
|
|
86
|
-
*/
|
|
87
|
-
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
88
|
-
const source = event.getSource();
|
|
89
|
-
source.setEnabled(false);
|
|
90
|
-
const fragmentName = this.model.getProperty('/newFragmentName');
|
|
91
|
-
const index = this.model.getProperty('/selectedIndex');
|
|
92
|
-
const targetAggregation = this.model.getProperty('/selectedAggregation/value');
|
|
93
|
-
const fragmentData = {
|
|
94
|
-
index,
|
|
95
|
-
fragmentName,
|
|
96
|
-
targetAggregation
|
|
97
|
-
};
|
|
98
|
-
await this.createFragmentChange(fragmentData);
|
|
99
|
-
notifyUser(`Note: The '${fragmentName}.fragment.xml' fragment will be created once you save the change.`, 8000);
|
|
100
|
-
this.handleDialogClose();
|
|
101
|
-
},
|
|
102
|
-
/**
|
|
103
|
-
* Builds data that is used in the dialog
|
|
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, radix);
|
|
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
|
-
this.specialIndexHandling(obj.value);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
} else {
|
|
148
|
-
this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
|
|
149
|
-
this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
|
|
150
|
-
this.specialIndexHandling(controlAggregation[0].value);
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
const {
|
|
154
|
-
fragments
|
|
155
|
-
} = await getFragments();
|
|
156
|
-
this.model.setProperty('/fragmentList', fragments);
|
|
157
|
-
} catch (e) {
|
|
158
|
-
this.handleError(e);
|
|
159
|
-
}
|
|
160
|
-
this.model.setProperty('/selectedIndex', indexArray.length - 1);
|
|
161
|
-
this.model.setProperty('/targetAggregation', controlAggregation);
|
|
162
|
-
this.model.setProperty('/index', indexArray);
|
|
163
|
-
},
|
|
164
|
-
/**
|
|
165
|
-
* Fills indexArray from selected control children
|
|
166
|
-
*
|
|
167
|
-
* @param selectedControlChildren Array of numbers
|
|
168
|
-
* @returns Array of key value pairs
|
|
169
|
-
*/
|
|
170
|
-
fillIndexArray: function _fillIndexArray(selectedControlChildren) {
|
|
171
|
-
let indexArray = [];
|
|
172
|
-
if (selectedControlChildren.length === 0) {
|
|
173
|
-
indexArray.push({
|
|
174
|
-
key: 0,
|
|
175
|
-
value: 0
|
|
176
|
-
});
|
|
177
|
-
} else {
|
|
178
|
-
indexArray = selectedControlChildren.map((elem, index) => {
|
|
179
|
-
return {
|
|
180
|
-
key: index + 1,
|
|
181
|
-
value: elem + 1
|
|
182
|
-
};
|
|
183
|
-
});
|
|
184
|
-
indexArray.unshift({
|
|
185
|
-
key: 0,
|
|
186
|
-
value: 0
|
|
187
|
-
});
|
|
188
|
-
indexArray.push({
|
|
189
|
-
key: selectedControlChildren.length + 1,
|
|
190
|
-
value: selectedControlChildren.length + 1
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
return indexArray;
|
|
194
|
-
},
|
|
195
|
-
/**
|
|
196
|
-
* Creates an addXML fragment command and pushes it to the command stack
|
|
197
|
-
*
|
|
198
|
-
* @param fragmentData Fragment Data
|
|
199
|
-
*/
|
|
200
|
-
createFragmentChange: async function _createFragmentChange(fragmentData) {
|
|
201
|
-
const {
|
|
202
|
-
fragmentName,
|
|
203
|
-
index,
|
|
204
|
-
targetAggregation
|
|
205
|
-
} = fragmentData;
|
|
206
|
-
const flexSettings = this.rta.getFlexSettings();
|
|
207
|
-
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
208
|
-
const designMetadata = overlay.getDesignTimeMetadata();
|
|
209
|
-
const modifiedValue = {
|
|
210
|
-
fragment: `<core:FragmentDefinition xmlns:core='sap.ui.core'></core:FragmentDefinition>`,
|
|
211
|
-
fragmentPath: `fragments/${fragmentName}.fragment.xml`,
|
|
212
|
-
index: index ?? 0,
|
|
213
|
-
targetAggregation: targetAggregation ?? 'content'
|
|
214
|
-
};
|
|
215
|
-
const command = await this.commandExecutor.getCommand(this.runtimeControl, 'addXML', modifiedValue, designMetadata, flexSettings);
|
|
216
|
-
await this.commandExecutor.pushAndExecuteCommand(command);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
return AddFragment;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/ui/model/json/JSONModel", "sap/ui/dt/OverlayRegistry", "../control-utils", "../command-executor", "../api-handler", "./BaseDialog.controller", "../utils"], function (JSONModel, OverlayRegistry, __ControlUtils, __CommandExecutor, ___api_handler, __BaseDialog, ___utils) {
|
|
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 BaseDialog = _interopRequireDefault(__BaseDialog);
|
|
13
|
+
const notifyUser = ___utils["notifyUser"];
|
|
14
|
+
const radix = 10;
|
|
15
|
+
/**
|
|
16
|
+
* @namespace open.ux.preview.client.adp.controllers
|
|
17
|
+
*/
|
|
18
|
+
const AddFragment = BaseDialog.extend("open.ux.preview.client.adp.controllers.AddFragment", {
|
|
19
|
+
constructor: function _constructor(name, overlays, rta) {
|
|
20
|
+
BaseDialog.prototype.constructor.call(this, name);
|
|
21
|
+
this.rta = rta;
|
|
22
|
+
this.overlays = overlays;
|
|
23
|
+
this.model = new JSONModel();
|
|
24
|
+
this.ui5Version = sap.ui.version;
|
|
25
|
+
this.commandExecutor = new CommandExecutor(this.rta);
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* Setups the Dialog and the JSON Model
|
|
29
|
+
*
|
|
30
|
+
* @param {Dialog} dialog - Dialog instance
|
|
31
|
+
*/
|
|
32
|
+
setup: async function _setup(dialog) {
|
|
33
|
+
this.dialog = dialog;
|
|
34
|
+
this.setEscapeHandler();
|
|
35
|
+
await this.buildDialogData();
|
|
36
|
+
this.dialog.setModel(this.model);
|
|
37
|
+
this.dialog.open();
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Handles the index field whenever a specific aggregation is chosen
|
|
41
|
+
*
|
|
42
|
+
* @param specialIndexAggregation string | number
|
|
43
|
+
*/
|
|
44
|
+
specialIndexHandling: function _specialIndexHandling(specialIndexAggregation) {
|
|
45
|
+
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
46
|
+
const aggregations = overlay.getDesignTimeMetadata().getData().aggregations;
|
|
47
|
+
if (specialIndexAggregation in aggregations && 'specialIndexHandling' in aggregations[specialIndexAggregation]) {
|
|
48
|
+
const controlType = this.runtimeControl.getMetadata().getName();
|
|
49
|
+
this.model.setProperty('/indexHandlingFlag', false);
|
|
50
|
+
this.model.setProperty('/specialIndexHandlingIcon', true);
|
|
51
|
+
this.model.setProperty('/iconTooltip', `Index is defined by special logic of ${controlType} and can't be set here`);
|
|
52
|
+
} else {
|
|
53
|
+
this.model.setProperty('/indexHandlingFlag', true);
|
|
54
|
+
this.model.setProperty('/specialIndexHandlingIcon', false);
|
|
55
|
+
this.model.setProperty('/specialIndexHandlingIconPressed', false);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Handles the change in aggregations
|
|
60
|
+
*
|
|
61
|
+
* @param event Event
|
|
62
|
+
*/
|
|
63
|
+
onAggregationChanged: function _onAggregationChanged(event) {
|
|
64
|
+
const source = event.getSource();
|
|
65
|
+
const selectedKey = source.getSelectedKey();
|
|
66
|
+
const selectedItem = source.getSelectedItem();
|
|
67
|
+
let selectedItemText = '';
|
|
68
|
+
if (selectedItem) {
|
|
69
|
+
selectedItemText = selectedItem.getText();
|
|
70
|
+
}
|
|
71
|
+
this.model.setProperty('/selectedAggregation/key', selectedKey);
|
|
72
|
+
this.model.setProperty('/selectedAggregation/value', selectedItemText);
|
|
73
|
+
let newSelectedControlChildren = Object.keys(ControlUtils.getControlAggregationByName(this.runtimeControl, selectedItemText));
|
|
74
|
+
newSelectedControlChildren = newSelectedControlChildren.map(key => {
|
|
75
|
+
return parseInt(key, radix);
|
|
76
|
+
});
|
|
77
|
+
this.specialIndexHandling(selectedItemText);
|
|
78
|
+
const updatedIndexArray = this.fillIndexArray(newSelectedControlChildren);
|
|
79
|
+
this.model.setProperty('/index', updatedIndexArray);
|
|
80
|
+
this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1);
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Handles create button press
|
|
84
|
+
*
|
|
85
|
+
* @param event Event
|
|
86
|
+
*/
|
|
87
|
+
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
88
|
+
const source = event.getSource();
|
|
89
|
+
source.setEnabled(false);
|
|
90
|
+
const fragmentName = this.model.getProperty('/newFragmentName');
|
|
91
|
+
const index = this.model.getProperty('/selectedIndex');
|
|
92
|
+
const targetAggregation = this.model.getProperty('/selectedAggregation/value');
|
|
93
|
+
const fragmentData = {
|
|
94
|
+
index,
|
|
95
|
+
fragmentName,
|
|
96
|
+
targetAggregation
|
|
97
|
+
};
|
|
98
|
+
await this.createFragmentChange(fragmentData);
|
|
99
|
+
notifyUser(`Note: The '${fragmentName}.fragment.xml' fragment will be created once you save the change.`, 8000);
|
|
100
|
+
this.handleDialogClose();
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* Builds data that is used in the dialog
|
|
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, radix);
|
|
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
|
+
this.specialIndexHandling(obj.value);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
this.model.setProperty('/selectedAggregation/key', controlAggregation[0].key);
|
|
149
|
+
this.model.setProperty('/selectedAggregation/value', controlAggregation[0].value);
|
|
150
|
+
this.specialIndexHandling(controlAggregation[0].value);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const {
|
|
154
|
+
fragments
|
|
155
|
+
} = await getFragments();
|
|
156
|
+
this.model.setProperty('/fragmentList', fragments);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
this.handleError(e);
|
|
159
|
+
}
|
|
160
|
+
this.model.setProperty('/selectedIndex', indexArray.length - 1);
|
|
161
|
+
this.model.setProperty('/targetAggregation', controlAggregation);
|
|
162
|
+
this.model.setProperty('/index', indexArray);
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Fills indexArray from selected control children
|
|
166
|
+
*
|
|
167
|
+
* @param selectedControlChildren Array of numbers
|
|
168
|
+
* @returns Array of key value pairs
|
|
169
|
+
*/
|
|
170
|
+
fillIndexArray: function _fillIndexArray(selectedControlChildren) {
|
|
171
|
+
let indexArray = [];
|
|
172
|
+
if (selectedControlChildren.length === 0) {
|
|
173
|
+
indexArray.push({
|
|
174
|
+
key: 0,
|
|
175
|
+
value: 0
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
indexArray = selectedControlChildren.map((elem, index) => {
|
|
179
|
+
return {
|
|
180
|
+
key: index + 1,
|
|
181
|
+
value: elem + 1
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
indexArray.unshift({
|
|
185
|
+
key: 0,
|
|
186
|
+
value: 0
|
|
187
|
+
});
|
|
188
|
+
indexArray.push({
|
|
189
|
+
key: selectedControlChildren.length + 1,
|
|
190
|
+
value: selectedControlChildren.length + 1
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return indexArray;
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* Creates an addXML fragment command and pushes it to the command stack
|
|
197
|
+
*
|
|
198
|
+
* @param fragmentData Fragment Data
|
|
199
|
+
*/
|
|
200
|
+
createFragmentChange: async function _createFragmentChange(fragmentData) {
|
|
201
|
+
const {
|
|
202
|
+
fragmentName,
|
|
203
|
+
index,
|
|
204
|
+
targetAggregation
|
|
205
|
+
} = fragmentData;
|
|
206
|
+
const flexSettings = this.rta.getFlexSettings();
|
|
207
|
+
const overlay = OverlayRegistry.getOverlay(this.runtimeControl);
|
|
208
|
+
const designMetadata = overlay.getDesignTimeMetadata();
|
|
209
|
+
const modifiedValue = {
|
|
210
|
+
fragment: `<core:FragmentDefinition xmlns:core='sap.ui.core'></core:FragmentDefinition>`,
|
|
211
|
+
fragmentPath: `fragments/${fragmentName}.fragment.xml`,
|
|
212
|
+
index: index ?? 0,
|
|
213
|
+
targetAggregation: targetAggregation ?? 'content'
|
|
214
|
+
};
|
|
215
|
+
const command = await this.commandExecutor.getCommand(this.runtimeControl, 'addXML', modifiedValue, designMetadata, flexSettings);
|
|
216
|
+
await this.commandExecutor.pushAndExecuteCommand(command);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return AddFragment;
|
|
220
220
|
});
|
|
221
221
|
//# sourceMappingURL=AddFragment.controller.js.map
|
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["sap/ui/core/library", "sap/ui/core/mvc/Controller", "sap/m/MessageToast", "../utils", "../../cpe/error-utils"], function (sap_ui_core_library, Controller, MessageToast, ___utils, ____cpe_error_utils) {
|
|
4
|
-
"use strict";
|
|
5
|
-
|
|
6
|
-
const ValueState = sap_ui_core_library["ValueState"];
|
|
7
|
-
const matchesFragmentName = ___utils["matchesFragmentName"];
|
|
8
|
-
const getError = ____cpe_error_utils["getError"];
|
|
9
|
-
/**
|
|
10
|
-
* @namespace open.ux.preview.client.adp.controllers
|
|
11
|
-
*/
|
|
12
|
-
const BaseDialog = Controller.extend("open.ux.preview.client.adp.controllers.BaseDialog", {
|
|
13
|
-
/**
|
|
14
|
-
* Handles fragment name input change
|
|
15
|
-
*
|
|
16
|
-
* @param event Event
|
|
17
|
-
*/
|
|
18
|
-
onFragmentNameInputChange: function _onFragmentNameInputChange(event) {
|
|
19
|
-
const input = event.getSource();
|
|
20
|
-
const beginBtn = this.dialog.getBeginButton();
|
|
21
|
-
const fragmentName = input.getValue();
|
|
22
|
-
const fragmentList = this.model.getProperty('/fragmentList');
|
|
23
|
-
const updateDialogState = function (valueState) {
|
|
24
|
-
let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
25
|
-
input.setValueState(valueState).setValueStateText(valueStateText);
|
|
26
|
-
beginBtn.setEnabled(valueState === ValueState.Success);
|
|
27
|
-
};
|
|
28
|
-
if (fragmentName.length <= 0) {
|
|
29
|
-
updateDialogState(ValueState.None);
|
|
30
|
-
this.model.setProperty('/newFragmentName', null);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const fileExists = fragmentList.some(f => f.fragmentName === `${fragmentName}.fragment.xml`);
|
|
34
|
-
if (fileExists) {
|
|
35
|
-
updateDialogState(ValueState.Error, 'Enter a different name. The fragment name that you entered already exists in your project.');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
|
|
39
|
-
if (!isValidName) {
|
|
40
|
-
updateDialogState(ValueState.Error, 'The fragment name cannot contain white spaces or special characters.');
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (fragmentName.length > 64) {
|
|
44
|
-
updateDialogState(ValueState.Error, 'A fragment file name cannot contain more than 64 characters.');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const changeExists = this.checkForExistingChange(fragmentName);
|
|
48
|
-
if (changeExists) {
|
|
49
|
-
updateDialogState(ValueState.Error, 'Enter a different name. The fragment name entered matches the name of an unsaved fragment.');
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
updateDialogState(ValueState.Success);
|
|
53
|
-
this.model.setProperty('/newFragmentName', fragmentName);
|
|
54
|
-
},
|
|
55
|
-
/**
|
|
56
|
-
* Checks for the existence of a change associated with a specific fragment name in the RTA command stack.
|
|
57
|
-
*
|
|
58
|
-
* @param {string} fragmentName - The name of the fragment to check for existing changes.
|
|
59
|
-
* @returns {Promise<boolean>} A promise that resolves to `true` if a matching change is found, otherwise `false`.
|
|
60
|
-
*/
|
|
61
|
-
checkForExistingChange: function _checkForExistingChange(fragmentName) {
|
|
62
|
-
const allCommands = this.rta.getCommandStack().getCommands();
|
|
63
|
-
return allCommands.some(command => {
|
|
64
|
-
if (command?.getProperty('name') === 'composite') {
|
|
65
|
-
const addXmlCommand = command.getCommands().find(c => c?.getProperty('name') === 'addXMLAtExtensionPoint');
|
|
66
|
-
return addXmlCommand && matchesFragmentName(addXmlCommand, fragmentName);
|
|
67
|
-
} else {
|
|
68
|
-
return matchesFragmentName(command, fragmentName);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
},
|
|
72
|
-
/**
|
|
73
|
-
* Sets custom function that fires when user presses escape key.
|
|
74
|
-
*/
|
|
75
|
-
setEscapeHandler: function _setEscapeHandler() {
|
|
76
|
-
this.dialog.setEscapeHandler(_ref => {
|
|
77
|
-
let {
|
|
78
|
-
resolve
|
|
79
|
-
} = _ref;
|
|
80
|
-
this.handleDialogClose();
|
|
81
|
-
resolve();
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
/**
|
|
85
|
-
* Handles the dialog closing and destruction of it.
|
|
86
|
-
*/
|
|
87
|
-
handleDialogClose: function _handleDialogClose() {
|
|
88
|
-
this.dialog.close();
|
|
89
|
-
this.dialog.destroy();
|
|
90
|
-
},
|
|
91
|
-
/**
|
|
92
|
-
* Function that handles runtime thrown errors with MessageToast
|
|
93
|
-
*
|
|
94
|
-
* @param e error instance
|
|
95
|
-
* @throws {Error}.
|
|
96
|
-
*/
|
|
97
|
-
handleError: function _handleError(e) {
|
|
98
|
-
const error = getError(e);
|
|
99
|
-
MessageToast.show(error.message, {
|
|
100
|
-
duration: 5000
|
|
101
|
-
});
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return BaseDialog;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/ui/core/library", "sap/ui/core/mvc/Controller", "sap/m/MessageToast", "../utils", "../../cpe/error-utils"], function (sap_ui_core_library, Controller, MessageToast, ___utils, ____cpe_error_utils) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
const ValueState = sap_ui_core_library["ValueState"];
|
|
7
|
+
const matchesFragmentName = ___utils["matchesFragmentName"];
|
|
8
|
+
const getError = ____cpe_error_utils["getError"];
|
|
9
|
+
/**
|
|
10
|
+
* @namespace open.ux.preview.client.adp.controllers
|
|
11
|
+
*/
|
|
12
|
+
const BaseDialog = Controller.extend("open.ux.preview.client.adp.controllers.BaseDialog", {
|
|
13
|
+
/**
|
|
14
|
+
* Handles fragment name input change
|
|
15
|
+
*
|
|
16
|
+
* @param event Event
|
|
17
|
+
*/
|
|
18
|
+
onFragmentNameInputChange: function _onFragmentNameInputChange(event) {
|
|
19
|
+
const input = event.getSource();
|
|
20
|
+
const beginBtn = this.dialog.getBeginButton();
|
|
21
|
+
const fragmentName = input.getValue();
|
|
22
|
+
const fragmentList = this.model.getProperty('/fragmentList');
|
|
23
|
+
const updateDialogState = function (valueState) {
|
|
24
|
+
let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
25
|
+
input.setValueState(valueState).setValueStateText(valueStateText);
|
|
26
|
+
beginBtn.setEnabled(valueState === ValueState.Success);
|
|
27
|
+
};
|
|
28
|
+
if (fragmentName.length <= 0) {
|
|
29
|
+
updateDialogState(ValueState.None);
|
|
30
|
+
this.model.setProperty('/newFragmentName', null);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const fileExists = fragmentList.some(f => f.fragmentName === `${fragmentName}.fragment.xml`);
|
|
34
|
+
if (fileExists) {
|
|
35
|
+
updateDialogState(ValueState.Error, 'Enter a different name. The fragment name that you entered already exists in your project.');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
|
|
39
|
+
if (!isValidName) {
|
|
40
|
+
updateDialogState(ValueState.Error, 'The fragment name cannot contain white spaces or special characters.');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (fragmentName.length > 64) {
|
|
44
|
+
updateDialogState(ValueState.Error, 'A fragment file name cannot contain more than 64 characters.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const changeExists = this.checkForExistingChange(fragmentName);
|
|
48
|
+
if (changeExists) {
|
|
49
|
+
updateDialogState(ValueState.Error, 'Enter a different name. The fragment name entered matches the name of an unsaved fragment.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
updateDialogState(ValueState.Success);
|
|
53
|
+
this.model.setProperty('/newFragmentName', fragmentName);
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Checks for the existence of a change associated with a specific fragment name in the RTA command stack.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} fragmentName - The name of the fragment to check for existing changes.
|
|
59
|
+
* @returns {Promise<boolean>} A promise that resolves to `true` if a matching change is found, otherwise `false`.
|
|
60
|
+
*/
|
|
61
|
+
checkForExistingChange: function _checkForExistingChange(fragmentName) {
|
|
62
|
+
const allCommands = this.rta.getCommandStack().getCommands();
|
|
63
|
+
return allCommands.some(command => {
|
|
64
|
+
if (command?.getProperty('name') === 'composite') {
|
|
65
|
+
const addXmlCommand = command.getCommands().find(c => c?.getProperty('name') === 'addXMLAtExtensionPoint');
|
|
66
|
+
return addXmlCommand && matchesFragmentName(addXmlCommand, fragmentName);
|
|
67
|
+
} else {
|
|
68
|
+
return matchesFragmentName(command, fragmentName);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Sets custom function that fires when user presses escape key.
|
|
74
|
+
*/
|
|
75
|
+
setEscapeHandler: function _setEscapeHandler() {
|
|
76
|
+
this.dialog.setEscapeHandler(_ref => {
|
|
77
|
+
let {
|
|
78
|
+
resolve
|
|
79
|
+
} = _ref;
|
|
80
|
+
this.handleDialogClose();
|
|
81
|
+
resolve();
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* Handles the dialog closing and destruction of it.
|
|
86
|
+
*/
|
|
87
|
+
handleDialogClose: function _handleDialogClose() {
|
|
88
|
+
this.dialog.close();
|
|
89
|
+
this.dialog.destroy();
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Function that handles runtime thrown errors with MessageToast
|
|
93
|
+
*
|
|
94
|
+
* @param e error instance
|
|
95
|
+
* @throws {Error}.
|
|
96
|
+
*/
|
|
97
|
+
handleError: function _handleError(e) {
|
|
98
|
+
const error = getError(e);
|
|
99
|
+
MessageToast.show(error.message, {
|
|
100
|
+
duration: 5000
|
|
101
|
+
});
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return BaseDialog;
|
|
106
106
|
});
|
|
107
107
|
//# sourceMappingURL=BaseDialog.controller.js.map
|