blob: d475c03c312c5ed8eeb7c1358fcb7d2f08f1d08e [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
svishnev091edfd2018-03-19 12:15:19 +02002 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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 */
16import ItemsHelper from '../../common/helpers/ItemsHelper.js';
17import {actionTypes} from './VersionsPageConstants.js';
18import {itemTypes} from './VersionsPageConstants.js';
19import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
20import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
21import i18n from 'nfvo-utils/i18n/i18n.js';
22import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
23import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
24
25
26const 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 });
miriamed411d152018-01-02 15:35:55 +020035 return Promise.resolve(response);
talig8e9c0652017-12-20 14:30:43 +020036 });
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});
svishnev091edfd2018-03-19 12:15:19 +020088 },
89
90 archiveItem(dispatch, itemId) {
91 ItemsHelper.archiveItem(itemId).then(() => {
92 ScreensHelper.loadScreen(dispatch, {
93 screen: enums.SCREEN.ONBOARDING_CATALOG
94 });
95 });
96 },
97
98 restoreItemFromArchive(dispatch, itemId) {
99 ItemsHelper.restoreItem(itemId).then(() => {
100 ScreensHelper.loadScreen(dispatch, {
101 screen: enums.SCREEN.ONBOARDING_CATALOG
102 });
103 });
talig8e9c0652017-12-20 14:30:43 +0200104 }
105};
106
107export default VersionsPageActionHelper;