@sap-ux/preview-middleware 0.13.13 → 0.13.14

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.
@@ -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
@@ -1,59 +1,59 @@
1
- "use strict";
2
-
3
- sap.ui.define(["sap/ui/core/library", "sap/ui/core/mvc/Controller"], function (sap_ui_core_library, Controller) {
4
- "use strict";
5
-
6
- const ValueState = sap_ui_core_library["ValueState"];
7
- /**
8
- * @namespace open.ux.preview.client.adp.controllers
9
- */
10
- const BaseDialog = Controller.extend("open.ux.preview.client.adp.controllers.BaseDialog", {
11
- onFragmentNameInputChange: function _onFragmentNameInputChange(event) {
12
- const input = event.getSource();
13
- const beginBtn = this.dialog.getBeginButton();
14
- const fragmentName = input.getValue();
15
- const fragmentList = this.model.getProperty('/fragmentList');
16
- const updateDialogState = function (valueState) {
17
- let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
18
- input.setValueState(valueState).setValueStateText(valueStateText);
19
- beginBtn.setEnabled(valueState === ValueState.Success);
20
- };
21
- if (fragmentName.length <= 0) {
22
- updateDialogState(ValueState.None);
23
- this.model.setProperty('/newFragmentName', null);
24
- return;
25
- }
26
- const fileExists = fragmentList.some(f => f.fragmentName === `${fragmentName}.fragment.xml`);
27
- if (fileExists) {
28
- updateDialogState(ValueState.Error, 'Enter a different name. The fragment name that you entered already exists in your project.');
29
- return;
30
- }
31
- const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
32
- if (!isValidName) {
33
- updateDialogState(ValueState.Error, 'The fragment name cannot contain white spaces or special characters.');
34
- return;
35
- }
36
- if (fragmentName.length > 64) {
37
- updateDialogState(ValueState.Error, 'A fragment file name cannot contain more than 64 characters.');
38
- return;
39
- }
40
- updateDialogState(ValueState.Success);
41
- this.model.setProperty('/newFragmentName', fragmentName);
42
- },
43
- setEscapeHandler: function _setEscapeHandler() {
44
- this.dialog.setEscapeHandler(_ref => {
45
- let {
46
- resolve
47
- } = _ref;
48
- this.handleDialogClose();
49
- resolve();
50
- });
51
- },
52
- handleDialogClose: function _handleDialogClose() {
53
- this.dialog.close();
54
- this.dialog.destroy();
55
- }
56
- });
57
- return BaseDialog;
1
+ "use strict";
2
+
3
+ sap.ui.define(["sap/ui/core/library", "sap/ui/core/mvc/Controller"], function (sap_ui_core_library, Controller) {
4
+ "use strict";
5
+
6
+ const ValueState = sap_ui_core_library["ValueState"];
7
+ /**
8
+ * @namespace open.ux.preview.client.adp.controllers
9
+ */
10
+ const BaseDialog = Controller.extend("open.ux.preview.client.adp.controllers.BaseDialog", {
11
+ onFragmentNameInputChange: function _onFragmentNameInputChange(event) {
12
+ const input = event.getSource();
13
+ const beginBtn = this.dialog.getBeginButton();
14
+ const fragmentName = input.getValue();
15
+ const fragmentList = this.model.getProperty('/fragmentList');
16
+ const updateDialogState = function (valueState) {
17
+ let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
18
+ input.setValueState(valueState).setValueStateText(valueStateText);
19
+ beginBtn.setEnabled(valueState === ValueState.Success);
20
+ };
21
+ if (fragmentName.length <= 0) {
22
+ updateDialogState(ValueState.None);
23
+ this.model.setProperty('/newFragmentName', null);
24
+ return;
25
+ }
26
+ const fileExists = fragmentList.some(f => f.fragmentName === `${fragmentName}.fragment.xml`);
27
+ if (fileExists) {
28
+ updateDialogState(ValueState.Error, 'Enter a different name. The fragment name that you entered already exists in your project.');
29
+ return;
30
+ }
31
+ const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
32
+ if (!isValidName) {
33
+ updateDialogState(ValueState.Error, 'The fragment name cannot contain white spaces or special characters.');
34
+ return;
35
+ }
36
+ if (fragmentName.length > 64) {
37
+ updateDialogState(ValueState.Error, 'A fragment file name cannot contain more than 64 characters.');
38
+ return;
39
+ }
40
+ updateDialogState(ValueState.Success);
41
+ this.model.setProperty('/newFragmentName', fragmentName);
42
+ },
43
+ setEscapeHandler: function _setEscapeHandler() {
44
+ this.dialog.setEscapeHandler(_ref => {
45
+ let {
46
+ resolve
47
+ } = _ref;
48
+ this.handleDialogClose();
49
+ resolve();
50
+ });
51
+ },
52
+ handleDialogClose: function _handleDialogClose() {
53
+ this.dialog.close();
54
+ this.dialog.destroy();
55
+ }
56
+ });
57
+ return BaseDialog;
58
58
  });
59
59
  //# sourceMappingURL=BaseDialog.controller.js.map