blob: 8087dceca0705a412712f981e102db57b7738779 [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';
svishnevfa538a12018-05-31 15:01:00 +030023import {
24 enums,
25 screenTypes,
26 onboardingActions
27} from 'sdc-app/onboarding/OnboardingConstants.js';
28import { notificationActions } from 'nfvo-components/notification/NotificationsConstants.js';
talig8e9c0652017-12-20 14:30:43 +020029
30const VersionsPageActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020031 fetchVersions(dispatch, { itemType, itemId }) {
32 return ItemsHelper.fetchVersions({ itemId }).then(response => {
33 dispatch({
34 type: actionTypes.VERSIONS_LOADED,
35 versions: response.results,
36 itemType,
37 itemId
38 });
39 return Promise.resolve(response);
40 });
41 },
talig8e9c0652017-12-20 14:30:43 +020042
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020043 selectVersion(dispatch, { version }) {
44 dispatch({
45 type: actionTypes.SELECT_VERSION,
46 versionId: version.id
47 });
48 },
talig8e9c0652017-12-20 14:30:43 +020049
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020050 selectNone(dispatch) {
51 dispatch({ type: actionTypes.SELECT_NONE });
52 },
talig8e9c0652017-12-20 14:30:43 +020053
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020054 onNavigateToVersion(dispatch, { version, itemId, itemType }) {
55 switch (itemType) {
56 case itemTypes.LICENSE_MODEL:
57 ScreensHelper.loadScreen(dispatch, {
58 screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
59 screenType: screenTypes.LICENSE_MODEL,
60 props: { licenseModelId: itemId, version }
61 });
62 break;
63 case itemTypes.SOFTWARE_PRODUCT:
64 ScreensHelper.loadScreen(dispatch, {
65 screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
66 screenType: screenTypes.SOFTWARE_PRODUCT,
67 props: { softwareProductId: itemId, version }
68 });
69 break;
70 }
71 },
talig8e9c0652017-12-20 14:30:43 +020072
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020073 openTree(dispatch, treeProps) {
74 dispatch({
75 type: modalActionTypes.GLOBAL_MODAL_SHOW,
76 data: {
77 modalComponentName: modalContentMapper.VERSION_TREE,
78 modalComponentProps: treeProps,
79 onDeclined: () =>
80 dispatch({
81 type: modalActionTypes.GLOBAL_MODAL_CLOSE
82 }),
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030083 bodyClassName: 'versions-tree-modal',
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020084 cancelButtonText: i18n('Close'),
85 title: i18n('Version Tree')
86 }
87 });
88 },
talig8e9c0652017-12-20 14:30:43 +020089
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020090 selectVersionFromModal(dispatch, { version }) {
91 dispatch({
92 type: modalActionTypes.GLOBAL_MODAL_CLOSE
93 });
94 this.selectVersion(dispatch, { version });
95 },
svishnev091edfd2018-03-19 12:15:19 +020096
svishnevfa538a12018-05-31 15:01:00 +030097 async archiveItem(dispatch, itemId) {
98 await ItemsHelper.archiveItem(itemId);
99 dispatch(onboardingActions.updateItemArchivedStatus(true));
100 dispatch(
101 notificationActions.showSuccess({
102 message: i18n('Item successfully archived')
103 })
104 );
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200105 },
svishnev091edfd2018-03-19 12:15:19 +0200106
svishnevfa538a12018-05-31 15:01:00 +0300107 async restoreItemFromArchive(dispatch, itemId) {
108 await ItemsHelper.restoreItem(itemId);
109 dispatch(onboardingActions.updateItemArchivedStatus(false));
110 dispatch(
111 notificationActions.showSuccess({
112 message: i18n('Item successfully restored')
113 })
114 );
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200115 }
talig8e9c0652017-12-20 14:30:43 +0200116};
117
118export default VersionsPageActionHelper;