AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 15 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { tabsMapping, actionTypes } from './OnboardConstants.js'; |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 17 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 18 | import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js'; |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 19 | import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 20 | import { catalogItemStatuses } from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js'; |
| 21 | import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js'; |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 22 | import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | |
| 24 | const OnboardActionHelper = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 25 | resetOnboardStore(dispatch) { |
| 26 | dispatch({ |
| 27 | type: actionTypes.RESET_ONBOARD_STORE |
| 28 | }); |
| 29 | }, |
| 30 | changeActiveTab(dispatch, activeTab) { |
| 31 | this.clearSearchValue(dispatch); |
| 32 | dispatch({ |
| 33 | type: actionTypes.CHANGE_ACTIVE_ONBOARD_TAB, |
| 34 | activeTab |
| 35 | }); |
| 36 | }, |
| 37 | changeSearchValue(dispatch, searchValue) { |
| 38 | dispatch({ |
| 39 | type: actionTypes.CHANGE_SEARCH_VALUE, |
| 40 | searchValue |
| 41 | }); |
| 42 | }, |
| 43 | clearSearchValue(dispatch) { |
| 44 | dispatch({ |
| 45 | type: actionTypes.CHANGE_SEARCH_VALUE, |
| 46 | searchValue: '' |
| 47 | }); |
| 48 | }, |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 49 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 50 | loadVLMScreen(dispatch, { id: licenseModelId, name }, users, tab) { |
| 51 | if (tab === tabsMapping.WORKSPACE) { |
| 52 | VersionsPageActionHelper.fetchVersions(dispatch, { |
| 53 | itemId: licenseModelId, |
| 54 | itemType: itemTypes.LICENSE_MODEL |
| 55 | }).then(({ results }) => { |
| 56 | results = results.filter( |
| 57 | version => version.status === catalogItemStatuses.DRAFT |
| 58 | ); |
| 59 | if (results.length !== 1) { |
| 60 | ScreensHelper.loadScreen(dispatch, { |
| 61 | screen: enums.SCREEN.VERSIONS_PAGE, |
| 62 | screenType: screenTypes.LICENSE_MODEL, |
| 63 | props: { |
| 64 | licenseModelId, |
| 65 | licenseModel: { name }, |
| 66 | usersList: users |
| 67 | } |
| 68 | }); |
| 69 | } else { |
| 70 | PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 71 | itemId: licenseModelId, |
| 72 | allUsers: users |
| 73 | }).then(() => |
| 74 | ScreensHelper.loadLandingScreen(dispatch, { |
| 75 | screenType: screenTypes.LICENSE_MODEL, |
| 76 | props: { licenseModelId, version: results[0] } |
| 77 | }) |
| 78 | ); |
| 79 | } |
| 80 | }); |
| 81 | } |
| 82 | if (tab === tabsMapping.CATALOG) { |
| 83 | ScreensHelper.loadScreen(dispatch, { |
| 84 | screen: enums.SCREEN.VERSIONS_PAGE, |
| 85 | screenType: screenTypes.LICENSE_MODEL, |
| 86 | props: { |
| 87 | licenseModelId, |
| 88 | licenseModel: { name }, |
| 89 | usersList: users |
| 90 | } |
| 91 | }); |
| 92 | } |
| 93 | }, |
| 94 | loadVSPScreen(dispatch, softwareProduct, users, tab) { |
| 95 | let { |
| 96 | id: softwareProductId, |
| 97 | vendorId: licenseModelId, |
| 98 | licensingVersion, |
| 99 | name |
| 100 | } = softwareProduct; |
| 101 | if (tab === tabsMapping.WORKSPACE) { |
| 102 | VersionsPageActionHelper.fetchVersions(dispatch, { |
| 103 | itemId: softwareProductId, |
| 104 | itemType: itemTypes.SOFTWARE_PRODUCT |
| 105 | }).then(({ results }) => { |
| 106 | results = results.filter( |
| 107 | version => version.status === catalogItemStatuses.DRAFT |
| 108 | ); |
| 109 | if (results.length !== 1) { |
| 110 | ScreensHelper.loadScreen(dispatch, { |
| 111 | screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, |
| 112 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 113 | props: { |
| 114 | softwareProductId, |
| 115 | softwareProduct: { |
| 116 | name, |
| 117 | vendorId: licenseModelId, |
| 118 | licensingVersion |
| 119 | }, |
| 120 | usersList: users |
| 121 | } |
| 122 | }); |
| 123 | } else { |
| 124 | PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 125 | itemId: softwareProductId, |
| 126 | allUsers: users |
| 127 | }).then(() => |
| 128 | ScreensHelper.loadLandingScreen(dispatch, { |
| 129 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 130 | props: { |
| 131 | softwareProductId, |
| 132 | licenseModelId, |
| 133 | version: results[0] |
| 134 | } |
| 135 | }) |
| 136 | ); |
| 137 | } |
| 138 | }); |
| 139 | } |
| 140 | if (tab === tabsMapping.CATALOG) { |
| 141 | ScreensHelper.loadScreen(dispatch, { |
| 142 | screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, |
| 143 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 144 | props: { |
| 145 | softwareProductId, |
| 146 | softwareProduct: { |
| 147 | name, |
| 148 | vendorId: licenseModelId, |
| 149 | licensingVersion |
| 150 | }, |
| 151 | usersList: users |
| 152 | } |
| 153 | }); |
| 154 | } |
| 155 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | export default OnboardActionHelper; |