|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright (c) 2021, Oracle and/or its affiliates. |
| 4 | + * Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/ |
| 5 | + */ |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +define(['accUtils', 'knockout', 'utils/i18n', 'utils/view-helper', 'ojs/ojarraydataprovider', 'ojs/ojknockout', |
| 9 | + 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout' ], |
| 10 | +function(accUtils, ko, i18n, viewHelper) { |
| 11 | + function InspectDialogModel(config) { |
| 12 | + const DIALOG_SELECTOR = '#wktInspectDialog'; |
| 13 | + |
| 14 | + this.connected = () => { |
| 15 | + accUtils.announce('Validation Error dialog loaded.', 'assertive'); |
| 16 | + |
| 17 | + this.dialogContainer = $(DIALOG_SELECTOR)[0]; |
| 18 | + |
| 19 | + // open the dialog when the container is ready. |
| 20 | + // using oj-dialog initial-visibility="show" causes vertical centering issues. |
| 21 | + viewHelper.componentReady(this.dialogContainer).then(() => { |
| 22 | + this.dialogContainer.open(); |
| 23 | + }); |
| 24 | + }; |
| 25 | + |
| 26 | + this.labelMapper = (labelId, payload) => { |
| 27 | + return i18n.t(`inspect-dialog-${labelId}`, payload); |
| 28 | + }; |
| 29 | + |
| 30 | + this.i18n = i18n; |
| 31 | + this.config = config; |
| 32 | + this.contents = config.contents; |
| 33 | + |
| 34 | + this.getTitle = () => { |
| 35 | + return this.config.title || this.labelMapper('default-title'); |
| 36 | + }; |
| 37 | + |
| 38 | + this.getMessage = () => { |
| 39 | + return this.config.message || this.labelMapper('default-message'); |
| 40 | + }; |
| 41 | + |
| 42 | + this.hasOsInfo = () => { |
| 43 | + return !!this.contents.os && !!this.contents.os.name && !!this.contents.os.version; |
| 44 | + }; |
| 45 | + |
| 46 | + this.getOsName = () => { |
| 47 | + return this.contents.os.name; |
| 48 | + }; |
| 49 | + |
| 50 | + this.getOsVersion = () => { |
| 51 | + return this.contents.os.version; |
| 52 | + }; |
| 53 | + |
| 54 | + this.hasJavaHome = () => { |
| 55 | + return !!this.contents.javaHome; |
| 56 | + }; |
| 57 | + |
| 58 | + this.getJavaHome = () => { |
| 59 | + return this.contents.javaHome; |
| 60 | + }; |
| 61 | + |
| 62 | + this.getJavaVersion = () => { |
| 63 | + return this.contents.javaVersion; |
| 64 | + }; |
| 65 | + |
| 66 | + this.hasOracleHome = () => { |
| 67 | + return !!this.contents.oracleHome; |
| 68 | + }; |
| 69 | + |
| 70 | + this.getOracleHome = () => { |
| 71 | + return this.contents.oracleHome; |
| 72 | + }; |
| 73 | + |
| 74 | + this.getWlsVersion = () => { |
| 75 | + return this.contents.wlsVersion; |
| 76 | + }; |
| 77 | + |
| 78 | + this.getOpatchVersion = () => { |
| 79 | + return this.contents.opatchVersion; |
| 80 | + }; |
| 81 | + |
| 82 | + this.hasOraclePatches = () => { |
| 83 | + return !!this.contents.oraclePatches && this.contents.oraclePatches.length > 0; |
| 84 | + }; |
| 85 | + |
| 86 | + this.patches = { }; |
| 87 | + |
| 88 | + this.buildPatchesData = () => { |
| 89 | + const namedPatches = [ ]; |
| 90 | + const oneOffPatches = [ ]; |
| 91 | + |
| 92 | + if (this.hasOraclePatches()) { |
| 93 | + this.contents.oraclePatches.forEach(patch => { |
| 94 | + if (patch.description.toLowerCase() === 'one-off') { |
| 95 | + oneOffPatches.push({ number: patch.patch }); |
| 96 | + } else { |
| 97 | + namedPatches.push({ name: patch.description, number: patch.patch }); |
| 98 | + } |
| 99 | + }); |
| 100 | + if (namedPatches.length > 0) { |
| 101 | + this.patches['namedPatches'] = namedPatches; |
| 102 | + } |
| 103 | + if (oneOffPatches.length > 0) { |
| 104 | + this.patches['oneOffPatches'] = oneOffPatches; |
| 105 | + } |
| 106 | + } |
| 107 | + }; |
| 108 | + |
| 109 | + this.hasNamedPatches = () => { |
| 110 | + return !!this.patches.namedPatches; |
| 111 | + }; |
| 112 | + |
| 113 | + this.hasOneOffPatches = () => { |
| 114 | + return !!this.patches.oneOffPatches; |
| 115 | + }; |
| 116 | + |
| 117 | + this.getNamedPatches = () => { |
| 118 | + return this.patches.namedPatches; |
| 119 | + }; |
| 120 | + |
| 121 | + this.getOneOffPatches = () => { |
| 122 | + return this.patches.oneOffPatches; |
| 123 | + }; |
| 124 | + |
| 125 | + this.dismissDialog = () => { |
| 126 | + const dialog = this.dialogContainer; |
| 127 | + if (dialog) { |
| 128 | + dialog.close(); |
| 129 | + } |
| 130 | + }; |
| 131 | + |
| 132 | + this.buildPatchesData(); |
| 133 | + } |
| 134 | + |
| 135 | + return InspectDialogModel; |
| 136 | +}); |
0 commit comments