talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [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 |
| 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 | */ |
| 16 | import ItemsHelper from '../../common/helpers/ItemsHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 17 | import { actionTypes } from './VersionsPageConstants.js'; |
| 18 | import { itemTypes } from './VersionsPageConstants.js'; |
| 19 | import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js'; |
| 20 | import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 21 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 22 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 23 | import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 24 | |
| 25 | const VersionsPageActionHelper = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 26 | fetchVersions(dispatch, { itemType, itemId }) { |
| 27 | return ItemsHelper.fetchVersions({ itemId }).then(response => { |
| 28 | dispatch({ |
| 29 | type: actionTypes.VERSIONS_LOADED, |
| 30 | versions: response.results, |
| 31 | itemType, |
| 32 | itemId |
| 33 | }); |
| 34 | return Promise.resolve(response); |
| 35 | }); |
| 36 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 37 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 38 | selectVersion(dispatch, { version }) { |
| 39 | dispatch({ |
| 40 | type: actionTypes.SELECT_VERSION, |
| 41 | versionId: version.id |
| 42 | }); |
| 43 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 44 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 45 | selectNone(dispatch) { |
| 46 | dispatch({ type: actionTypes.SELECT_NONE }); |
| 47 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 48 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 49 | onNavigateToVersion(dispatch, { version, itemId, itemType }) { |
| 50 | switch (itemType) { |
| 51 | case itemTypes.LICENSE_MODEL: |
| 52 | ScreensHelper.loadScreen(dispatch, { |
| 53 | screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, |
| 54 | screenType: screenTypes.LICENSE_MODEL, |
| 55 | props: { licenseModelId: itemId, version } |
| 56 | }); |
| 57 | break; |
| 58 | case itemTypes.SOFTWARE_PRODUCT: |
| 59 | ScreensHelper.loadScreen(dispatch, { |
| 60 | screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, |
| 61 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 62 | props: { softwareProductId: itemId, version } |
| 63 | }); |
| 64 | break; |
| 65 | } |
| 66 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 67 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 68 | openTree(dispatch, treeProps) { |
| 69 | dispatch({ |
| 70 | type: modalActionTypes.GLOBAL_MODAL_SHOW, |
| 71 | data: { |
| 72 | modalComponentName: modalContentMapper.VERSION_TREE, |
| 73 | modalComponentProps: treeProps, |
| 74 | onDeclined: () => |
| 75 | dispatch({ |
| 76 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 77 | }), |
| 78 | modalClassName: 'versions-tree-modal', |
| 79 | cancelButtonText: i18n('Close'), |
| 80 | title: i18n('Version Tree') |
| 81 | } |
| 82 | }); |
| 83 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 84 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 85 | selectVersionFromModal(dispatch, { version }) { |
| 86 | dispatch({ |
| 87 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 88 | }); |
| 89 | this.selectVersion(dispatch, { version }); |
| 90 | }, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 91 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 92 | archiveItem(dispatch, itemId) { |
| 93 | ItemsHelper.archiveItem(itemId).then(() => { |
| 94 | ScreensHelper.loadScreen(dispatch, { |
| 95 | screen: enums.SCREEN.ONBOARDING_CATALOG |
| 96 | }); |
| 97 | }); |
| 98 | }, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 99 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 100 | restoreItemFromArchive(dispatch, itemId) { |
| 101 | ItemsHelper.restoreItem(itemId).then(() => { |
| 102 | ScreensHelper.loadScreen(dispatch, { |
| 103 | screen: enums.SCREEN.ONBOARDING_CATALOG |
| 104 | }); |
| 105 | }); |
| 106 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | export default VersionsPageActionHelper; |