Skip to content

Commit 07ed1a0

Browse files
committed
Merge branch 'disable-nav-model-hide-go-items' into 'main'
Update nav menu and app menu based on project configuration See merge request weblogic-cloud/weblogic-toolkit-ui!257
2 parents fbf1f4a + 8759672 commit 07ed1a0

File tree

12 files changed

+117
-88
lines changed

12 files changed

+117
-88
lines changed

electron/app/js/ipcRendererPreload.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ contextBridge.exposeInMainWorld(
3737
'open-project',
3838
'window-app-quit',
3939
'window-is-ready',
40-
'set-has-open-dialog',
4140
'set-divider-location',
4241
'set-navigation-collapsed',
43-
'set-target-type',
42+
'set-window-attribute',
4443
'skip-quickstart-at-startup',
4544
'log-remote-message'
4645
];

electron/app/js/wktWindow.js

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
const { app, BrowserWindow, dialog, Menu, shell } = require('electron');
@@ -33,19 +33,34 @@ function initialize(isJetDevMode, wktApp, wktMode) {
3333
}
3434

3535
class WktAppMenu {
36-
constructor(hasOpenDialog, targetType) {
36+
constructor(window) {
37+
this._wktApp = _wktApp;
38+
3739
// hasOpenDialog: the focused window has a dialog displayed
38-
// targetType: the target type for the window, such as 'wko', 'vz'
40+
this._hasOpenDialog = getWindowStatus(window, 'hasOpenDialog');
3941

40-
this._isJetDevMode = _isJetDevMode;
41-
this._wktApp = _wktApp;
42-
this._hasOpenDialog = hasOpenDialog;
42+
// targetType: the target type for the window, such as 'wko', 'vz'
43+
const targetType = getWindowStatus(window, 'targetType');
4344
this._isWkoTarget = targetType === 'wko';
45+
46+
// domain location: mii, pv, etc.
47+
const domainLocation = getWindowStatus(window, 'domainLocation');
48+
this._auxImageKey = (domainLocation === 'pv') ? 'domain-creation' : 'aux';
49+
50+
// does project use a model, based on domain type and configuration
51+
this._usesModel = getWindowStatus(window, 'usesModel');
52+
53+
// is the project creating primary or aux images
54+
this._isCreatingPrimaryImage = getWindowStatus(window, 'isCreatingPrimaryImage');
55+
this._isCreatingAuxImage = getWindowStatus(window, 'isCreatingAuxImage');
56+
4457
this.appMenuTemplate = this._generateAppMenuTemplate();
4558
}
4659

4760
_generateAppMenuTemplate() {
4861
const project = require('./project');
62+
const auxImageKey = this._auxImageKey;
63+
4964
const appMenuTemplate = [
5065
{
5166
id: 'file',
@@ -244,6 +259,7 @@ class WktAppMenu {
244259
{
245260
id: 'validateModel',
246261
label: i18n.t('menu-go-validate-model'),
262+
visible: this._usesModel,
247263
enabled: !this._hasOpenDialog,
248264
click(item, focusedWindow) {
249265
if (!focusedWindow) {
@@ -258,6 +274,7 @@ class WktAppMenu {
258274
{
259275
id: 'prepareModel',
260276
label: i18n.t('menu-go-prepare-model-for-k8s'),
277+
visible: this._usesModel,
261278
enabled: !this._hasOpenDialog,
262279
click(item, focusedWindow) {
263280
if (!focusedWindow) {
@@ -272,6 +289,7 @@ class WktAppMenu {
272289
{
273290
id: 'createImage',
274291
label: i18n.t('menu-go-create-image'),
292+
visible: this._isCreatingPrimaryImage,
275293
enabled: !this._hasOpenDialog,
276294
click(item, focusedWindow) {
277295
if (!focusedWindow) {
@@ -286,6 +304,7 @@ class WktAppMenu {
286304
{
287305
id: 'pushImage',
288306
label: i18n.t('menu-go-push-image'),
307+
visible: this._isCreatingPrimaryImage,
289308
enabled: !this._hasOpenDialog,
290309
click(item, focusedWindow) {
291310
if (!focusedWindow) {
@@ -299,27 +318,29 @@ class WktAppMenu {
299318
},
300319
{
301320
id: 'createAuxImage',
302-
label: i18n.t('menu-go-create-aux-image'),
321+
label: i18n.t(`menu-go-create-${auxImageKey}-image`),
322+
visible: this._isCreatingAuxImage,
303323
enabled: !this._hasOpenDialog,
304324
click(item, focusedWindow) {
305325
if (!focusedWindow) {
306326
return dialog.showErrorBox(
307-
i18n.t('menu-go-create-aux-image-error-title'),
308-
i18n.t('menu-go-create-aux-image-error-message')
327+
i18n.t(`menu-go-create-${auxImageKey}-image-error-title`),
328+
i18n.t(`menu-go-create-${auxImageKey}-image-error-message`)
309329
);
310330
}
311331
sendToWindow(focusedWindow,'start-create-aux-image');
312332
}
313333
},
314334
{
315335
id: 'pushAuxImage',
316-
label: i18n.t('menu-go-push-aux-image'),
336+
label: i18n.t(`menu-go-push-${auxImageKey}-image`),
337+
visible: this._isCreatingAuxImage,
317338
enabled: !this._hasOpenDialog,
318339
click(item, focusedWindow) {
319340
if (!focusedWindow) {
320341
return dialog.showErrorBox(
321-
i18n.t('menu-go-push-aux-image-error-title'),
322-
i18n.t('menu-go-push-aux-image-error-message')
342+
i18n.t(`menu-go-push-${auxImageKey}-image-error-title`),
343+
i18n.t(`menu-go-push-${auxImageKey}-image-error-message`)
323344
);
324345
}
325346
sendToWindow(focusedWindow,'start-push-aux-image');
@@ -1051,15 +1072,8 @@ function setWindowStatus(window, key, status) {
10511072
}
10521073
}
10531074

1054-
function setHasOpenDialog(window, value) {
1055-
setWindowStatus(window, 'hasOpenDialog', value);
1056-
if(window.isFocused()) {
1057-
createApplicationMenu(window);
1058-
}
1059-
}
1060-
1061-
function setTargetType(window, targetType) {
1062-
setWindowStatus(window, 'targetType', targetType);
1075+
function setWindowAttribute(window, key, value) {
1076+
setWindowStatus(window, key, value);
10631077
if(window.isFocused()) {
10641078
createApplicationMenu(window);
10651079
}
@@ -1156,9 +1170,7 @@ function createApplicationMenu(newWindow) {
11561170
return Menu.setApplicationMenu(null);
11571171
}
11581172

1159-
const hasOpenDialog = getWindowStatus(newWindow, 'hasOpenDialog');
1160-
const targetType = getWindowStatus(newWindow, 'targetType');
1161-
const appMenuTemplate = new WktAppMenu(hasOpenDialog, targetType).appMenuTemplate;
1173+
const appMenuTemplate = new WktAppMenu(newWindow).appMenuTemplate;
11621174
let menu = Menu.buildFromTemplate(appMenuTemplate);
11631175

11641176
// blur the focused item in the renderer when a top-level menu item is opened.
@@ -1259,8 +1271,7 @@ module.exports = {
12591271
initialize,
12601272
isSingleWindow,
12611273
setTitleFileName,
1262-
setHasOpenDialog,
1263-
setTargetType,
1274+
setWindowAttribute,
12641275
showErrorMessage,
12651276
promptUserForOkOrCancelAnswer,
12661277
promptUserForYesOrNoAnswer,

electron/app/locales/en/electron.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@
4545
"menu-go-create-aux-image": "Create Auxiliary Image",
4646
"menu-go-create-aux-image-error-title": "No Active Project Window",
4747
"menu-go-create-aux-image-error-message": "Cannot run Create Auxiliary Image since there is no active window, and therefore no project with an image to create.",
48+
"menu-go-create-domain-creation-image": "Create Domain Creation Image",
49+
"menu-go-create-domain-creation-image-error-title": "No Active Project Window",
50+
"menu-go-create-domain-creation-image-error-message": "Cannot run Create Domain Creation Image since there is no active window, and therefore no project with an image to create.",
4851
"menu-go-push-aux-image": "Push Auxiliary Image to Registry",
4952
"menu-go-push-aux-image-error-title": "No Active Project Window",
50-
"menu-go-push-aux-image-error-message": "Cannot push primary image since there is no active window, and therefore no project with an image to push.",
53+
"menu-go-push-aux-image-error-message": "Cannot push auxiliary image since there is no active window, and therefore no project with an image to push.",
54+
"menu-go-push-domain-creation-image": "Push Domain Creation Image to Registry",
55+
"menu-go-push-domain-creation-image-error-title": "No Active Project Window",
56+
"menu-go-push-domain-creation-image-error-message": "Cannot push domain creation image since there is no active window, and therefore no project with an image to push.",
5157
"menu-go-kubectl-verify-connectivity": "Verify Kubernetes Client Connection",
5258
"menu-go-kubectl-verify-connectivity-error-title": "No Active Project Window",
5359
"menu-go-kubectl-verify-connectivity-error-message": "Cannot verify Kubernetes client connectivity since there is no active window, and therefore no project with a Kubernetes configuration to verify.",

electron/app/main.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const WktApp = require('./js/wktApp');
1313
const i18n = require('./js/i18next.config');
1414
const { initializeLoggingSystem, logRendererMessage } = require('./js/wktLogging');
1515
const userSettings = require('./js/userSettings');
16-
const { chooseFromFileSystem, createNetworkWindow, createWindow, initialize, setHasOpenDialog, setTargetType,
16+
const { chooseFromFileSystem, createNetworkWindow, createWindow, initialize, setWindowAttribute,
1717
showErrorMessage, promptUserForOkOrCancelAnswer, promptUserForYesOrNoAnswer, promptUserForYesNoOrCancelAnswer } =
1818
require('./js/wktWindow');
1919
const project = require('./js/project');
@@ -300,11 +300,6 @@ class Main {
300300
userSettings.setSkipQuickstartAtStartup(true);
301301
});
302302

303-
ipcMain.on('set-has-open-dialog', (event, hasOpenDialogs) => {
304-
const window = event.sender.getOwnerBrowserWindow();
305-
return setHasOpenDialog(window, hasOpenDialogs);
306-
});
307-
308303
ipcMain.on('set-divider-location', (event, name, percent) => {
309304
return userSettings.setDividerLocation(name, percent);
310305
});
@@ -313,9 +308,9 @@ class Main {
313308
return userSettings.setNavigationCollapsed(collapsed);
314309
});
315310

316-
ipcMain.on('set-target-type', (event, targetType) => {
311+
ipcMain.on('set-window-attribute', (event, key, value) => {
317312
const window = event.sender.getOwnerBrowserWindow();
318-
return setTargetType(window, targetType);
313+
return setWindowAttribute(window, key, value);
319314
});
320315

321316
ipcMain.on('log-remote-message', (event, logLevel, logMessage, ...logArgs) => {

webui/src/js/models/project-settings-definition.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
'use strict';
@@ -18,11 +18,6 @@ define(['utils/observable-properties'],
1818
this.targetDomainLocation = props.createProperty('mii');
1919
this.wdtTargetType = props.createProperty('wko');
2020

21-
window.api.ipc.send('set-target-type', this.wdtTargetType.value);
22-
this.wdtTargetType.observable.subscribe(targetType => {
23-
window.api.ipc.send('set-target-type', targetType);
24-
});
25-
2621
this.javaHome = props.createProperty(window.api.ipc.invoke('get-java-home'));
2722
this.oracleHome = props.createProperty(window.api.ipc.invoke('get-oracle-home'));
2823

webui/src/js/models/wkt-project.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ function (ko, wdtConstructor, imageConstructor, kubectlConstructor, domainConstr
212212
return projectContents;
213213
};
214214

215+
// synchronize some attributes with electron window to disable/hide menu items on change
216+
this.synchronizeWithWindow = (attribute_key, observable) => {
217+
window.api.ipc.send('set-window-attribute', attribute_key, observable());
218+
observable.subscribe(value => {
219+
window.api.ipc.send('set-window-attribute', attribute_key, value);
220+
});
221+
};
222+
223+
this.synchronizeWithWindow('domainLocation', this.settings.targetDomainLocation.observable);
224+
this.synchronizeWithWindow('targetType', this.settings.wdtTargetType.observable);
225+
this.synchronizeWithWindow('isCreatingPrimaryImage', this.image.createPrimaryImage.observable);
226+
215227
// return true if the project has unsaved changes.
216228
this.isDirty = () => {
217229
return this.pages.some(p => p.isChanged());

webui/src/js/utils/aux-image-helper.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,41 @@
77

88
define(['models/wkt-project'],
99
function(project) {
10-
class AuxImageHelper {
11-
constructor() {
12-
this.project = project;
13-
}
10+
function AuxImageHelper() {
1411

15-
supportsDomainCreationImages() {
16-
return this.project.settings.targetDomainLocation.value === 'pv' && this.wkoVersion41OrHigher();
17-
}
12+
this.supportsDomainCreationImages = () => {
13+
return project.settings.targetDomainLocation.value === 'pv' && this.wkoVersion41OrHigher();
14+
};
1815

19-
wkoVersion41OrHigher() {
16+
this.wkoVersion41OrHigher = () => {
2017
// If the actual installed version is not known, assume true.
2118
let result = true;
22-
if (this.project.wko.installedVersion.hasValue() &&
23-
window.api.utils.compareVersions(this.project.wko.installedVersion.value, '4.1.0') < 0) {
19+
if (project.wko.installedVersion.hasValue() &&
20+
window.api.utils.compareVersions(project.wko.installedVersion.value, '4.1.0') < 0) {
2421
result = false;
2522
}
2623
return result;
27-
}
24+
};
2825

29-
domainUsesJRF() {
30-
return this.project.image.useAuxImage.value && this.project.k8sDomain.domainType.value !== 'WLS' &&
31-
this.project.k8sDomain.domainType.value !== 'RestrictedJRF';
32-
}
26+
this.domainUsesJRF = () => {
27+
return project.image.useAuxImage.value && project.k8sDomain.domainType.value !== 'WLS' &&
28+
project.k8sDomain.domainType.value !== 'RestrictedJRF';
29+
};
30+
31+
this.projectUsesModel = () => {
32+
if (project.settings.targetDomainLocation.observable() === 'pv') {
33+
return this.supportsDomainCreationImages() && project.image.useAuxImage.observable();
34+
}
35+
return true;
36+
};
37+
38+
this.isCreatingAuxImage = () => {
39+
if (project.settings.targetDomainLocation.observable() === 'mii' ||
40+
this.supportsDomainCreationImages()) {
41+
return project.image.useAuxImage.observable() && project.image.createAuxImage.observable();
42+
}
43+
return false;
44+
};
3345
}
3446

3547
return new AuxImageHelper();

webui/src/js/utils/view-helper.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ define(['ojs/ojcontext'],
8282
};
8383

8484
this.initializeDialog = (dialog) => {
85-
window.api.ipc.send('set-has-open-dialog', dialog.isOpen());
85+
this.updateDialogStatus(dialog.isOpen());
8686
thisHelper.componentReady(dialog).then(() => {
8787
// notify when the dialog is open or closed
88-
dialog.addEventListener('ojBeforeOpen', () => {
89-
window.api.ipc.send('set-has-open-dialog', true);
90-
});
91-
dialog.addEventListener('ojBeforeClose', () => {
92-
window.api.ipc.send('set-has-open-dialog', false);
93-
});
88+
dialog.addEventListener('ojBeforeOpen', () => this.updateDialogStatus(true));
89+
dialog.addEventListener('ojBeforeClose', () => this.updateDialogStatus(false));
9490
});
9591
};
9692

93+
this.updateDialogStatus = (isOpen) => {
94+
window.api.ipc.send('set-window-attribute', 'hasOpenDialog', isOpen);
95+
};
96+
9797
function compareValues(a, b) {
9898
a = a ? a.toString() : '';
9999
b = b ? b.toString() : '';

webui/src/js/viewModels/app-main.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
55
*/
66
'use strict';
77

88
define(['accUtils', 'knockout', 'utils/i18n', 'models/wkt-project', 'models/wkt-console', 'utils/dialog-helper',
9-
'utils/view-helper', 'utils/screen-utils', 'ojs/ojarraydataprovider', 'ojs/ojarraytreedataprovider', 'ojs/ojcorerouter',
10-
'ojs/ojmodule-element-utils', 'ojs/ojmodulerouter-adapter', 'ojs/ojknockoutrouteradapter', 'ojs/ojurlparamadapter',
11-
'ojs/ojoffcanvas', 'ojs/ojknockouttemplateutils', 'ojs/ojresponsiveutils', 'ojs/ojresponsiveknockoututils',
12-
'utils/wkt-logger', 'ojs/ojknockout', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog',
13-
'ojs/ojformlayout', 'ojs/ojselectsingle', 'ojs/ojvalidationgroup', 'ojs/ojcollapsible'],
14-
function(accUtils, ko, i18n, project, wktConsole, dialogHelper, viewHelper, screenUtils, ArrayDataProvider,
9+
'utils/view-helper', 'utils/screen-utils', 'utils/aux-image-helper', 'ojs/ojarraydataprovider',
10+
'ojs/ojarraytreedataprovider', 'ojs/ojcorerouter', 'ojs/ojmodule-element-utils', 'ojs/ojmodulerouter-adapter',
11+
'ojs/ojknockoutrouteradapter', 'ojs/ojurlparamadapter', 'ojs/ojoffcanvas', 'ojs/ojknockouttemplateutils',
12+
'ojs/ojresponsiveutils', 'ojs/ojresponsiveknockoututils', 'utils/wkt-logger', 'ojs/ojknockout', 'ojs/ojinputtext',
13+
'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout', 'ojs/ojselectsingle', 'ojs/ojvalidationgroup',
14+
'ojs/ojcollapsible'],
15+
function(accUtils, ko, i18n, project, wktConsole,
16+
dialogHelper, viewHelper, screenUtils, auxImageHelper, ArrayDataProvider,
1517
ArrayTreeDataProvider, CoreRouter, ModuleElementUtils, ModuleRouterAdapter, KnockoutRouterAdapter, UrlParamAdapter,
1618
OffCanvasUtils, KnockoutTemplateUtils, ResponsiveUtils, ResponsiveKnockoutUtils, wktLogger) {
1719

@@ -23,7 +25,7 @@ function(accUtils, ko, i18n, project, wktConsole, dialogHelper, viewHelper, scre
2325
accUtils.announce('Application main loaded.', 'assertive');
2426

2527
// in case of page reload, clear dialog status in electron
26-
window.api.ipc.send('set-has-open-dialog', false);
28+
viewHelper.updateDialogStatus(false);
2729

2830
// listen for components that need special handling
2931
viewHelper.listenForComponents('wktMainPane');
@@ -151,7 +153,10 @@ function(accUtils, ko, i18n, project, wktConsole, dialogHelper, viewHelper, scre
151153
},
152154
{ name: this.labelMapper('model'),
153155
id: 'model-page',
154-
icon: 'oj-ux-ico-model-change-mgmt'
156+
icon: 'oj-ux-ico-model-change-mgmt',
157+
disabled: ko.computed(() => {
158+
return !auxImageHelper.projectUsesModel();
159+
})
155160
},
156161
{ name: this.labelMapper('image'),
157162
id: 'image-page',
@@ -276,6 +281,11 @@ function(accUtils, ko, i18n, project, wktConsole, dialogHelper, viewHelper, scre
276281
this.updateDialog(dialogHelper.showDialog());
277282
}
278283
});
284+
285+
// synchronize calculated values with electron window to disable/hide menu items on change
286+
287+
project.synchronizeWithWindow('usesModel', ko.computed(auxImageHelper.projectUsesModel));
288+
project.synchronizeWithWindow('isCreatingAuxImage', ko.computed(auxImageHelper.isCreatingAuxImage));
279289
}
280290

281291
/*

0 commit comments

Comments
 (0)