blob: 606b17b8972213aa5fcf920d1d98d246027286c5 [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';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020017import { 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';
talig8e9c0652017-12-20 14:30:43 +020021import i18n from 'nfvo-utils/i18n/i18n.js';
22import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
talig8e9c0652017-12-20 14:30:43 +020024
25const VersionsPageActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020026 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 },
talig8e9c0652017-12-20 14:30:43 +020037
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020038 selectVersion(dispatch, { version }) {
39 dispatch({
40 type: actionTypes.SELECT_VERSION,
41 versionId: version.id
42 });
43 },
talig8e9c0652017-12-20 14:30:43 +020044
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020045 selectNone(dispatch) {
46 dispatch({ type: actionTypes.SELECT_NONE });
47 },
talig8e9c0652017-12-20 14:30:43 +020048
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020049 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 },
talig8e9c0652017-12-20 14:30:43 +020067
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020068 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 },
talig8e9c0652017-12-20 14:30:43 +020084
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020085 selectVersionFromModal(dispatch, { version }) {
86 dispatch({
87 type: modalActionTypes.GLOBAL_MODAL_CLOSE
88 });
89 this.selectVersion(dispatch, { version });
90 },
svishnev091edfd2018-03-19 12:15:19 +020091
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020092 archiveItem(dispatch, itemId) {
93 ItemsHelper.archiveItem(itemId).then(() => {
94 ScreensHelper.loadScreen(dispatch, {
95 screen: enums.SCREEN.ONBOARDING_CATALOG
96 });
97 });
98 },
svishnev091edfd2018-03-19 12:15:19 +020099
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200100 restoreItemFromArchive(dispatch, itemId) {
101 ItemsHelper.restoreItem(itemId).then(() => {
102 ScreensHelper.loadScreen(dispatch, {
103 screen: enums.SCREEN.ONBOARDING_CATALOG
104 });
105 });
106 }
talig8e9c0652017-12-20 14:30:43 +0200107};
108
109export default VersionsPageActionHelper;