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