svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 20 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 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'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 23 | import { actionTypes as filterActionTypes } from './filter/FilterConstants.js'; |
svishnev | cee71ef | 2018-05-01 17:56:49 +0300 | [diff] [blame] | 24 | import { versionStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 25 | |
| 26 | const OnboardActionHelper = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 27 | resetOnboardStore(dispatch) { |
| 28 | dispatch({ |
| 29 | type: actionTypes.RESET_ONBOARD_STORE |
| 30 | }); |
| 31 | }, |
| 32 | changeActiveTab(dispatch, activeTab) { |
| 33 | this.clearSearchValue(dispatch); |
| 34 | dispatch({ |
| 35 | type: actionTypes.CHANGE_ACTIVE_ONBOARD_TAB, |
| 36 | activeTab |
| 37 | }); |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 38 | dispatch({ |
| 39 | type: filterActionTypes.FILTER_DATA_CHANGED, |
| 40 | deltaData: |
| 41 | activeTab === tabsMapping.WORKSPACE |
| 42 | ? { |
svishnev | cee71ef | 2018-05-01 17:56:49 +0300 | [diff] [blame] | 43 | versionStatus: versionStatus.DRAFT |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 44 | } |
| 45 | : { |
| 46 | versionStatus: versionStatus.CERTIFIED |
| 47 | } |
| 48 | }); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 49 | }, |
| 50 | changeSearchValue(dispatch, searchValue) { |
| 51 | dispatch({ |
| 52 | type: actionTypes.CHANGE_SEARCH_VALUE, |
| 53 | searchValue |
| 54 | }); |
| 55 | }, |
| 56 | clearSearchValue(dispatch) { |
| 57 | dispatch({ |
| 58 | type: actionTypes.CHANGE_SEARCH_VALUE, |
| 59 | searchValue: '' |
| 60 | }); |
| 61 | }, |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 62 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 63 | loadVLMScreen(dispatch, { id: licenseModelId, name }, users, tab) { |
| 64 | if (tab === tabsMapping.WORKSPACE) { |
| 65 | VersionsPageActionHelper.fetchVersions(dispatch, { |
| 66 | itemId: licenseModelId, |
| 67 | itemType: itemTypes.LICENSE_MODEL |
| 68 | }).then(({ results }) => { |
| 69 | results = results.filter( |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 70 | version => version.status === versionStatus.DRAFT |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 71 | ); |
| 72 | if (results.length !== 1) { |
| 73 | ScreensHelper.loadScreen(dispatch, { |
| 74 | screen: enums.SCREEN.VERSIONS_PAGE, |
| 75 | screenType: screenTypes.LICENSE_MODEL, |
| 76 | props: { |
| 77 | licenseModelId, |
| 78 | licenseModel: { name }, |
| 79 | usersList: users |
| 80 | } |
| 81 | }); |
| 82 | } else { |
| 83 | PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 84 | itemId: licenseModelId, |
| 85 | allUsers: users |
| 86 | }).then(() => |
| 87 | ScreensHelper.loadLandingScreen(dispatch, { |
| 88 | screenType: screenTypes.LICENSE_MODEL, |
| 89 | props: { licenseModelId, version: results[0] } |
| 90 | }) |
| 91 | ); |
| 92 | } |
| 93 | }); |
| 94 | } |
| 95 | if (tab === tabsMapping.CATALOG) { |
| 96 | ScreensHelper.loadScreen(dispatch, { |
| 97 | screen: enums.SCREEN.VERSIONS_PAGE, |
| 98 | screenType: screenTypes.LICENSE_MODEL, |
| 99 | props: { |
| 100 | licenseModelId, |
| 101 | licenseModel: { name }, |
| 102 | usersList: users |
| 103 | } |
| 104 | }); |
| 105 | } |
| 106 | }, |
| 107 | loadVSPScreen(dispatch, softwareProduct, users, tab) { |
| 108 | let { |
| 109 | id: softwareProductId, |
| 110 | vendorId: licenseModelId, |
| 111 | licensingVersion, |
| 112 | name |
| 113 | } = softwareProduct; |
| 114 | if (tab === tabsMapping.WORKSPACE) { |
| 115 | VersionsPageActionHelper.fetchVersions(dispatch, { |
| 116 | itemId: softwareProductId, |
| 117 | itemType: itemTypes.SOFTWARE_PRODUCT |
| 118 | }).then(({ results }) => { |
| 119 | results = results.filter( |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 120 | version => version.status === versionStatus.DRAFT |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 121 | ); |
| 122 | if (results.length !== 1) { |
| 123 | ScreensHelper.loadScreen(dispatch, { |
| 124 | screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, |
| 125 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 126 | props: { |
| 127 | softwareProductId, |
| 128 | softwareProduct: { |
| 129 | name, |
| 130 | vendorId: licenseModelId, |
| 131 | licensingVersion |
| 132 | }, |
| 133 | usersList: users |
| 134 | } |
| 135 | }); |
| 136 | } else { |
| 137 | PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 138 | itemId: softwareProductId, |
| 139 | allUsers: users |
| 140 | }).then(() => |
| 141 | ScreensHelper.loadLandingScreen(dispatch, { |
| 142 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 143 | props: { |
| 144 | softwareProductId, |
| 145 | licenseModelId, |
| 146 | version: results[0] |
| 147 | } |
| 148 | }) |
| 149 | ); |
| 150 | } |
| 151 | }); |
| 152 | } |
| 153 | if (tab === tabsMapping.CATALOG) { |
| 154 | ScreensHelper.loadScreen(dispatch, { |
| 155 | screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, |
| 156 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 157 | props: { |
| 158 | softwareProductId, |
| 159 | softwareProduct: { |
| 160 | name, |
| 161 | vendorId: licenseModelId, |
| 162 | licensingVersion |
| 163 | }, |
| 164 | usersList: users |
| 165 | } |
| 166 | }); |
| 167 | } |
| 168 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | export default OnboardActionHelper; |