|
6 | 6 |
|
7 | 7 | define(['utils/i18n', 'accUtils', 'knockout', 'ojs/ojarraydataprovider',
|
8 | 8 | 'ojs/ojbufferingdataprovider', 'models/wkt-project', 'utils/dialog-helper',
|
9 |
| - 'utils/ingress-routes-updater', 'utils/view-helper', 'ojs/ojtreeview', |
| 9 | + 'utils/ingress-routes-updater', 'utils/view-helper', 'utils/k8s-helper', 'ojs/ojtreeview', |
10 | 10 | 'ojs/ojformlayout', 'ojs/ojinputtext', 'ojs/ojcollapsible', 'ojs/ojselectsingle', 'ojs/ojswitch', 'ojs/ojtable',
|
11 | 11 | 'ojs/ojcheckboxset'
|
12 | 12 | ],
|
13 | 13 | function(i18n, accUtils, ko, ArrayDataProvider, BufferingDataProvider, project, dialogHelper,
|
14 |
| - ingressRouteUpdater, viewHelper) { |
| 14 | + ingressRouteUpdater, viewHelper, k8sHelper) { |
15 | 15 |
|
16 | 16 | function IngressDesignViewModel() {
|
17 | 17 |
|
@@ -209,31 +209,58 @@ function(i18n, accUtils, ko, ArrayDataProvider, BufferingDataProvider, project,
|
209 | 209 | window.api.ipc.invoke('show-error-message', title, message);
|
210 | 210 | };
|
211 | 211 |
|
212 |
| - this.handleEditRoute = (event, context) => { |
| 212 | + async function getTargetServiceDetails (project) { |
| 213 | + |
| 214 | + const kubectlExe = k8sHelper.getKubectlExe(); |
| 215 | + const kubectlOptions = k8sHelper.getKubectlOptions(); |
| 216 | + const results = await window.api.ipc.invoke('k8s-get-service-details', |
| 217 | + kubectlExe, project.k8sDomain.kubernetesNamespace.value, '', kubectlOptions); |
| 218 | + let serviceLists = {}; |
| 219 | + if (results.isSuccess) { |
| 220 | + for (const item of results.serviceDetails.items) { |
| 221 | + serviceLists[item.metadata.name] = { ports: item.spec.ports}; |
| 222 | + } |
| 223 | + } else { |
| 224 | + const errTitle = i18n.t('ingress-design-ingress-routes-getting-target-service-title'); |
| 225 | + const errMessage = i18n.t('ingress-design-ingress-routes-getting-target-service-error-message', { |
| 226 | + error: results.reason, |
| 227 | + namespace: namespace |
| 228 | + }); |
| 229 | + await window.api.ipc.invoke('show-error-message', errTitle, errMessage); |
| 230 | + return Promise.resolve(false); |
| 231 | + } |
| 232 | + return Promise.resolve( { serviceList: serviceLists}); |
| 233 | + }; |
| 234 | + |
| 235 | + this.handleEditRoute = async (event, context) => { |
213 | 236 | // using context.item.data directly was causing problems
|
214 | 237 | // when project data was reloaded with matching UIDs.
|
215 | 238 | const index = context.item.index;
|
216 | 239 | let route = this.routes.observable()[index];
|
217 |
| - const options = {route: route}; |
218 |
| - |
219 |
| - dialogHelper.promptDialog('route-edit-dialog', options) |
220 |
| - .then(result => { |
221 |
| - |
222 |
| - // no result indicates operation was cancelled |
223 |
| - if (result) { |
224 |
| - let changed = false; |
225 |
| - project.ingress.ingressRouteKeys.forEach(key => { |
226 |
| - if ((key !== 'uid') && result.hasOwnProperty(key)) { |
227 |
| - route[key] = result[key]; |
228 |
| - changed = true; |
| 240 | + getTargetServiceDetails(this.project).then( svc => { |
| 241 | + const options = {route: route, serviceList: svc.serviceList}; |
| 242 | + dialogHelper.promptDialog('route-edit-dialog', options) |
| 243 | + .then(result => { |
| 244 | + |
| 245 | + // no result indicates operation was cancelled |
| 246 | + if (result) { |
| 247 | + let changed = false; |
| 248 | + project.ingress.ingressRouteKeys.forEach(key => { |
| 249 | + if ((key !== 'uid') && result.hasOwnProperty(key)) { |
| 250 | + route[key] = result[key]; |
| 251 | + changed = true; |
| 252 | + } |
| 253 | + }); |
| 254 | + |
| 255 | + if (changed) { |
| 256 | + this.routes.observable.replace(route, route); |
229 | 257 | }
|
230 |
| - }); |
231 |
| - |
232 |
| - if (changed) { |
233 |
| - this.routes.observable.replace(route, route); |
234 | 258 | }
|
235 |
| - } |
236 |
| - }); |
| 259 | + }); |
| 260 | + } |
| 261 | + ); |
| 262 | + |
| 263 | + |
237 | 264 | };
|
238 | 265 |
|
239 | 266 | this.handleCancel = () => {
|
|
0 commit comments