blob: 61ccad0cc4ea47ce0ebf8c35d3022cb0e4819273 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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
17import i18n from 'nfvo-utils/i18n/i18n.js';
18import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020019import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
20import { actionsEnum as vcActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
talig8e9c0652017-12-20 14:30:43 +020021
22import Configuration from 'sdc-app/config/Configuration.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
talig8e9c0652017-12-20 14:30:43 +020024import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020025import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
talig8e9c0652017-12-20 14:30:43 +020026
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020027import { actionTypes } from './RevisionsConstants.js';
talig8e9c0652017-12-20 14:30:43 +020028
29function baseUrl(itemId, version) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030 const restPrefix = Configuration.get('restPrefix');
31 return `${restPrefix}/v1.0/items/${itemId}/versions/${version.id}`;
talig8e9c0652017-12-20 14:30:43 +020032}
33
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020034function fetchRevisions(itemId, version) {
35 let fetchUrl = `${baseUrl(itemId, version)}/revisions`;
36 return RestAPIUtil.fetch(fetchUrl);
talig8e9c0652017-12-20 14:30:43 +020037}
38
39function revertToRevision(itemId, version, revisionId) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020040 let putUrl = `${baseUrl(itemId, version)}/actions`;
41 let requestBody = {
42 action: vcActionsEnum.REVERT,
43 revisionRequest: {
44 revisionId: revisionId
45 }
46 };
47 return RestAPIUtil.put(putUrl, requestBody);
talig8e9c0652017-12-20 14:30:43 +020048}
49
50const RevisionaActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020051 openRevisionsView(dispatch, { itemId, version, itemType }) {
52 this.fetchRevisions(dispatch, { itemId, version }).then(() => {
53 dispatch({
54 type: modalActionTypes.GLOBAL_MODAL_SHOW,
55 data: {
56 modalComponentName: modalContentMapper.REVISIONS_LIST,
57 modalClassName: 'manage-revisions-modal',
58 title: i18n('Revert'),
59 modalComponentProps: {
60 itemId: itemId,
61 version: version,
62 itemType
63 }
64 }
65 });
66 });
67 },
talig8e9c0652017-12-20 14:30:43 +020068
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020069 closeRevisionsView(dispatch) {
70 dispatch({
71 type: modalActionTypes.GLOBAL_MODAL_CLOSE
72 });
73 },
talig8e9c0652017-12-20 14:30:43 +020074
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020075 fetchRevisions(dispatch, { itemId, version }) {
76 return fetchRevisions(itemId, version).then(response => {
77 dispatch({
78 type: actionTypes.ITEM_REVISIONS_LOADED,
79 response: response
80 });
81 });
82 },
talig8e9c0652017-12-20 14:30:43 +020083
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020084 revertToRevision(dispatch, { itemId, version, revisionId, itemType }) {
85 return revertToRevision(itemId, version, revisionId).then(() => {
86 this.closeRevisionsView(dispatch);
87 if (itemType === screenTypes.LICENSE_MODEL) {
88 ScreensHelper.loadScreen(dispatch, {
89 screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
90 screenType: screenTypes.LICENSE_MODEL,
91 props: { licenseModelId: itemId, version }
92 });
93 } else {
94 ScreensHelper.loadScreen(dispatch, {
95 screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
96 screenType: screenTypes.SOFTWARE_PRODUCT,
97 props: { softwareProductId: itemId, version }
98 });
99 }
100 });
101 }
talig8e9c0652017-12-20 14:30:43 +0200102};
103
104export default RevisionaActionHelper;