@sap-ux/preview-middleware 0.8.7 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,8 @@ import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
5
5
  import type { FlexSettings } from 'sap/ui/rta/RuntimeAuthoring';
6
6
  import type DesignTimeMetadata from 'sap/ui/dt/DesignTimeMetadata';
7
7
 
8
+ type CommandNames = 'addXML';
9
+
8
10
  /**
9
11
  * Class responsible for handling rta calls
10
12
  */
@@ -26,7 +28,7 @@ export default class CommandExecutor {
26
28
  */
27
29
  public async generateAndExecuteCommand(
28
30
  runtimeControl: ManagedObject,
29
- commandName: 'addXML',
31
+ commandName: CommandNames,
30
32
  modifiedValue: object,
31
33
  designMetadata: DesignTimeMetadata,
32
34
  flexSettings: FlexSettings
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
 
3
- sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/JSONModel", "sap/ui/dt/OverlayRegistry", "../control-utils", "../command-executor", "../api-handler", "./BaseDialog.controller"], function (MessageToast, sap_ui_core_library, JSONModel, OverlayRegistry, __ControlUtils, __CommandExecutor, ___api_handler, __BaseDialog) {
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
4
  "use strict";
5
5
 
6
6
  function _interopRequireDefault(obj) {
7
7
  return obj && obj.__esModule && typeof obj.default !== "undefined" ? obj.default : obj;
8
8
  }
9
- /** sap.ui.core */
10
- const ValueState = sap_ui_core_library["ValueState"];
11
- /** sap.ui.base */
12
9
  const ControlUtils = _interopRequireDefault(__ControlUtils);
13
10
  const CommandExecutor = _interopRequireDefault(__CommandExecutor);
14
11
  const getFragments = ___api_handler["getFragments"];
@@ -27,6 +24,7 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
27
24
  },
28
25
  onInit: async function _onInit() {
29
26
  this.dialog = this.byId('addNewFragmentDialog');
27
+ this.setEscapeHandler();
30
28
  await this.buildDialogData();
31
29
  this.getView()?.setModel(this.model);
32
30
  this.dialog.open();
@@ -54,34 +52,6 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
54
52
  const selectedIndex = source.getSelectedItem()?.getText();
55
53
  this.model.setProperty('/selectedIndex', selectedIndex);
56
54
  },
57
- onFragmentNameInputChange: function _onFragmentNameInputChange(event) {
58
- const source = event.getSource();
59
- const fragmentName = source.getValue().trim();
60
- const fragmentList = this.model.getProperty('/fragmentList');
61
- if (fragmentName.length <= 0) {
62
- this.dialog.getBeginButton().setEnabled(false);
63
- source.setValueState(ValueState.None);
64
- this.model.setProperty('/newFragmentName', null);
65
- } else {
66
- const fileExists = fragmentList.find(f => {
67
- return f.fragmentName === `${fragmentName}.fragment.xml`;
68
- });
69
- const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
70
- if (fileExists) {
71
- source.setValueState(ValueState.Error);
72
- source.setValueStateText('Enter a different name. The fragment name that you entered already exists in your project.');
73
- this.dialog.getBeginButton().setEnabled(false);
74
- } else if (!isValidName) {
75
- source.setValueState(ValueState.Error);
76
- source.setValueStateText('A Fragment Name cannot contain white spaces or special characters.');
77
- this.dialog.getBeginButton().setEnabled(false);
78
- } else {
79
- this.dialog.getBeginButton().setEnabled(true);
80
- source.setValueState(ValueState.None);
81
- this.model.setProperty('/newFragmentName', fragmentName);
82
- }
83
- }
84
- },
85
55
  onCreateBtnPress: async function _onCreateBtnPress(event) {
86
56
  const source = event.getSource();
87
57
  source.setEnabled(false);
@@ -147,6 +117,7 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
147
117
  } = await getFragments();
148
118
  this.model.setProperty('/fragmentList', fragments);
149
119
  } catch (e) {
120
+ MessageToast.show(e.message);
150
121
  throw new Error(e.message);
151
122
  }
152
123
  this.model.setProperty('/selectedIndex', indexArray.length - 1);
@@ -1,12 +1,10 @@
1
1
  /** sap.m */
2
- import Input from 'sap/m/Input';
3
2
  import Button from 'sap/m/Button';
4
3
  import type Dialog from 'sap/m/Dialog';
5
4
  import type ComboBox from 'sap/m/ComboBox';
