talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [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 | */ |
| 16 | import ItemsHelper from '../../common/helpers/ItemsHelper.js'; |
| 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'; |
| 21 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 22 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
| 23 | import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 24 | |
| 25 | |
| 26 | const VersionsPageActionHelper = { |
| 27 | fetchVersions(dispatch, {itemType, itemId}) { |
| 28 | return ItemsHelper.fetchVersions({itemId}).then(response => { |
| 29 | dispatch({ |
| 30 | type: actionTypes.VERSIONS_LOADED, |
| 31 | versions: response.results, |
| 32 | itemType, |
| 33 | itemId |
| 34 | }); |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 35 | return Promise.resolve(response); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 36 | }); |
| 37 | }, |
| 38 | |
| 39 | selectVersion(dispatch, {version}) { |
| 40 | dispatch({ |
| 41 | type: actionTypes.SELECT_VERSION, |
| 42 | versionId: version.id |
| 43 | }); |
| 44 | }, |
| 45 | |
| 46 | selectNone(dispatch) { |
| 47 | dispatch({ type: actionTypes.SELECT_NONE }); |
| 48 | }, |
| 49 | |
| 50 | onNavigateToVersion(dispatch, {version, itemId, itemType}) { |
| 51 | switch (itemType) { |
| 52 | case itemTypes.LICENSE_MODEL: |
| 53 | ScreensHelper.loadScreen(dispatch, { |
| 54 | screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, 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, screenType: screenTypes.SOFTWARE_PRODUCT, |
| 61 | props: {softwareProductId: itemId, version} |
| 62 | }); |
| 63 | break; |
| 64 | } |
| 65 | }, |
| 66 | |
| 67 | openTree(dispatch, treeProps) { |
| 68 | dispatch({ |
| 69 | type: modalActionTypes.GLOBAL_MODAL_SHOW, |
| 70 | data: { |
| 71 | modalComponentName: modalContentMapper.VERSION_TREE, |
| 72 | modalComponentProps: treeProps, |
| 73 | onDeclined: () => dispatch({ |
| 74 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 75 | }), |
| 76 | modalClassName: 'versions-tree-modal', |
| 77 | cancelButtonText: i18n('Close'), |
| 78 | title: i18n('Version Tree') |
| 79 | } |
| 80 | }); |
| 81 | }, |
| 82 | |
| 83 | selectVersionFromModal(dispatch, {version}) { |
| 84 | dispatch({ |
| 85 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 86 | }); |
| 87 | this.selectVersion(dispatch, {version}); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | export default VersionsPageActionHelper; |