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 RestAPIUtil from 'nfvo-utils/RestAPIUtil.js'; |
| 17 | import Configuration from 'sdc-app/config/Configuration.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 18 | import { actionTypes } from './VersionsPageCreationConstants.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 ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 23 | import { actionTypes as VersionsPageActionTypes } from '../VersionsPageConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 24 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 25 | function baseUrl({ itemId, baseVersion }) { |
| 26 | const restPrefix = Configuration.get('restPrefix'); |
| 27 | return `${restPrefix}/v1.0/items/${itemId}/versions/${baseVersion.id}/`; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | function createVersion({ |
| 31 | itemId, |
| 32 | baseVersion, |
| 33 | payload: { description, creationMethod } |
| 34 | }) { |
| 35 | return RestAPIUtil.post(baseUrl({ itemId, baseVersion }), { |
| 36 | description, |
| 37 | creationMethod |
| 38 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 39 | } |
| 40 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 41 | export default { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 42 | open(dispatch, { itemType, itemId, additionalProps, baseVersion }) { |
| 43 | dispatch({ |
| 44 | type: actionTypes.OPEN |
| 45 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 46 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 47 | dispatch({ |
| 48 | type: modalActionTypes.GLOBAL_MODAL_SHOW, |
| 49 | data: { |
| 50 | modalComponentName: modalContentMapper.VERSION_CREATION, |
| 51 | modalComponentProps: { |
| 52 | itemType, |
| 53 | itemId, |
| 54 | additionalProps, |
| 55 | baseVersion |
| 56 | }, |
| 57 | title: i18n('New Version - From {name}', { |
| 58 | name: baseVersion.name |
| 59 | }) |
| 60 | } |
| 61 | }); |
| 62 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 63 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 64 | close(dispatch) { |
| 65 | dispatch({ |
| 66 | type: actionTypes.CLOSE |
| 67 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 68 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 69 | dispatch({ |
| 70 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 71 | }); |
| 72 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 73 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 74 | createVersion(dispatch, { itemId, baseVersion, payload }) { |
| 75 | return createVersion({ itemId, baseVersion, payload }).then(result => { |
| 76 | return ItemsHelper.fetchVersions({ itemId }).then(response => { |
| 77 | dispatch({ |
| 78 | type: VersionsPageActionTypes.VERSIONS_LOADED, |
| 79 | versions: response.results, |
| 80 | itemId |
| 81 | }); |
| 82 | dispatch({ |
| 83 | type: actionTypes.VERSION_CREATED, |
| 84 | result |
| 85 | }); |
| 86 | return result; |
| 87 | }); |
| 88 | }); |
| 89 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 90 | }; |