@sap-ux/preview-middleware 0.13.18 → 0.13.19
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/base/flex.d.ts +5 -15
- package/dist/base/flex.js +4 -32
- package/dist/base/flp.d.ts +12 -2
- package/dist/base/flp.js +27 -5
- package/dist/client/adp/api-handler.js +141 -141
- package/dist/client/adp/command-executor.js +54 -54
- package/dist/client/adp/control-utils.js +44 -44
- package/dist/client/adp/controllers/AddFragment.controller.js +185 -206
- package/dist/client/adp/controllers/AddFragment.controller.ts +5 -24
- package/dist/client/adp/controllers/BaseDialog.controller.js +74 -57
- package/dist/client/adp/controllers/BaseDialog.controller.ts +36 -2
- package/dist/client/adp/controllers/ControllerExtension.controller.js +179 -179
- package/dist/client/adp/controllers/ExtensionPoint.controller.js +90 -100
- package/dist/client/adp/controllers/ExtensionPoint.controller.ts +9 -22
- package/dist/client/adp/init-dialogs.js +74 -74
- package/dist/client/adp/ui5-version-utils.js +63 -63
- package/dist/client/adp/utils.js +61 -33
- package/dist/client/adp/utils.ts +34 -0
- package/dist/client/cpe/changes/flex-change.js +51 -51
- package/dist/client/cpe/changes/index.js +10 -10
- package/dist/client/cpe/changes/validator.js +35 -35
- package/dist/client/cpe/documentation.js +164 -164
- package/dist/client/cpe/logger.js +30 -30
- package/dist/client/cpe/outline/nodes.js +84 -84
- package/dist/client/cpe/outline/utils.js +37 -37
- package/dist/client/cpe/types.js +4 -4
- package/dist/client/cpe/ui5-utils.js +49 -49
- package/dist/client/cpe/utils.js +48 -48
- package/dist/client/flp/WorkspaceConnector.js +84 -84
- package/dist/client/flp/common.js +28 -28
- package/dist/client/flp/enableFakeConnector.js +77 -77
- package/dist/client/flp/init.js +220 -220
- package/dist/client/flp/initConnectors.js +33 -33
- package/dist/client/flp/initRta.js +178 -178
- package/package.json +7 -3
|
@@ -1,59 +1,76 @@
|
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/ui/core/library", "sap/ui/core/mvc/Controller", "../utils"], function (sap_ui_core_library, Controller, ___utils) {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
const ValueState = sap_ui_core_library["ValueState"];
|
|
7
|
+
const matchesFragmentName = ___utils["matchesFragmentName"];
|
|
8
|
+
/**
|
|
9
|
+
* @namespace open.ux.preview.client.adp.controllers
|
|
10
|
+
*/
|
|
11
|
+
const BaseDialog = Controller.extend("open.ux.preview.client.adp.controllers.BaseDialog", {
|
|
12
|
+
onFragmentNameInputChange: function _onFragmentNameInputChange(event) {
|
|
13
|
+
const input = event.getSource();
|
|
14
|
+
const beginBtn = this.dialog.getBeginButton();
|
|
15
|
+
const fragmentName = input.getValue();
|
|
16
|
+
const fragmentList = this.model.getProperty('/fragmentList');
|
|
17
|
+
const updateDialogState = function (valueState) {
|
|
18
|
+
let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
19
|
+
input.setValueState(valueState).setValueStateText(valueStateText);
|
|
20
|
+
beginBtn.setEnabled(valueState === ValueState.Success);
|
|
21
|
+
};
|
|
22
|
+
if (fragmentName.length <= 0) {
|
|
23
|
+
updateDialogState(ValueState.None);
|
|
24
|
+
this.model.setProperty('/newFragmentName', null);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const fileExists = fragmentList.some(f => f.fragmentName === `${fragmentName}.fragment.xml`);
|
|
28
|
+
if (fileExists) {
|
|
29
|
+
updateDialogState(ValueState.Error, 'Enter a different name. The fragment name that you entered already exists in your project.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(fragmentName);
|
|
33
|
+
if (!isValidName) {
|
|
34
|
+
updateDialogState(ValueState.Error, 'The fragment name cannot contain white spaces or special characters.');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (fragmentName.length > 64) {
|
|
38
|
+
updateDialogState(ValueState.Error, 'A fragment file name cannot contain more than 64 characters.');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const changeExists = this.checkForExistingChange(fragmentName);
|
|
42
|
+
if (changeExists) {
|
|
43
|
+
updateDialogState(ValueState.Error, 'Enter a different name. The fragment name entered matches the name of an unsaved fragment.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
updateDialogState(ValueState.Success);
|
|
47
|
+
this.model.setProperty('/newFragmentName', fragmentName);
|
|
48
|
+
},
|
|
49
|
+
checkForExistingChange: function _checkForExistingChange(fragmentName) {
|
|
50
|
+
const allCommands = this.rta.getCommandStack().getCommands();
|
|
51
|
+
return allCommands.some(command => {
|
|
52
|
+
if (command?.getProperty('name') === 'composite') {
|
|
53
|
+
const addXmlCommand = command.getCommands().find(c => c?.getProperty('name') === 'addXMLAtExtensionPoint');
|
|
54
|
+
return addXmlCommand && matchesFragmentName(addXmlCommand, fragmentName);
|
|
55
|
+
} else {
|
|
56
|
+
return matchesFragmentName(command, fragmentName);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
setEscapeHandler: function _setEscapeHandler() {
|
|
61
|
+
this.dialog.setEscapeHandler(_ref => {
|
|
62
|
+
let {
|
|
63
|
+
resolve
|
|
64
|
+
} = _ref;
|
|
65
|
+
this.handleDialogClose();
|
|
66
|
+
resolve();
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
handleDialogClose: function _handleDialogClose() {
|
|
70
|
+
this.dialog.close();
|
|
71
|
+
this.dialog.destroy();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return BaseDialog;
|
|
58
75
|
});
|
|
59
76
|
//# sourceMappingURL=BaseDialog.controller.js.map
|
|
@@ -7,8 +7,10 @@ import { ValueState } from 'sap/ui/core/library';
|
|
|
7
7
|
import Controller from 'sap/ui/core/mvc/Controller';
|
|
8
8
|
import JSONModel from 'sap/ui/model/json/JSONModel';
|
|
9
9
|
import RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
|
|
10
|
+
import FlexCommand from 'sap/ui/rta/command/FlexCommand';
|
|
10
11
|
|
|
11
12
|
import CommandExecutor from '../command-executor';
|
|
13
|
+
import { matchesFragmentName } from '../utils';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @namespace open.ux.preview.client.adp.controllers
|
|
@@ -45,7 +47,7 @@ export default abstract class BaseDialog extends Controller {
|
|
|
45
47
|
|
|
46
48
|
abstract setup(dialog: Dialog): Promise<void>;
|
|
47
49
|
|
|
48
|
-
abstract onCreateBtnPress(event: Event): Promise<void
|
|
50
|
+
abstract onCreateBtnPress(event: Event): Promise<void> | void;
|
|
49
51
|
|
|
50
52
|
abstract buildDialogData(): Promise<void>;
|
|
51
53
|
|
|
@@ -54,7 +56,7 @@ export default abstract class BaseDialog extends Controller {
|
|
|
54
56
|
*
|
|
55
57
|
* @param event Event
|
|
56
58
|
*/
|
|
57
|
-
onFragmentNameInputChange(event: Event) {
|
|
59
|
+
onFragmentNameInputChange(event: Event): void {
|
|
58
60
|
const input = event.getSource<Input>();
|
|
59
61
|
const beginBtn = this.dialog.getBeginButton();
|
|
60
62
|
|
|
@@ -94,10 +96,42 @@ export default abstract class BaseDialog extends Controller {
|
|
|
94
96
|
return;
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
const changeExists = this.checkForExistingChange(fragmentName);
|
|
100
|
+
|
|
101
|
+
if (changeExists) {
|
|
102
|
+
updateDialogState(
|
|
103
|
+
ValueState.Error,
|
|
104
|
+
'Enter a different name. The fragment name entered matches the name of an unsaved fragment.'
|
|
105
|
+
);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
97
109
|
updateDialogState(ValueState.Success);
|
|
98
110
|
this.model.setProperty('/newFragmentName', fragmentName);
|
|
99
111
|
}
|
|
100
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Checks for the existence of a change associated with a specific fragment name in the RTA command stack.
|
|
115
|
+
*
|
|
116
|
+
* @param {string} fragmentName - The name of the fragment to check for existing changes.
|
|
117
|
+
* @returns {Promise<boolean>} A promise that resolves to `true` if a matching change is found, otherwise `false`.
|
|
118
|
+
*/
|
|
119
|
+
checkForExistingChange(fragmentName: string): boolean {
|
|
120
|
+
const allCommands = this.rta.getCommandStack().getCommands();
|
|
121
|
+
|
|
122
|
+
return allCommands.some((command: FlexCommand) => {
|
|
123
|
+
if (command?.getProperty('name') === 'composite') {
|
|
124
|
+
const addXmlCommand = command
|
|
125
|
+
.getCommands()
|
|
126
|
+
.find((c: FlexCommand) => c?.getProperty('name') === 'addXMLAtExtensionPoint');
|
|
127
|
+
|
|
128
|
+
return addXmlCommand && matchesFragmentName(addXmlCommand, fragmentName);
|
|
129
|
+
} else {
|
|
130
|
+
return matchesFragmentName(command, fragmentName);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
101
135
|
/**
|
|
102
136
|
* Sets custom function that fires when user presses escape key.
|
|
103
137
|
*/
|
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/JSONModel", "sap/ui/fl/Utils", "../api-handler", "./BaseDialog.controller"], function (MessageToast, sap_ui_core_library, JSONModel, Utils, ___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
|
-
/** sap.ui.core */
|
|
10
|
-
const ValueState = sap_ui_core_library["ValueState"];
|
|
11
|
-
/** sap.ui.base */
|
|
12
|
-
const getExistingController = ___api_handler["getExistingController"];
|
|
13
|
-
const getManifestAppdescr = ___api_handler["getManifestAppdescr"];
|
|
14
|
-
const readControllers = ___api_handler["readControllers"];
|
|
15
|
-
const writeChange = ___api_handler["writeChange"];
|
|
16
|
-
const writeController = ___api_handler["writeController"];
|
|
17
|
-
const BaseDialog = _interopRequireDefault(__BaseDialog);
|
|
18
|
-
/**
|
|
19
|
-
* @namespace open.ux.preview.client.adp.controllers
|
|
20
|
-
*/
|
|
21
|
-
const ControllerExtension = BaseDialog.extend("open.ux.preview.client.adp.controllers.ControllerExtension", {
|
|
22
|
-
constructor: function _constructor(name, overlays, rta) {
|
|
23
|
-
BaseDialog.prototype.constructor.call(this, name);
|
|
24
|
-
this.rta = rta;
|
|
25
|
-
this.overlays = overlays;
|
|
26
|
-
this.model = new JSONModel();
|
|
27
|
-
},
|
|
28
|
-
setup: async function _setup(dialog) {
|
|
29
|
-
this.dialog = dialog;
|
|
30
|
-
this.setEscapeHandler();
|
|
31
|
-
await this.buildDialogData();
|
|
32
|
-
this.dialog.setModel(this.model);
|
|
33
|
-
this.dialog.open();
|
|
34
|
-
},
|
|
35
|
-
onControllerNameInputChange: function _onControllerNameInputChange(event) {
|
|
36
|
-
const input = event.getSource();
|
|
37
|
-
const beginBtn = this.dialog.getBeginButton();
|
|
38
|
-
const controllerName = input.getValue();
|
|
39
|
-
const controllerList = this.model.getProperty('/controllersList');
|
|
40
|
-
const updateDialogState = function (valueState) {
|
|
41
|
-
let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
42
|
-
input.setValueState(valueState).setValueStateText(valueStateText);
|
|
43
|
-
beginBtn.setEnabled(valueState === ValueState.Success);
|
|
44
|
-
};
|
|
45
|
-
if (controllerName.length <= 0) {
|
|
46
|
-
updateDialogState(ValueState.None);
|
|
47
|
-
this.model.setProperty('/newControllerName', null);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const fileExists = controllerList.some(f => f.controllerName === `${controllerName}.js`);
|
|
51
|
-
if (fileExists) {
|
|
52
|
-
updateDialogState(ValueState.Error, 'Enter a different name. The controller name that you entered already exists in your project.');
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(controllerName);
|
|
56
|
-
if (!isValidName) {
|
|
57
|
-
updateDialogState(ValueState.Error, 'The controller name cannot contain white spaces or special characters.');
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (controllerName.length > 64) {
|
|
61
|
-
updateDialogState(ValueState.Error, 'A controller file name cannot contain more than 64 characters.');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
updateDialogState(ValueState.Success);
|
|
65
|
-
this.model.setProperty('/newControllerName', controllerName);
|
|
66
|
-
},
|
|
67
|
-
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
68
|
-
const source = event.getSource();
|
|
69
|
-
const controllerExists = this.model.getProperty('/controllerExists');
|
|
70
|
-
if (!controllerExists) {
|
|
71
|
-
source.setEnabled(false);
|
|
72
|
-
const controllerName = this.model.getProperty('/newControllerName');
|
|
73
|
-
const viewId = this.model.getProperty('/viewId');
|
|
74
|
-
await this.createNewController(controllerName, viewId);
|
|
75
|
-
} else {
|
|
76
|
-
const controllerPath = this.model.getProperty('/controllerPath');
|
|
77
|
-
window.open(`vscode://file${controllerPath}`);
|
|
78
|
-
}
|
|
79
|
-
this.handleDialogClose();
|
|
80
|
-
},
|
|
81
|
-
buildDialogData: async function _buildDialogData() {
|
|
82
|
-
const selectorId = this.overlays.getId();
|
|
83
|
-
const overlayControl = sap.ui.getCore().byId(selectorId);
|
|
84
|
-
const {
|
|
85
|
-
controllerName,
|
|
86
|
-
viewId
|
|
87
|
-
} = this.getControllerInfo(overlayControl);
|
|
88
|
-
const {
|
|
89
|
-
controllerExists,
|
|
90
|
-
controllerPath,
|
|
91
|
-
controllerPathFromRoot,
|
|
92
|
-
isRunningInBAS
|
|
93
|
-
} = await this.getExistingController(controllerName);
|
|
94
|
-
if (controllerExists) {
|
|
95
|
-
this.updateModelForExistingController(controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS);
|
|
96
|
-
} else {
|
|
97
|
-
this.updateModelForNewController(viewId);
|
|
98
|
-
await this.getControllers();
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
getControllerInfo: function _getControllerInfo(overlayControl) {
|
|
102
|
-
const control = overlayControl.getElement();
|
|
103
|
-
const view = Utils.getViewForControl(control);
|
|
104
|
-
const controllerName = view.getController().getMetadata().getName();
|
|
105
|
-
const viewId = view.getId();
|
|
106
|
-
return {
|
|
107
|
-
controllerName,
|
|
108
|
-
viewId
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
|
-
updateModelForExistingController: function _updateModelForExistingController(controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS) {
|
|
112
|
-
this.model.setProperty('/controllerExists', controllerExists);
|
|
113
|
-
this.model.setProperty('/controllerPath', controllerPath);
|
|
114
|
-
this.model.setProperty('/controllerPathFromRoot', controllerPathFromRoot);
|
|
115
|
-
const content = this.dialog.getContent();
|
|
116
|
-
const form = content[0];
|
|
117
|
-
form.setVisible(false);
|
|
118
|
-
const messageForm = content[1];
|
|
119
|
-
messageForm.setVisible(true);
|
|
120
|
-
if (isRunningInBAS) {
|
|
121
|
-
this.dialog.getBeginButton().setVisible(false);
|
|
122
|
-
} else {
|
|
123
|
-
this.dialog.getBeginButton().setText('Open in VS Code').setEnabled(true);
|
|
124
|
-
}
|
|
125
|
-
this.dialog.getEndButton().setText('Close');
|
|
126
|
-
},
|
|
127
|
-
updateModelForNewController: function _updateModelForNewController(viewId) {
|
|
128
|
-
this.model.setProperty('/viewId', viewId);
|
|
129
|
-
},
|
|
130
|
-
getExistingController: async function _getExistingController(controllerName) {
|
|
131
|
-
try {
|
|
132
|
-
const data = await getExistingController(controllerName);
|
|
133
|
-
return data;
|
|
134
|
-
} catch (e) {
|
|
135
|
-
MessageToast.show(e.message, {
|
|
136
|
-
duration: 5000
|
|
137
|
-
});
|
|
138
|
-
throw new Error(e.message);
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
getControllers: async function _getControllers() {
|
|
142
|
-
try {
|
|
143
|
-
const {
|
|
144
|
-
controllers
|
|
145
|
-
} = await readControllers();
|
|
146
|
-
this.model.setProperty('/controllersList', controllers);
|
|
147
|
-
} catch (e) {
|
|
148
|
-
MessageToast.show(e.message, {
|
|
149
|
-
duration: 5000
|
|
150
|
-
});
|
|
151
|
-
throw new Error(e.message);
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
createNewController: async function _createNewController(controllerName, viewId) {
|
|
155
|
-
try {
|
|
156
|
-
const manifest = await getManifestAppdescr();
|
|
157
|
-
await writeController({
|
|
158
|
-
controllerName,
|
|
159
|
-
projectId: manifest.id
|
|
160
|
-
});
|
|
161
|
-
const controllerRef = {
|
|
162
|
-
codeRef: `coding/${controllerName}.js`,
|
|
163
|
-
viewId
|
|
164
|
-
};
|
|
165
|
-
const service = await this.rta.getService('controllerExtension');
|
|
166
|
-
const change = await service.add(controllerRef.codeRef, controllerRef.viewId);
|
|
167
|
-
change.creation = new Date().toISOString();
|
|
168
|
-
await writeChange(change);
|
|
169
|
-
MessageToast.show(`Controller extension with name '${controllerName}' was created.`);
|
|
170
|
-
} catch (e) {
|
|
171
|
-
// We want to update the model incase we have already created a controller file but failed when creating a change file,
|
|
172
|
-
// so when the user types the same controller name again he does not get 409 from the server, instead an error is shown in the UI
|
|
173
|
-
await this.getControllers();
|
|
174
|
-
MessageToast.show(e.message);
|
|
175
|
-
throw new Error(e.message);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
return ControllerExtension;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
sap.ui.define(["sap/m/MessageToast", "sap/ui/core/library", "sap/ui/model/json/JSONModel", "sap/ui/fl/Utils", "../api-handler", "./BaseDialog.controller"], function (MessageToast, sap_ui_core_library, JSONModel, Utils, ___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
|
+
/** sap.ui.core */
|
|
10
|
+
const ValueState = sap_ui_core_library["ValueState"];
|
|
11
|
+
/** sap.ui.base */
|
|
12
|
+
const getExistingController = ___api_handler["getExistingController"];
|
|
13
|
+
const getManifestAppdescr = ___api_handler["getManifestAppdescr"];
|
|
14
|
+
const readControllers = ___api_handler["readControllers"];
|
|
15
|
+
const writeChange = ___api_handler["writeChange"];
|
|
16
|
+
const writeController = ___api_handler["writeController"];
|
|
17
|
+
const BaseDialog = _interopRequireDefault(__BaseDialog);
|
|
18
|
+
/**
|
|
19
|
+
* @namespace open.ux.preview.client.adp.controllers
|
|
20
|
+
*/
|
|
21
|
+
const ControllerExtension = BaseDialog.extend("open.ux.preview.client.adp.controllers.ControllerExtension", {
|
|
22
|
+
constructor: function _constructor(name, overlays, rta) {
|
|
23
|
+
BaseDialog.prototype.constructor.call(this, name);
|
|
24
|
+
this.rta = rta;
|
|
25
|
+
this.overlays = overlays;
|
|
26
|
+
this.model = new JSONModel();
|
|
27
|
+
},
|
|
28
|
+
setup: async function _setup(dialog) {
|
|
29
|
+
this.dialog = dialog;
|
|
30
|
+
this.setEscapeHandler();
|
|
31
|
+
await this.buildDialogData();
|
|
32
|
+
this.dialog.setModel(this.model);
|
|
33
|
+
this.dialog.open();
|
|
34
|
+
},
|
|
35
|
+
onControllerNameInputChange: function _onControllerNameInputChange(event) {
|
|
36
|
+
const input = event.getSource();
|
|
37
|
+
const beginBtn = this.dialog.getBeginButton();
|
|
38
|
+
const controllerName = input.getValue();
|
|
39
|
+
const controllerList = this.model.getProperty('/controllersList');
|
|
40
|
+
const updateDialogState = function (valueState) {
|
|
41
|
+
let valueStateText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
42
|
+
input.setValueState(valueState).setValueStateText(valueStateText);
|
|
43
|
+
beginBtn.setEnabled(valueState === ValueState.Success);
|
|
44
|
+
};
|
|
45
|
+
if (controllerName.length <= 0) {
|
|
46
|
+
updateDialogState(ValueState.None);
|
|
47
|
+
this.model.setProperty('/newControllerName', null);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const fileExists = controllerList.some(f => f.controllerName === `${controllerName}.js`);
|
|
51
|
+
if (fileExists) {
|
|
52
|
+
updateDialogState(ValueState.Error, 'Enter a different name. The controller name that you entered already exists in your project.');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const isValidName = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(controllerName);
|
|
56
|
+
if (!isValidName) {
|
|
57
|
+
updateDialogState(ValueState.Error, 'The controller name cannot contain white spaces or special characters.');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (controllerName.length > 64) {
|
|
61
|
+
updateDialogState(ValueState.Error, 'A controller file name cannot contain more than 64 characters.');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
updateDialogState(ValueState.Success);
|
|
65
|
+
this.model.setProperty('/newControllerName', controllerName);
|
|
66
|
+
},
|
|
67
|
+
onCreateBtnPress: async function _onCreateBtnPress(event) {
|
|
68
|
+
const source = event.getSource();
|
|
69
|
+
const controllerExists = this.model.getProperty('/controllerExists');
|
|
70
|
+
if (!controllerExists) {
|
|
71
|
+
source.setEnabled(false);
|
|
72
|
+
const controllerName = this.model.getProperty('/newControllerName');
|
|
73
|
+
const viewId = this.model.getProperty('/viewId');
|
|
74
|
+
await this.createNewController(controllerName, viewId);
|
|
75
|
+
} else {
|
|
76
|
+
const controllerPath = this.model.getProperty('/controllerPath');
|
|
77
|
+
window.open(`vscode://file${controllerPath}`);
|
|
78
|
+
}
|
|
79
|
+
this.handleDialogClose();
|
|
80
|
+
},
|
|
81
|
+
buildDialogData: async function _buildDialogData() {
|
|
82
|
+
const selectorId = this.overlays.getId();
|
|
83
|
+
const overlayControl = sap.ui.getCore().byId(selectorId);
|
|
84
|
+
const {
|
|
85
|
+
controllerName,
|
|
86
|
+
viewId
|
|
87
|
+
} = this.getControllerInfo(overlayControl);
|
|
88
|
+
const {
|
|
89
|
+
controllerExists,
|
|
90
|
+
controllerPath,
|
|
91
|
+
controllerPathFromRoot,
|
|
92
|
+
isRunningInBAS
|
|
93
|
+
} = await this.getExistingController(controllerName);
|
|
94
|
+
if (controllerExists) {
|
|
95
|
+
this.updateModelForExistingController(controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS);
|
|
96
|
+
} else {
|
|
97
|
+
this.updateModelForNewController(viewId);
|
|
98
|
+
await this.getControllers();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
getControllerInfo: function _getControllerInfo(overlayControl) {
|
|
102
|
+
const control = overlayControl.getElement();
|
|
103
|
+
const view = Utils.getViewForControl(control);
|
|
104
|
+
const controllerName = view.getController().getMetadata().getName();
|
|
105
|
+
const viewId = view.getId();
|
|
106
|
+
return {
|
|
107
|
+
controllerName,
|
|
108
|
+
viewId
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
updateModelForExistingController: function _updateModelForExistingController(controllerExists, controllerPath, controllerPathFromRoot, isRunningInBAS) {
|
|
112
|
+
this.model.setProperty('/controllerExists', controllerExists);
|
|
113
|
+
this.model.setProperty('/controllerPath', controllerPath);
|
|
114
|
+
this.model.setProperty('/controllerPathFromRoot', controllerPathFromRoot);
|
|
115
|
+
const content = this.dialog.getContent();
|
|
116
|
+
const form = content[0];
|
|
117
|
+
form.setVisible(false);
|
|
118
|
+
const messageForm = content[1];
|
|
119
|
+
messageForm.setVisible(true);
|
|
120
|
+
if (isRunningInBAS) {
|
|
121
|
+
this.dialog.getBeginButton().setVisible(false);
|
|
122
|
+
} else {
|
|
123
|
+
this.dialog.getBeginButton().setText('Open in VS Code').setEnabled(true);
|
|
124
|
+
}
|
|
125
|
+
this.dialog.getEndButton().setText('Close');
|
|
126
|
+
},
|
|
127
|
+
updateModelForNewController: function _updateModelForNewController(viewId) {
|
|
128
|
+
this.model.setProperty('/viewId', viewId);
|
|
129
|
+
},
|
|
130
|
+
getExistingController: async function _getExistingController(controllerName) {
|
|
131
|
+
try {
|
|
132
|
+
const data = await getExistingController(controllerName);
|
|
133
|
+
return data;
|
|
134
|
+
} catch (e) {
|
|
135
|
+
MessageToast.show(e.message, {
|
|
136
|
+
duration: 5000
|
|
137
|
+
});
|
|
138
|
+
throw new Error(e.message);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
getControllers: async function _getControllers() {
|
|
142
|
+
try {
|
|
143
|
+
const {
|
|
144
|
+
controllers
|
|
145
|
+
} = await readControllers();
|
|
146
|
+
this.model.setProperty('/controllersList', controllers);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
MessageToast.show(e.message, {
|
|
149
|
+
duration: 5000
|
|
150
|
+
});
|
|
151
|
+
throw new Error(e.message);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
createNewController: async function _createNewController(controllerName, viewId) {
|
|
155
|
+
try {
|
|
156
|
+
const manifest = await getManifestAppdescr();
|
|
157
|
+
await writeController({
|
|
158
|
+
controllerName,
|
|
159
|
+
projectId: manifest.id
|
|
160
|
+
});
|
|
161
|
+
const controllerRef = {
|
|
162
|
+
codeRef: `coding/${controllerName}.js`,
|
|
163
|
+
viewId
|
|
164
|
+
};
|
|
165
|
+
const service = await this.rta.getService('controllerExtension');
|
|
166
|
+
const change = await service.add(controllerRef.codeRef, controllerRef.viewId);
|
|
167
|
+
change.creation = new Date().toISOString();
|
|
168
|
+
await writeChange(change);
|
|
169
|
+
MessageToast.show(`Controller extension with name '${controllerName}' was created.`);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
// We want to update the model incase we have already created a controller file but failed when creating a change file,
|
|
172
|
+
// so when the user types the same controller name again he does not get 409 from the server, instead an error is shown in the UI
|
|
173
|
+
await this.getControllers();
|
|
174
|
+
MessageToast.show(e.message);
|
|
175
|
+
throw new Error(e.message);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return ControllerExtension;
|
|
180
180
|
});
|
|
181
181
|
//# sourceMappingURL=ControllerExtension.controller.js.map
|