talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | import {itemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js'; |
| 2 | import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 3 | import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js'; |
| 4 | import {actionTypes as SoftwareProductActionTypes} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; |
| 5 | import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js'; |
| 6 | import versionPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js'; |
| 7 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 8 | import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js'; |
| 9 | |
| 10 | const ScreensHelper = { |
| 11 | loadScreen(dispatch, {screen, screenType, props}) { |
| 12 | if(screen === enums.SCREEN.ONBOARDING_CATALOG) { |
| 13 | OnboardingActionHelper.navigateToOnboardingCatalog(dispatch); |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | screenType = !screenType ? this.getScreenType(screen) : screenType; |
| 18 | |
| 19 | if(screenType === screenTypes.LICENSE_MODEL) { |
| 20 | const {licenseModelId, version, licenseModel, usersList} = props; |
| 21 | let itemStatusPromise = version && screen ? |
| 22 | ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id}) : |
| 23 | Promise.resolve(); |
| 24 | itemStatusPromise.then((updatedVersion) => { |
| 25 | if (updatedVersion && updatedVersion.status !== version.status) { |
| 26 | dispatch({ |
| 27 | type: modalActionTypes.GLOBAL_MODAL_WARNING, |
| 28 | data: { |
| 29 | title: i18n('Commit error'), |
| 30 | msg: i18n('Item version was certified by Owner'), |
| 31 | cancelButtonText: i18n('Cancel') |
| 32 | } |
| 33 | }); |
| 34 | versionPageActionHelper.fetchVersions(dispatch, {itemType: itemTypes.LICENSE_MODEL, itemId: licenseModelId}); |
| 35 | } |
| 36 | let newVersion = updatedVersion ? updatedVersion : version; |
| 37 | switch (screen) { |
| 38 | case enums.SCREEN.LICENSE_MODEL_OVERVIEW: |
| 39 | OnboardingActionHelper.navigateToLicenseModelOverview(dispatch, {licenseModelId, version: newVersion}); |
| 40 | break; |
| 41 | case enums.SCREEN.LICENSE_AGREEMENTS: |
| 42 | OnboardingActionHelper.navigateToLicenseAgreements(dispatch, {licenseModelId, version: newVersion}); |
| 43 | break; |
| 44 | case enums.SCREEN.FEATURE_GROUPS: |
| 45 | OnboardingActionHelper.navigateToFeatureGroups(dispatch, {licenseModelId, version: newVersion}); |
| 46 | break; |
| 47 | case enums.SCREEN.ENTITLEMENT_POOLS: |
| 48 | OnboardingActionHelper.navigateToEntitlementPools(dispatch, {licenseModelId, version: newVersion}); |
| 49 | break; |
| 50 | case enums.SCREEN.LICENSE_KEY_GROUPS: |
| 51 | OnboardingActionHelper.navigateToLicenseKeyGroups(dispatch, {licenseModelId, version: newVersion}); |
| 52 | break; |
| 53 | case enums.SCREEN.ACTIVITY_LOG: |
| 54 | OnboardingActionHelper.navigateToLicenseModelActivityLog(dispatch, {licenseModelId, version: newVersion}); |
| 55 | break; |
| 56 | case enums.SCREEN.VERSIONS_PAGE: |
| 57 | default: |
| 58 | OnboardingActionHelper.navigateToVersionsPage(dispatch, { |
| 59 | itemId: licenseModelId, |
| 60 | itemType: itemTypes.LICENSE_MODEL, |
| 61 | itemName: licenseModel.name, |
| 62 | users: usersList |
| 63 | }); |
| 64 | break; |
| 65 | } |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | else if(screenType === screenTypes.SOFTWARE_PRODUCT) { |
| 70 | const {softwareProductId, componentId, version, softwareProduct, usersList} = props; |
| 71 | let itemStatusPromise = version && screen ? |
| 72 | ItemsHelper.checkItemStatus(dispatch, {itemId: softwareProductId, versionId: version.id}) : |
| 73 | Promise.resolve(); |
| 74 | itemStatusPromise.then((updatedVersion) => { |
| 75 | if (updatedVersion && updatedVersion.status !== version.status) { |
| 76 | dispatch({ |
| 77 | type: modalActionTypes.GLOBAL_MODAL_WARNING, |
| 78 | data: { |
| 79 | title: i18n('Commit error'), |
| 80 | msg: i18n('Item version already Certified'), |
| 81 | cancelButtonText: i18n('Cancel') |
| 82 | } |
| 83 | }); |
| 84 | versionPageActionHelper.fetchVersions(dispatch, {itemType: itemTypes.SOFTWARE_PRODUCT, itemId: softwareProductId}); |
| 85 | } |
| 86 | |
| 87 | let newVersion = updatedVersion ? updatedVersion : version; |
| 88 | if (screen === screenTypes.SOFTWARE_PRODUCT_COMPONENT_DEFAULT_GENERAL) { |
| 89 | OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, { |
| 90 | softwareProductId, |
| 91 | componentId, |
| 92 | version: newVersion |
| 93 | }); |
| 94 | } |
| 95 | if (componentId) { |
| 96 | switch (screen) { |
| 97 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENTS: |
| 98 | OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, { |
| 99 | softwareProductId, |
| 100 | componentId, |
| 101 | version: newVersion |
| 102 | }); |
| 103 | break; |
| 104 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_GENERAL: |
| 105 | OnboardingActionHelper.navigateToSoftwareProductComponentGeneral(dispatch, { |
| 106 | softwareProductId, |
| 107 | componentId, |
| 108 | version: newVersion |
| 109 | }); |
| 110 | break; |
| 111 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_COMPUTE: |
| 112 | OnboardingActionHelper.navigateToComponentCompute(dispatch, { |
| 113 | softwareProductId, |
| 114 | componentId, |
| 115 | version: newVersion |
| 116 | }); |
| 117 | break; |
| 118 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_LOAD_BALANCING: |
| 119 | OnboardingActionHelper.navigateToComponentLoadBalancing(dispatch, { |
| 120 | softwareProductId, |
| 121 | componentId, |
| 122 | version: newVersion |
| 123 | }); |
| 124 | break; |
| 125 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_NETWORK: |
| 126 | OnboardingActionHelper.navigateToComponentNetwork(dispatch, { |
| 127 | softwareProductId, |
| 128 | componentId, |
| 129 | version: newVersion |
| 130 | }); |
| 131 | break; |
| 132 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_STORAGE: |
| 133 | OnboardingActionHelper.navigateToComponentStorage(dispatch, { |
| 134 | softwareProductId, |
| 135 | componentId, |
| 136 | version: newVersion |
| 137 | }); |
| 138 | break; |
| 139 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_PROCESSES: |
| 140 | OnboardingActionHelper.navigateToSoftwareProductComponentProcesses(dispatch, { |
| 141 | softwareProductId, |
| 142 | componentId, |
| 143 | version: newVersion |
| 144 | }); |
| 145 | break; |
| 146 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_MONITORING: |
| 147 | OnboardingActionHelper.navigateToSoftwareProductComponentMonitoring(dispatch, { |
| 148 | softwareProductId, |
| 149 | componentId, |
| 150 | version: newVersion |
| 151 | }); |
| 152 | break; |
| 153 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_IMAGES: |
| 154 | OnboardingActionHelper.navigateToComponentImages(dispatch, { |
| 155 | softwareProductId, |
| 156 | componentId, |
| 157 | version: newVersion |
| 158 | }); |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | else { |
| 163 | switch (screen) { |
| 164 | case enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE: |
| 165 | OnboardingActionHelper.navigateToSoftwareProductLandingPage(dispatch, { |
| 166 | softwareProductId, |
| 167 | version: newVersion |
| 168 | }); |
| 169 | break; |
| 170 | case enums.SCREEN.SOFTWARE_PRODUCT_DETAILS: |
| 171 | OnboardingActionHelper.navigateToSoftwareProductDetails(dispatch, { |
| 172 | softwareProductId, |
| 173 | version: newVersion |
| 174 | }); |
| 175 | break; |
| 176 | case enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS_SETUP: |
| 177 | OnboardingActionHelper.navigateToSoftwareProductAttachmentsSetupTab(dispatch, { |
| 178 | softwareProductId, |
| 179 | version |
| 180 | }); |
| 181 | break; |
| 182 | case enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS_VALIDATION: |
| 183 | OnboardingActionHelper.navigateToSoftwareProductAttachmentsValidationTab(dispatch, { |
| 184 | softwareProductId, |
| 185 | version |
| 186 | }); |
| 187 | break; |
| 188 | case enums.SCREEN.SOFTWARE_PRODUCT_PROCESSES: |
| 189 | OnboardingActionHelper.navigateToSoftwareProductProcesses(dispatch, { |
| 190 | softwareProductId, |
| 191 | version: newVersion |
| 192 | }); |
| 193 | break; |
| 194 | case enums.SCREEN.SOFTWARE_PRODUCT_DEPLOYMENT: |
| 195 | OnboardingActionHelper.navigateToSoftwareProductDeployment(dispatch, { |
| 196 | softwareProductId, |
| 197 | version: newVersion |
| 198 | }); |
| 199 | break; |
| 200 | case enums.SCREEN.SOFTWARE_PRODUCT_NETWORKS: |
| 201 | OnboardingActionHelper.navigateToSoftwareProductNetworks(dispatch, { |
| 202 | softwareProductId, |
| 203 | version: newVersion |
| 204 | }); |
| 205 | break; |
| 206 | case enums.SCREEN.SOFTWARE_PRODUCT_DEPENDENCIES: |
| 207 | OnboardingActionHelper.navigateToSoftwareProductDependencies(dispatch, { |
| 208 | softwareProductId, |
| 209 | version: newVersion |
| 210 | }); |
| 211 | break; |
| 212 | case enums.SCREEN.SOFTWARE_PRODUCT_ACTIVITY_LOG: |
| 213 | OnboardingActionHelper.navigateToSoftwareProductActivityLog(dispatch, { |
| 214 | softwareProductId, |
| 215 | version: newVersion |
| 216 | }); |
| 217 | break; |
| 218 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENTS: |
| 219 | OnboardingActionHelper.navigateToSoftwareProductComponents(dispatch, { |
| 220 | softwareProductId, |
| 221 | version: newVersion |
| 222 | }); |
| 223 | dispatch({ |
| 224 | type: SoftwareProductActionTypes.TOGGLE_NAVIGATION_ITEM, |
| 225 | mapOfExpandedIds: { |
| 226 | [enums.SCREEN.SOFTWARE_PRODUCT_COMPONENTS]: true |
| 227 | } |
| 228 | }); |
| 229 | break; |
| 230 | case enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE: |
| 231 | default: |
| 232 | OnboardingActionHelper.navigateToVersionsPage(dispatch, { |
| 233 | itemId: softwareProductId, |
| 234 | itemType: itemTypes.SOFTWARE_PRODUCT, |
| 235 | itemName: softwareProduct.name, |
| 236 | users: usersList, |
| 237 | additionalProps: { |
| 238 | licenseModelId: softwareProduct.vendorId, |
| 239 | licensingVersion: softwareProduct.licensingVersion |
| 240 | } |
| 241 | }); |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | }); |
| 246 | } |
| 247 | }, |
| 248 | |
| 249 | getScreenType(screen) { |
| 250 | switch (screen) { |
| 251 | case enums.SCREEN.LICENSE_MODEL_OVERVIEW: |
| 252 | case enums.SCREEN.LICENSE_AGREEMENTS: |
| 253 | case enums.SCREEN.FEATURE_GROUPS: |
| 254 | case enums.SCREEN.ENTITLEMENT_POOLS: |
| 255 | case enums.SCREEN.LICENSE_KEY_GROUPS: |
| 256 | case enums.SCREEN.ACTIVITY_LOG: |
| 257 | return screenTypes.LICENSE_MODEL; |
| 258 | case screenTypes.SOFTWARE_PRODUCT_COMPONENT_DEFAULT_GENERAL: |
| 259 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_GENERAL: |
| 260 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_COMPUTE: |
| 261 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_LOAD_BALANCING: |
| 262 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_NETWORK: |
| 263 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_STORAGE: |
| 264 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_PROCESSES: |
| 265 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_MONITORING: |
| 266 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENT_IMAGES: |
| 267 | case enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE: |
| 268 | case enums.SCREEN.SOFTWARE_PRODUCT_DETAILS: |
| 269 | case enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS: |
| 270 | case enums.SCREEN.SOFTWARE_PRODUCT_PROCESSES: |
| 271 | case enums.SCREEN.SOFTWARE_PRODUCT_DEPLOYMENT: |
| 272 | case enums.SCREEN.SOFTWARE_PRODUCT_NETWORKS: |
| 273 | case enums.SCREEN.SOFTWARE_PRODUCT_DEPENDENCIES: |
| 274 | case enums.SCREEN.SOFTWARE_PRODUCT_ACTIVITY_LOG: |
| 275 | case enums.SCREEN.SOFTWARE_PRODUCT_COMPONENTS: |
| 276 | return screenTypes.SOFTWARE_PRODUCT; |
| 277 | } |
| 278 | }, |
| 279 | |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame^] | 280 | loadLandingScreen(dispatch, {previousScreenName, screenType, props: {licenseModelId, softwareProductId, version}}) { |
| 281 | let selectedScreenType = screenType ? screenType : this.getScreenType(previousScreenName); |
| 282 | let screen = selectedScreenType === screenTypes.SOFTWARE_PRODUCT ? |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 283 | enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE : |
| 284 | enums.SCREEN.LICENSE_MODEL_OVERVIEW; |
| 285 | let props = {licenseModelId, softwareProductId, version}; |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame^] | 286 | return this.loadScreen(dispatch, {screen, screenType: selectedScreenType, props}); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 287 | } |
| 288 | }; |
| 289 | |
| 290 | export default ScreensHelper; |