6
5
  import MessageToast from 'sap/m/MessageToast';
7
6
 
8
7
  /** sap.ui.core */
9
- import { ValueState } from 'sap/ui/core/library';
10
8
  import type UI5Element from 'sap/ui/core/Element';
11
9
 
12
10
  /** sap.ui.base */
@@ -52,6 +50,8 @@ export default class AddFragment extends BaseDialog {
52
50
  async onInit() {
53
51
  this.dialog = this.byId('addNewFragmentDialog') as unknown as Dialog;
54
52
 
53
+ this.setEscapeHandler();
54
+
55
55
  await this.buildDialogData();
56
56
 
57
57
  this.getView()?.setModel(this.model);
@@ -103,46 +103,6 @@ export default class AddFragment extends BaseDialog {
103
103
  this.model.setProperty('/selectedIndex', selectedIndex);
104
104
  }
105
105
 
106
- /**
107
- * Handles fragment name input change
108
- *
109
- * @param event Event
110
- */
111
- onFragmentNameInputChange(event: Event) {
112
- const source = event.getSource<Input>();
113
-
114
- const fragmentName: string = source.getValue().trim();
115
- const fragmentList: { fragmentName: string }[] = this.model.getProperty('/fragmentList');
116
-
117
- if (fragmentName.length <= 0) {
118
- this.dialog.getBeginButton().setEnabled(false);
119
- source.setValueState(ValueState.None);
120
- this.model.setProperty('/newFragmentName', null);
121
- } else {
122
- const fileExists = fragmentList.find((f: { fragmentName: string }) => {
123
- return f.fragmentName === `${fragmentName}.fragment.xml`;
124
- });
125
-
126
- const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
127
-
128
- if (fileExists) {
129
- source.setValueState(ValueState.Error);
130
- source.setValueStateText(
131
- 'Enter a different name. The fragment name that you entered already exists in your project.'
132
- );
133
- this.dialog.getBeginButton().setEnabled(false);
134
- } else if (!isValidName) {
135
- source.setValueState(ValueState.Error);
136
- source.setValueStateText('A Fragment Name cannot contain white spaces or special characters.');
137
- this.dialog.getBeginButton().setEnabled(false);
138
- } else {
139
- this.dialog.getBeginButton().setEnabled(true);
140
- source.setValueState(ValueState.None);
141
- this.model.setProperty('/newFragmentName', fragmentName);
142
- }
143
- }
144
- }
145
-
146
106
  /**
147
107
  * Handles create button press
148
108
  *
@@ -230,6 +190,7 @@ export default class AddFragment extends BaseDialog {
230
190
 
231
191
  this.model.setProperty('/fragmentList', fragments);
232
192
  } catch (e) {
193
+ MessageToast.show(e.message);
233
194
  throw new Error(e.message);
234
195
  }
235
196
 
@@ -1,12 +1,50 @@
1
1
  "use strict";
2
2
 
3
- sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {
3
+ sap.ui.define(["sap/ui/core/library", "sap/ui/core/mvc/Controller"], function (sap_ui_core_library, Controller) {
4
4
  "use strict";
5
5
 
6
+ const ValueState = sap_ui_core_library["ValueState"];
6
7
  /**
7
8
  * @namespace open.ux.preview.client.adp.controllers
8
9
  */
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().trim();
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
+ updateDialogState(ValueState.Success);
37
+ this.model.setProperty('/newFragmentName', fragmentName);
38
+ },
39
+ setEscapeHandler: function _setEscapeHandler() {
40
+ this.dialog.setEscapeHandler(_ref => {
41
+ let {
42
+ resolve
43
+ } = _ref;
44
+ this.handleDialogClose();
45
+ resolve();
46
+ });
47
+ },
10
48
  handleDialogClose: function _handleDialogClose() {
11
49
  this.dialog.close();
12
50
  this.getView()?.destroy();
@@ -1,7 +1,9 @@
1
1
  import Dialog from 'sap/m/Dialog';
2
+ import Input from 'sap/m/Input';
2
3
  import Event from 'sap/ui/base/Event';
3
4
  import ManagedObject from 'sap/ui/base/ManagedObject';
4
5
  import UI5Element from 'sap/ui/core/Element';
6
+ import { ValueState } from 'sap/ui/core/library';
5
7
  import Controller from 'sap/ui/core/mvc/Controller';
6
8
  import JSONModel from 'sap/ui/model/json/JSONModel';
7
9
  import RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
@@ -42,7 +44,61 @@ export default abstract class BaseDialog extends Controller {
42
44
  abstract buildDialogData(): Promise<void>;
43
45
 
44
46
  /**
45
- * Handles the dialog closing and destruction of it
47
+ * Handles fragment name input change
48
+ *
49
+ * @param event Event
50
+ */
51
+ onFragmentNameInputChange(event: Event) {
52
+ const input = event.getSource<Input>();
53
+ const beginBtn = this.dialog.getBeginButton();
54
+
55
+ const fragmentName: string = input.getValue().trim();
56
+ const fragmentList: { fragmentName: string }[] = this.model.getProperty('/fragmentList');
57
+
58
+ const updateDialogState = (valueState: ValueState, valueStateText = '') => {
59
+ input.setValueState(valueState).setValueStateText(valueStateText);
60
+ beginBtn.setEnabled(valueState === ValueState.Success);
61
+ };
62
+
63
+ if (fragmentName.length <= 0) {
64
+ updateDialogState(ValueState.None);
65
+ this.model.setProperty('/newFragmentName', null);
66
+ return;
67
+ }
68
+
69
+ const fileExists = fragmentList.some((f) => f.fragmentName === `${fragmentName}.fragment.xml`);
70
+
71
+ if (fileExists) {
72
+ updateDialogState(
73
+ ValueState.Error,
74
+ 'Enter a different name. The fragment name that you entered already exists in your project.'
75
+ );
76
+ return;
77
+ }
78
+
79
+ const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
80
+
81
+ if (!isValidName) {
82
+ updateDialogState(ValueState.Error, 'The fragment name cannot contain white spaces or special characters.');
83
+ return;
84
+ }
85
+
86
+ updateDialogState(ValueState.Success);
87
+ this.model.setProperty('/newFragmentName', fragmentName);
88
+ }
89
+
90
+ /**
91
+ * Sets custom function that fires when user presses escape key.
92
+ */
93
+ setEscapeHandler() {
94
+ this.dialog.setEscapeHandler(({ resolve }) => {
95
+ this.handleDialogClose();
96
+ resolve();
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Handles the dialog closing and destruction of it.
46
102
  */
47
103
  handleDialogClose() {
48
104
  this.dialog.close();
@@ -26,37 +26,38 @@ sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/J
26
26
  },
27
27
  onInit: async function _onInit() {
28
28
  this.dialog = this.byId('controllerExtensionDialog');
29
+ this.setEscapeHandler();
29
30
  await this.buildDialogData();
30
31
  this.getView()?.setModel(this.model);
31
32
  this.dialog.open();
32
33
  },
33
34
  onControllerNameInputChange: function _onControllerNameInputChange(event) {
34
- const source = event.getSource();
35
- const controllerName = source.getValue().trim();
35
+ const input = event.getSource();
36
+ const beginBtn = this.dialog.getBeginButton();
37
+ const controllerName = input.getValue().trim();
36
38
  const controllerList = this.model.getProperty('/controllersList');
39
+ const updateDialogState = function (valueState) {
40
+ let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
41
+ input.setValueState(valueState).setValueStateText(valueStateText);
42
+ beginBtn.setEnabled(valueState === ValueState.Success);
43
+ };
37
44
  if (controllerName.length <= 0) {
38
- this.dialog.getBeginButton().setEnabled(false);
39
- source.setValueState(ValueState.None);
45
+ updateDialogState(ValueState.None);
40
46
  this.model.setProperty('/newControllerName', null);
41
- } else {
42
- const fileExists = controllerList.find(f => {
43
- return f.controllerName === `${controllerName}.js`;
44
- });
45
- const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(controllerName);
46
- if (fileExists) {
47
- source.setValueState(ValueState.Error);
48
- source.setValueStateText('Enter a different name. The controller name that you entered already exists in your project.');
49
- this.dialog.getBeginButton().setEnabled(false);
50
- } else if (!isValidName) {
51
- source.setValueState(ValueState.Error);
52
- source.setValueStateText('The controller name cannot contain white spaces or special characters.');
53
- this.dialog.getBeginButton().setEnabled(false);
54
- } else {
55
- this.dialog.getBeginButton().setEnabled(true);
56
- source.setValueState(ValueState.None);
57
- this.model.setProperty('/newControllerName', controllerName);
58
- }
47
+ return;
48
+ }
49
+ const fileExists = controllerList.some(f => f.controllerName === `${controllerName}.js`);
50
+ if (fileExists) {
51
+ updateDialogState(ValueState.Error, 'Enter a different name. The controller name that you entered already exists in your project.');
52
+ return;
53
+ }
54
+ const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(controllerName);
55
+ if (!isValidName) {
56
+ updateDialogState(ValueState.Error, 'The controller name cannot contain white spaces or special characters.');
57
+ return;
59
58
  }
59
+ updateDialogState(ValueState.Success);
60
+ this.model.setProperty('/newControllerName', controllerName);
60
61
  },
61
62
  onCreateBtnPress: async function _onCreateBtnPress(event) {
62
63
  const source = event.getSource();
@@ -48,6 +48,8 @@ export default class ControllerExtension extends BaseDialog {
48
48
  async onInit() {
49
49
  this.dialog = this.byId('controllerExtensionDialog') as unknown as Dialog;
50
50
 
51
+ this.setEscapeHandler();
52
+
51
53
  await this.buildDialogData();
52
54
 
53
55
  this.getView()?.setModel(this.model);
@@ -61,38 +63,45 @@ export default class ControllerExtension extends BaseDialog {
61
63
  * @param event Event
62
64
  */
63
65
  onControllerNameInputChange(event: Event) {
64
- const source = event.getSource<Input>();
66
+ const input = event.getSource<Input>();
67
+ const beginBtn = this.dialog.getBeginButton();
65
68
 
66
- const controllerName: string = source.getValue().trim();
69
+ const controllerName: string = input.getValue().trim();
67
70
  const controllerList: { controllerName: string }[] = this.model.getProperty('/controllersList');
68
71
 
72
+ const updateDialogState = (valueState: ValueState, valueStateText = '') => {
73
+ input.setValueState(valueState).setValueStateText(valueStateText);
74
+ beginBtn.setEnabled(valueState === ValueState.Success);
75
+ };
76
+
69
77
  if (controllerName.length <= 0) {
70
- this.dialog.getBeginButton().setEnabled(false);
71
- source.setValueState(ValueState.None);
78
+ updateDialogState(ValueState.None);
72
79
  this.model.setProperty('/newControllerName', null);
73
- } else {
74
- const fileExists = controllerList.find((f: { controllerName: string }) => {
75
- return f.controllerName === `${controllerName}.js`;
76
- });
77
-
78
- const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(controllerName);
79
-
80
- if (fileExists) {
81
- source.setValueState(ValueState.Error);
82
- source.setValueStateText(
83
- 'Enter a different name. The controller name that you entered already exists in your project.'
84
- );
85
- this.dialog.getBeginButton().setEnabled(false);
86
- } else if (!isValidName) {
87
- source.setValueState(ValueState.Error);
88
- source.setValueStateText('The controller name cannot contain white spaces or special characters.');
89
- this.dialog.getBeginButton().setEnabled(false);
90
- } else {
91
- this.dialog.getBeginButton().setEnabled(true);
92
- source.setValueState(ValueState.None);
93
- this.model.setProperty('/newControllerName', controllerName);
94
- }
80
+ return;
81
+ }
82
+
83
+ const fileExists = controllerList.some((f) => f.controllerName === `${controllerName}.js`);
84
+
85
+ if (fileExists) {
86
+ updateDialogState(
87
+ ValueState.Error,
88
+ 'Enter a different name. The controller name that you entered already exists in your project.'
89
+ );
90
+ return;
95
91
  }
92
+
93
+ const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(controllerName);
94
+
95
+ if (!isValidName) {
96
+ updateDialogState(
97
+ ValueState.Error,
98
+ 'The controller name cannot contain white spaces or special characters.'
99
+ );
100
+ return;
101
+ }
102
+
103
+ updateDialogState(ValueState.Success);
104
+ this.model.setProperty('/newControllerName', controllerName);
96
105
  }
97
106
 
98
107
  /**
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ sap.ui.define(["sap/m/MessageToast", "sap/ui/model/json/JSONModel", "../api-handler", "./BaseDialog.controller"], function (MessageToast, JSONModel, ___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 getFragments = ___api_handler["getFragments"];
10
+ const writeFragment = ___api_handler["writeFragment"];
11
+ const BaseDialog = _interopRequireDefault(__BaseDialog);
12
+ /**
13
+ * @namespace open.ux.preview.client.adp.controllers
14
+ */
15
+ const ExtensionPoint = BaseDialog.extend("open.ux.preview.client.adp.controllers.ExtensionPoint", {
16
+ constructor: function _constructor(name, _overlays, _rta, extensionPointData) {
17
+ BaseDialog.prototype.constructor.call(this, name);
18
+ this.model = new JSONModel();
19
+ this.extensionPointData = extensionPointData;
20
+ },
21
+ onInit: async function _onInit() {
22
+ this.dialog = this.byId('addFragmentAtExtPointDialog');
23
+ this.setEscapeHandler();
24
+ await this.buildDialogData();
25
+ this.getView()?.setModel(this.model);
26
+ this.dialog.open();
27
+ },
28
+ onCreateBtnPress: async function _onCreateBtnPress(event) {
29
+ const source = event.getSource();
30
+ source.setEnabled(false);
31
+ const fragmentName = this.model.getProperty('/newFragmentName');
32
+ await this.createNewFragment(fragmentName);
33
+ this.handleDialogClose();
34
+ },
35
+ buildDialogData: async function _buildDialogData() {
36
+ this.model.setProperty('/extensionPointName', this.extensionPointData?.name);
37
+ try {
38
+ const {
39
+ fragments
40
+ } = await getFragments();
41
+ this.model.setProperty('/fragmentList', fragments);
42
+ } catch (e) {
43
+ MessageToast.show(e.message);
44
+ throw new Error(e.message);
45
+ }
46
+ },
47
+ createNewFragment: async function _createNewFragment(fragmentName) {
48
+ try {
49
+ await writeFragment({
50
+ fragmentName
51
+ });
52
+ MessageToast.show(`Fragment with name '${fragmentName}' was created.`);
53
+ } catch (e) {
54
+ // In case of error when creating a new fragment, we should not create a change file
55
+ MessageToast.show(e.message);
56
+ throw new Error(e.message);
57
+ }
58
+ await this.createExtensionPointFragmentChange(fragmentName);
59
+ },
60
+ createExtensionPointFragmentChange: async function _createExtensionPointFragmentChange(fragmentName) {
61
+ const modifiedValue = {
62
+ fragmentPath: `fragments/${fragmentName}.fragment.xml`,
63
+ extensionPointName: this.extensionPointData.name
64
+ };
65
+ this.extensionPointData.deffered.resolve(modifiedValue);
66
+ }
67
+ });
68
+ return ExtensionPoint;
69
+ });
70
+ //# sourceMappingURL=ExtensionPoint.controller.js.map
@@ -0,0 +1,112 @@
1
+ /** sap.m */
2
+ import Button from 'sap/m/Button';
3
+ import type Dialog from 'sap/m/Dialog';
4
+ import MessageToast from 'sap/m/MessageToast';
5
+
6
+ /** sap.ui.core */
7
+ import type UI5Element from 'sap/ui/core/Element';
8
+
9
+ /** sap.ui.base */
10
+ import type Event from 'sap/ui/base/Event';
11
+
12
+ /** sap.ui.model */
13
+ import JSONModel from 'sap/ui/model/json/JSONModel';
14
+
15
+ /** sap.ui.rta */
16
+ import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
17
+
18
+ import { getFragments, writeFragment } from '../api-handler';
19
+ import BaseDialog from './BaseDialog.controller';
20
+ import { ExtensionPointData } from '../extension-point';
21
+
22
+ /**
23
+ * @namespace open.ux.preview.client.adp.controllers
24
+ */
25
+ export default class ExtensionPoint extends BaseDialog {
26
+ public readonly extensionPointData: ExtensionPointData;
27
+
28
+ constructor(name: string, _overlays: UI5Element, _rta: RuntimeAuthoring, extensionPointData: ExtensionPointData) {
29
+ super(name);
30
+ this.model = new JSONModel();
31
+ this.extensionPointData = extensionPointData;
32
+ }
33
+
34
+ /**
35
+ * Initializes controller, fills model with data and opens the dialog
36
+ */
37
+ async onInit() {
38
+ this.dialog = this.byId('addFragmentAtExtPointDialog') as unknown as Dialog;
39
+
40
+ this.setEscapeHandler();
41
+
42
+ await this.buildDialogData();
43
+
44
+ this.getView()?.setModel(this.model);
45
+
46
+ this.dialog.open();
47
+ }
48
+
49
+ /**
50
+ * Handles create button press
51
+ *
52
+ * @param event Event
53
+ */
54
+ async onCreateBtnPress(event: Event) {
55
+ const source = event.getSource<Button>();
56
+ source.setEnabled(false);
57
+
58
+ const fragmentName = this.model.getProperty('/newFragmentName');
59
+
60
+ await this.createNewFragment(fragmentName);
61
+
62
+ this.handleDialogClose();
63
+ }
64
+
65
+ /**
66
+ * Builds data that is used in the dialog
67
+ */
68
+ async buildDialogData(): Promise<void> {
69
+ this.model.setProperty('/extensionPointName', this.extensionPointData?.name);
70
+
71
+ try {
72
+ const { fragments } = await getFragments();
73
+
74
+ this.model.setProperty('/fragmentList', fragments);
75
+ } catch (e) {
76
+ MessageToast.show(e.message);
77
+ throw new Error(e.message);
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Creates a new fragment for the specified extension point
83
+ *
84
+ * @param fragmentName Fragment name
85
+ */
86
+ private async createNewFragment(fragmentName: string): Promise<void> {
87
+ try {
88
+ await writeFragment<unknown>({ fragmentName });
89
+ MessageToast.show(`Fragment with name '${fragmentName}' was created.`);
90
+ } catch (e) {
91
+ // In case of error when creating a new fragment, we should not create a change file
92
+ MessageToast.show(e.message);
93
+ throw new Error(e.message);
94
+ }
95
+
96
+ await this.createExtensionPointFragmentChange(fragmentName);
97
+ }
98
+
99
+ /**
100
+ * Creates add xml at extension point changes
101
+ *
102
+ * @param fragmentName Fragment name
103
+ */
104
+ private async createExtensionPointFragmentChange(fragmentName: string): Promise<void> {
105
+ const modifiedValue = {
106
+ fragmentPath: `fragments/${fragmentName}.fragment.xml`,
107
+ extensionPointName: this.extensionPointData.name
108
+ };
109
+
110
+ this.extensionPointData.deffered.resolve(modifiedValue);
111
+ }
112
+ }
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+ sap.ui.define([
3
+ 'sap/ui/rta/plugin/AddXMLAtExtensionPoint',
4
+ 'sap/ui/rta/command/CommandFactory',
5
+ 'open/ux/preview/client/thirdparty/@sap-ux-private/control-property-editor-common',
6
+ './utils',
7
+ './init-dialogs'
8
+ ], function (AddXMLAtExtensionPoint, CommandFactory, ___sap_ux_private_control_property_editor_common, ___utils, ___init_dialogs) {
9
+ 'use strict';
10
+ const addExtensionPoint = ___sap_ux_private_control_property_editor_common['addExtensionPoint'];
11
+ const createDeferred = ___utils['createDeferred'];
12
+ const DialogNames = ___init_dialogs['DialogNames'];
13
+ const handler = ___init_dialogs['handler'];
14
+ class ExtensionPointService {
15
+ actionId = 'CTX_ADDXML_AT_EXTENSIONPOINT';
16
+ constructor(rta) {
17
+ this.rta = rta;
18
+ }
19
+ init(subscribe) {
20
+ this.initPlugin();
21
+ subscribe(async action => {
22
+ if (addExtensionPoint.match(action)) {
23
+ try {
24
+ const {controlId} = action.payload;
25
+ const service = await this.rta.getService('action');
26
+ service.execute(controlId, this.actionId);
27
+ } catch (e) {
28
+ throw new Error(`Failed to execute service with actionId: ${ this.actionId }`);
29
+ }
30
+ }
31
+ });
32
+ }
33
+ initPlugin() {
34
+ const flexSettings = this.rta.getFlexSettings();
35
+ const commandFactory = new CommandFactory({ flexSettings });
36
+ const plugin = new AddXMLAtExtensionPoint({
37
+ commandFactory,
38
+ fragmentHandler: async (overlay, info) => await this.fragmentHandler(overlay, info[0])
39
+ });
40
+ const defaultPlugins = this.rta.getDefaultPlugins();
41
+ defaultPlugins.addXMLAtExtensionPoint = plugin;
42
+ this.rta.setPlugins(defaultPlugins);
43
+ }
44
+ async fragmentHandler(overlay, info) {
45
+ let deffered = createDeferred();
46
+ await handler(overlay, this.rta, DialogNames.ADD_FRAGMENT_AT_EXTENSION_POINT, {
47
+ name: info.name,
48
+ deffered
49
+ });
50
+ return deffered.promise;
51
+ }
52
+ }
53
+ return ExtensionPointService;
54
+ });