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'; |
| 24 | import { |
| 25 | versionStatus, |
| 26 | itemStatus |
| 27 | } from 'sdc-app/common/helpers/ItemsHelperConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | |
| 29 | const OnboardActionHelper = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | resetOnboardStore(dispatch) { |
| 31 | dispatch({ |
| 32 | type: actionTypes.RESET_ONBOARD_STORE |
| 33 | }); |
| 34 | }, |
| 35 | changeActiveTab(dispatch, activeTab) { |
| 36 | this.clearSearchValue(dispatch); |
| 37 | dispatch({ |
| 38 | type: actionTypes.CHANGE_ACTIVE_ONBOARD_TAB, |
| 39 | activeTab |
| 40 | }); |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame^] | 41 | dispatch({ |
| 42 | type: filterActionTypes.FILTER_DATA_CHANGED, |
| 43 | deltaData: |
| 44 | activeTab === tabsMapping.WORKSPACE |
| 45 | ? { |
| 46 | versionStatus: versionStatus.DRAFT, |
| 47 | itemStatus: itemStatus.ACTIVE |
| 48 | } |
| 49 | : { |
| 50 | versionStatus: versionStatus.CERTIFIED |
| 51 | } |
| 52 | }); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 53 | }, |
| 54 | changeSearchValue(dispatch, searchValue) { |
| 55 | dispatch({ |
| 56 | type: actionTypes.CHANGE_SEARCH_VALUE, |
| 57 | searchValue |
| 58 | }); |
| 59 | }, |
| 60 | clearSearchValue(dispatch) { |
| 61 | dispatch({ |
| 62 | type: actionTypes.CHANGE_SEARCH_VALUE, |
| 63 | searchValue: '' |
| 64 | }); |
| 65 | }, |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 66 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 67 | loadVLMScreen(dispatch, { id: licenseModelId, name }, users, tab) { |
| 68 | if (tab === tabsMapping.WORKSPACE) { |
| 69 | VersionsPageActionHelper.fetchVersions(dispatch, { |
| 70 | itemId: licenseModelId, |
| 71 | itemType: itemTypes.LICENSE_MODEL |
| 72 | }).then(({ results }) => { |
| 73 | results = results.filter( |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame^] | 74 | version => version.status === versionStatus.DRAFT |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 75 | ); |
| 76 | if (results.length !== 1) { |
| 77 | ScreensHelper.loadScreen(dispatch, { |
| 78 | screen: enums.SCREEN.VERSIONS_PAGE, |
| 79 | screenType: screenTypes.LICENSE_MODEL, |
| 80 | props: { |
| 81 | licenseModelId, |
| 82 | licenseModel: { name }, |
| 83 | usersList: users |
| 84 | } |
| 85 | }); |
| 86 | } else { |
| 87 | PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 88 | itemId: licenseModelId, |
| 89 | allUsers: users |
| 90 | }).then(() => |
| 91 | ScreensHelper.loadLandingScreen(dispatch, { |
| 92 | screenType: screenTypes.LICENSE_MODEL, |
| 93 | props: { licenseModelId, version: results[0] } |
| 94 | }) |
| 95 | ); |
| 96 | } |
| 97 | }); |
| 98 | } |
| 99 | if (tab === tabsMapping.CATALOG) { |
| 100 | ScreensHelper.loadScreen(dispatch, { |
| 101 | screen: enums.SCREEN.VERSIONS_PAGE, |
| 102 | screenType: screenTypes.LICENSE_MODEL, |
| 103 | props: { |
| 104 | licenseModelId, |
| 105 | licenseModel: { name }, |
| 106 | usersList: users |
| 107 | } |
| 108 | }); |
| 109 | } |
| 110 | }, |
| 111 | loadVSPScreen(dispatch, softwareProduct, users, tab) { |
| 112 | let { |
| 113 | id: softwareProductId, |
| 114 | vendorId: licenseModelId, |
| 115 | licensingVersion, |
| 116 | name |
| 117 | } = softwareProduct; |
| 118 | if (tab === tabsMapping.WORKSPACE) { |
| 119 | VersionsPageActionHelper.fetchVersions(dispatch, { |
| 120 | itemId: softwareProductId, |
| 121 | itemType: itemTypes.SOFTWARE_PRODUCT |
| 122 | }).then(({ results }) => { |
| 123 | results = results.filter( |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame^] | 124 | version => version.status === versionStatus.DRAFT |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 125 | ); |
| 126 | if (results.length !== 1) { |
| 127 | ScreensHelper.loadScreen(dispatch, { |
| 128 | screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, |
| 129 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 130 | props: { |
| 131 | softwareProductId, |
| 132 | softwareProduct: { |
| 133 | name, |
| 134 | vendorId: licenseModelId, |
| 135 | licensingVersion |
| 136 | }, |
| 137 | usersList: users |
| 138 | } |
| 139 | }); |
| 140 | } else { |
| 141 | PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 142 | itemId: softwareProductId, |
| 143 | allUsers: users |
| 144 | }).then(() => |
| 145 | ScreensHelper.loadLandingScreen(dispatch, { |
| 146 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 147 | props: { |
| 148 | softwareProductId, |
| 149 | licenseModelId, |
| 150 | version: results[0] |
| 151 | } |
| 152 | }) |
| 153 | ); |
| 154 | } |
| 155 | }); |
| 156 | } |
| 157 | if (tab === tabsMapping.CATALOG) { |
| 158 | ScreensHelper.loadScreen(dispatch, { |
| 159 | screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, |
| 160 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 161 | props: { |
| 162 | softwareProductId, |
| 163 | softwareProduct: { |
| 164 | name, |
| 165 | vendorId: licenseModelId, |
| 166 | licensingVersion |
| 167 | }, |
| 168 | usersList: users |
| 169 | } |
| 170 | }); |
| 171 | } |
| 172 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | export default OnboardActionHelper; |